unit U_QCRKInPut_CPNo;

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,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, Menus,IniFiles,ShellAPI;

type
  TfrmQCRKInPut_CPNo = 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;
    MYName: TEdit;
    cxGroupBox1: TcxGroupBox;
    QtyLRM: TEdit;
    Label7: TLabel;
    UnitM: TEdit;
    Label9: TLabel;
    UnitKg: TEdit;
    Label10: TLabel;
    Label11: TLabel;
    MYColor: TEdit;
    Label12: TLabel;
    MYKZ: TEdit;
    Label14: TLabel;
    MYMF: TEdit;
    Label15: TLabel;
    Label16: TLabel;
    Label22: TLabel;
    RCGangNo: TEdit;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    QtyLRKg: TEdit;
    Label2: TLabel;
    MYColorNo: TEdit;
    Label3: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    Label4: TLabel;
    GangQty: TEdit;
    Label8: TLabel;
    MXHZPS: TEdit;
    Label17: TLabel;
    MXHZKGQty: TEdit;
    Label18: TLabel;
    MYType: TBtnEditA;
    BtnDel: TButton;
    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;
    RM1: TRMGridReport;
    CDS_Print: TClientDataSet;
    RMDB_Main: TRMDBDataSet;
    Label27: TLabel;
    Edit1: TEdit;
    BtnM: TButton;
    BtnKg: TButton;
    Button3: TButton;
    Panel6: TPanel;
    Button2: TButton;
    Button5: TButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    Label33: TLabel;
    Note2: TEdit;
    Label32: TLabel;
    MXNote: TEdit;
    Label6: TLabel;
    Label31: TLabel;
    KuWei: TEdit;
    GYLXName: TEdit;
    Button4: TButton;
    Button8: TButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1MYCode: TcxGridDBColumn;
    v1MYName: TcxGridDBColumn;
    v1MXGYLXName: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1MYColor: TcxGridDBColumn;
    v1MYColorNo: TcxGridDBColumn;
    v1MYMF: TcxGridDBColumn;
    v1MYKZ: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1KuWei: TcxGridDBColumn;
    v1MXNote: TcxGridDBColumn;
    v1Laster: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel4: TPanel;
    Label23: TLabel;
    Label24: TLabel;
    Label20: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    KgQty1: TEdit;
    MQty1: TEdit;
    Button6: TButton;
    RCGangNO1: TEdit;
    Button1: TButton;
    MXGYLXName: TEdit;
    BGY: TButton;
    MXKuWeI: TEdit;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    MXMYName: TEdit;
    Button12: TButton;
    MXMYCode: TEdit;
    MXMYMF: TEdit;
    MXMYKZ: TEdit;
    MXMYColor: TEdit;
    MXMYColorNo: TEdit;
    MXDYID: TEdit;
    MXMLID: TEdit;
    MXBPID: TEdit;
    MXPTID: TEdit;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N2: TMenuItem;
    RKNo: TEdit;
    Label37: TLabel;
    MXNote1: TEdit;
    N3: TMenuItem;
    Image1: TImage;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    TPID: TEdit;
    adoqueryPicture: TADOQuery;
    Image11: TImage;
    Panel16: TPanel;
    N5: TMenuItem;
    N6: TMenuItem;
    FGYLXName: TMemo;
    Label41: TLabel;
    YICeng: TEdit;
    Label42: TLabel;
    ERCeng: TEdit;
    Label43: TLabel;
    SanCeng: TEdit;
    Label44: TLabel;
    SICeng: TEdit;
    Label45: TLabel;
    WUCeng: TEdit;
    Label46: TLabel;
    LIUCeng: TEdit;
    v1YICeng: TcxGridDBColumn;
    v1ERCeng: TcxGridDBColumn;
    v1SanCeng: TcxGridDBColumn;
    v1SICeng: TcxGridDBColumn;
    v1WUCeng: TcxGridDBColumn;
    v1LIUCeng: TcxGridDBColumn;
    Button7: TButton;
    Panel5: TPanel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    ComboBox2: TComboBox;
    ComboBox1: TComboBox;
    BtnPrt: TButton;
    BtnQX: TButton;
    v1MYType: TcxGridDBColumn;
    Label47: TLabel;
    LCeng: TEdit;
    v1LCeng: TcxGridDBColumn;
    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 Button1Click(Sender: TObject);
    procedure BtnMClick(Sender: TObject);
    procedure BtnKgClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Panel6DblClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure UnitMChange(Sender: TObject);
    procedure UnitKgChange(Sender: TObject);
    procedure KuWeiKeyPress(Sender: TObject; var Key: Char);
    procedure Button7Click(Sender: TObject);
    procedure MXKuWeIKeyPress(Sender: TObject; var Key: Char);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure BGYClick(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Image1DblClick(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure MYCodeKeyPress(Sender: TObject; var Key: Char);
    procedure Image11DblClick(Sender: TObject);
  private
    lstPat:TStringList;
    FangXiang1:String;
    procedure ReadINIFile10();
    procedure InitData();
    procedure InitMXData();
    function  SaveData():Boolean;
    procedure GetHZData();
    procedure InitColor();
    procedure ShowImage();
    procedure SaveImage(maxnoWB:String);
    procedure DYShowImage();
    { Private declarations }
  public
    canshu1,FileName:String;
    PState,CopyInt:Integer;
    FMainId:String;
    FRead:String;
    FSaveFlag:string;
    Fstr:string;
    { Public declarations }
  end;

var
  frmQCRKInPut_CPNo: TfrmQCRKInPut_CPNo;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel, U_GYSList,U_SCPerson,U_BPZdy_LRGX_CX,U_ZHCPBigTP
  ,U_QCRKJLList,U_RSColorBig,U_MLMangeRS_GYCX,U_MLMangeRS_CX,U_RTPTColor,U_ZDYCPName,
  U_KuWeiKCList,U_KuWeiList,U_ZHCPList_CX;

{$R *.dfm}
procedure TfrmQCRKInPut_CPNo.DYShowImage();
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(MYCode.Text)+'''');
    sql.Add(' and isnull(A.IMNo,'''')=''图片'' and A.Valid=''Y'' ');
    Open;
  end;
  if adoqueryPicture.IsEmpty=False then
  begin
    Fstr:=Trim(adoqueryPicture.fieldbyname('ImageName').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;
    Image11.Visible:=True;
    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;
  end;
end;

procedure TfrmQCRKInPut_CPNo.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_CPNo.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('期初明细无编号录入',Tv1,'贸易生产管理');
  Close;
end;

procedure TfrmQCRKInPut_CPNo.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 Trim(labMYType.Caption)='' then
  begin
    labMYType.Caption:='        ';
  end;
  if PState=0 then
  begin
    CRTime.Date:=SGetServerDate(ADOTemp);
  end;
  InitMXData();
  GetHZData();
  if Trim(TPID.Text)<>'' then
  ShowImage();
  if Trim(PTID.Text)<>'' then
  begin
    InitColor();
  end;
  if Trim(ADOQuery1.fieldbyname('MYType').AsString)='单面料' then
  begin
    Label41.Visible:=false;
    YICeng.Visible:=false;
    Label43.Visible:=false;
    SanCeng.Visible:=false;
    Label45.Visible:=false;
    WUCeng.Visible:=false;
    Label42.Visible:=false;
    ERCeng.Visible:=false;
    Label44.Visible:=false;
    SICeng.Visible:=false;
    LCeng.Visible:=false;
    Label47.Visible:=false;
    v1YICeng.Visible:=false;
    v1ERCeng.Visible:=false;
    v1SanCeng.Visible:=false;
    v1SICeng.Visible:=false;
    v1WUCeng.Visible:=false;
    v1LCeng.Visible:=false;
  end
  else
  begin
    Label41.Visible:=true;
    YICeng.Visible:=true;
    Label43.Visible:=true;
    SanCeng.Visible:=true;
    Label45.Visible:=true;
    WUCeng.Visible:=true;
    Label42.Visible:=true;
    ERCeng.Visible:=true;
    Label44.Visible:=true;
    SICeng.Visible:=true;
    LCeng.Visible:=true;
    Label47.Visible:=true;
    v1YICeng.Visible:=true;
    v1ERCeng.Visible:=true;
    v1SanCeng.Visible:=true;
    v1SICeng.Visible:=true;
    v1WUCeng.Visible:=true;
    v1LCeng.Visible:=true;
  end;
end;

procedure TfrmQCRKInPut_CPNo.SaveImage(maxnoWB:string);
var
  ImagePath,ImagName,MaxNo,MaxNoFile:String;
  AJpeg:TJPEGImage;
  myStream:TADOBlobStream;
begin
  try
    ImagePath:=Trim(ClientDataSet1.fieldbyname('TPID').AsString);
    ImagName:=Trim(ClientDataSet1.fieldbyname('TPID').AsString);
    AJpeg:=TJpegImage.Create();
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('UPdate Image_File Set Valid=''N'' ');
      sql.Add(' where IMID=(select IMID from Image_Info');
      Sql.Add('where WBID='''+Trim(maxnoWB)+''' and Valid=''Y'' )');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('UPdate Image_Info Set Editer='''+Trim(DName)+''',EditerCode='''+Trim(DCode)+''',EditTime=getdate()');
      sql.Add(',Valid=''N''  where WBID='''+Trim(maxnoWB)+''' and Valid=''Y''  ');
      ExecSQL;
    end;
    if GetLSNo(ADOCmd,MaxNo,'IM','Image_Info',4,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取图片信息最大号失败！','提示',0);
      Exit;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from Image_Info where 1=2');
      Open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('IMID').Value:=Trim(MaxNo);
      FieldByName('WBID').Value:=Trim(maxnoWB);
      FieldByName('ImageName').Value:=Trim(ImagName);
      FieldByName('ImagePath').Value:=Trim(MaxNo)+Trim(ImagName);
      FieldByName('ImageDate').Value:=SGetServerDate(ADOTemp);
      Fieldbyname('ImageType').value:=Trim('YP');
      Fieldbyname('Valid').value:=Trim('Y');
      Post;
    end;
    if GetLSNo(ADOCmd,MaxNoFile,'IF','Image_File',4,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取图片文件最大号失败！','提示',0);
      Exit;
    end;
    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' select *  from Image_File where 1=2');
      open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('IMID').Value:=Trim(MaxNo);
      FieldByName('IFID').Value:=Trim(MaxNoFile);
      Fieldbyname('Valid').value:=Trim('Y');
      FieldByName('ImageWidth').Value:=Image11.Width;
      FieldByName('ImageHeight').Value:=Image11.Height;
      FieldByName('FangXiang').Value:=FangXiang1;
      FieldByName('IFType').Value:='小';
      myStream := TADOBlobStream.Create(TBlobField(ADOCmd.FieldByName('ImageFile')), bmWrite);
      AJpeg.Assign(Image11.Picture.Graphic);
      AJpeg.SaveToStream(myStream);
      myStream.Free;
      Post;
    end;
    if lstPat.Count=1 then
    begin
      try
        ReadINIFile10();
        server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
        IdFTP1.Host :=server;//PicSvr;
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
      except
        IdFTP1.Quit;
        Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
        Exit;
      end;
      if IdFTP1.Connected then
      begin
        IdFTP1.Put(lstPat[0], 'YP'+'\'+Trim(MaxNo)+Trim(ImagName));
      end;
      if IdFTP1.Connected then IdFTP1.Quit;
    end;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('图片保存失败！','提示',0);
  end;
end;

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

procedure TfrmQCRKInPut_CPNo.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_CPNo.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_CPNo.FormShow(Sender: TObject);
begin
  ReadCxGrid('期初明细无编号录入',Tv1,'贸易生产管理');
  InitData();
  QtyLRM.Visible:=True;
  BtnM.Visible:=True;
  if Trim(UnitKg.Text)<>'' then
  begin
    BtnM.Visible:=False;
  end;
end;

function TfrmQCRKInPut_CPNo.SaveData():Boolean;
var
  maxno,maxmxno,maxnoflag,fsj,FMXID,FRKNo,FCode: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;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' Delete CK_MYSC_CR where RKNo='''+Trim(RKNo.text)+'''');
    ExecSQL;
  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;
        if Trim(FieldByName('MYCode').AsString)='' then
        begin
          if GetLSNo(ADOCmd,FCode,'W','CK_MYSC_CR',5,0)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!','提示',0);
            Exit;
          end;
        end
        else
        begin
          FCode:=Trim(FieldByName('MYCode').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('CRFlag').Value:='入库';
          FieldByName('MYType').Value:=Trim(ClientDataSet1.fieldbyname('MYType').AsString);
          FieldByName('CRQtyFlag').Value:=1;
          FieldByName('RKNo').Value:=Trim(RKNo.Text);
          FieldByName('CRTime').Value:=SGetServerDateTime(ADOTemp);
          FieldByName('MYCode').Value:=Trim(FCode);
          FieldByName('MYName').Value:=Trim(ClientDataSet1.fieldbyname('MYName').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);
          fieldbyname('TPID').AsString:=Trim(ClientDataSet1.fieldbyname('TPID').AsString);
          FieldByName('YICeng').Value:=Trim(ClientDataSet1.fieldbyname('YICeng').AsString);
          FieldByName('ERCeng').Value:=Trim(ClientDataSet1.fieldbyname('ERCeng').AsString);
          FieldByName('SanCeng').Value:=Trim(ClientDataSet1.fieldbyname('SanCeng').AsString);
          FieldByName('SICeng').Value:=Trim(ClientDataSet1.fieldbyname('SICeng').AsString);
          FieldByName('WUCeng').Value:=Trim(ClientDataSet1.fieldbyname('WUCeng').AsString);
          FieldByName('LiuCeng').Value:=Trim(ClientDataSet1.fieldbyname('LiuCeng').AsString);
          FieldByName('LCeng').Value:=Trim(ClientDataSet1.fieldbyname('LCeng').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 ClientDataSet1 do
        begin
          edit;
          FieldByName('MYID').AsString:=Trim(maxno);
        end;
        if Trim(ClientDataSet1.fieldbyname('TPID').AsString)<>'' then
        begin
          SaveImage(Trim(ClientDataSet1.fieldbyname('TPID').AsString));
        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);
          fieldbyname('TPID').AsString:=Trim(ClientDataSet1.fieldbyname('TPID').AsString);
          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;
        if Trim(ClientDataSet1.fieldbyname('TPID').AsString)<>'' then
        begin
          SaveImage(FMXID);
        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_CPNo.TBSaveClick(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  if Trim(MYName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  if Trim(MYCode.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_CPNo.ShuiXiSuoLvClick(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text)='' then
  begin
    TEdit(Sender).Text:='√';
  end else
  begin
    TEdit(Sender).Text:='';
  end;
end;

procedure TfrmQCRKInPut_CPNo.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_CPNo.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_CPNo.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_CPNo.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('MYType').Value:=Trim(MYType.Text);
      FieldByName('MYMF').Value:=Trim(MYMF.Text);
      FieldByName('MYKZ').Value:=Trim(MYKZ.Text);
      FieldByName('MYColorNo').Value:=Trim(MYColorNo.Text);
      FieldByName('YICeng').Value:=Trim(YICeng.Text);
      FieldByName('ERCeng').Value:=Trim(ERCeng.Text);
      FieldByName('SanCeng').Value:=Trim(SanCeng.Text);
      FieldByName('SICeng').Value:=Trim(SICeng.Text);
      FieldByName('WUCeng').Value:=Trim(WUCeng.Text);
      FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
      FieldByName('LCeng').Value:=Trim(LCeng.Text);
      FieldByName('MYColor').Value:=Trim(MYColor.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);
      fieldbyname('TPID').AsString:=Trim(Self.TPID.Text);
      Post;
    end;
    QtyLRM.Text:='';
    GetHZData();
    TBSave.Caption:='未保存';
  end;
end;

procedure TfrmQCRKInPut_CPNo.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('MYType').Value:=Trim(MYType.Text);
      FieldByName('YICeng').Value:=Trim(YICeng.Text);
      FieldByName('ERCeng').Value:=Trim(ERCeng.Text);
      FieldByName('SanCeng').Value:=Trim(SanCeng.Text);
      FieldByName('SICeng').Value:=Trim(SICeng.Text);
      FieldByName('WUCeng').Value:=Trim(WUCeng.Text);
      FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
      FieldByName('LCeng').Value:=Trim(LCeng.Text);
      FieldByName('MYColorNo').Value:=Trim(MYColorNo.Text);
      FieldByName('MYColor').Value:=Trim(MYColor.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);
      fieldbyname('TPID').AsString:=Trim(Self.TPID.Text);
      Post;
    end;
    QtyLRM.Text:='';
    QtyLRKg.Text:='';
    if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
    GetHZData();
    TBSave.Caption:='未保存';
  end;
end;

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

procedure TfrmQCRKInPut_CPNo.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_CPNo.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.MXMYColor.Text:=Trim(ClientDataSet1.fieldbyname('MYColor').AsString);
  Self.MXMYColorNo.Text:=Trim(ClientDataSet1.fieldbyname('MYColorNo').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);
  Self.MXNote1.Text:=Trim(ClientDataSet1.fieldbyname('MXNote').AsString);
  Panel6.PopupMenu:=PopupMenu1;
  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_CPNo.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('MYColor').AsString:=Trim(Self.MXMYColor.Text);
    fieldbyname('MYColorNo').AsString:=Trim(Self.MXMYColorNo.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);
    fieldbyname('TPID').AsString:=Trim(Self.TPID.Text);
    fieldbyname('MXNote').AsString:=Trim(Self.MXNote1.Text);
    Post;
  end;
  Panel4.Visible:=False;
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_CPNo.BtnDelClick(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
        ClientDataSet1.Delete;
      end;
    end;
    ClientDataSet1.EnableControls;
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmQCRKInPut_CPNo.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_CPNo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ModalResult:=1;
end;

procedure TfrmQCRKInPut_CPNo.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_CPNo.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_CPNo.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_CPNo.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('MYType').Value:=Trim(MYType.Text);
    FieldByName('MYMF').Value:=Trim(MYMF.Text);
    FieldByName('MYKZ').Value:=Trim(MYKZ.Text);
    FieldByName('YICeng').Value:=Trim(YICeng.Text);
    FieldByName('ERCeng').Value:=Trim(ERCeng.Text);
    FieldByName('SanCeng').Value:=Trim(SanCeng.Text);
    FieldByName('SICeng').Value:=Trim(SICeng.Text);
    FieldByName('WUCeng').Value:=Trim(WUCeng.Text);
    FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
    FieldByName('LCeng').Value:=Trim(LCeng.Text);
    FieldByName('MYColorNo').Value:=Trim(MYColorNo.Text);
    FieldByName('MYColor').Value:=Trim(MYColor.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);
    fieldbyname('TPID').AsString:=Trim(Self.TPID.Text);
    Post;
  end;
  QtyLRM.Text:='';
  GetHZData();
  TBSave.Caption:='未保存';
end;

procedure TfrmQCRKInPut_CPNo.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('MYType').Value:=Trim(MYType.Text);
    FieldByName('YICeng').Value:=Trim(YICeng.Text);
    FieldByName('ERCeng').Value:=Trim(ERCeng.Text);
    FieldByName('SanCeng').Value:=Trim(SanCeng.Text);
    FieldByName('SICeng').Value:=Trim(SICeng.Text);
    FieldByName('WUCeng').Value:=Trim(WUCeng.Text);
    FieldByName('LiuCeng').Value:=Trim(LiuCeng.Text);
    FieldByName('LCeng').Value:=Trim(LCeng.Text);
    FieldByName('MYColorNo').Value:=Trim(MYColorNo.Text);
    FieldByName('MYColor').Value:=Trim(MYColor.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);
    fieldbyname('TPID').AsString:=Trim(Self.TPID.Text);
    Post;
  end;
  QtyLRM.Text:='';
  QtyLRKg.Text:='';
  if Trim(UnitM.Text)<>'' then QtyLRM.SetFocus;
  GetHZData();
  TBSave.Caption:='未保存';
end;

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

procedure TfrmQCRKInPut_CPNo.Panel6DblClick(Sender: TObject);
begin
  try
    frmRSColorBig:=TfrmRSColorBig.Create(Application);
    with frmRSColorBig do
    begin
      frmRSColorBig.Label1.Caption:=Self.MYColorNo.Text+'#';
      frmRSColorBig.Label2.Caption:=Self.MYColor.Text;
      frmRSColorBig.Color:=Self.Panel6.Color;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
  end;
end;

procedure TfrmQCRKInPut_CPNo.Button2Click(Sender: TObject);
var FDate:TDateTime;
    SXMaxno:string;
begin
  frmMLMangeRS_CX:=TfrmMLMangeRS_CX.create(self);
  with frmMLMangeRS_CX 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,'SX','CK_MYSC_CR',3,1)=False then
      begin
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
      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.MYColor.Text:=Trim(CDS_Main.fieldbyname('ColNamekh').AsString);
      Self.MYColorNo.Text:=Trim(CDS_Main.fieldbyname('ColNo').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);
      labMYType.Caption:='染色面料';
      if Trim(MYType.Text)='染色面料' then
      begin
        MYType.TxtCode:='RS';
      end;
      Edit1.Text:='';
      FDate:=SGetServerDate(ADOTemp);
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from CK_MYSC_CR where MLID='''+Trim(MLID.Text)+'''');
        sql.Add(' and BPID='''+Trim(BPID.Text)+'''');
        sql.Add(' and PTID='''+Trim(PTID.Text)+'''');
        sql.Add(' and CRTime='''+Trim(FormatDateTime('yyyy-MM-dd',FDate))+'''');
        Open;
      end;
      FMainId:=Trim(ADOTemp.fieldbyname('MYID').AsString);
      InitMXData();
      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;
      InitColor();
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_CPNo.N1Click(Sender: TObject);
begin
  try
    frmRTPTColor:=TfrmRTPTColor.Create(Application);
    with frmRTPTColor do
    begin
      if ShowModal=1 then
      begin
        Self.PTID.Text:=Trim(frmRTPTColor.FPTID);
        Self.MYColor.Text:=Trim(frmRTPTColor.FColNameKH);
        Self.MYColorNo.Text:=Trim(frmRTPTColor.FColName);
      end;
    end;
  finally
    frmRTPTColor.Free;
  end;
  if Trim(PTID.Text)<>'' then
  begin
    InitColor();
  end;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete from Image_File where ');
    sql.Add('IMID in (select IMID from Image_Info where WBID='''+Trim(ClientDataSet1.fieldbyname('MYID').AsString)+''' and Valid=''Y'')');
    sql.Add('delete from Image_Info ');
    sql.Add(' where WBID='''+Trim(ClientDataSet1.fieldbyname('MYID').AsString)+''' and Valid=''Y''');
    ExecSQL;
  end;
  TPID.Text:='';
  ShowImage();
end;

procedure TfrmQCRKInPut_CPNo.Button5Click(Sender: TObject);
begin
  frmZDYCPName:=TfrmZDYCPName.create(self);
  with frmZDYCPName do
  begin
    flag:='MYName';
    flagName:='品名';
    V1Code.Visible:=true;
    if showmodal=1 then
    begin
      MYName.text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      MYCode.text:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_CPNo.Button4Click(Sender: TObject);
begin
  frmBPZDY_LRGX_CX:=TfrmBPZDY_LRGX_CX.Create(self);
  with frmBPZDY_LRGX_CX do
  begin
    if ShowModal=1 then
    begin
      GYLXName.Text:=Trim(FZGY);
    end;
    free;
  end;
end;

procedure TfrmQCRKInPut_CPNo.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_CPNo.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_CPNo.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_CPNo.Button7Click(Sender: TObject);
begin
  frmZHCPList_CX:=TfrmZHCPList_CX.create(self);
  with frmZHCPList_CX do
  begin
    if showmodal=1 then
    begin
      if Order_Main.FieldByName('DYID').AsString='' then
      begin
        DYID.Text:=Trim(Order_Main.fieldbyname('ZIID').AsString)+'1';
        TPID.Text:=Trim(Order_Main.fieldbyname('ZIID').AsString)+'1';
      end
      else
      begin
        DYID.Text:=Trim(Order_Main.fieldbyname('DYID').AsString);
        TPID.Text:=Trim(Order_Main.fieldbyname('DYID').AsString);
      end;
      MYCode.Text:=Trim(Order_Main.fieldbyname('ZIID').AsString);
      MYCode.Hint:=Trim(Order_Main.fieldbyname('ZIID').AsString);
      MYType.Text:=Trim(Order_Main.fieldbyname('ZIType').AsString);
      MYName.Text:=Trim(Order_Main.fieldbyname('ZIName').AsString);
      MYMF.Text:=Trim(Order_Main.fieldbyname('ZIMF').AsString);
      MYKZ.Text:=Trim(Order_Main.fieldbyname('ZIKZ').AsString);
      MLID.Text:=Trim(Order_Main.fieldbyname('ZIID').AsString);
      FGYLXName.Text:=Trim(Order_Main.fieldbyname('ZIGY').AsString);
      MYType.TxtCode:=Trim(Order_Main.fieldbyname('ZIType').AsString);
      DYShowImage();
      GetHZData();
      if Trim(Order_Main.fieldbyname('ZIType').AsString)='单面料' then
      begin
        Label41.Visible:=false;
        YICeng.Visible:=false;
        Label43.Visible:=false;
        SanCeng.Visible:=false;
        Label45.Visible:=false;
        WUCeng.Visible:=false;
        Label42.Visible:=false;
        ERCeng.Visible:=false;
        Label44.Visible:=false;
        SICeng.Visible:=false;
        v1YICeng.Visible:=false;
        v1ERCeng.Visible:=false;
        v1SanCeng.Visible:=false;
        v1SICeng.Visible:=false;
        v1WUCeng.Visible:=false;
      end
      else
      begin
        Label41.Visible:=true;
        YICeng.Visible:=true;
        Label43.Visible:=true;
        SanCeng.Visible:=true;
        Label45.Visible:=true;
        WUCeng.Visible:=true;
        Label42.Visible:=true;
        ERCeng.Visible:=true;
        Label44.Visible:=true;
        SICeng.Visible:=true;
        v1YICeng.Visible:=true;;
        v1ERCeng.Visible:=true;
        v1SanCeng.Visible:=true;
        v1SICeng.Visible:=true;
        v1WUCeng.Visible:=true;
      end;
    end;
    free;
  end;
  //ShowMessage(TPID.Text);
end;

procedure TfrmQCRKInPut_CPNo.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_CPNo.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
      KuWei.Text:=Trim(Order_Main.fieldbyname('KWName').AsString);
    end;
    Free;
  end;
end;

procedure TfrmQCRKInPut_CPNo.Button9Click(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_CPNo.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.MYColor.Text:=Trim(ClientDataSet1.fieldbyname('MYColor').AsString);
  Self.MYColorNo.Text:=Trim(ClientDataSet1.fieldbyname('MYColorNo').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);
  Self.TPID.Text:=Trim(ClientDataSet1.fieldbyname('TPID').AsString);
  YICeng.Text:=Trim(ClientDataSet1.FieldByName('YICeng').AsString);
  ERCeng.Text:=Trim(ClientDataSet1.FieldByName('ERCeng').AsString);
  SanCeng.Text:=Trim(ClientDataSet1.FieldByName('SanCeng').AsString);
  SICeng.Text:=Trim(ClientDataSet1.FieldByName('SICeng').AsString);
  WUCeng.Text:=Trim(ClientDataSet1.FieldByName('WUCeng').AsString);
  LiuCeng.Text:=Trim(ClientDataSet1.FieldByName('LiuCeng').AsString);
  LCeng.Text:=Trim(ClientDataSet1.FieldByName('LCeng').AsString);
  InitColor();
  ShowImage();
  //ShowMessage(TPID.Text);
end;

procedure TfrmQCRKInPut_CPNo.BGYClick(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_CPNo.MenuItem1Click(Sender: TObject);
begin
  SelOKNo(ClientDataSet1,true);
end;

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

procedure TfrmQCRKInPut_CPNo.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 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_CPNo.Button11Click(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_CPNo.Button12Click(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.MXMYColor.Text:=Trim(CDS_Main.fieldbyname('ColNamekh').AsString);
      Self.MXMYColorNo.Text:=Trim(CDS_Main.fieldbyname('ColNo').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.MYColor.Text:=Trim(CDS_Main.fieldbyname('ColNamekh').AsString);
      Self.MYColorNo.Text:=Trim(CDS_Main.fieldbyname('ColNo').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_CPNo.N3Click(Sender: TObject);
var
  AJpeg:TJPEGImage;
  Bitmap,Bitmap11: TBitmap;
  ARect,ARect11: TRect;
  TPHeight, AHeightOffset: Integer;
  TPWidth, AWidthOffset: Integer;
  WZShuiPing,WZChuiZhi:Integer;
  WZFlag:String;
  FHFStr:String;
begin
  lstPat.Clear;
  if ODPat.Execute then
  begin
    lstPat.AddStrings(ODPat.Files);
  end else
  begin
    Exit;
  end;
  if  lstPat.Count>1 then
  begin
    lstPat.Clear;
    Application.MessageBox('不能上传多个图片!','提示',0);
    Exit;
  end else
  if lstPat.Count<1 then
  begin
    Exit;
  end;
  AJpeg:=TJpegImage.Create();
  AJpeg.LoadFromFile(ExtractFileName(ODPat.FileName));
  Image1.Hint:=ExtractFileName(ODPat.FileName);
  TPID.Text:=ExtractFileName(ODPat.FileName);
  FileName:=Trim(ExtractFileName(ODPat.FileName));
  TPWidth:=AJpeg.Width;
  TPHeight:=AJpeg.Height;
  Bitmap := TBitmap.Create;
  Bitmap11 := TBitmap.Create;
  Bitmap.Width :=Panel6.Width-2;
  Bitmap.Height :=Round(Panel6.Width/TPWidth*TPHeight);
  if Bitmap.Height>Panel6.Height then
  begin
    WZFlag:='垂直';
    Bitmap.Height:=Panel6.Height-2;
    Bitmap.Width :=Round(Panel6.Height/TPHeight*TPWidth);
  end;
  Bitmap11.Width:=Bitmap.Width*2;
  Bitmap11.Height:=Bitmap.Height*2;
  Bitmap.Canvas.FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height));
  ARect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
  Bitmap.Canvas.StretchDraw(ARect, AJPeg);
  Image1.Height:=Bitmap.Height;
  Image1.Width:=Bitmap.Width;
  Image1.Picture.Assign(BitMap);
  if Trim(WZFlag)='垂直' then
  begin
    Image1.Top:=1;
    Image1.Left:=Round((Panel6.Width-Image1.Width)/2);
  end else
  begin
    Image1.Left:=1;
    Image1.Top:=Round((Panel6.Height-Image1.Height)/2);
  end;
  FangXiang1:=WZFlag;
  Image1.Visible:=True;
  Bitmap11.Canvas.FillRect(Rect(0, 0, Bitmap11.Width, Bitmap11.Height));
  ARect11 := Rect(0, 0, Bitmap11.Width, Bitmap11.Height);
  Bitmap11.Canvas.StretchDraw(ARect11, AJPeg);
  Image11.Height:=Bitmap11.Height;
  Image11.Width:=Bitmap11.Width;
  Image11.Picture.Assign(BitMap11);
  PTID.Text:='';
  Panel6.Color:=clBtnFace;
end;

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

procedure TfrmQCRKInPut_CPNo.Image1DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
  maxno:string;
  j,i:Integer;
  fPrintFile,fFileName:string;
begin
  if TPID.Text='' then exit;
  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;
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('YP\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

procedure TfrmQCRKInPut_CPNo.N5Click(Sender: TObject);
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.MXMYColor.Text:=Trim(ClientDataSet1.fieldbyname('MYColor').AsString);
  Self.MXMYColorNo.Text:=Trim(ClientDataSet1.fieldbyname('MYColorNo').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);
  Self.MXNote1.Text:=Trim(ClientDataSet1.fieldbyname('MXNote').AsString);
  Panel6.PopupMenu:=PopupMenu1;
  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_CPNo.N6Click(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(' 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)+'''');
            ExecSQL;
          end;
        end; }

        ClientDataSet1.Delete;
      end;
    end;
    ClientDataSet1.EnableControls;
    {if Trim(FMainId)<>'' then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' exec P_Update_QCRK_Qty :MYID');
        Parameters.ParamByName('MYID').Value:=Trim(FMainId);
        ExecSQL;
      end;
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from CK_MYSC_CR where MYID='''+Trim(FMainId)+'''');
        Open;
      end;
      SCSHDataNew(ADOTemp,Panel2,2);
    end;}
    //GetHZData();
    ADOCmd.Connection.CommitTrans;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('数据删除异常！','提示',0);
    Exit;
  end;
end;

procedure TfrmQCRKInPut_CPNo.MYCodeKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOTemp do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.*,Cast(ROW_NUMBER() OVER(order by ZIID) as int) as RowNum ');
      sql.Add(' ,ImageFileTP=(select ImageFile from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
      sql.Add('             where B.WBID=A.ZIID and B.IMNO=''图片'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
      sql.Add(' ,ImageFileNR=(select ImageFile from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
      sql.Add('             where B.WBID=A.ZIID and B.IMNO=''内容'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
      sql.Add(',GS=(select Sum(GGQty) from ZH_CP_Info_KC KC where KC.ZIID=A.ZIID )');
      sql.Add(' from ZH_CP_Info A  ');
      sql.Add(' where A.Valid=''Y''  ');
      sql.Add(' and exists (select KC.ZIID from ZH_CP_Info_KC KC where KC.ZIID=A.ZIID and KC.DYID='''+trim(MYCode.Text)+''')');
      open;
    end;
    DYID.Text:=Trim(MYCode.Text);
    MYCode.Text:=Trim(ADOTemp.fieldbyname('ZIID').AsString);
    MYCode.Hint:=Trim(ADOTemp.fieldbyname('ZIID').AsString);
    MYType.Text:=Trim(ADOTemp.fieldbyname('ZIType').AsString);
    MYName.Text:=Trim(ADOTemp.fieldbyname('ZIName').AsString);
    MYMF.Text:=Trim(ADOTemp.fieldbyname('ZIMF').AsString);
    MYKZ.Text:=Trim(ADOTemp.fieldbyname('ZIKZ').AsString);
    MLID.Text:=Trim(ADOTemp.fieldbyname('ZIID').AsString);
    TPID.Text:=Trim(DYID.Text);
    FGYLXName.Text:=Trim(ADOTemp.fieldbyname('ZIGY').AsString);
    MYType.TxtCode:=Trim(ADOTemp.fieldbyname('ZIType').AsString);
    DYShowImage();
    GetHZData();
  end;
end;

procedure TfrmQCRKInPut_CPNo.Image11DblClick(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;
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('YP\'+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.
