unit U_QCRKInPut_YHML;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer,
  cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB,
  ExtCtrls, BtnEdit, cxCalendar,StrUtils, cxDropDownEdit,jpeg,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP, cxPC,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGroupBox, cxCheckBox,ShellAPI,IniFiles,
  Menus, RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport;

type
  TfrmQCRKInPut_YHML = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    TBSave: TToolButton;
    Panel3: TPanel;
    Label34: TLabel;
    Label13: TLabel;
    Label1: TLabel;
    MYCode: TEdit;
    CRTime: TDateTimePicker;
    Label11: TLabel;
    LIUCeng: TEdit;
    Label12: TLabel;
    MYKZ: TEdit;
    Label14: TLabel;
    MYMF: TEdit;
    Label15: TLabel;
    Label16: TLabel;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    Panel2: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label4: TLabel;
    GangQty: TEdit;
    Label8: TLabel;
    MXHZPS: TEdit;
    Label17: TLabel;
    MXHZKGQty: TEdit;
    Label18: TLabel;
    MYType: TBtnEditA;
    BtnDel: TButton;
    v1Column4: TcxGridDBColumn;
    Panel4: TPanel;
    Label23: TLabel;
    Label24: TLabel;
    KgQty1: TEdit;
    MQty1: TEdit;
    Button6: TButton;
    Label20: TLabel;
    RCGangNO1: TEdit;
    MLID: TEdit;
    BPID: TEdit;
    DYID: TEdit;
    PTID: TEdit;
    KgQtyAvg: TEdit;
    Label25: TLabel;
    QtyAvg: TEdit;
    Label5: TLabel;
    Label21: TLabel;
    Label26: TLabel;
    Label19: TLabel;
    labMYType: TLabel;
    MXHZQty: TEdit;
    v1Column7: TcxGridDBColumn;
    RM1: TRMGridReport;
    CDS_Print: TClientDataSet;
    RMDB_Main: TRMDBDataSet;
    Label27: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Panel5: TPanel;
    Label28: TLabel;
    ComboBox2: TComboBox;
    Label29: TLabel;
    ComboBox1: TComboBox;
    BtnPrt: TButton;
    BtnQX: TButton;
    Label30: TLabel;
    Button3: TButton;
    Panel6: TPanel;
    Button2: TButton;
    Label33: TLabel;
    Note2: TEdit;
    v1MXNote: TcxGridDBColumn;
    v1MXGYLXName: TcxGridDBColumn;
    v1KuWei: TcxGridDBColumn;
    Label35: TLabel;
    MXGYLXName: TEdit;
    Button5: TButton;
    Label36: TLabel;
    MXKuWeI: TEdit;
    Button8: TButton;
    v1MYCode: TcxGridDBColumn;
    v1MYName: TcxGridDBColumn;
    v1MYMF: TcxGridDBColumn;
    v1MYKZ: TcxGridDBColumn;
    v1Liuceng: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label37: TLabel;
    RKNo: TEdit;
    cxGroupBox1: TcxGroupBox;
    Label7: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label22: TLabel;
    Label32: TLabel;
    Label6: TLabel;
    Label31: TLabel;
    QtyLRM: TEdit;
    UnitM: TEdit;
    UnitKg: TEdit;
    RCGangNo: TEdit;
    QtyLRKg: TEdit;
    BtnM: TButton;
    BtnKg: TButton;
    MXNote: TEdit;
    KuWei: TEdit;
    GYLXName: TEdit;
    Button4: TButton;
    Button7: TButton;
    Button9: TButton;
    Button10: TButton;
    Label38: TLabel;
    MXMYName: TEdit;
    Button11: TButton;
    MXMYCode: TEdit;
    MXMYMF: TEdit;
    MXMYKZ: TEdit;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    MXDYID: TEdit;
    MXMLID: TEdit;
    MXBPID: TEdit;
    MXPTID: TEdit;
    Image2: TImage;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    TPID: TEdit;
    adoqueryPicture: TADOQuery;
    Panel16: TPanel;
    MYName: TEdit;
    MLCode: TEdit;
    MLName: TEdit;
    Image11: TImage;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ShuiXiSuoLvClick(Sender: TObject);
    procedure ShuiXiSuoLvJGMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure UnitMClick(Sender: TObject);
    procedure UnitKgClick(Sender: TObject);
    procedure QtyLRMKeyPress(Sender: TObject; var Key: Char);
    procedure QtyLRKgKeyPress(Sender: TObject; var Key: Char);
    procedure BtnQXClick(Sender: TObject);
    procedure MYNameKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button6Click(Sender: TObject);
    procedure BtnDelClick(Sender: TObject);
    procedure v1Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnPrtClick(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure BtnMClick(Sender: TObject);
    procedure BtnKgClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure UnitMChange(Sender: TObject);
    procedure UnitKgChange(Sender: TObject);
    procedure KuWeiKeyPress(Sender: TObject; var Key: Char);
    procedure MXKuWeIKeyPress(Sender: TObject; var Key: Char);
    procedure Button5Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Image2DblClick(Sender: TObject);
  private
    lstPat:TStringList;
    procedure InitData();
    procedure InitMXData();
    function  SaveData():Boolean;
    procedure GetHZData();
    procedure InitColor();
    procedure ShowImage();
    procedure ReadINIFile10();
    { Private declarations }
  public
    canshu1,FileName:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FSaveFlag:string;
    { Public declarations }
  end;

var
  frmQCRKInPut_YHML: TfrmQCRKInPut_YHML;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel, U_GYSList,U_SCPerson,U_KuWeiList,U_MLMangeTJCX
  ,U_QCRKJLList,U_RSColorBig,U_MLMangeRS_GYCX,U_MLMangeRS_CX,U_KuWeiKCList,U_RTPTColor,U_MLMangeYHCX;

{$R *.dfm}

procedure TfrmQCRKInPut_YHML.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('期初明细录入1',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmQCRKInPut_YHML.ShowImage();
var
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  with adoqueryPicture do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Image_Info A');
    sql.Add(' inner join Image_File B on A.IMID=B.IMID');
    sql.Add(' and A.WBID='''+Trim(TPID.Text)+'''');
    sql.Add(' and A.Valid=''Y'' ');
    //ShowMessage(sql.Text);
    Open;
  end;
  if adoqueryPicture.IsEmpty=False then
  begin
    FileName:=Trim(adoqueryPicture.fieldbyname('ImagePath').AsString);
    jpg:=TJpegImage.Create();
    myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
    jpg.LoadFromStream(myStream);
    Image11.Picture.Assign(jpg);
    Image11.Width:=adoqueryPicture.fieldbyname('ImageWidth').Value;
    Image11.Height:=adoqueryPicture.fieldbyname('ImageHeight').Value;
    if Trim(adoqueryPicture.fieldbyname('FangXiang').AsString)='垂直' then
    begin
      Image11.Top:=1;
      Image11.Left:=Round((Panel6.Width-Image11.Width)/2);
    end else
    begin
      Image11.Left:=1;
      Image11.Top:=Round((Panel6.Height-Image11.Height)/2);
    end;
    Image11.Visible:=True;
  end;
end;

procedure TfrmQCRKInPut_YHML.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*');
    sql.Add(' from CK_MYSC_CR A  ');
    sql.Add(' where A.RKNo='''+Trim(FMainId)+'''');
    sql.Add(' and isnull(A.CRType,'''')=''期初入库'' ');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel3,2);
  SCSHDataNew(ADOQuery1,Panel2,2);
  MYCode.Hint:=Trim(ADOQuery1.fieldbyname('MYCode').AsString);
  //labMYType.Caption:=Trim(ADOQuery1.fieldbyname('MYType').AsString);
  if PState=0 then
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
  end;
  InitMXData();
  GetHZData();
  Edit1.SetFocus;
  if Trim(TPID.Text)<>'' then
  ShowImage();
  if Trim(PTID.Text)<>'' then
  begin
    InitColor();
  end;
end;

procedure TfrmQCRKInPut_YHML.InitMXData();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,Laster=isnull(A.Editer,A.Filler) ');
    sql.Add(',RCGangNo1=(case when isnull(A.RCGangNo,'''')='''' then A.GangNo else A.RCGangNo end)');
    sql.Add(' from CK_MYSC_CR_MX A inner join CK_MYSC_CR B on B.MYID=A.MYID ');
    SQL.Add('where isnull(B.RKNo,'''')='''+Trim(FMainId)+'''');
    sql.Add(' and isnull(B.CRType,'''')=''期初入库'' ');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOTemp,ClientDataSet1);
  SInitCDSData20(ADOTemp,ClientDataSet1);
