unit U_TJCKOutOKChk; //10 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxButtonEdit, cxCalendar, cxDropDownEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, StdCtrls, ExtCtrls, ComCtrls, ToolWin, DBClient, ADODB, cxCheckBox, cxPC, BtnEdit, cxGridDBTableView, cxGridCustomPopupMenu, cxGridPopupMenu, cxTextEdit; type TfrmTJCKOutOKChk = class(TForm) Panel1: TPanel; Label3: TLabel; OrderNo: TEdit; cxGrid2: TcxGrid; Tv2: TcxGridDBBandedTableView; cxGridDBBandedColumn1: TcxGridDBBandedColumn; cxGridDBBandedColumn2: TcxGridDBBandedColumn; Tv2Column1: TcxGridDBBandedColumn; v6DutyPerson: TcxGridDBBandedColumn; v6DutyFactoryName: TcxGridDBBandedColumn; v6DutyReason: TcxGridDBBandedColumn; v6Column4: TcxGridDBBandedColumn; v6Column5: TcxGridDBBandedColumn; v6Column6: TcxGridDBBandedColumn; v6ToFactoryName: TcxGridDBBandedColumn; v6Column7: TcxGridDBBandedColumn; cxGridLevel3: TcxGridLevel; v6Column15: TcxGridDBBandedColumn; v6Column16: TcxGridDBBandedColumn; v6Column17: TcxGridDBBandedColumn; v6Column18: TcxGridDBBandedColumn; ClientDataSet1: TClientDataSet; DataSource1: TDataSource; ADOQuery1: TADOQuery; ADOQueryTemp: TADOQuery; ADOQueryCmd: TADOQuery; Label1: TLabel; BegDate: TDateTimePicker; EndDate: TDateTimePicker; cxTabControl1: TcxTabControl; ScrollBox3: TScrollBox; Button8: TButton; Button9: TButton; Button10: TButton; cxGrid3: TcxGrid; Tv3: TcxGridDBTableView; cxGridDBColumn9: TcxGridDBColumn; v5Column2: TcxGridDBColumn; v5Column7: TcxGridDBColumn; cxGridDBColumn8: TcxGridDBColumn; v5Column3: TcxGridDBColumn; v5Column4: TcxGridDBColumn; v5Column5: TcxGridDBColumn; v5Column1: TcxGridDBColumn; v5Column9: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; Panel3: TPanel; Label16: TLabel; v5Column6: TcxGridDBColumn; Label18: TLabel; C_Code: TEdit; Label19: TLabel; C_CodeName: TEdit; v5Column8: TcxGridDBColumn; v6Column3: TcxGridDBBandedColumn; DataSource2: TDataSource; ClientDataSet2: TClientDataSet; DataSource3: TDataSource; ClientDataSet3: TClientDataSet; v6Column14: TcxGridDBBandedColumn; v6Column19: TcxGridDBBandedColumn; ADOQueryMain: TADOQuery; cxGridPopupMenu1: TcxGridPopupMenu; cxGridPopupMenu3: TcxGridPopupMenu; cxGridPopupMenu2: TcxGridPopupMenu; Panel5: TPanel; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; cxGridDBColumn1: TcxGridDBColumn; cxGridDBColumn2: TcxGridDBColumn; cxGridDBColumn7: TcxGridDBColumn; cxGridDBColumn3: TcxGridDBColumn; cxGridDBColumn4: TcxGridDBColumn; cxGridDBColumn10: TcxGridDBColumn; cxGridDBColumn11: TcxGridDBColumn; cxGridLevel5: TcxGridLevel; Tv1Column1: TcxGridDBColumn; Tv1Column2: TcxGridDBColumn; Tv1Column3: TcxGridDBColumn; v1Column1: TcxGridDBColumn; v1Column2: TcxGridDBColumn; v1Column3: TcxGridDBColumn; Label5: TLabel; FromPrice: TEdit; Label4: TLabel; FromConTypeOther: TBtnEditA; Label6: TLabel; ToFactoryName: TBtnEditA; Label7: TLabel; Label8: TLabel; ToPrice: TEdit; Label9: TLabel; ToConTypeOther: TBtnEditA; Label10: TLabel; Button1: TButton; v1Column4: TcxGridDBColumn; FromFactoryName: TBtnEditA; Label2: TLabel; Label11: TLabel; FromPSName: TComboBox; Label12: TLabel; ToPSName: TComboBox; v3Column1: TcxGridDBColumn; Button2: TButton; Button3: TButton; Label13: TLabel; FromSpec: TEdit; Label14: TLabel; ToSpec: TEdit; v1Column5: TcxGridDBColumn; v2Column1: TcxGridDBBandedColumn; v2Column2: TcxGridDBBandedColumn; procedure FormDestroy(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBRafreshClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure cxTabControl1Change(Sender: TObject); procedure Button10Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure TBFindClick(Sender: TObject); procedure Button9Click(Sender: TObject); procedure FromFactoryNameBtnClick(Sender: TObject); procedure ToFactoryNameBtnClick(Sender: TObject); procedure FromConTypeOtherBtnClick(Sender: TObject); procedure ToConTypeOtherBtnClick(Sender: TObject); procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); procedure Tv2CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure OrderNoChange(Sender: TObject); procedure OrderNoKeyPress(Sender: TObject; var Key: Char); private { Private declarations } procedure InitGrid(); function SaveData():Boolean; function SaveConData(FONID:string):Boolean; function SaveMDData(FONID,FOrdMainId,FOrdSubId,FPSID,FPFID,FConMainid,FConSubId:string):Boolean; public { Public declarations } end; var frmTJCKOutOKChk: TfrmTJCKOutOKChk; implementation uses U_DataLink,U_RTFun, U_GYSList,U_ZDYHelp, U_ModuleNote; {$R *.dfm} procedure TfrmTJCKOutOKChk.FormDestroy(Sender: TObject); begin frmTJCKOutOKChk:=nil; end; procedure TfrmTJCKOutOKChk.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; procedure TfrmTJCKOutOKChk.TBRafreshClick(Sender: TObject); begin InitGrid(); end; procedure TfrmTJCKOutOKChk.InitGrid(); begin with ADOQueryMain do begin Filtered:=False; Close; sql.Clear; sql.Add('select B.OrderNo,B.MPRTCode,B.MPRTCodeName,C.PRTHX,C.PRTColorNo,D.PSName,B.Mainid,C.SubId,A.*'); sql.Add(',MDNOStr=dbo.F_Get_Order_SubStr(A.PFID,''MDNOStr'')'); sql.Add(' from JYOrder_PCS_Sub A'); sql.Add(' inner join JYOrder_Main B on A.Mainid=B.MainId'); sql.Add(' left join JYOrder_Sub C on A.SubId=C.SubId'); SQL.Add(' inner join JYOrder_Process D on A.PSID=D.PSID'); sql.Add(' where isnull(A.CKName,'''')=''调节仓库'' '); if cxTabControl1.TabIndex=0 then begin sql.Add(' and A.TJOutFlag=0'); end else if cxTabControl1.TabIndex=1 then begin sql.Add(' and A.TJOutFlag=1'); end; if cxTabControl1.TabIndex<>0 then begin sql.Add(' and A.FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+''''); sql.Add(' and A.FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+''''); end; Open; end; SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); end; procedure TfrmTJCKOutOKChk.FormShow(Sender: TObject); begin {ReadCxBandedGrid('Tv6',Tv6,'调节仓库'); ReadCxBandedGrid('Tv2',Tv2,'调节仓库'); ReadCxBandedGrid('Tv3',Tv3,'调节仓库'); ReadCxGrid('Tv5',Tv5,'调节仓库'); } EndDate.Date:=SGetServerDate(ADOQuery1); BegDate.Date:=EndDate.Date-30; cxTabControl1.TabIndex:=0; end; procedure TfrmTJCKOutOKChk.TBCloseClick(Sender: TObject); begin close; end; procedure TfrmTJCKOutOKChk.cxTabControl1Change(Sender: TObject); begin InitGrid(); end; procedure TfrmTJCKOutOKChk.Button10Click(Sender: TObject); begin close; end; procedure TfrmTJCKOutOKChk.Button8Click(Sender: TObject); begin InitGrid(); end; procedure TfrmTJCKOutOKChk.TBFindClick(Sender: TObject); begin if ADOQueryMain.Active=False then Exit; SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2)); SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); end; procedure TfrmTJCKOutOKChk.Button9Click(Sender: TObject); begin if ADOQueryMain.Active=False then Exit; SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2)); SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); end; procedure TfrmTJCKOutOKChk.FromFactoryNameBtnClick(Sender: TObject); begin try frmGYSList:=TfrmGYSList.Create(Application); with frmGYSList do begin if ShowModal=1 then begin FromFactoryName.TxtCode:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString); FromFactoryName.Text:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString); end; end; finally frmGYSList.Free; end; end; procedure TfrmTJCKOutOKChk.ToFactoryNameBtnClick(Sender: TObject); begin try frmGYSList:=TfrmGYSList.Create(Application); with frmGYSList do begin if ShowModal=1 then begin ToFactoryName.TxtCode:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString); ToFactoryName.Text:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString); end; end; finally frmGYSList.Free; end; end; procedure TfrmTJCKOutOKChk.FromConTypeOtherBtnClick(Sender: TObject); begin try frmZDYHelp:=TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag:='ConTypeOther'; flagname:='采购加工合同类型'; if ShowModal=1 then begin FromConTypeOther.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmTJCKOutOKChk.ToConTypeOtherBtnClick(Sender: TObject); begin try frmZDYHelp:=TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag:='ConTypeOther'; flagname:='采购加工合同类型'; if ShowModal=1 then begin ToConTypeOther.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmTJCKOutOKChk.Tv1FocusedRecordChanged( Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); var fsj:string; begin fsj:=' select Code=PSName,Name=PSName from JYOrder_Process where MainId='''+Trim(ClientDataSet1.fieldbyname('MainId').AsString)+'''' +' order by PSXH'; //SInitComBoxBySql(ADOQueryTemp,FromPSName,False,fsj); SInitComBoxBySql(ADOQueryTemp,ToPSName,False,fsj); with ADOQuery1 do begin Close; sql.Clear; sql.Add('select AM.CKID,AM.CKPS,AM.CKQty,AM.SJCKPS,AM.SJCKQty,JM.OrderNo, A.*,B.PSName OrdPSName, '); sql.Add(' JS.PRTHX,JS.PRTColor,JS.PRTColorNo,D.C_Code,D.C_CodeName,ClotheType10=A.ClotheType,'); sql.Add(' JSKCPS=A.RKPS-A.CKPS,'); sql.Add(' JSKCQty=A.RKQty-A.CKQty'); sql.Add(' from JYOrder_Main_MD_Out AM'); sql.Add(' inner join JYOrder_Main_MD A on AM.MDID=A.MDID'); sql.Add(' inner join JYOrder_Main JM on A.OrdMainId=JM.MainId'); sql.Add(' left join JYOrder_Sub JS on A.OrdSubId=JS.SubId'); sql.Add(' inner join JYOrder_Process B on A.PSID=B.PSID'); sql.Add(' inner join Contract_Main C on A.ConMainid=C.MainID'); sql.Add(' inner join Contract_Sub D on A.ConSubid=D.SubID'); if ClientDataSet1.IsEmpty=False then SQL.Add(' where AM.PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+'''') else sql.Add(' where 1<>1'); Open; end; SCreateCDS20(ADOQuery1,ClientDataSet2); SInitCDSData20(ADOQuery1,ClientDataSet2); SClearData(Panel5,99); if cxTabControl1.TabIndex=0 then begin FromFactoryName.Text:=Trim(ClientDataSet1.fieldbyname('FactoryName').AsString); FromFactoryName.TxtCode:=Trim(ClientDataSet1.fieldbyname('FactoryNo').AsString); FromPSName.Text:=Trim(ClientDataSet1.fieldbyname('PSName').AsString); end else begin with ADOQuery1 do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_OutNote where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); Open; end; SCSHDataNew(ADOQuery1,Panel5,99); FromPSName.Text:=Trim(ADOQuery1.fieldbyname('FromPSName').AsString); ToPSName.Text:=Trim(ADOQuery1.fieldbyname('ToPSName').AsString); end; with ADOQuery1 do begin Close; sql.Clear; sql.Add('select * from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId '); if ClientDataSet2.IsEmpty=False then sql.Add(' where A.ConNo like '''+'%'+Trim(ClientDataSet2.fieldbyname('OrderNo').AsString)+'%'+'''') else sql.Add(' where 1<>1'); Open; end; SCreateCDS20(ADOQuery1,ClientDataSet3); SInitCDSData20(ADOQuery1,ClientDataSet3); end; procedure TfrmTJCKOutOKChk.Tv2CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin with ADOQuery1 do begin Close; sql.Clear; sql.Add('select * from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId '); if ClientDataSet2.IsEmpty=False then sql.Add(' where A.ConNo like '''+'%'+Trim(ClientDataSet2.fieldbyname('OrderNo').AsString)+'%'+'''') else sql.Add(' where 1<>1'); Open; end; SCreateCDS20(ADOQuery1,ClientDataSet3); SInitCDSData20(ADOQuery1,ClientDataSet3); end; procedure TfrmTJCKOutOKChk.Button1Click(Sender: TObject); Var FReal:Double; FInt:Integer; begin if Trim(FromFactoryName.Text)='' then begin Application.MessageBox('本道供应商不能为空!','提示',0); Exit; end; if Trim(FromPrice.Text)='' then begin Application.MessageBox('本道价格不能为空!','提示',0); Exit; end; if Trim(FromSpec.Text)='' then begin Application.MessageBox('本道规格型号不能为空!','提示',0); Exit; end; if TryStrToFloat(FromPrice.Text,FReal)=False then begin Application.MessageBox('本道价格非法数字!','提示',0); Exit; end; if Trim(FromConTypeOther.Text)='' then begin Application.MessageBox('本道合同类型不能为空!','提示',0); Exit; end; if (Trim(ToFactoryName.Text)+Trim(ToConTypeOther.Text))<>'' then begin if Trim(ToFactoryName.Text)='' then begin Application.MessageBox('下道供应商不能为空!','提示',0); Exit; end; if Trim(ToConTypeOther.Text)='' then begin Application.MessageBox('下道合同类型不能为空!','提示',0); Exit; end; if Trim(ToPSName.Text)='' then begin Application.MessageBox('下道工序名称不能为空!','提示',0); Exit; end; if Trim(ToSpec.Text)='' then begin Application.MessageBox('下道规格型号不能为空!','提示',0); Exit; end; end; if Trim(ToPrice.Text)<>'' then begin if TryStrToFloat(ToPrice.Text,FReal)=False then begin Application.MessageBox('下道价格非法数字!','提示',0); Exit; end; end; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; if SaveData() then begin Application.MessageBox('操作成功!','提示',0); Exit; end; end; function TfrmTJCKOutOKChk.SaveData():Boolean; var maxno,ONID:string; begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_OutNote where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin ONID:=Trim(ADOQueryTemp.fieldbyname('ONID').AsString); end else begin ONID:=''; end; try ADOQueryCmd.Connection.BeginTrans; if Trim(ONID)='' then begin if GetLSNo(ADOQueryCmd,maxno,'ON','JYOrder_Main_MD_OutNote',3,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox('取调节仓库出库流水号失败!!','提示',0); Exit; end; end else begin maxno:=Trim(ONID); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_OutNote where ONID='''+Trim(ONID)+''''); Open; end; with ADOQueryCmd do begin if Trim(ONID)='' then begin Append; FieldByName('Filler').Value:=Trim(DName); end else begin Edit; FieldByName('Editer').Value:=Trim(DName); FieldByName('EditTIme').Value:=SGetServerDateTime(ADOQuery1); end; FieldByName('PFID').Value:=Trim(ClientDataSet1.fieldbyname('PFID').AsString); FieldByName('ONID').Value:=Trim(maxno); FieldByName('FromFactoryName').Value:=Trim(FromFactoryName.Text); FieldByName('FromFactoryNo').Value:=Trim(FromFactoryName.TxtCode); FieldByName('ToFactoryName').Value:=Trim(ToFactoryName.Text); FieldByName('ToFactoryNo').Value:=Trim(FromFactoryName.TxtCode); FieldByName('FromConTypeOther').Value:=Trim(FromConTypeOther.Text); FieldByName('ToConTypeOther').Value:=Trim(ToConTypeOther.Text); FieldByName('FromSpec').Value:=Trim(FromSpec.Text); FieldByName('ToSpec').Value:=Trim(ToSpec.Text); FieldByName('FromPSName').Value:=Trim(FromPSName.Text); FieldByName('ToPSName').Value:=Trim(ToPSName.Text); if Trim(FromPrice.Text)<>'' then begin FieldByName('FromPrice').Value:=Trim(FromPrice.Text); end else begin FieldByName('FromPrice').Value:='0'; end; if Trim(ToPrice.Text)<>'' then begin FieldByName('ToPrice').Value:=Trim(ToPrice.Text); end else begin FieldByName('ToPrice').Value:='0'; end; Post; end; SaveConData(maxno); with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_PCS_Sub Set TJOutFlag=1'); sql.Add(' where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); ExecSQL; end; {with ClientDataSet2 do begin First; while not Eof do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD_Out Set '); if Trim(ClientDataSet2.fieldbyname('SJCKPS').AsString)<>'' then begin sql.Add(' SJCKPS='+ClientDataSet2.fieldbyname('SJCKPS').AsString); end else begin sql.Add(' SJCKPS=0'); end; if Trim(ClientDataSet2.fieldbyname('SJCKQty').AsString)<>'' then begin sql.Add(' ,SJCKQty='+ClientDataSet2.fieldbyname('SJCKQty').AsString); end else begin sql.Add(' ,SJCKQty=0'); end; SQL.Add(' where CKID='''+Trim(ClientDataSet2.fieldbyname('CKID').AsString)+''''); ExecSQL; end; Next; end; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set CKPS='); sql.Add('(select isnull(sum(SJCKPS),0) from JYOrder_Main_MD_Out A where A.MDID=JYOrder_Main_MD.MDID) '); sql.Add(',CKQty=(select isnull(sum(SJCKQty),0) from JYOrder_Main_MD_Out A where A.MDID=JYOrder_Main_MD.MDID) '); sql.Add(' where MDID='''+Trim(ClientDataSet2.fieldbyname('MDID').AsString)+''''); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_PCS_Sub Set TJOutFlag=1'); sql.Add(' where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); ExecSQL; end; if Trim(ClientDataSet1.fieldbyname('PFTPUnit').AsString)<>'M' then begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_PCS_Sub Set WCMQty='); sql.Add('(select isnull(sum(Qty),0) from JYOrder_Main_MD A where A.PFID=JYOrder_PCS_Sub.PFID and isnull(CKName,'''')='''')*'); sql.Add('(select KgZM from JYOrder_Process A where A.PSID=JYOrder_PCS_Sub.PSID)'); sql.Add(' where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); ExecSQL; end; end else begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_PCS_Sub Set WCMQty='); sql.Add('(select isnull(sum(Qty),0) from JYOrder_Main_MD A where A.PFID=JYOrder_PCS_Sub.PFID and isnull(CKName,'''')='''')'); sql.Add(' where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); ExecSQL; end; end; } if cxTabControl1.TabIndex=0 then ClientDataSet1.Delete; ADOQueryCmd.Connection.CommitTrans; //Application.MessageBox('保存成功!','提示',0); Result:=True; Exit; except ADOQueryCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox('保存异常!','提示',0); end; end; function TfrmTJCKOutOKChk.SaveConData(FONID:string):Boolean; var maxno,maxsubno,MainID,SubId,PSName:string; begin Result:=False; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Contract_Main where ONID='''+Trim(FONID)+''''); sql.Add(' and ConType='''+Trim(ClientDataSet1.fieldbyname('PSName').AsString)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin MainID:=Trim(ADOQueryTemp.fieldbyname('MainID').AsString); end else begin MainID:=''; end; if Trim(MainID)='' then begin if GetLSNo(ADOQueryCmd,maxno,'NM','Contract_Main',3,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox('取加工采购合同流水号失败!!','提示',0); Exit; end; end else begin maxno:=Trim(MainID); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from Contract_Main where MainId='''+Trim(MainID)+''''); Open; end; with ADOQueryCmd do begin if Trim(MainID)='' then begin Append; FieldByName('Filler').Value:=Trim(DName); end else begin Edit; FieldByName('Editer').Value:=Trim(DName); FieldByName('EditTIme').Value:=SGetServerDateTime(ADOQuery1); end; FieldByName('ONID').Value:=Trim(FONID); FieldByName('MainID').Value:=Trim(maxno); FieldByName('ConNo').Value:=Trim(ClientDataSet1.fieldbyname('OrderNo').AsString); FieldByName('FactoryNoName').Value:=Trim(FromFactoryName.Text); FieldByName('FactoryNo').Value:=Trim(FromFactoryName.TxtCode); FieldByName('ConTypeOther').Value:=Trim(FromConTypeOther.Text); FieldByName('ConType').Value:=Trim(ClientDataSet1.fieldbyname('PSName').AsString); Post; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Contract_Sub where MainId='''+Trim(maxno)+''''); Open; end; if ADOQueryTemp.IsEmpty then begin SubId:=''; end else begin SubId:=Trim(ADOQueryTemp.fieldbyname('SubId').AsString); end; if Trim(SubId)='' then begin if GetLSNo(ADOQueryCmd,maxsubno,'NS','Contract_Sub',3,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox('取加工采购合同子流水号失败!!','提示',0); Exit; end; end else begin maxsubno:=Trim(SubId); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from Contract_Sub where SubId='''+Trim(SubId)+''''); Open; end; with ADOQueryCmd do begin if Trim(SubId)='' then begin Append; end else begin Edit; end; FieldByName('MainId').Value:=Trim(maxno); FieldByName('SubId').Value:=Trim(maxsubno); FieldByName('C_Code').Value:=ClientDataSet1.fieldbyname('MPRTCode').Value; FieldByName('C_CodeName').Value:=ClientDataSet1.fieldbyname('MPRTCodeName').Value; FieldByName('PS').Value:=ClientDataSet1.fieldbyname('PFTPPS').Value; FieldByName('C_Qty').Value:=ClientDataSet1.fieldbyname('PFTPQty').Value; FieldByName('C_Unit').Value:=ClientDataSet2.fieldbyname('RKQtyUnit').Value; FieldByName('ConQty').Value:=ClientDataSet1.fieldbyname('PFTPQty').Value; FieldByName('ConUnit').Value:=ClientDataSet2.fieldbyname('RKQtyUnit').Value; FieldByName('C_Spec').Value:=Trim(FromSpec.Text); if Trim(FromPrice.Text)='' then begin FieldByName('Price').Value:=0; FieldByName('ConPrice').Value:=0; end else begin FieldByName('Price').Value:=Trim(FromPrice.Text); FieldByName('ConPrice').Value:=Trim(FromPrice.Text); end; Post; end; //更新码单合同编号 with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('Update JYOrder_Main_MD Set'); sql.Add('ConMainId='''+Trim(maxno)+''''); sql.Add(',ConSubId='''+Trim(maxsubno)+''''); sql.Add(' where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); ExecSQL; end; //SaveMDData(); if Trim(ToFactoryName.Text)<>'' then begin PSName:=Trim(ToPSName.Text); with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Contract_Main where ONID='''+Trim(FONID)+''''); sql.Add(' and ConType='''+Trim(PSName)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin MainID:=Trim(ADOQueryTemp.fieldbyname('MainID').AsString); end else begin MainID:=''; end; if Trim(MainID)='' then begin if GetLSNo(ADOQueryCmd,maxno,'JM','Contract_Main',3,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox('取加工采购合同流水号失败!!','提示',0); Exit; end; end else begin maxno:=Trim(MainID); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from Contract_Main where MainId='''+Trim(MainID)+''''); Open; end; with ADOQueryCmd do begin if Trim(MainID)='' then begin Append; FieldByName('Filler').Value:=Trim(DName); end else begin Edit; FieldByName('Editer').Value:=Trim(DName); FieldByName('EditTIme').Value:=SGetServerDateTime(ADOQuery1); end; FieldByName('ONID').Value:=Trim(FONID); FieldByName('ConNo').Value:=Trim(ClientDataSet1.fieldbyname('OrderNo').AsString); FieldByName('MainID').Value:=Trim(maxno); FieldByName('FactoryNoName').Value:=Trim(ToFactoryName.Text); FieldByName('FactoryNo').Value:=Trim(ToFactoryName.TxtCode); FieldByName('ConTypeOther').Value:=Trim(ToConTypeOther.Text); FieldByName('ConType').Value:=Trim(PSName); Post; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Contract_Sub where MainId='''+Trim(maxno)+''''); Open; end; if ADOQueryTemp.IsEmpty then begin SubId:=''; end else begin SubId:=Trim(ADOQueryTemp.fieldbyname('SubId').AsString); end; if Trim(SubId)='' then begin if GetLSNo(ADOQueryCmd,maxsubno,'JS','Contract_Sub',3,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox('取加工采购合同子流水号失败!!','提示',0); Exit; end; end else begin maxsubno:=Trim(SubId); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from Contract_Sub where SubId='''+Trim(SubId)+''''); Open; end; with ADOQueryCmd do begin if Trim(SubId)='' then begin Append; end else begin Edit; end; FieldByName('MainId').Value:=Trim(maxno); FieldByName('SubId').Value:=Trim(maxsubno); FieldByName('C_Code').Value:=ClientDataSet1.fieldbyname('MPRTCode').Value; FieldByName('C_CodeName').Value:=ClientDataSet1.fieldbyname('MPRTCodeName').Value; FieldByName('PS').Value:=ClientDataSet1.fieldbyname('PFTPPS').Value; FieldByName('C_Qty').Value:=ClientDataSet1.fieldbyname('PFTPQty').Value; FieldByName('C_Unit').Value:=ClientDataSet2.fieldbyname('RKQtyUnit').Value; FieldByName('ConQty').Value:=ClientDataSet1.fieldbyname('PFTPQty').Value; FieldByName('ConUnit').Value:=ClientDataSet2.fieldbyname('RKQtyUnit').Value; FieldByName('C_Spec').Value:=Trim(FromSpec.Text); if Trim(FromPrice.Text)='' then begin FieldByName('Price').Value:=0; FieldByName('ConPrice').Value:=0; end else begin FieldByName('Price').Value:=Trim(FromPrice.Text); FieldByName('ConPrice').Value:=Trim(FromPrice.Text); end; Post; end; end; Result:=True; end; function TfrmTJCKOutOKChk.SaveMDData(FONID,FOrdMainId,FOrdSubId,FPSID,FPFID,FConMainid,FConSubId:string):Boolean; var maxno,MDID:string; begin end; procedure TfrmTJCKOutOKChk.Button2Click(Sender: TObject); begin try frmModuleNote:=TfrmModuleNote.Create(Application); with frmModuleNote do begin flag:='调节仓库出库管理'; if ShowModal=1 then begin end; end; finally frmModuleNote.Free; end; end; procedure TfrmTJCKOutOKChk.Button3Click(Sender: TObject); var BDInt,CPInt,JYInt,Fint:Integer; begin if cxTabControl1.TabIndex<>1 then Exit; if ClientDataSet1.IsEmpty then Exit; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from WFB_MJJY A'); sql.Add(' inner join JYOrder_Main_MD B on A.APID=B.MDID'); sql.Add(' inner join JYOrder_Main_MD_OutNote C on B.ONID=C.ONID'); SQL.Add(' where C.PFID='''+Trim(ClientDataSet1.fieldbyName('PFID').AsString)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin Application.MessageBox('已产生打包数据,不能撤销!','提示',0); Exit; end; //判断工序是否允许自动插入码单 with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_PCS_Sub A'); sql.Add(' inner join JYorder_Process B on A.PSID=B.PSID'); sql.Add(' where A.PFID='''+Trim(ClientDataSet1.fieldbyName('PFID').AsString)+''''); Open; end; BDInt:=ADOQueryTemp.fieldbyname('PSXH').AsInteger; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select isnull(PSXH,-1) PSXH from JYOrder_Process where PSName=''成品'' '); sql.Add(' and MainId='''+Trim(ClientDataSet1.fieldbyname('MainId').AsString)+''''); Open; end; CPInt:=ADOQueryTemp.fieldbyname('PSXH').AsInteger; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select isnull(PSXH,-1) PSXH from JYOrder_Process where PSName=''检验包装'' '); sql.Add(' and MainId='''+Trim(ClientDataSet1.fieldbyname('MainId').AsString)+''''); Open; end; JYInt:=ADOQueryTemp.fieldbyname('PSXH').AsInteger; if BDInt-1 then begin if BDInt+1>=CPInt then begin Fint:=99; end; end else begin if BDInt+1=JYInt then begin Fint:=99; end; end; end else begin Fint:=99; end; //判断工序是否允许自动插入码单 //成品调入码单不能删除 if Fint=99 then begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add(' select * from JYOrder_Main_MD '); SQL.Add(' where PFID='''+Trim(ClientDataSet1.fieldbyName('PFID').AsString)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin Application.MessageBox('已录入码单,不能撤销!','提示',0); Exit; end; end; if Application.MessageBox('确定要执行撤销操作吗?','提示',32+4)<>IDYES then exit; try ADOQueryCmd.Connection.BeginTrans; with ADOQueryCmd do begin Close; sql.Clear; //删除自动生成的合同 sql.Add('delete Contract_Main where ONID in('); sql.Add(' select ONID from JYOrder_Main_MD_OutNote where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''')'); sql.Add(' and isnull(ONID,'''')<>'''' '); SQL.Add(' delete Contract_Sub where not exists(select * from Contract_Main A where A.Mainid=Contract_Sub.MainId)'); //更新安排状态 sql.Add(' Update JYOrder_PCS_Sub Set TJOutFlag=0 where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); //删除调节仓库调出备注 sql.Add(' Delete JYOrder_Main_MD_OutNote where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); //取消码单合同 sql.Add(' Update JYOrder_Main_MD Set ConMainId=Null,ConSubId=Null where PFID='''+Trim(ClientDataSet1.fieldbyname('PFID').AsString)+''''); ExecSQL; end; ADOQueryCmd.Connection.CommitTrans; ClientDataSet1.Delete; Application.MessageBox('操作成功!','提示',0); Exit; except ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('撤销异常!','提示',0); end; end; procedure TfrmTJCKOutOKChk.OrderNoChange(Sender: TObject); begin Button9.Click; end; procedure TfrmTJCKOutOKChk.OrderNoKeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin if Length(Trim(OrderNo.Text))<3 then Exit; with ADOQueryMain do begin Filtered:=False; Close; sql.Clear; sql.Add('select B.OrderNo,B.MPRTCode,B.MPRTCodeName,C.PRTHX,C.PRTColorNo,D.PSName,B.Mainid,C.SubId,A.*'); sql.Add(',MDNOStr=dbo.F_Get_Order_SubStr(A.PFID,''MDNOStr'')'); sql.Add(' from JYOrder_PCS_Sub A'); sql.Add(' inner join JYOrder_Main B on A.Mainid=B.MainId'); sql.Add(' left join JYOrder_Sub C on A.SubId=C.SubId'); SQL.Add(' inner join JYOrder_Process D on A.PSID=D.PSID'); sql.Add(' where isnull(A.CKName,'''')=''调节仓库'' '); if cxTabControl1.TabIndex=0 then begin sql.Add(' and A.TJOutFlag=0'); end else if cxTabControl1.TabIndex=1 then begin sql.Add(' and A.TJOutFlag=1'); end; sql.Add(' and B.OrderNo like '''+'%'+Trim(OrderNo.Text)+'%'+''''); Open; end; SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); end; end; end.