unit U_FCDJSMCK;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, StdCtrls, ExtCtrls, ADODB, DBClient,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, MovePanel, cxCheckBox, Menus, ComCtrls, BtnEdit, ShellAPI, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans,
  dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmFCDJSMCK = class(TForm)
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_MainSel: TDataSource;
    CDS_MainSel: TClientDataSet;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel2: TPanel;
    Label5: TLabel;
    Label4: TLabel;
    Label9: TLabel;
    CKOrdNo: TEdit;
    BaoID: TEdit;
    CRTime: TDateTimePicker;
    KHName: TEdit;
    Button2: TButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label12: TLabel;
    CDS_Main: TClientDataSet;
    Button1: TButton;
    v3Column2: TcxGridDBColumn;
    Button3: TButton;
    CKType: TComboBox;
    Label1: TLabel;
    edtIsSMTH: TEdit;
    Label2: TLabel;
    Button4: TButton;
    CDS_DCK: TClientDataSet;
    MovePanel2: TMovePanel;
    v3Column4: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BaoIDKeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure CKTypeChange(Sender: TObject);
    procedure edtIsSMTHClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Tv3DblClick(Sender: TObject);
  private
    { Private declarations }
    FSMID, FCKOrdNo, FRKOrdID, FMJID, CZZT: string;
    function JudgeSQD(): Boolean;
    function JudgeRKD(): Boolean;
    function JudgeJTM(): Boolean;
    function JudgeRKDCX(): Boolean;
    function JudgeJTMCX(): Boolean;
    procedure SaveCKData();
    procedure SaveCKDataJTM();
    procedure SaveCKDataCX();
    procedure SaveCKDataJTMCX();
    procedure InitCKGrid();
  public
    { Public declarations }
  end;

var
  frmFCDJSMCK: TfrmFCDJSMCK;

implementation

uses
  U_DataLink, U_Fun, MMSystem, U_ZdyAttachment, U_ZdyAttachGYS,
  U_CKProductBCPKCListSel, U_CPOutListSel;

{$R *.dfm}
function TfrmFCDJSMCK.JudgeSQD(): Boolean;
begin
  Result := false;
  try
    if CKType.Text = '回修出库' then
    begin
      if Trim(KHName.Text) = '' then
        raise Exception.Create('请选择收货单位!');
    end;

    if Trim(CKOrdNo.Text) = '' then
      raise Exception.Create('未扫描申请单暂停发货!');

    Result := True;
  except
    Result := false;
    MovePanel2.Visible := False;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
//      PlaySound('未扫描申请单暂停发货.wav', 0, SND_FILENAME or SND_ASYNC);
  end;
end;

function TfrmFCDJSMCK.JudgeRKD(): Boolean;
begin
  try
    if CKType.Text = '回修出库' then
    begin
      if Trim(KHName.Text) = '' then
        raise Exception.Create('请选择收货单位!');
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select   * from WFB_MJJY A   ');
      sql.Add('where  RKOrdID=' + quotedstr(trim(FRKOrdID)));
      Open;
    end;

    if ADOQueryTemp.IsEmpty then
      raise Exception.Create('条码错误暂停发货!');

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT RKOrdID,CKOrdNo FROM CK_BanCP_CR where CRFlag=''出库'' and RKOrdID=' + quotedstr(trim(FRKOrdID)));
      Open;
    end;
    if not ADOQueryTemp.IsEmpty then
      raise Exception.Create('已扫描!');

    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

function TfrmFCDJSMCK.JudgeJTM(): Boolean;
begin
  try
    if CKType.Text = '回修出库' then
    begin
      if Trim(KHName.Text) = '' then
        raise Exception.Create('请选择收货单位');
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select MJID from WFB_MJJY  where MJID=' + quotedstr(trim(FMJID)));
      Open;
    end;
    if ADOQueryTemp.IsEmpty then
    begin
      raise Exception.Create('条码错误暂停发货');
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select RKOrdID from CK_BanCP_CR where CRFlag=''入库'' and MJID=' + quotedstr(trim(FMJID)));
      Open;
    end;
    if ADOQueryTemp.IsEmpty then
    begin
      raise Exception.Create('未入库暂停发货');
    end
    else
    begin
      FRKOrdID := Trim(ADOQueryTemp.fieldbyname('RKOrdID').AsString);
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT RKOrdID,CKOrdNo FROM CK_BanCP_CR where CRFlag=''出库'' and MJID=' + quotedstr(trim(FMJID)));
      Open;
    end;
    if ADOQueryTemp.IsEmpty = False then
    begin
      if Trim(ADOQueryTemp.fieldbyname('CKOrdNo').AsString) = Trim(CKOrdNo.Text) then
      begin
        raise Exception.Create('已扫描');
      end
      else
      begin
        raise Exception.Create('已出库暂停发货');
      end;
    end;

    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