end;

procedure TfrmQCRKInPut_YHML.GetHZData();
var
  FKG,FM,FPS:String;
begin
  FKG:=Tv1.DataController.Summary.FooterSummaryTexts[0];
  FM:=Tv1.DataController.Summary.FooterSummaryTexts[1];
  FPS:=Tv1.DataController.Summary.FooterSummaryTexts[2];
  MXHZPS.Text:=FPS;
  MXHZKGQty.Text:=FKG;
  MXHZQty.Text:=FM;
  if (Trim(FPS)='') or (Trim(FPS)='0')  then
  begin
    SClearData(Panel2,2);
    SClearData(Panel2,99);
  end else
  begin
    with ADOTemp do
    begin
      close;
      sql.Clear;
      sql.Add('exec P_Avg_JS :KgQty,:MQty,:PS');
      if Trim(FKG)<>'' then
      begin
        Parameters.ParamByName('KGQty').Value:=FKG;
      end else
      begin
        Parameters.ParamByName('KGQty').Value:=Null;
      end;
      if Trim(FM)<>'' then
      begin
        Parameters.ParamByName('MQty').Value:=FM;
      end else
      begin
        Parameters.ParamByName('MQty').Value:=Null;
      end;
      Parameters.ParamByName('PS').Value:=FPS;
      Open;
    end;
    KgQtyAvg.Text:=ADOTemp.fieldbyname('KgQtyAvg').Value;
    QtyAvg.Text:=ADOTemp.fieldbyname('QtyAvg').Value;
  end;
end;

procedure TfrmQCRKInPut_YHML.FormShow(Sender: TObject);
begin
  ReadCxGrid('期初明细录入1',Tv1,'贸易生产管理');
  InitData();
end;

function TfrmQCRKInPut_YHML.SaveData():Boolean;
var
  maxno,maxmxno,maxnoflag,fsj,FMXID,FRKNo:String;
  i:integer;
