unit U_FCSMCK; 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, U_BaseList, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu; type TfrmFCSMCK = class(TFrmBaseList) 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; Label3: TLabel; edtNote: TEdit; 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 CKOrdNoKeyPress(Sender: TObject; var Key: Char); procedure Button4Click(Sender: TObject); private { Private declarations } FSMID, FCKOrdNo, FRKOrdID, FJYID: 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 frmFCSMCK: TfrmFCSMCK; implementation uses U_DataLink, U_RTFun, MMSystem, U_ZdyAttachment, U_ZdyAttachGYS, U_CKProductBCPKCListSel; {$R *.dfm} function TfrmFCSMCK.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; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); // PlaySound('未扫描申请单暂停发货.wav', 0, SND_FILENAME or SND_ASYNC); end; end; function TfrmFCSMCK.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_Cloth_CR where CRFlag=''出库'' and RKOrdID=' + quotedstr(trim(FRKOrdID))); Open; end; if not ADOQueryTemp.IsEmpty then raise Exception.Create('已扫描'); Result := True; except Result := false; PlaySound(PChar('wav\' + Exception(ExceptObject).Message + '.wav'), 0, SND_FILENAME or SND_ASYNC); end; end; function TfrmFCSMCK.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 JYID from WFB_MJJY where JYID=' + quotedstr(trim(FJYID))); Open; end; if ADOQueryTemp.IsEmpty then begin raise Exception.Create('条码错误暂停发货'); end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select RKOrdID from CK_Cloth_CR where CRFlag=''入库'' and JYID=' + quotedstr(trim(FJYID))); 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_Cloth_CR where CRFlag=''出库'' and JYID=' + quotedstr(trim(FJYID))); 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(pchar('wav\' + Exception(ExceptObject).Message + '.wav'), 0, SND_FILENAME or SND_ASYNC); end; end; function TfrmFCSMCK.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_Cloth_CR where CRFlag=''出库'' and JYID=' + quotedstr(FJYID)); Open; end; if ADOQueryTemp.IsEmpty then raise Exception.Create('无可撤销的数据!'); Result := True; except Result := false; PlaySound(PChar('wav\' + Exception(ExceptObject).Message + '.wav'), 0, SND_FILENAME or SND_ASYNC); end; end; function TfrmFCSMCK.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_Cloth_CR where CRFlag=''出库'' and CKOrdNo=' + quotedstr(FCKOrdNo)); Open; end; if ADOQueryTemp.IsEmpty then raise Exception.Create('无可撤销的数据'); Result := True; except Result := false; PlaySound(PChar('wav\' + Exception(ExceptObject).Message + '.wav'), 0, SND_FILENAME or SND_ASYNC); end; end; procedure TfrmFCSMCK.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_Cloth_CR Set '); sql.add(' CRTime=getdate(),CRType=''扫描出库'',CRFlag=''出库'' '); sql.add(',CKOrdNo=' + Quotedstr(FCKOrdNo)); sql.add(',RKOrdID=' + Quotedstr(FRKOrdID)); sql.add(',RKOrdID=' + Quotedstr(edtNote.Text)); sql.Add(' where exists(select JYID from CK_Cloth_CR X where CK_Cloth_CR.JYID=X.JYID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ') '); sql.Add('and CK_Cloth_CR.CRFlag=''待出库'' '); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('UPDATE CK_Cloth_KC Set '); sql.add(' KCValid=''N'' '); sql.Add(' where exists(select JYID from CK_Cloth_CR X where CK_Cloth_KC.JYID=X.JYID 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 JYID from CK_Cloth_CR X where WFB_MJJY.JYID=X.JYID 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; PlaySound('wav\出库失败.wav', 0, SND_FILENAME or SND_ASYNC); end; end; procedure TfrmFCSMCK.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_Cloth_CR Set '); sql.add(' CRTime=' + quotedstr(FormatDateTime('yyyy-MM-dd', CRTime.DateTime)) + ',CRType=' + quotedstr(CKType.Text) + ',CRFlag=''出库'' '); sql.add(',CKOrdNo=' + Quotedstr(FCKOrdNo)); sql.add(',RKOrdID=' + Quotedstr(FRKOrdID)); sql.Add(',CDDanwei= ' + Quotedstr(KHName.Text)); sql.Add(',CRNote= ' + Quotedstr(edtNote.Text)); sql.Add(' where CK_Cloth_CR.JYID=' + Quotedstr(Trim(FJYID))); sql.Add('and CK_Cloth_CR.CRFlag=''待出库'' '); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('UPDATE CK_Cloth_KC Set '); sql.add(' KCValid=''N'' '); sql.Add(' where CK_Cloth_KC.JYID=' + Quotedstr(Trim(FJYID))); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('UPDATE WFB_MJJY Set MJStr2=''已出库'' '); sql.Add(' where WFB_MJJY.JYID=' + Quotedstr(Trim(FJYID))); SQL.Add(' and WFB_MJJY.MJStr2=''已入库'' '); ExecSQL; end; ADOQueryCmd.Connection.CommitTrans; PlaySound('wav\正确.wav', 0, SND_FILENAME or SND_ASYNC); except ADOQueryCmd.Connection.RollbackTrans; PlaySound('wav\出库失败.wav', 0, SND_FILENAME or SND_ASYNC); end; end; procedure TfrmFCSMCK.SaveCKDataCX(); begin try ADOQueryCmd.Connection.BeginTrans; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update CK_Cloth_CR Set CRFlag=''待出库'',CRType='''',CRTime=NULL,CRNote='''',CKOrdNo='''' '); sql.Add(' where exists(select JYID from CK_Cloth_CR X where CK_Cloth_CR.JYID=X.JYID and X.CRFlag=''入库'' and X.RKOrdID=' + Quotedstr(FRKOrdID) + ') '); sql.Add(' and CRFlag=''出库'''); sql.Add(' UPdate CK_Cloth_KC Set KCValid=''Y'' '); sql.Add(' where exists(select JYID from CK_Cloth_CR X where CK_Cloth_KC.JYID=X.JYID 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 JYID from CK_Cloth_CR X where WFB_MJJY.JYID=X.JYID 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; PlaySound('wav\撤销出库失败.wav', 0, SND_FILENAME or SND_ASYNC); end; end; procedure TfrmFCSMCK.SaveCKDataJTMCX(); begin try ADOQueryCmd.Connection.BeginTrans; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update CK_Cloth_CR Set CRFlag=''待出库'',CRType='''',CRTime=NULL,CRNote='''',CKOrdNo='''' '); sql.Add(' where CK_Cloth_CR.JYID=' + Quotedstr(Trim(FJYID))); sql.Add(' and CRFlag=''出库'''); sql.Add(' UPdate CK_Cloth_KC Set KCValid=''Y'' '); sql.Add(' where CK_Cloth_KC.JYID=' + Quotedstr(Trim(FJYID))); sql.Add(' and KCValid=''N'' '); sql.Add(' Update WFB_MJJY Set MJStr2=''已入库'' '); sql.Add(' where WFB_MJJY.JYID=' + Quotedstr(Trim(FJYID))); 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(FJYID) + ' 出库单号:' + 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; PlaySound('wav\撤销出库失败.wav', 0, SND_FILENAME or SND_ASYNC); end; end; procedure TfrmFCSMCK.InitCKGrid(); begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select AA.*, B.OrderNo,B.MPRTCode,B.MPRTCodeName,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.RKOrdID'); sql.Add('from CK_Cloth_CR A where A.CRFlag=''出库'' and CKOrdNo=' + quotedstr(FCKOrdNo)); sql.Add('group by A.MainId,A.SubId,A.QtyUnit,A.CPType,A.ganghao,A.RKOrdID ) 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; SCreateCDS(ADOQueryTemp, CDS_MainSel); SInitCDSData(ADOQueryTemp, CDS_MainSel); end; procedure TfrmFCSMCK.FormClose(Sender: TObject; var Action: TCloseAction); begin inherited; Action := caFree; end; procedure TfrmFCSMCK.FormDestroy(Sender: TObject); begin inherited; frmFCSMCK := nil; end; procedure TfrmFCSMCK.FormShow(Sender: TObject); begin inherited; BaoID.SetFocus; ReadCxGrid('扫描出库', Tv3, '坯布仓库'); CRTime.DateTime := SGetServerDate(ADOQueryTemp); end; procedure TfrmFCSMCK.BaoIDKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin FSMID := TRIM(BaoID.Text); BaoID.Text := ''; FRKOrdID := ''; FJYID := ''; if edtIsSMTH.Text = '' then begin //扫描出库 //检测出库单 // if not JudgeSQD() then // exit; if Copy(FSMID, 1, 2) = 'RK' then begin //检测入库码单 FRKOrdID := FSMID; if JudgeRKD() then SaveCKData(); end else begin //检测卷条码 FJYID := FSMID; if JudgeJTM() then SaveCKDataJTM(); end; end else begin //扫描退回 if Copy(FSMID, 1, 2) = 'RK' then begin //检测入库码单 FRKOrdID := FSMID; if JudgeRKDCX() then SaveCKDataCX(); end else begin // application.MessageBox('条码错误', '提示信息', 0); //检测卷条码 FJYID := FSMID; if JudgeJTMCX() then SaveCKDataJTMCX(); end; end; InitCKGrid(); end; end; procedure TfrmFCSMCK.Button2Click(Sender: TObject); begin Close; WriteCxGrid('扫描出库', Tv3, '坯布仓库'); end; procedure TfrmFCSMCK.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 TfrmFCSMCK.Button3Click(Sender: TObject); begin if GetLSNo(ADOQueryTemp, FCKOrdNo, 'CK', 'CK_Cloth_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 TfrmFCSMCK.CKTypeChange(Sender: TObject); begin KHName.Text := ''; end; procedure TfrmFCSMCK.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 TfrmFCSMCK.CKOrdNoKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin FCKOrdNo := CKOrdNo.TEXT; InitCKGrid(); end; end; procedure TfrmFCSMCK.Button4Click(Sender: TObject); var MKey: Char; begin MKey := #13; 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('JYID').AsString); BaoIDKeyPress(BaoID, MKey); Sleep(200); end; Next; end; end; end; end; finally frmCKProductBCPKCListSel.Free; end; InitCKGrid(); end; end.