//    PlaySound('wav\'+Exception(ExceptObject).Message+'.wav', 0, SND_FILENAME or SND_ASYNC);
  end;
end;

function TfrmFCDJSMCK.JudgeJTMCX(): Boolean;
begin
  try
    if Trim(CKOrdNo.Text) = '' then
      raise Exception.Create('出库单号不能为空!');

    if CDS_MainSel.IsEmpty then
      raise Exception.Create('无可撤销的数据!');

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT RKOrdID,CKOrdNo FROM CK_BanCP_CR where CRFlag=''出库'' and MJID=' + quotedstr(FMJID));
      Open;
    end;

    if ADOQueryTemp.IsEmpty then
      raise Exception.Create('无可撤销的数据!');

    Result := True;
  except
    Result := false;
    MovePanel2.Visible := False;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

function TfrmFCDJSMCK.JudgeRKDCX(): Boolean;
begin
  try
    if Trim(CKOrdNo.Text) = '' then
      raise Exception.Create('出库单号不能为空!');

    if CDS_MainSel.IsEmpty then
      raise Exception.Create('无可撤销的数据!');

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT RKOrdID,CKOrdNo FROM CK_BanCP_CR where CRFlag=''出库'' and CKOrdNo=' + quotedstr(FCKOrdNo));
      Open;
    end;

    if ADOQueryTemp.IsEmpty then
      raise Exception.Create('无可撤销的数据!');

    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmFCDJSMCK.SaveCKData();
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_CKList Set CKDate=getdate() ');
      sql.Add(',KHNmae= ' + Quotedstr(KHName.Text));
      sql.Add(',CKType= ' + Quotedstr(CKType.Text));
      sql.Add('where CKOrdNo=' + Quotedstr(FCKOrdNo));
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add(' CRTime=getdate(),CRType=''扫描出库'',CRFlag=''出库''  ');
      sql.add(',CKOrdNo=' + Quotedstr(FCKOrdNo));
      sql.add(',RKOrdID=' + Quotedstr(FRKOrdID));
      sql.Add(' where exists(select MJID from CK_BanCP_CR X where CK_BanCP_CR.MJID=X.MJID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ')  ');
      sql.Add('and CK_BanCP_CR.CRFlag=''待出库''  ');
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_KC Set  ');
      sql.add(' KCValid=''N''  ');
      sql.Add(' where exists(select MJID from CK_BanCP_CR X where CK_BanCP_KC.MJID=X.MJID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ')  ');
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE WFB_MJJY Set  MJStr2=''已出库''  ');
      sql.Add(' where exists (select MJID from CK_BanCP_CR X where WFB_MJJY.MJID=X.MJID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ')  ');
      SQL.Add(' and WFB_MJJY.MJStr2=''已入库'' ');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    PlaySound('wav\正确.wav', 0, SND_FILENAME or SND_ASYNC);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('出库失败！', '提示信息', 0);
  end;
end;

procedure TfrmFCDJSMCK.SaveCKDataJTM();
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_CKList Set CKDate=' + quotedstr(FormatDateTime('yyyy-MM-dd', CRTime.DateTime)));
      sql.Add(',KHNmae= ' + Quotedstr(KHName.Text));
      sql.Add(',CKType= ' + Quotedstr(CKType.Text));
      sql.Add('where CKOrdNo=' + Quotedstr(FCKOrdNo));
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add(' CRTime=' + quotedstr(FormatDateTime('yyyy-MM-dd', CRTime.DateTime)) + ',CRType=''扫描出库'',CRFlag=''出库''  ');
      sql.add(',CKOrdNo=' + Quotedstr(FCKOrdNo));
      sql.add(',RKOrdID=' + Quotedstr(FRKOrdID));
      sql.Add(' where CK_BanCP_CR.MJID=' + Quotedstr(Trim(FMJID)));
      sql.Add('and CK_BanCP_CR.CRFlag=''待出库''  ');
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_KC Set  ');
      sql.add(' KCValid=''N''  ');
      sql.Add(' where CK_BanCP_KC.MJID=' + Quotedstr(Trim(FMJID)));
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE WFB_MJJY Set  MJStr2=''已出库''  ');
      sql.Add(' where WFB_MJJY.MJID=' + Quotedstr(Trim(FMJID)));
      SQL.Add(' and WFB_MJJY.MJStr2=''已入库'' ');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    MovePanel2.Visible := False;
    MovePanel2.Visible := False;
    application.MessageBox('出库失败！', '提示信息', 0);
  end;