begin
  Result:=False;
  if RKNo.text='' then
  begin
    if GetLSNo(ADOCmd,FRKNo,'RK','CK_MYSC_CR',3,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
    RKNo.text:=Trim(FRKNo);
    FMainId:=Trim(FRKNo);
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if Trim(fieldbyname('MYID').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxno,'QC','CK_MYSC_CR',3,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(fieldbyname('MYID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from CK_MYSC_CR where MYId='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if IsEmpty then
          begin
            Append;
            FieldByName('Filler').Value:=Trim(DName);
            FieldByName('FillerCode').Value:=Trim(DCode);
          end
          else begin
            Edit;
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditerCode').Value:=Trim(DCode);
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
          end;
          FieldByName('MYId').Value:=Trim(maxno);
          FieldByName('CRType').Value:='期初入库';
          FieldByName('MYType').Value:='染色面料';
          FieldByName('CRFlag').Value:='入库';
          FieldByName('CRQtyFlag').Value:=1;
          FieldByName('RKNo').Value:=Trim(RKNo.Text);
          FieldByName('CRTime').Value:=SGetServerDateTime(ADOTemp);
          FieldByName('MYCode').Value:=Trim(ClientDataSet1.fieldbyname('MYCode').AsString);
          FieldByName('MYName').Value:=Trim(ClientDataSet1.fieldbyname('MYName').AsString);
          FieldByName('MLCode').Value:=Trim(ClientDataSet1.fieldbyname('MLCode').AsString);
          FieldByName('MLName').Value:=Trim(ClientDataSet1.fieldbyname('MLName').AsString);
          FieldByName('GYLXName').Value:=Trim(ClientDataSet1.fieldbyname('MXGYLXName').AsString);
          FieldByName('MYColor').Value:=Trim(ClientDataSet1.fieldbyname('MYColor').AsString);
          FieldByName('MYColorNo').Value:=Trim(ClientDataSet1.fieldbyname('MYColorNo').AsString);
          FieldByName('Note').Value:=Trim(ClientDataSet1.fieldbyname('KuWei').AsString);
          FieldByName('MYMF').Value:=Trim(ClientDataSet1.fieldbyname('MYMF').AsString);
          FieldByName('MYKZ').Value:=Trim(ClientDataSet1.fieldbyname('MYKZ').AsString);
          FieldByName('DYID').Value:=Trim(ClientDataSet1.fieldbyname('DYID').AsString);
          fieldbyname('MLID').AsString:=Trim(ClientDataSet1.fieldbyname('MLID').AsString);
          fieldbyname('BPID').AsString:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
          fieldbyname('PTID').AsString:=Trim(ClientDataSet1.fieldbyname('PTID').AsString);
          Post;
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('UPdate CK_MYSC_CR Set KHDayCS=isnull((select isnull(max(KHDayCS),0) from CK_MYSC_CR A ');
          sql.Add(' where A.CRTime=CK_MYSC_CR.CRTime and isnull(A.KHName,'''')=isnull(CK_MYSC_CR.KHName,'''') ');
          sql.Add(' and isnull(A.CRType,'''')=''期初入库''),'''')');
          SQL.Add(' where RKNo='''+Trim(RKNo.Text)+''' and isnull(KHName,'''')<>'''' and isnull(CRType,'''')=''期初入库''');
          ExecSQL;
        end;
        {with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete from CK_MYSC_CR_MX where MYID='''+Trim(maxno)+'''');
          ExecSQL;
        end;}
        with ClientDataSet1 do
        begin
          edit;
          FieldByName('MYID').AsString:=Trim(maxno);
        end;
        Next;
      end;
    end;
    ClientDataSet1.EnableControls;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      i:=1;
      while not Eof do
      begin
        if FieldByName('MXID').AsString='' then
        begin
          if GetLSNo(ADOCmd,FMXID,'QM','CK_MYSC_CR_MX',5,1)=False then
          begin
            ClientDataSet1.EnableControls;
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取期初入库数据最大号失败','提示',0);
            Exit;
          end;
        end
        else
        begin
          FMXID:=Trim(FieldByName('MXID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(FMXID)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if IsEmpty then
            Append
          else
            edit;
          FieldByName('MYID').Value:=Trim(ClientDataSet1.fieldbyname('MYID').AsString);
          FieldByName('MXID').Value:=Trim(FMXID);
          FieldByName('JH').Value:=i;
          FieldByName('RCGangNo').Value:=ClientDataSet1.fieldbyname('RCGangNo1').Value;
          FieldByName('KuWei').Value:=ClientDataSet1.fieldbyname('KuWei').Value;
          FieldByName('MXGYLXName').Value:=ClientDataSet1.fieldbyname('MXGYLXName').Value;
          FieldByName('MXNote').Value:=ClientDataSet1.fieldbyname('MXNote').Value;
          FieldByName('KgQty').Value:=ClientDataSet1.fieldbyname('KgQty').Value;
          FieldByName('MQty').Value:=ClientDataSet1.fieldbyname('MQty').Value;
          FieldByName('Filler').Value:=Trim(DName);
          FieldByName('FillerCode').Value:=Trim(DCode);
          Post;
        end;
        i:=i+1;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' exec P_Update_QCRK_GangNo :MYID');
          Parameters.ParamByName('MYID').Value:=Trim(ClientDataSet1.fieldbyname('MYID').AsString);
          ExecSQL;
        end;
        Edit;
        FieldByName('MXID').Value:=Trim(FMXID);
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' exec P_Update_QCRK_Qty :MYID');
          Parameters.ParamByName('MYID').Value:=Trim(ClientDataSet1.fieldbyname('MYID').AsString);
          ExecSQL;
        end;
        //Post;
        Next;
      end;
    end;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.CommitTrans;
    InitData();
    Result:=True;
  except
    Result:=False;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmQCRKInPut_YHML.TBSaveClick(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  if Trim(MYName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  {if Trim(PTID.Text)='' then
  begin
    application.MessageBox('请选择颜色','提示');
    exit;
  end;}
  if SaveData() then
  begin
    GetHZData();
    if Trim(FSaveFlag)<>'99' then
    begin
      Application.MessageBox('保存成功！','提示',0);
      TBSave.Caption:='已保存';
      if ClientDataSet1.IsEmpty then
      ModalResult:=1;
    end;
  end;
end;

procedure TfrmQCRKInPut_YHML.ShuiXiSuoLvClick(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text)='' then
  begin
    TEdit(Sender).Text:='√';
  end else
  begin
    TEdit(Sender).Text:='';
  end;
end;

procedure TfrmQCRKInPut_YHML.ShuiXiSuoLvJGMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(FRead)='' then
  begin
    TEdit(Sender).ReadOnly:=True;
  end else
  begin
    TEdit(Sender).ReadOnly:=False;
  end;
end;

procedure TfrmQCRKInPut_YHML.UnitMClick(Sender: TObject);
begin
  if Trim(UnitM.Text)='' then
  begin
    UnitM.Text:='√';
    QtyLRM.Visible:=True;
    BtnM.Visible:=True;
    if Trim(UnitKg.Text)<>'' then
    begin
      BtnM.Visible:=False;
    end;
  end else
  begin
    UnitM.Text:='';
    QtyLRM.Visible:=False;
    BtnM.Visible:=False;
  end;
end;

procedure TfrmQCRKInPut_YHML.UnitKgClick(Sender: TObject);
begin
  if Trim(UnitKg.Text)='' then
  begin
    UnitKg.Text:='√';
    QtyLRKg.Visible:=True;
    BtnKg.Visible:=True;
    if Trim(UnitM.Text)<>'' then
    begin
      BtnM.Visible:=False;
    end;
  end else
  begin
    UnitKg.Text:='';
    QtyLRKg.Visible:=False;
    BtnKg.Visible:=False;
  end;
end;

procedure TfrmQCRKInPut_YHML.QtyLRMKeyPress(Sender: TObject; var Key: Char);
var
  FReal:Double;
begin
  if Key=#13 then
  begin
    if Trim(QtyLRM.Text)='' then Exit;
    if KuWei.Text='' then
    begin
      Application.MessageBox('库位不能为空','提示');
      exit;
    end;
    if TryStrToFloat(QtyLRM.Text,FReal)=False then
    begin
      Application.MessageBox('非法数字!','提示',0);
      Exit;
    end;
    if Trim(UnitKg.Text)<>'' then
    begin
      QtyLRKg.SetFocus;
      Exit;
    end;
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
      FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
      FieldByName('MQty').Value:=Trim(QtyLRM.Text);
      FieldByName('MXNote').Value:=Trim(MXNote.Text);
      FieldByName('MXGYLXName').Value:=Trim(GYLXName.Text);
      FieldByName('KuWei').Value:=Trim(KuWei.Text);
      FieldByName('MYCode').Value:=Trim(MYCode.Text);
      FieldByName('MYName').Value:=Trim(MYName.Text);
      FieldByName('MYMF').Value:=Trim(MYMF.Text);
      FieldByName('MYKZ').Value:=Trim(MYKZ.Text);
      FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
      FieldByName('DYID').Value:=Trim(DYID.Text);
      fieldbyname('MLID').AsString:=Trim(Self.MLID.Text);
      fieldbyname('BPID').AsString:=Trim(Self.BPID.Text);
      fieldbyname('PTID').AsString:=Trim(Self.PTID.Text);
      Post;
    end;
    QtyLRM.Text:='';
    GetHZData();
    TBSave.Caption:='未保存';
  end;
end;

procedure TfrmQCRKInPut_YHML.QtyLRKgKeyPress(Sender: TObject; var Key: Char);
var
  FReal:Double;
begin
  if Key=#13 then
  begin
    if Trim(QtyLRKg.Text)='' then Exit;
    if KuWei.Text='' then
    begin
      Application.MessageBox('库位不能为空','提示');
      exit;
    end;
    if Trim(UnitM.Text)<>'' then
    begin
      if Trim(QtyLRM.Text)='' then
      begin
        Application.MessageBox('米数不能为空!','提示',0);
        Exit;
      end;
    end;
    if TryStrToFloat(QtyLRKg.Text,FReal)=False then
    begin
      Application.MessageBox('非法数字!','提示',0);
      Exit;
    end;
    with ClientDataSet1 do
    begin
      Append;
      FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
      FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
      FieldByName('MXNote').Value:=Trim(MXNote.Text);
      FieldByName('KgQty').Value:=Trim(QtyLRKg.Text);
      FieldByName('MXGYLXName').Value:=Trim(GYLXName.Text);
      FieldByName('KuWei').Value:=Trim(KuWei.Text);
      if Trim(UnitM.Text)<>'' then
      begin
        FieldByName('MQty').Value:=Trim(QtyLRM.Text);
      end;
      FieldByName('MYCode').Value:=Trim(MYCode.Text);
      FieldByName('MYName').Value:=Trim(MYName.Text);
      FieldByName('MYMF').Value:=Trim(MYMF.Text);
      FieldByName('MYKZ').Value:=Trim(MYKZ.Text);
      FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
      FieldByName('DYID').Value:=Trim(DYID.Text);
      fieldbyname('MLID').AsString:=Trim(Self.MLID.Text);
      fieldbyname('BPID').AsString:=Trim(Self.BPID.Text);
      fieldbyname('PTID').AsString:=Trim(Self.PTID.Text);
      Post;
    end;
    QtyLRM.Text:='';
    QtyLRKg.Text:='';
    if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
    GetHZData();
    TBSave.Caption:='未保存';
  end;
end;

procedure TfrmQCRKInPut_YHML.BtnQXClick(Sender: TObject);
begin
  Panel5.Visible:=False;
end;

procedure TfrmQCRKInPut_YHML.MYNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(MYType.Text)='' then
    begin
      Application.MessageBox('没有选择产品类型!','提示',0);
      Exit;
    end;
  end;
end;

procedure TfrmQCRKInPut_YHML.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if ClientDataSet1.IsEmpty then Exit;
  if BtnDel.Visible=False then Exit;
  Panel4.Visible:=True;
  RCGangNO1.Text:=ClientDataSet1.fieldbyname('RCGangNO1').AsString;
  MXGYLXName.Text:=ClientDataSet1.fieldbyname('MXGYLXName').AsString;
  MXKuWeI.Text:=ClientDataSet1.fieldbyname('KuWeI').AsString;
  Self.MXMYCode.Text:=Trim(ClientDataSet1.fieldbyname('MYCode').AsString);
  Self.MXMYName.Text:=Trim(ClientDataSet1.fieldbyname('MYName').AsString);
  Self.MXMYMF.Text:=Trim(ClientDataSet1.fieldbyname('MYMF').AsString);
  Self.MXMYKZ.Text:=Trim(ClientDataSet1.fieldbyname('MYKZ').AsString);
  Self.MXDYID.Text:=Trim(ClientDataSet1.fieldbyname('DYID').AsString);
  Self.MXMLID.Text:=Trim(ClientDataSet1.fieldbyname('MLID').AsString);
  Self.MXBPID.Text:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
  Self.MXPTID.Text:=Trim(ClientDataSet1.fieldbyname('PTID').AsString);
  if Trim(ClientDataSet1.fieldbyname('KgQty').AsString)<>'' then
    KgQty1.Text:=ClientDataSet1.fieldbyname('KgQty').Value
  else
     KgQty1.Text:='';
  if Trim(ClientDataSet1.fieldbyname('MQty').AsString)<>'' then
    MQty1.Text:=ClientDataSet1.fieldbyname('MQty').Value
  else
     MQty1.Text:='';
end;

procedure TfrmQCRKInPut_YHML.Button6Click(Sender: TObject);
var
  FReal:Double;
begin
  if Trim(KgQty1.Text)<>'' then
  begin
    if TryStrToFloat(KgQty1.Text,FReal)=False then
    begin
      Application.MessageBox('公斤数非法数字!','提示',0);
      Exit;
    end;
  end;
  if Trim(MQty1.Text)<>'' then
  begin
    if TryStrToFloat(MQty1.Text,FReal)=False then
    begin
      Application.MessageBox('米数非法数字!','提示',0);
      Exit;
    end;
  end;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('RCGangNo').Value:=Trim(RCGangNo1.Text);
    FieldByName('RCGangNo1').Value:=Trim(RCGangNo1.Text);
    FieldByName('MXGYLXName').Value:=Trim(MXGYLXName.Text);
    FieldByName('KuWeI').Value:=Trim(MXKuWeI.Text);
    if Trim(MQty1.Text)<>'' then
      FieldByName('MQty').Value:=Trim(MQty1.Text)
    else
      FieldByName('MQty').Value:=Null;
    if Trim(KgQty1.Text)<>'' then
      FieldByName('KgQty').Value:=Trim(KgQty1.Text)
    else
      FieldByName('KgQty').Value:=Null;
    FieldByName('Laster').Value:=Trim(DName);

    fieldbyname('MXGYLXName').AsString:=MXGYLXName.Text;
    fieldbyname('KuWeI').AsString:=MXKuWeI.Text;
    fieldbyname('MYCode').AsString:=Trim(Self.MXMYCode.Text);
    fieldbyname('MYName').AsString:=Trim(Self.MXMYName.Text);
    fieldbyname('MYMF').AsString:=Trim(Self.MXMYMF.Text);
    fieldbyname('MYKZ').AsString:=Trim(Self.MXMYKZ.Text);
    fieldbyname('DYID').AsString:=Trim(Self.MXDYID.Text);
    fieldbyname('MLID').AsString:=Trim(Self.MXMLID.Text);
    fieldbyname('BPID').AsString:=Trim(Self.MXBPID.Text);
    fieldbyname('PTID').AsString:=Trim(Self.MXPTID.Text);
    Post;
  end;
  Panel4.Visible:=False;
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_YHML.BtnDelClick(Sender: TObject);
var
  FFMXID:string;
begin
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if application.MessageBox('确定要删除吗','提示',1)=2 then exit;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      first;
      while ClientDataSet1.Locate('SSel',True,[]) do
      begin
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
          Open;
        end;
        FFMXID:=Trim(ADOTemp.fieldbyname('MXID').AsString);
        if Trim(FFMXID)<>'' then
        begin
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' insert into CK_MYSC_CR_MX_Log  ');
            sql.Add(' select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            sql.Add(' UPdate CK_MYSC_CR_MX_Log Set DelTime=getdate(),DelerCode='''+Trim(DCode)+''',Deler='''+Trim(DName)+'''');
            sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            sql.Add(' Delete CK_MYSC_CR_MX  where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            sql.Add(' Delete CK_MYSC_CR  where MYID='''+Trim(ClientDataSet1.fieldbyname('MYID').AsString)+'''');
            ExecSQL;
          end;
        end;
        ClientDataSet1.Delete;
      end;
    end;
    ClientDataSet1.EnableControls;
    if ClientDataSet1.IsEmpty then
    begin
      ModalResult:=1;
    end;
    GetHZData();
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmQCRKInPut_YHML.v1Column7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmQCRKJLList:=TfrmQCRKJLList.Create(Application);
    with frmQCRKJLList do
    begin
      FMXID:=Trim(Self.ClientDataSet1.fieldbyname('MXID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmQCRKJLList.Free;
  end;
end;

procedure TfrmQCRKInPut_YHML.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ModalResult:=1;
end;

procedure TfrmQCRKInPut_YHML.BtnPrtClick(Sender: TObject);
var
   fPrintFile,Txt,fImagePath:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if ClientDataSet1.Locate('GangNo',null,[])=true then
  begin
    Application.MessageBox('没有保存数据, 请先点击保存，再打印标签。','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('SSel',True,[])=false then
  begin
    Application.MessageBox('没有选择数据, 请先选择数据，再打印标签。','提示',0);
    Exit;
  end;
  if ComboBox2.Text='' then
  begin
    Application.MessageBox('请选择张数!','提示',0);
    Exit;
  end;
  if ComboBox1.Text='' then
  begin
    Application.MessageBox('请选择尺寸!','提示',0);
    Exit;
  end;
  if ComboBox1.Text='9*7' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\期初入库染色面料标签97.rmf';
  end else
  if ComboBox1.Text='8*5' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\期初入库染色面料标签85.rmf';
  end;
  if FileExists(fPrintFile)=False then
  begin
    if ComboBox1.Text='9*7' then
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\期初入库染色面料标签97.rmf'),'提示',0);
    if ComboBox1.Text='8*5' then
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\期初入库染色面料标签85.rmf'),'提示',0);
    exit;
  end;
  ClientDataSet1.DisableControls;
  with ClientDataSet1 do
  begin
    First;
    while Locate('SSel',True,[]) do
    begin
      with ADOTemp do
      begin
        Close;
        SQL.Clear;
        sql.Add(' Exec P_PRT_QCRK_RSML :MXID');
        Parameters.ParamByName('MXID').Value:=Trim(ClientDataSet1.fieldbyname('MXID').AsString);
        Open;
      end;
      SCreateCDS20(ADOTemp,CDS_Print);
      SInitCDSData20(ADOTemp,CDS_Print);
      try
        Moudle:=LoadLibrary('MakeQRBarcode.dll');
        @Makebar:=GetProcAddress(Moudle,'Make');
        @Mixtext:=GetProcAddress(Moudle,'MixText');
        Txt:=Trim(ClientDataSet1.fieldbyname('MXID').AsString);
        fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
        if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
          CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
        if FileExists(fImagePath) then DeleteFile(fImagePath);
        Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
      except
        application.MessageBox('二维码生成失败！','提示信息',MB_ICONERROR);
        exit;
      end;
      Edit;
      FieldByName('SSel').Value:=False;
      RMVariables['QRBARCODE']:=fImagePath;
      RM1.LoadFromFile(fPrintFile);
      //RM1.ShowReport;
      for i:=1 to StrToInt(ComboBox2.Text) do
      begin
        RM1.PrintReport;
      end;
    end;
  end;
  ClientDataSet1.EnableControls;
  ComboBox2.ItemIndex:=0;
  ComboBox1.ItemIndex:=-1;
  Panel5.Visible:=False;
end;

procedure TfrmQCRKInPut_YHML.InitColor();
var
  fsj:string;
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from RT_PTColor where PTID='''+Trim(PTID.Text)+'''');
    Open;
  end;
  fsj:=Trim(ADOTemp.fieldbyname('ColDaiMa').AsString);
  if fsj<>'' then
  Panel6.Color:=StrToInt('$'+Trim(fsj));
end;

procedure TfrmQCRKInPut_YHML.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  FDate:TDateTime;
begin
  if Key=#13 then
  begin
    if ClientDataSet1.IsEmpty=False then
    begin
      if ClientDataSet1.Locate('GangNo',Null,[])=True then
      begin
        FSaveFlag:='99';
        TBSave.Click;
        FSaveFlag:='';
      end;
    end;
    with ADOTemp do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select A.*,B.*,B.TJTPID TJ,MLDLNo SKID ');
      sql.Add(' from ML_Manage A ');
      sql.Add(' left join Image_Info B on B.TJML=A.TJML ');
      sql.Add(' left join BP_DY C on C.TFID=B.IMID and C.MLID=A.MLID');
      sql.Add(' left join BP_DY D on D.TFID=A.PTID and D.MLID=A.MLID');
      sql.Add(' where isnull(A.MLType,'''')=''印花面料'' and isnull(C.DYID,'''')='''+trim(edit1.Text)+'''');
      //ShowMessage(sql.Text);
      Open;
    end;
    MYCode.Text:=Trim(ADOTemp.fieldbyname('TJML').AsString);
    MYCode.Hint:=Trim(ADOTemp.fieldbyname('TJML').AsString);
    MYType.Text:=Trim(ADOTemp.fieldbyname('MLType').AsString);
    MYName.Text:=Trim(ADOTemp.fieldbyname('MLName').AsString);
    MLCode.Text:=Trim(ADOTemp.fieldbyname('MLXXNO').AsString);
    MLName.Text:=Trim(ADOTemp.fieldbyname('MLXXName').AsString);
    MYMF.Text:=Trim(ADOTemp.fieldbyname('MLMF').AsString);
    MYKZ.Text:=Trim(ADOTemp.fieldbyname('MLKZ').AsString);
    LIUCeng.Text:=Trim(ADOTemp.fieldbyname('HXType').AsString);
    DYID.Text:=Trim(edit1.Text);
    MLID.Text:=Trim(ADOTemp.fieldbyname('MLID').AsString);
    BPID.Text:=Trim(ADOTemp.fieldbyname('MBPID').AsString);
    //PTID.Text:=Trim(ADOTemp.fieldbyname('PTID').AsString);
    TPID.Text:=Trim(ADOTemp.fieldbyname('TJ').AsString);
    GYLXName.Text:=Trim(ADOTemp.fieldbyname('TJGYName').AsString);
    labMYType.Caption:=Trim(ADOTemp.fieldbyname('MLType').AsString);
    if Trim(MYType.Text)='印花面料' then
    begin
      MYType.TxtCode:='YH';
    end;
    Edit1.Text:='';
    FDate:=SGetServerDate(ADOTemp);
    GetHZData();
    if Trim(UnitM.Text)<>'' then
    begin
      QtyLRM.SetFocus;
      BtnM.Visible:=True;
      if Trim(UnitKg.Text)<>'' then
      begin
        BtnM.Visible:=False;
        BtnKg.Visible:=True;
      end;
    end else
    begin
      if Trim(UnitKg.Text)<>'' then
      begin
        QtyLRKg.SetFocus;
        BtnKg.Visible:=True;
      end else
      begin
        UnitM.Text:='√';
        QtyLRM.Visible:=True;
        QtyLRM.SetFocus;
        BtnM.Visible:=True;
      end;
    end;
    if PTID.Text<>'' then
    InitColor();
    if TPID.Text<>'' then
    ShowImage();
  end;
end;

procedure TfrmQCRKInPut_YHML.Button1Click(Sender: TObject);
var
  FFMXID:string;
begin
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      first;
      while ClientDataSet1.Locate('SSel',True,[]) do
      begin
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
          Open;
        end;
        FFMXID:=Trim(ADOTemp.fieldbyname('MXID').AsString);
        if Trim(FFMXID)<>'' then
        begin
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate CK_MYSC_CR_MX Set RCGangNo='''+Trim(RCGangNO1.Text)+'''');
            sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Edit;
        FieldByName('SSel').Value:=false;
        FieldByName('RCGangNo').Value:=Trim(RCGangNO1.Text);
        FieldByName('RCGangNo1').Value:=Trim(RCGangNO1.Text);
      end;
    end;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.CommitTrans;
    FSaveFlag:='99';
    TBSave.Click;
    FSaveFlag:='';
    GetHZData();
    application.MessageBox('保存成功','提示');
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_YHML.BtnMClick(Sender: TObject);
var
  FReal:Double;
begin
  if Trim(QtyLRM.Text)='' then Exit;
  if KuWei.Text='' then
    begin
      Application.MessageBox('库位不能为空','提示');
      exit;
    end;
  if TryStrToFloat(QtyLRM.Text,FReal)=False then
  begin
    Application.MessageBox('非法数字!','提示',0);
    Exit;
  end;
  if Trim(UnitKg.Text)<>'' then
  begin
    QtyLRKg.SetFocus;
    Exit;
  end;
  with ClientDataSet1 do
  begin
    Append;
    FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
    FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
    FieldByName('MQty').Value:=Trim(QtyLRM.Text);
    FieldByName('MXNote').Value:=Trim(MXNote.Text);
    FieldByName('MXGYLXName').Value:=Trim(GYLXName.Text);
    FieldByName('KuWei').Value:=Trim(KuWei.Text);
    FieldByName('MYCode').Value:=Trim(MYCode.Text);
    FieldByName('MYName').Value:=Trim(MYName.Text);
    FieldByName('MYMF').Value:=Trim(MYMF.Text);
    FieldByName('MYKZ').Value:=Trim(MYKZ.Text);
    FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
    FieldByName('DYID').Value:=Trim(DYID.Text);
    fieldbyname('MLID').AsString:=Trim(Self.MLID.Text);
    fieldbyname('BPID').AsString:=Trim(Self.BPID.Text);
    fieldbyname('PTID').AsString:=Trim(Self.PTID.Text);
    Post;
  end;
  QtyLRM.Text:='';
  GetHZData();
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_YHML.BtnKgClick(Sender: TObject);
var
  FReal:Double;
begin
  if Trim(QtyLRKg.Text)='' then Exit;
  if KuWei.Text='' then
  begin
    Application.MessageBox('库位不能为空','提示');
    exit;
  end;
  if Trim(UnitM.Text)<>'' then
  begin
    if Trim(QtyLRM.Text)='' then
    begin
      Application.MessageBox('米数不能为空!','提示',0);
      Exit;
    end;
  end;
  if TryStrToFloat(QtyLRKg.Text,FReal)=False then
  begin
    Application.MessageBox('非法数字!','提示',0);
    Exit;
  end;
  with ClientDataSet1 do
  begin
    Append;
    FieldByName('RCGangNo').Value:=Trim(RCGangNo.Text);
    FieldByName('RCGangNo1').Value:=Trim(RCGangNo.Text);
    FieldByName('MXNote').Value:=Trim(MXNote.Text);
    FieldByName('KgQty').Value:=Trim(QtyLRKg.Text);
    FieldByName('MXGYLXName').Value:=Trim(GYLXName.Text);
    FieldByName('KuWei').Value:=Trim(KuWei.Text);
    if Trim(UnitM.Text)<>'' then
    begin
      FieldByName('MQty').Value:=Trim(QtyLRM.Text);
    end;
    FieldByName('MYCode').Value:=Trim(MYCode.Text);
    FieldByName('MYName').Value:=Trim(MYName.Text);
    FieldByName('MYMF').Value:=Trim(MYMF.Text);
    FieldByName('MYKZ').Value:=Trim(MYKZ.Text);
    FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
    FieldByName('DYID').Value:=Trim(DYID.Text);
    fieldbyname('MLID').AsString:=Trim(Self.MLID.Text);
    fieldbyname('BPID').AsString:=Trim(Self.BPID.Text);
    fieldbyname('PTID').AsString:=Trim(Self.PTID.Text);
    Post;
  end;
  QtyLRM.Text:='';
  QtyLRKg.Text:='';
  if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
  GetHZData();
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_YHML.Button3Click(Sender: TObject);
begin
  Panel5.Visible:=True;
end;

procedure TfrmQCRKInPut_YHML.Button2Click(Sender: TObject);
var FDate:TDateTime;
    SXMaxno:string;
begin
  frmMLMangeYHCX:=TfrmMLMangeYHCX.create(self);
  with frmMLMangeYHCX do
  begin
    if showmodal=1 then
    begin
      if Self.ClientDataSet1.IsEmpty=False then
      begin
        if Self.ClientDataSet1.Locate('GangNo',Null,[])=True then
        begin
          FSaveFlag:='99';
          TBSave.Click;
          FSaveFlag:='';
        end;
      end;
      if GetLSNo(ADOCmd,SXMaxno,'SCTJ','CK_MYSC_CR',3,1)=False then
      begin
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
      Self.MYCode.Text:=Trim(CDS_Main.fieldbyname('TJML').AsString);
      Self.MYCode.Hint:=Trim(CDS_Main.fieldbyname('TJML').AsString);
      Self.MLCode.Text:=Trim(CDS_Main.fieldbyname('MLXXNO').AsString);
      Self.MLName.Text:=Trim(CDS_Main.fieldbyname('MLXXName').AsString);
      Self.LIUCeng.Text:=Trim(CDS_Main.fieldbyname('HXType').AsString);
      Self.MYType.Text:='印花面料';
      Self.MYName.Text:=Trim(CDS_Main.fieldbyname('MLName').AsString);
      Self.MYMF.Text:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
      Self.MYKZ.Text:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
      Self.DYID.Text:=Trim(SXMaxno);
      Self.MLID.Text:=Trim(CDS_Main.fieldbyname('MLID').AsString);
      Self.BPID.Text:=Trim(CDS_Main.fieldbyname('MBPID').AsString);
      //Self.PTID.Text:=Trim(CDS_Main.fieldbyname('PTID').AsString);
      Self.GYLXName.Text:=Trim(CDS_Main.fieldbyname('TJGYName').AsString);
      Self.TPID.Text:=Trim(FTJTPID);
      if Trim(MYType.Text)='印花面料' then
      begin
        MYType.TxtCode:='YH';
      end;
      Edit1.Text:='';
      FDate:=SGetServerDate(ADOTemp);
      GetHZData();
      if Trim(UnitM.Text)<>'' then
      begin
        QtyLRM.SetFocus;
        BtnM.Visible:=True;
        if Trim(UnitKg.Text)<>'' then
        begin
          BtnM.Visible:=False;
          BtnKg.Visible:=True;
        end;
      end else
      begin
        if Trim(UnitKg.Text)<>'' then
        begin
          QtyLRKg.SetFocus;
          BtnKg.Visible:=True;
        end else
        begin
          UnitM.Text:='√';
          QtyLRM.Visible:=True;
          QtyLRM.SetFocus;
          BtnM.Visible:=True;
        end;
      end;
      if TPID.Text<>'' then
      ShowImage();
      if PTID.Text<>'' then
      InitColor();
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_YHML.Button4Click(Sender: TObject);
var FDate:TDateTime;
    SXMaxno:string;
begin
  frmMLMangeRS_GYCX:=TfrmMLMangeRS_GYCX.create(self);
  with frmMLMangeRS_GYCX do
  begin
    MLNo.Text:=Trim(MYCode.Text);
    if showmodal=1 then
    begin
      Self.MLID.Text:=Trim(CDS_Main.fieldbyname('MLID').AsString);
      Self.BPID.Text:=Trim(CDS_Main.fieldbyname('MBPID').AsString);
      Self.GYLXName.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_YHML.UnitMChange(Sender: TObject);
begin
  if UnitM.Text='√' then
  begin
    v1Column3.Visible:=true;
    Label18.Visible:=true;
    MXHZQty.Visible:=true;
    Label24.Visible:=true;
    MQty1.Visible:=true;
  end
  else
  begin
    v1Column3.Visible:=false;
    Label18.Visible:=false;
    MXHZQty.Visible:=false;
    Label24.Visible:=false;
    MQty1.Visible:=false;
  end;
end;

procedure TfrmQCRKInPut_YHML.UnitKgChange(Sender: TObject);
begin
  if UnitKG.Text='√' then
  begin
    v1Column17.Visible:=true;
    label17.Visible:=true;
    MXHZKGQty.Visible:=true;
    Label23.Visible:=true;
    KgQty1.Visible:=true;
  end
  else
  begin
    v1Column17.Visible:=false;
    label17.Visible:=false;
    MXHZKGQty.Visible:=false;
    Label23.Visible:=false;
    KgQty1.Visible:=false;
  end;
end;

procedure TfrmQCRKInPut_YHML.KuWeiKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQuery1 do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from KuWei A where KWType=''GG'' and Valid=''Y'' ');
      sql.Add(' and KWID='''+trim(KuWei.Text)+'''');
      Open;
    end;
    KuWei.Text:=Trim(ADOQuery1.fieldbyname('KWName').AsString);
  end;
end;

procedure TfrmQCRKInPut_YHML.MXKuWeIKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQuery1 do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from KuWei A where KWType=''GG'' and Valid=''Y'' ');
      sql.Add(' and KWID='''+trim(MXKuWeI.Text)+'''');
      Open;
    end;
    MXKuWeI.Text:=Trim(ADOQuery1.fieldbyname('KWName').AsString);
  end;
end;

procedure TfrmQCRKInPut_YHML.Button5Click(Sender: TObject);
var FDate:TDateTime;
    SXMaxno:string;
begin
  frmMLMangeRS_GYCX:=TfrmMLMangeRS_GYCX.create(self);
  with frmMLMangeRS_GYCX do
  begin
    MLNo.Text:=Trim(MYCode.Text);
    if showmodal=1 then
    begin
      Self.MXGYLXName.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_YHML.Button7Click(Sender: TObject);
begin
  frmKuWeiList:=TfrmKuWeiList.Create(Self);
  with frmKuWeiList do
  begin
    TBAdd.Visible:=false;
    TBDel.Visible:=false;
    ToolButton4.Visible:=false;
    Panel2.Visible:=false;
    if ShowModal=1 then
    begin
      KuWei.Text:=Trim(Order_Main.fieldbyname('KWName').AsString);
    end;
    Free;
  end;
end;

procedure TfrmQCRKInPut_YHML.Button8Click(Sender: TObject);
begin
  frmKuWeiList:=TfrmKuWeiList.Create(Self);
  with frmKuWeiList do
  begin
    TBAdd.Visible:=false;
    TBDel.Visible:=false;
    ToolButton4.Visible:=false;
    Panel2.Visible:=false;
    if ShowModal=1 then
    begin
      MXKuWeI.Text:=Trim(Order_Main.fieldbyname('KWName').AsString);
    end;
    Free;
  end;
end;

procedure TfrmQCRKInPut_YHML.N1Click(Sender: TObject);
begin
  SelOKNo(ClientDataSet1,true);
end;

procedure TfrmQCRKInPut_YHML.N2Click(Sender: TObject);
begin
  SelOKNo(ClientDataSet1,false);
end;

procedure TfrmQCRKInPut_YHML.Button11Click(Sender: TObject);
var FDate:TDateTime;
    SXMaxno:string;
begin
  frmMLMangeRS_CX:=TfrmMLMangeRS_CX.create(self);
  with frmMLMangeRS_CX do
  begin
    if showmodal=1 then
    begin
      Self.MXMYCode.Text:=Trim(CDS_Main.fieldbyname('MLNo').AsString);
      Self.MXMYName.Text:=Trim(CDS_Main.fieldbyname('MLName').AsString);
      Self.MXMYMF.Text:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
      Self.MXMYKZ.Text:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
      Self.MXDYID.Text:=Trim(SXMaxno);
      Self.MXMLID.Text:=Trim(CDS_Main.fieldbyname('MLID').AsString);
      Self.MXBPID.Text:=Trim(CDS_Main.fieldbyname('MBPID').AsString);
      Self.MXPTID.Text:=Trim(CDS_Main.fieldbyname('PTID').AsString);
      Self.MXGYLXName.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);

      Self.MYCode.Text:=Trim(CDS_Main.fieldbyname('MLNo').AsString);
      Self.MYCode.Hint:=Trim(CDS_Main.fieldbyname('MLNo').AsString);
      Self.MYType.Text:='染色面料';
      Self.MYName.Text:=Trim(CDS_Main.fieldbyname('MLName').AsString);
      Self.MYMF.Text:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
      Self.MYKZ.Text:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
      Self.LIUCeng.Text:=Trim(CDS_Main.fieldbyname('LIUCeng').AsString);
      Self.DYID.Text:=Trim(SXMaxno);
      Self.MLID.Text:=Trim(CDS_Main.fieldbyname('MLID').AsString);
      Self.BPID.Text:=Trim(CDS_Main.fieldbyname('MBPID').AsString);
      Self.PTID.Text:=Trim(CDS_Main.fieldbyname('PTID').AsString);
      Self.GYLXName.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      InitColor();
      GetHZData();
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_YHML.Button9Click(Sender: TObject);
var
  FFMXID:string;
begin
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      first;
      while ClientDataSet1.Locate('SSel',True,[]) do
      begin
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from CK_MYSC_CR where MYID='''+Trim(ClientDataSet1.fieldbyname('MYID').AsString)+'''');
          Open;
        end;
        FFMXID:=Trim(ADOTemp.fieldbyname('MYID').AsString);
        if Trim(FFMXID)<>'' then
        begin
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate CK_MYSC_CR Set MYName='''+Trim(MXMYName.Text)+'''');
            sql.Add(' where MYID='''+Trim(ClientDataSet1.fieldbyname('MYID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Edit;
        FieldByName('SSel').Value:=false;
        FieldByName('MYName').Value:=Trim(MXMYName.Text);
      end;
    end;
    ClientDataSet1.EnableControls;
    application.MessageBox('保存成功','提示');
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_YHML.Button10Click(Sender: TObject);
var
  FFMXID:string;
begin
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      first;
      while ClientDataSet1.Locate('SSel',True,[]) do
      begin
        with ADOTemp do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from CK_MYSC_CR_MX where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
          Open;
        end;
        FFMXID:=Trim(ADOTemp.fieldbyname('MXID').AsString);
        if Trim(FFMXID)<>'' then
        begin
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate CK_MYSC_CR_MX Set KuWeI='''+Trim(MXKuWeI.Text)+'''');
            sql.Add(' where MXID='''+Trim(ClientDataSet1.fieldbyname('MXID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Edit;
        FieldByName('SSel').Value:=false;
        FieldByName('KuWeI').Value:=Trim(MXKuWeI.Text);
      end;
    end;
    ClientDataSet1.EnableControls;
    application.MessageBox('保存成功','提示');
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_YHML.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if ClientDataSet1.IsEmpty then Exit;
  Self.MYCode.Text:=Trim(ClientDataSet1.fieldbyname('MYCode').AsString);
  Self.MYName.Text:=Trim(ClientDataSet1.fieldbyname('MYName').AsString);
  Self.MYMF.Text:=Trim(ClientDataSet1.fieldbyname('MYMF').AsString);
  Self.MYKZ.Text:=Trim(ClientDataSet1.fieldbyname('MYKZ').AsString);
  Self.Liuceng.Text:=Trim(ClientDataSet1.fieldbyname('Liuceng').AsString);
  Self.DYID.Text:=Trim(ClientDataSet1.fieldbyname('DYID').AsString);
  Self.MLID.Text:=Trim(ClientDataSet1.fieldbyname('MLID').AsString);
  Self.BPID.Text:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
  Self.PTID.Text:=Trim(ClientDataSet1.fieldbyname('PTID').AsString);
  InitColor();
end;

procedure TfrmQCRKInPut_YHML.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
end;

procedure TfrmQCRKInPut_YHML.ReadINIFile10();
var
  programIni:Tinifile;  //配置文件名
  FileName5:string;
begin
  FileName5:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName5);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmQCRKInPut_YHML.Image2DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
  maxno:string;
  j,i:Integer;
  fPrintFile,fFileName:string;
begin
  if Application.MessageBox('原图下载需要等待时间，确定要查看原图吗？','提示',32+4)<>IDYES then Exit;
  try
    ReadINIFile10();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=server;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  Panel16.Visible:=true;
  Panel16.Refresh;
  fPrintFile:= ExtractFilePath(Application.ExeName)+'Photo\';
  if not DirectoryExists(ExtractFileDir(FPrintFile)) then
    CreateDir(ExtractFileDir(fPrintFile));
  FFName:=Trim(FileName);
  FFName:=fPrintFile+FFName+'.jpg';
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('TJ\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

end.