end;

procedure TfrmFCDJSMCK.SaveCKDataCX();
begin
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update CK_BanCP_CR Set CRFlag=''待出库'',CRType='''',CRTime=NULL,CRNote='''',CKOrdNo='''' ');
      sql.Add(' where exists(select MJID from CK_BanCP_CR X where CK_BanCP_CR.MJID=X.MJID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ')  ');
      sql.Add(' and CRFlag=''出库''');

      sql.Add(' UPdate CK_BanCP_KC Set KCValid=''Y'' ');
      sql.Add(' where exists(select MJID from CK_BanCP_CR X where CK_BanCP_KC.MJID=X.MJID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ')  ');
      sql.Add(' and KCValid=''N'' ');

      sql.Add(' Update WFB_MJJY Set MJStr2=''已入库'' ');
      sql.Add(' where exists (select MJID from CK_BanCP_CR X where WFB_MJJY.MJID=X.MJID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ')  ');
      SQL.Add(' and WFB_MJJY.MJStr2=''已出库'' ');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(''));
      sql.Add(',' + quotedstr(trim('出库扫描撤销')));
      sql.Add(',' + quotedstr('入库单号：' + trim(FRKOrdID) + ' 出库单号：' + trim(FCKOrdNo)));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    PlaySound('wav\正确.wav', 0, SND_FILENAME or SND_ASYNC);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('撤销出库失败！', '提示信息', 0);
  end;
end;

procedure TfrmFCDJSMCK.SaveCKDataJTMCX();
begin
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update CK_BanCP_CR Set CRFlag=''待出库'',CRType='''',CRTime=NULL,CRNote='''',CKOrdNo='''' ');
      sql.Add(' where  CK_BanCP_CR.MJID=' + Quotedstr(Trim(FMJID)));
      sql.Add(' and CRFlag=''出库''');

      sql.Add(' UPdate CK_BanCP_KC Set KCValid=''Y'' ');
      sql.Add(' where  CK_BanCP_KC.MJID=' + Quotedstr(Trim(FMJID)));
      sql.Add(' and KCValid=''N'' ');

      sql.Add(' Update WFB_MJJY Set MJStr2=''已入库'' ');
      sql.Add(' where  WFB_MJJY.MJID=' + Quotedstr(Trim(FMJID)));
      SQL.Add(' and WFB_MJJY.MJStr2=''已出库'' ');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(''));
      sql.Add(',' + quotedstr(trim('出库扫描撤销')));
      sql.Add(',' + quotedstr('卷条码：' + trim(FMJID) + ' 出库单号：' + trim(FCKOrdNo)));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('撤销出库失败！', '提示信息', 0);
  end;
end;

procedure TfrmFCDJSMCK.InitCKGrid();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select AA.*, B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTSpec,B.MPRTMF,B.MPRTKZ ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo ');
    sql.Add('from  (select count(SubId) ps,SUM(A.KGQty) KGQty,SUM(A.Qty) Qty,SUM(A.NetKGQty) NetKGQty');
    sql.Add(',A.MainId,A.SubId,A.QtyUnit,A.CPType,A.ganghao,A.APID');
    sql.Add('from CK_BanCP_CR A where A.CRFlag=''出库'' and CKOrdNo=' + quotedstr(FCKOrdNo));
    sql.Add('group by  A.MainId,A.SubId,A.QtyUnit,A.CPType,A.ganghao,A.APID ) AA  inner join JYOrder_Main B on AA.MainId=B.MainId');
    sql.Add(' inner join JYOrder_Sub C on AA.SubId=C.SubId ');
//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_MainSel);
  SInitCDSData20(ADOQueryTemp, CDS_MainSel);

end;

procedure TfrmFCDJSMCK.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmFCDJSMCK.FormDestroy(Sender: TObject);
begin
  frmFCDJSMCK := nil;
end;

procedure TfrmFCDJSMCK.FormShow(Sender: TObject);
begin
  BaoID.SetFocus;
  ReadCxGrid('扫描出库', Tv3, '坯布仓库');
  CRTime.DateTime := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmFCDJSMCK.BaoIDKeyPress(Sender: TObject; var Key: Char);
begin

  if Key = #13 then
  begin
    MovePanel2.Visible := True;
    MovePanel2.Refresh;
    FSMID := TRIM(BaoID.Text);
    BaoID.Text := '';
    FCKOrdNo := Trim(CKOrdNo.text);
    FRKOrdID := '';
    FMJID := '';
    if edtIsSMTH.Text = '' then
    begin
      if not JudgeSQD() then//检测出库单
        exit;

      if Copy(FSMID, 1, 2) = 'CZ' then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add(' select MJID from WFB_MJJY where MJStr2=''已入库'' and APID=' + quotedstr(FSMID));
          Open;
        end;
        SCreateCDS20(ADOQueryTemp, CDS_DCK);
        SInitCDSData20(ADOQueryTemp, CDS_DCK);

        while not CDS_DCK.IsEmpty do
        begin
          FMJID := Trim(CDS_DCK.fieldbyname('MJID').AsString);
          if JudgeJTM() then   //检测卷条码
            SaveCKDataJTM();
          CDS_DCK.Delete;
        end;
      end
      else
      begin
        FMJID := FSMID;
        if JudgeJTM() then  //检测卷条码
          SaveCKDataJTM();
      end;
    end
    else
    begin
      FMJID := FSMID;
      if JudgeJTMCX() then  //检测卷条码
        SaveCKDataJTMCX();
    end;
    MovePanel2.Visible := False;
    if CZZT <> '选择库存' then
      InitCKGrid();
  end;

end;

procedure TfrmFCDJSMCK.Button2Click(Sender: TObject);
begin
  Close;
  WriteCxGrid('扫描出库', Tv3, '坯布仓库');
end;

procedure TfrmFCDJSMCK.Button1Click(Sender: TObject);
begin
  if CKType.Text = '销售出库' then
  begin
    try
      frmZdyAttachment := TfrmZdyAttachment.Create(Application);
      with frmZdyAttachment do
      begin

        if ShowModal = 1 then
        begin
          KHName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    finally
      frmZdyAttachment.Free;
    end;
  end
  else
  begin
    try
      frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
      with frmZdyAttachGYS do
      begin

        if ShowModal = 1 then
        begin
          KHName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);

        end;
      end;
    finally
      frmZdyAttachGYS.Free;
    end;
  end;
end;

procedure TfrmFCDJSMCK.Button3Click(Sender: TObject);
begin
  if GetLSNo(ADOQueryTemp, FCKOrdNo, 'CK', 'CK_BanCP_CR', 4, 1) = False then
  begin
    Application.MessageBox('生成流水号异常！', '提示', 0);
    exit;
  end;
  CKOrdNo.TEXT := FCKOrdNo;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('insert into  CK_BanCP_CKList(CKOrdNo) ');
    sql.add('values(' + quotedstr(FCKOrdNo) + ')  ');
    ExecSQL;
  end;
end;

procedure TfrmFCDJSMCK.CKTypeChange(Sender: TObject);
begin
  KHName.Text := '';
end;

procedure TfrmFCDJSMCK.edtIsSMTHClick(Sender: TObject);
begin
  BaoID.SetFocus;
  if edtIsSMTH.Text = '√' then
  begin
    edtIsSMTH.Text := '';
  end
  else
  begin
    if Application.MessageBox('确定要扫描退货吗？', '提示', 32 + 4) = IDYES then
      edtIsSMTH.Text := '√';
  end;
end;

procedure TfrmFCDJSMCK.Button4Click(Sender: TObject);
var
  MKey: Char;
begin
  MKey := #13;
  CZZT := '选择库存';
  try
    frmCKProductBCPKCListSel := TfrmCKProductBCPKCListSel.Create(Application);
    with frmCKProductBCPKCListSel do
    begin
      CustomerNoName.text := trim(Self.KHName.text);
      if ShowModal = 1 then
      begin
        with frmCKProductBCPKCListSel.CDS_Main do
        begin
          First;
          while not Eof do
          begin
            if Fieldbyname('ssel').AsBoolean then
            begin
              BaoID.Text := Trim(Fieldbyname('MJID').AsString);
              BaoIDKeyPress(BaoID, MKey);
              Sleep(200);
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmCKProductBCPKCListSel.Free;
  end;
  InitCKGrid();
end;

procedure TfrmFCDJSMCK.Tv3DblClick(Sender: TObject);
begin
  if CDS_MainSel.IsEmpty then
    Exit;
  try
    frmCPOutListSel := TfrmCPOutListSel.Create(Application);
    with frmCPOutListSel do
    begin
      CkOrdNo.text := trim(Self.CKOrdNo.text);
      apid.text := Trim(Self.CDS_MainSel.fieldbyname('apid').AsString);
      if ShowModal = 1 then
      begin
        InitCKGrid();
      end;
    end;
  finally
    frmCPOutListSel.Free;
  end;
end;

end.

