unit U_MDChkFLView; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxButtonEdit, cxDropDownEdit, cxSplitter, cxCheckBox, cxCalendar, Menus, cxGridCustomPopupMenu, cxGridPopupMenu, DBClient, ADODB, cxPC, cxTextEdit; type TfrmMDChkFLView = class(TForm) ToolBar1: TToolBar; TBRafresh: TToolButton; TBFind: TToolButton; ToolButton5: TToolButton; ToolButton6: TToolButton; TBExport: TToolButton; ToolButton2: TToolButton; TBClose: TToolButton; Panel1: TPanel; Label2: TLabel; Label5: TLabel; BegDate: TDateTimePicker; EndDate: TDateTimePicker; orderNo: TEdit; Panel2: TPanel; cxGrid2: TcxGrid; Tv2: TcxGridDBTableView; cxGridDBColumn29: TcxGridDBColumn; v5Column6: TcxGridDBColumn; v5Column2: TcxGridDBColumn; v5Column7: TcxGridDBColumn; v5Column3: TcxGridDBColumn; v5Column4: TcxGridDBColumn; v5Column5: TcxGridDBColumn; v5Column10: TcxGridDBColumn; v5Column1: TcxGridDBColumn; v5Column9: TcxGridDBColumn; v77Column1: TcxGridDBColumn; cxGridLevel4: TcxGridLevel; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; v1Column7: TcxGridDBColumn; v1GenDan: TcxGridDBColumn; v1SOrddefstr1: TcxGridDBColumn; V1OrderNo: TcxGridDBColumn; cxGridDBColumn28: TcxGridDBColumn; v1Column3: TcxGridDBColumn; v1PRTOrderQty: TcxGridDBColumn; v1Column5: TcxGridDBColumn; v1FactoryName: TcxGridDBColumn; v1ToFactoryName: TcxGridDBColumn; cxGrid1Level1: TcxGridLevel; cxSplitter1: TcxSplitter; cxSplitter2: TcxSplitter; PopupMenu1: TPopupMenu; N1: TMenuItem; v72Column1: TcxGridDBColumn; v72Column2: TcxGridDBColumn; v72Column3: TcxGridDBColumn; v72Column4: TcxGridDBColumn; v72Column5: TcxGridDBColumn; v72Column6: TcxGridDBColumn; v72Column7: TcxGridDBColumn; v72Column8: TcxGridDBColumn; v72Column9: TcxGridDBColumn; Label7: TLabel; FactoryName: TEdit; Panel3: TPanel; Label11: TLabel; PS: TEdit; Label12: TLabel; Qty: TEdit; Label13: TLabel; Money: TEdit; DataSource3: TDataSource; ClientDataSet3: TClientDataSet; cxGridPopupMenu3: TcxGridPopupMenu; DataSource1: TDataSource; ClientDataSet1: TClientDataSet; cxGridPopupMenu1: TcxGridPopupMenu; DataSource2: TDataSource; ClientDataSet2: TClientDataSet; cxGridPopupMenu2: TcxGridPopupMenu; ADOQueryMain: TADOQuery; ADOQueryCmd: TADOQuery; ADOQueryTemp: TADOQuery; ADOQuery1: TADOQuery; Panel5: TPanel; cxGrid3: TcxGrid; Tv3: TcxGridDBTableView; v3Column14: TcxGridDBColumn; v3Column20: TcxGridDBColumn; v3Column1: TcxGridDBColumn; cxGridDBColumn2: TcxGridDBColumn; v3Column12: TcxGridDBColumn; cxGridDBColumn11: TcxGridDBColumn; cxGridDBColumn14: TcxGridDBColumn; v3Column17: TcxGridDBColumn; v3Column18: TcxGridDBColumn; v3Column16: TcxGridDBColumn; v3Column2: TcxGridDBColumn; cxGridDBColumn12: TcxGridDBColumn; v3Column19: TcxGridDBColumn; Tv3Column1: TcxGridDBColumn; v3Column3: TcxGridDBColumn; cxGridDBColumn3: TcxGridDBColumn; cxGridDBColumn7: TcxGridDBColumn; v3Column4: TcxGridDBColumn; v3Column5: TcxGridDBColumn; Tv3Column2: TcxGridDBColumn; Tv3Column3: TcxGridDBColumn; v3Column6: TcxGridDBColumn; v3Column7: TcxGridDBColumn; v3Column8: TcxGridDBColumn; v3Column9: TcxGridDBColumn; v3Column10: TcxGridDBColumn; v3Column11: TcxGridDBColumn; v3Column15: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; cxTabControl1: TcxTabControl; Panel4: TPanel; Label6: TLabel; Label4: TLabel; Label8: TLabel; Label9: TLabel; Label3: TLabel; Label10: TLabel; Panel10: TPanel; Image2: TImage; MDNO: TEdit; MDType: TComboBox; PSName: TComboBox; ComboBox1: TComboBox; ComboBox2: TComboBox; ComboBox3: TComboBox; Edit1: TEdit; Button1: TButton; N3: TMenuItem; v1Column1: TcxGridDBColumn; ToolButton1: TToolButton; v3Column13: TcxGridDBColumn; v3Column21: TcxGridDBColumn; v3Column22: TcxGridDBColumn; v3Column23: TcxGridDBColumn; v1PSName: TcxGridDBColumn; v3Column24: TcxGridDBColumn; ToolButton3: TToolButton; cxTabControl2: TcxTabControl; ToolButton4: TToolButton; ToolButton7: TToolButton; ComboBox4: TComboBox; v1Column2: TcxGridDBColumn; Button2: TButton; v1Column4: TcxGridDBColumn; ToolButton8: TToolButton; Panel6: TPanel; Button3: TButton; Button4: TButton; ToolButton9: TToolButton; v1Column6: TcxGridDBColumn; v1Column8: TcxGridDBColumn; v1Column9: TcxGridDBColumn; v1Column10: TcxGridDBColumn; v1Column11: TcxGridDBColumn; v1Column12: TcxGridDBColumn; v1Column13: TcxGridDBColumn; v1Column14: TcxGridDBColumn; v1Column15: TcxGridDBColumn; ToolButton10: TToolButton; v1Column16: TcxGridDBColumn; v1Column17: TcxGridDBColumn; CheckBox1: TCheckBox; v1Column18: TcxGridDBColumn; procedure FormDestroy(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBCloseClick(Sender: TObject); procedure Image2Click(Sender: TObject); procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure N1Click(Sender: TObject); procedure ToolButton5Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBRafreshClick(Sender: TObject); procedure V1OrderNoPropertiesEditValueChanged(Sender: TObject); procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure ToolButton1Click(Sender: TObject); procedure cxTabControl1Change(Sender: TObject); procedure MenuItem1Click(Sender: TObject); procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure v1Column7PropertiesEditValueChanged(Sender: TObject); procedure v1Column1PropertiesEditValueChanged(Sender: TObject); procedure v1FactoryNamePropertiesEditValueChanged(Sender: TObject); procedure v1PSNamePropertiesEditValueChanged(Sender: TObject); procedure N3Click(Sender: TObject); procedure v3Column14PropertiesEditValueChanged(Sender: TObject); procedure ToolButton6Click(Sender: TObject); procedure TBExportClick(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); procedure ToolButton7Click(Sender: TObject); procedure cxTabControl2Change(Sender: TObject); procedure v1ToFactoryNamePropertiesEditValueChanged(Sender: TObject); procedure v72Column2PropertiesEditValueChanged(Sender: TObject); procedure Button2Click(Sender: TObject); procedure ToolButton8Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); procedure TBFindClick(Sender: TObject); procedure orderNoChange(Sender: TObject); procedure FactoryNameChange(Sender: TObject); procedure ToolButton9Click(Sender: TObject); procedure ToolButton10Click(Sender: TObject); procedure v1Column4PropertiesEditValueChanged(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure orderNoKeyPress(Sender: TObject; var Key: Char); private { Private declarations } FMHId:String; procedure InitGrid(); function SaveData():Boolean; procedure InitGridMD(); function YFHZData(CWFactoryNo,CWFactoryName:String):Boolean; function DelYFHZData():Boolean; public { Public declarations } end; var frmMDChkFLView: TfrmMDChkFLView; implementation uses U_DataLink,U_RTFun, U_GYSList,U_ZDYHelp, U_ModuleNote; {$R *.dfm} procedure TfrmMDChkFLView.FormDestroy(Sender: TObject); begin frmMDChkFLView:=nil; end; procedure TfrmMDChkFLView.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; procedure TfrmMDChkFLView.TBCloseClick(Sender: TObject); begin WriteCxGrid('Tv1',Tv1,'码单核查'); WriteCxGrid('Tv2',Tv2,'码单核查'); WriteCxGrid('Tv3',Tv3,'码单核查'); close; end; procedure TfrmMDChkFLView.Image2Click(Sender: TObject); begin Panel4.Visible:=False; end; procedure TfrmMDChkFLView.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin ReleaseCapture; TWinControl(Panel4).Perform(WM_SYSCOMMAND,$F012,0); end; procedure TfrmMDChkFLView.N1Click(Sender: TObject); begin Panel4.Left:=cxSplitter1.Left+20; Panel4.Top:=Panel1.Top+150; Panel4.Visible:=True; end; procedure TfrmMDChkFLView.InitGrid(); begin try ADOQueryMain.DisableControls; with ADOQueryMain do begin Filtered:=False; Close; sql.Clear; sql.Add('select A.*,isnull(B.YiFuMoney,0) YiFuMoney,YingFuYMoney=isnull(B.Money,0)-isnull(B.YiFuMoney,0) '); sql.Add('from JYOrder_Main_MD_HZ A '); sql.Add(' left join YF_Money_CR B on A.MHID=B.MHID where'); if ComboBox4.ItemIndex=0 then begin sql.Add(' A.MHDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''); sql.Add(' and A.MHDate<'''+Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1))+''''); end else if ComboBox4.ItemIndex=1 then begin sql.Add(' A.FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''); sql.Add(' and A.FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1))+''''); end else if ComboBox4.ItemIndex=2 then begin sql.Add(' A.YFDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''); sql.Add(' and A.YFDate<'''+Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1))+''''); end else if ComboBox4.ItemIndex=3 then begin sql.Add(' A.DuiZhangTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''); sql.Add(' and A.DuiZhangTime<'''+Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1))+''''); end; if cxTabControl2.TabIndex=0 then begin sql.Add(' and isnull(A.Status,'''')='''' '); end else if cxTabControl2.TabIndex<3 then begin sql.Add(' and isnull(A.Status,'''')<>'''' '); end; if cxTabControl2.TabIndex=1 then begin sql.Add(' and isnull(A.DuiZhangStatus,'''')='''' '); end else if cxTabControl2.TabIndex=2 then begin sql.Add(' and isnull(A.DuiZhangStatus,'''')=''已对账'' '); end; Open; end; SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); finally ADOQueryMain.EnableControls; end; end; function TfrmMDChkFLView.SaveData():Boolean; var maxno:String; begin Result:=False; try ADOQueryCmd.Connection.BeginTrans; if GetLSNo(ADOQueryCmd,maxno,'MH','JYOrder_Main_MD_HZ',4,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('取码单汇总号失败!','提示',0); Exit; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where MHID='''+Trim(maxno)+''''); Open; end; with ADOQueryCmd do begin Append; FieldByName('MHID').Value:=Trim(maxno); FieldByName('Filler').Value:=Trim(DName); FieldByName('MHDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOQueryTemp))); Post; end; ADOQueryCmd.Connection.CommitTrans; with ClientDataSet1 do begin Append; FieldByName('MHID').Value:=Trim(maxno); FieldByName('Filler').Value:=Trim(DName); FieldByName('MHDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOQueryTemp))); Post; end; except Result:=False; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('增行异常!','提示',0); end; end; procedure TfrmMDChkFLView.ToolButton5Click(Sender: TObject); begin if cxTabControl2.TabIndex<>0 then Exit; SaveData(); end; procedure TfrmMDChkFLView.FormShow(Sender: TObject); begin {with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID=Null where MDID in('); sql.Add('select MDID from JYOrder_Main_MD A where isnull(MHID,'''')<>'''' '); sql.Add('and not exists(select * from JYOrder_Main_MD_HZ B where '); sql.Add('B.MHID=A.MHID and B.ORDMainId=A.ORDMainId and isnull(B.OrderNo,'''')<>''''))'); ExecSQL; end; } cxTabControl2.TabIndex:=0; cxTabControl1.TabIndex:=1; EndDate.DateTime:=SGetServerDate(ADOQueryTemp); BegDate.Date:=EndDate.Date; ReadCxGrid('Tv1',Tv1,'码单核查'); ReadCxGrid('Tv2',Tv2,'码单核查'); ReadCxGrid('Tv3',Tv3,'码单核查'); InitGrid(); end; procedure TfrmMDChkFLView.TBRafreshClick(Sender: TObject); begin InitGrid(); end; procedure TfrmMDChkFLView.V1OrderNoPropertiesEditValueChanged(Sender: TObject); var mvalue,FOrderNo,fsj:String; begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where isnull(MHID,'''')='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; FOrderNo:=Trim(ADOQueryTemp.fieldbyname('OrderNo').AsString); mvalue:=TcxTextEdit(Sender).EditingText; with ClientDataSet1 do begin Edit; FieldByName('OrderNO').Value:=Trim(mvalue); Post; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD where isnull(MHID,'''')='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); sql.Add(' and isnull(MHID,'''')<>'''' '); Open; end; if ADOQueryTemp.IsEmpty=False then begin with ClientDataSet1 do begin Edit; FieldByName('OrderNO').Value:=Trim(FOrderNo); Post; end; Application.MessageBox(PChar('此条数据已存在核查码单不能更改订单号!'),'提示',0); Exit; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(mvalue)+''''); Open; end; if ADOQueryTemp.IsEmpty then begin with ClientDataSet1 do begin Edit; FieldByName('OrderNO').Value:=Trim(FOrderNo); Post; end; Application.MessageBox(PChar('订单号:'+Trim(mvalue)+'不存在!'),'提示',0); Exit; end else begin with ClientDataSet1 do begin Edit; FieldByName('TaiTou').Value:=Trim(ADOQueryTemp.fieldbyname('ComTaiTou').AsString); FieldByName('MPRTCode').Value:=Trim(ADOQueryTemp.fieldbyname('MPRTCode').AsString)+ Trim(ADOQueryTemp.fieldbyname('MPRTGY').AsString); FieldByName('MPRTGY').Value:=Trim(ADOQueryTemp.fieldbyname('MPRTGYHZ').AsString); FieldByName('ORDMainId').Value:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString); Post; end; end; {fsj:='select distinct(PFGenDanPerson) Name,Code='''' from JYOrder_PCS_Sub where Mainid='''+Trim(ClientDataSet1.fieldbyname('ORDMainId').AsString)+''''; SInitCxGridComboBoxBySql(ADOQueryTemp,v1GenDan,fsj,0,False,''); fsj:='select distinct(FactoryName) Name,Code='''' from JYOrder_Main_MD where ORDMainid='''+Trim(ClientDataSet1.fieldbyname('ORDMainId').AsString)+''''; SInitCxGridComboBoxBySql(ADOQueryTemp,v1FactoryName,fsj,0,False,''); } InitGridMD(); end; procedure TfrmMDChkFLView.InitGridMD(); var fsj:String; begin fsj:=''; if ClientDataSet1.IsEmpty then begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('exec P_View_MDTJ_JS :begdate,:enddate,:orderno,:MDType,:WSql'); Parameters.ParamByName('orderno').Value:=''; Parameters.ParamByName('MDType').Value:=''; Parameters.ParamByName('WSql').Value:=' and 1<>1'; Open; end; SCreateCDS20(ADOQueryTemp,ClientDataSet3); SInitCDSData20(ADOQueryTemp,ClientDataSet3); Exit; end; if ((Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)='') and (Trim(ClientDataSet1.fieldbyname('PSName').AsString)='')) then begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('exec P_View_MDTJ_JS :begdate,:enddate,:orderno,:MDType,:WSql'); Parameters.ParamByName('orderno').Value:=Trim(ClientDataSet1.fieldbyname('OrderNo').AsString); Parameters.ParamByName('MDType').Value:=''; Parameters.ParamByName('WSql').Value:=' and 1<>1'; Open; end; SCreateCDS20(ADOQueryTemp,ClientDataSet3); SInitCDSData20(ADOQueryTemp,ClientDataSet3); Exit; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('exec P_View_MDTJ_JS :begdate,:enddate,:orderno,:MDType,:WSql'); Parameters.ParamByName('orderno').Value:=Trim(ClientDataSet1.fieldbyname('OrderNo').AsString); Parameters.ParamByName('MDType').Value:=''; if cxTabControl1.TabIndex=0 then begin fsj:=' and isnull(MHID,'''')='''' '; end else if cxTabControl1.TabIndex=1 then begin fsj:=' and isnull(MHID,'''')='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''; end; if Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)<>'' then begin fsj:=fsj+' and isnull(JMM.FactoryName,'''')='''+Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)+''''; end; if Trim(ClientDataSet1.fieldbyname('PSName').AsString)<>'' then begin fsj:=fsj+' and isnull(JMM.PSName,'''')='''+Trim(ClientDataSet1.fieldbyname('PSName').AsString)+''''; end; Parameters.ParamByName('WSql').Value:=fsj; Open; end; SCreateCDS20(ADOQueryTemp,ClientDataSet3); SInitCDSData20(ADOQueryTemp,ClientDataSet3); end; procedure TfrmMDChkFLView.v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp:=TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag:='YFName'; flagName:='项目名称'; fnote:=True; if ShowModal=1 then begin with Self.ClientDataSet1 do begin Edit; FieldByName('ItemName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString); //Post; end; end; end; finally frmZDYHelp.Free; end; end; procedure TfrmMDChkFLView.ToolButton1Click(Sender: TObject); begin if cxTabControl2.TabIndex>1 then Exit; if ClientDataSet1.IsEmpty then Exit; BegDate.SetFocus; if Trim(ClientDataSet1.fieldbyname('OrderNo').AsString)='' then begin Application.MessageBox('订单号不能为空!','提示',0); Exit; end; if Trim(ClientDataSet1.fieldbyname('MHDate').AsString)='' then begin Application.MessageBox('工厂码单日期不能为空!','提示',0); Exit; end; if Trim(ClientDataSet1.fieldbyname('PSName').AsString)='' then begin Application.MessageBox('工序不能为空!','提示',0); Exit; end; if Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)='' then begin Application.MessageBox('供应商不能为空!','提示',0); Exit; end; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; ClientDataSet1.DisableControls; with ClientDataSet1 do begin //while ClientDataSet1.Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; with ADOQueryCmd do begin Edit; FieldByName('ORDMainid').Value:=Trim(ClientDataSet1.fieldbyname('ORDMainid').AsString); FieldByName('FactoryNo').Value:=Trim(ClientDataSet1.fieldbyname('FactoryNo').AsString); FieldByName('ToFactoryNo').Value:=Trim(ClientDataSet1.fieldbyname('ToFactoryNo').AsString); FieldByName('Status').Value:='已核对'; RTSetSaveDataCDS(ADOQueryCmd,Tv1,ClientDataSet1,'JYOrder_Main_MD_HZ',2); Post; end; if cxTabControl1.TabIndex=0 then begin if ClientDataSet3.IsEmpty=False then begin ClientDataSet3.DisableControls; with ClientDataSet3 do begin First; while Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); sql.Add(',HCFlag=1,HCDate=getdate(),HCPerson='''+Trim(DName)+''''); sql.Add(' where MDID='''+Trim(ClientDataSet3.fieldbyname('MDID').AsString)+''''); ExecSQL; end; ClientDataSet3.Delete; end; end; ClientDataSet3.EnableControls; end; end; if cxTabControl2.TabIndex=0 then begin ClientDataSet1.Delete; end; ps.Text:=''; Qty.Text:=''; Money.Text:=''; end; end; ADOQueryCmd.Connection.CommitTrans; ClientDataSet1.EnableControls; except ClientDataSet1.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('操作失败!','提示',0); end; end; procedure TfrmMDChkFLView.cxTabControl1Change(Sender: TObject); begin if cxTabControl1.TabIndex=0 then begin N3.Visible:=False; end else begin //Tv3.OptionsSelection.CellSelect:=False; N3.Visible:=True; end; PS.Text:=''; Qty.Text:=''; Money.Text:=''; InitGridMD(); end; procedure TfrmMDChkFLView.MenuItem1Click(Sender: TObject); var fsj:string; begin end; procedure TfrmMDChkFLView.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var fsj,FName:String; begin FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; if cxTabControl2.TabIndex=2 then begin if Trim(FName)='Ssel' then begin Tv1.OptionsData.Editing:=True; end else begin Tv1.OptionsData.Editing:=False; end; end; if cxTabControl2.TabIndex>1 then exit; if Trim(FName)='GenDan' then begin fsj:='select distinct(PFGenDanPerson) Name,Code='''' from JYOrder_PCS_Sub where Mainid='''+Trim(ClientDataSet1.fieldbyname('ORDMainId').AsString)+''''; SInitCxGridComboBoxBySql(ADOQueryTemp,v1GenDan,fsj,0,False,''); end else if Trim(FName)='FactoryName' then begin fsj:='select distinct(FactoryName) Name,Code=FactoryNo from JYOrder_Main_MD '+ ' where ORDMainid='''+Trim(ClientDataSet1.fieldbyname('ORDMainId').AsString)+''''+ ' Group by FactoryName,FactoryNo'; SInitCxGridComboBoxBySql(ADOQueryTemp,v1FactoryName,fsj,1,False,''); end else if Trim(FName)='ToFactoryName' then begin fsj:='select distinct(FactoryName) Name,Code=FactoryNo from JYOrder_Main_MD '+ ' where ORDMainid='''+Trim(ClientDataSet1.fieldbyname('ORDMainId').AsString)+''''+ ' Group by FactoryName,FactoryNo'; SInitCxGridComboBoxBySql(ADOQueryTemp,v1ToFactoryName,fsj,1,False,''); end else if Trim(FName)='PSName' then begin fsj:='select PSName Name,Code='''' from JYOrder_Process where Mainid='''+Trim(ClientDataSet1.fieldbyname('ORDMainId').AsString)+'''' +' order by PSXH '; SInitCxGridComboBoxBySql(ADOQueryTemp,v1PSName,fsj,0,False,''); end; end; procedure TfrmMDChkFLView.v1Column7PropertiesEditValueChanged(Sender: TObject); var mvalue:String; begin mvalue:=TcxTextEdit(Sender).EditingText; if Trim(mvalue)='' then begin mvalue:='0'; end; with ClientDataSet1 do begin Edit; FieldByName('FKDays').Value:=mvalue; Post; end; with ClientDataSet1 do begin Edit; FieldByName('YFDate').Value:=FieldByName('MHDate').Value+FieldByName('FKDays').Value; Post; end; end; procedure TfrmMDChkFLView.v1Column1PropertiesEditValueChanged(Sender: TObject); var mvalue:String; begin mvalue:=TcxTextEdit(Sender).EditingText; if Trim(mvalue)='' then begin mvalue:=Null; end; with ClientDataSet1 do begin Edit; FieldByName('MHDate').Value:=mvalue; Post; end; with ClientDataSet1 do begin Edit; if mvalue=Null then begin FieldByName('YFDate').Value:=Null; end else begin FieldByName('YFDate').Value:=FieldByName('MHDate').Value+FieldByName('FKDays').Value; end; Post; end; end; procedure TfrmMDChkFLView.v1FactoryNamePropertiesEditValueChanged( Sender: TObject); var mvalue:string; begin mvalue:=TcxComboBox(Sender).EditingText; with ClientDataSet1 do begin Edit; FieldByName('FactoryName').Value:=mvalue; FieldByName('FactoryNo').Value:=TA((v1FactoryName.Properties as TcxComboBoxProperties).Items. Objects[(v1FactoryName.Properties as TcxComboBoxProperties).Items.IndexOf(Trim(mvalue))]).S; Post; end; InitGridMD(); end; procedure TfrmMDChkFLView.v1PSNamePropertiesEditValueChanged(Sender: TObject); var mvalue:string; begin mvalue:=TcxComboBox(Sender).EditingText; with ClientDataSet1 do begin Edit; FieldByName('PSName').Value:=mvalue; Post; end; InitGridMD(); end; procedure TfrmMDChkFLView.N3Click(Sender: TObject); begin if cxTabControl1.TabIndex<>1 then Exit; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; if cxTabControl1.TabIndex=1 then begin if ClientDataSet3.IsEmpty=False then begin ClientDataSet3.DisableControls; with ClientDataSet3 do begin First; while Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID=Null'); sql.Add(',HCFlag=0,HCDate=Null,HCPerson=Null'); sql.Add(' where MDID='''+Trim(ClientDataSet3.fieldbyname('MDID').AsString)+''''); ExecSQL; end; ClientDataSet3.Delete; end; end; ClientDataSet3.EnableControls; end; end; ADOQueryCmd.Connection.CommitTrans; except ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('操作失败!','提示',0); end; end; procedure TfrmMDChkFLView.v3Column14PropertiesEditValueChanged( Sender: TObject); var mvalue,mvalueCS:Boolean; FPS,FQty,FMoney:Double; begin //mvalueCS:=ClientDataSet3.FieldByName('SSel').AsBoolean; if CheckBox1.Checked=True then exit; if Trim(PS.Text)='' then begin PS.Text:='0'; end; FPS:=StrToFloat(PS.Text); if Trim(Qty.Text)='' then begin Qty.Text:='0'; end; FQty:=StrToFloat(Qty.Text); if Trim(Money.Text)='' then begin Money.Text:='0'; end; FMoney:=StrToFloat(Money.Text); mvalue:=TcxCheckBox(Sender).EditingValue; if mvalue=True then begin FPS:=FPS+ClientDataSet3.fieldbyname('PS').Value; FQty:=FQty+ClientDataSet3.fieldbyname('Qty').Value; FMoney:=FMoney+ClientDataSet3.fieldbyname('Money').Value; end else begin FPS:=FPS-ClientDataSet3.fieldbyname('PS').Value; FQty:=FQty-ClientDataSet3.fieldbyname('Qty').Value; FMoney:=FMoney-ClientDataSet3.fieldbyname('Money').Value; end; PS.Text:=FloatToStr(FPS); Qty.Text:=FloatToStr(FQty); Money.Text:=FloatToStr(FMoney); {if cxTabControl1.TabIndex=0 then begin with ClientDataSet1 do begin Edit; if Trim(ClientDataSet1.fieldbyname('PS').AsString)='' then begin FieldByName('PS').Value:=0; end; if Trim(ClientDataSet1.fieldbyname('Qty').AsString)='' then begin FieldByName('Qty').Value:=0; end; if Trim(ClientDataSet1.fieldbyname('Money').AsString)='' then begin FieldByName('Money').Value:=0; end; Post; end; with ClientDataSet1 do begin Edit; FieldByName('').Value:= Post; end; end; } end; procedure TfrmMDChkFLView.ToolButton6Click(Sender: TObject); var FOrderNo,fsj:String; begin if cxTabControl2.TabIndex>1 then Exit; if ClientDataSet1.IsEmpty then Exit; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; FOrderNo:=Trim(ADOQueryTemp.fieldbyname('OrderNo').AsString); if Trim(ForderNo)<>'' then begin fsj:=''; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('exec P_View_MDTJ_JS :begdate,:enddate,:orderno,:MDType,:WSql'); Parameters.ParamByName('orderno').Value:=Trim(ClientDataSet1.fieldbyname('OrderNo').AsString); Parameters.ParamByName('MDType').Value:=''; fsj:=' and isnull(MHID,'''')='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''; if Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)<>'' then begin fsj:=fsj+' and isnull(JMM.FactoryName,'''')='''+Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)+''''; end; if Trim(ClientDataSet1.fieldbyname('PSName').AsString)<>'' then begin fsj:=fsj+' and isnull(JMM.PSName,'''')='''+Trim(ClientDataSet1.fieldbyname('PSName').AsString)+''''; end; Parameters.ParamByName('WSql').Value:=fsj; Open; end; {with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end;} if ADOQueryTemp.IsEmpty=False then begin Application.MessageBox('已有核查信息不能删除!','提示',0); Exit; end else begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID=Null where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; end; end else begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID=Null where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; end; if Application.MessageBox('确定要删除信息吗?','提示',32+4)<>IDYES then Exit; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('delete JYOrder_Main_MD_HZ where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; ClientDataSet1.Delete; end; procedure TfrmMDChkFLView.TBExportClick(Sender: TObject); begin if ClientDataSet1.IsEmpty then Exit; TcxGridToExcel('核查汇总单',cxGrid1); end; procedure TfrmMDChkFLView.ToolButton2Click(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 TfrmMDChkFLView.ToolButton3Click(Sender: TObject); begin if cxTabControl2.TabIndex>1 then Exit; if ClientDataSet1.IsEmpty then exit; try frmGYSList:=TfrmGYSList.Create(Application); with frmGYSList do begin if ShowModal=1 then begin with Self.ClientDataSet1 do begin Edit; FieldByName('FactoryName').Value:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString) ; FieldByName('FactoryNo').Value:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString) ; end; end; end; finally frmGYSList.Free; end; end; procedure TfrmMDChkFLView.ToolButton4Click(Sender: TObject); begin if ClientDataSet1.IsEmpty then Exit; if cxTabControl2.TabIndex<>1 then Exit; BegDate.SetFocus; if ClientDataSet1.Locate('SSel',True,[])=False then begin Application.MessageBox('没有选择数据!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;FtyMoney',VarArrayOf([True,Null]),[loPartialKey])=True then begin Application.MessageBox('工厂金额不能为空!','提示',0); Exit; end; {if Trim(ClientDataSet1.fieldbyname('FtyMoney').AsString)='' then begin Application.MessageBox('工厂金额不能为空!','提示',0); Exit; end; } if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while ClientDataSet1.Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD_HZ Set DuiZhangTime=Getdate(),'); SQL.Add('DuiZhangPerson='''+Trim(DName)+''',DuiZhangStatus=''已对账'' ' ); if Trim(ClientDataSet1.fieldbyname('FtyQty').AsString)<>'' then begin SQL.Add(',FtyQty='+Trim(ClientDataSet1.fieldbyname('FtyQty').AsString)); end; if Trim(ClientDataSet1.fieldbyname('FtyPrice').AsString)<>'' then begin SQL.Add(',FtyPrice='+Trim(ClientDataSet1.fieldbyname('FtyPrice').AsString)); end; if Trim(ClientDataSet1.fieldbyname('FtyMoney').AsString)<>'' then begin SQL.Add(',FtyMoney='+Trim(ClientDataSet1.fieldbyname('FtyMoney').AsString)); end; if Trim(ClientDataSet1.fieldbyname('ChaEMoney').AsString)<>'' then begin SQL.Add(',ChaEMoney='+Trim(ClientDataSet1.fieldbyname('ChaEMoney').AsString)); end; sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; YFHZData(Trim(ClientDataSet1.fieldbyname('FactoryNo').AsString), Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)); ClientDataSet1.Delete; end; end; ADOQueryCmd.Connection.CommitTrans; ClientDataSet1.EnableControls; except ClientDataSet1.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('操作异常!','提示',0); end; end; function TfrmMDChkFLView.DelYFHZData():Boolean; var CRID:String; begin Result:=False; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from YF_Money_CR where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; CRID:=Trim(ADOQueryTemp.fieldbyname('CRID').AsString); if ADOQueryTemp.IsEmpty then Exit; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update YF_Money_KC Set '); sql.Add(' KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'')'); sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'' )'); sql.Add(' where CRID='+CRID); ExecSQL; end; {with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)'); sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)'); sql.Add(' where CRID='+Trim(CRID)); ExecSQL; end; } with ADOQueryCmd do begin Close; sql.Clear; sql.Add('delete YF_Money_CR where '); sql.Add(' MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); sql.Add(' Update JYOrder_Main_MD_HZ Set YFID=Null where '); sql.Add(' MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; Result:=True; end; procedure TfrmMDChkFLView.ToolButton7Click(Sender: TObject); begin if ClientDataSet1.IsEmpty then Exit; if cxTabControl2.TabIndex<>2 then Exit; BegDate.SetFocus; if ClientDataSet1.Locate('SSel',True,[])=False then begin Application.MessageBox('没有选择数据!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'待处理']),[loPartialKey]) then begin Application.MessageBox('数据有争议不能执行操作!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'处理中']),[loPartialKey]) then begin Application.MessageBox('数据正在处理中不能执行操作!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'处理完成']),[loPartialKey]) then begin Application.MessageBox('数据已处理完成不能执行操作!','提示',0); Exit; end; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while ClientDataSet1.Locate('SSel',True,[]) do begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from YF_Money_CR_HX A inner join YF_Money_CR B on A.YFID=B.YFID'); sql.Add(' inner join JYOrder_Main_MD_HZ C on B.MHID=C.MHID'); sql.Add(' where C.MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin ClientDataSet1.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('已有付款记录,不能撤销!','提示',0); Exit; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD_HZ Set DuiZhangTime=Null,'); SQL.Add('DuiZhangPerson=Null,DuiZhangStatus=Null,FtyQty=Null,FtyPrice=Null,FtyMoney=Null,ChaEMoney=Null ' ); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; DelYFHZData(); ClientDataSet1.Delete; end; end; ADOQueryCmd.Connection.CommitTrans; ClientDataSet1.EnableControls; except ClientDataSet1.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('操作异常!','提示',0); end; end; procedure TfrmMDChkFLView.cxTabControl2Change(Sender: TObject); begin if cxTabControl2.TabIndex<2 then begin //Tv1.OptionsSelection.CellSelect:=True; Tv1.OptionsData.Editing:=True; end else begin //Tv3.OptionsSelection.CellSelect:=False; Tv1.OptionsData.Editing:=False; end; InitGrid(); end; function TfrmMDChkFLView.YFHZData(CWFactoryNo,CWFactoryName:String):Boolean; var CRID,OrdMainId,YFID,FComTaiTou,FCRID,FFactoryName:String; begin Result:=False; with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('select * from YF_Money_KC where FactoryNo='''+Trim(CWFactoryNo)+''''); Open; end; if ADOQueryTemp.IsEmpty=False then begin CRID:=ADOQueryTemp.fieldbyname('CRID').AsString; end else begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update YF_Money_CRID set CRID=CRID+1'); sql.Add('select * from YF_Money_CRID '); Open; end; CRID:=ADOQueryCmd.fieldbyname('CRID').AsString; with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('select * from YF_Money_KC where 1<>1'); Open; end; with ADOQueryCmd do begin Append; FieldByName('CRID').Value:=StrToInt(CRID); FieldByName('FactoryName').Value:=Trim(CWFactoryName); FieldByName('FactoryNo').Value:=Trim(CWFactoryNo); FieldByName('ZdyStr1').Value:='应付付'; Post; end; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from YF_Money_CR where FactoryNo='''+Trim(CWFactoryNo)+''''); sql.Add(' and MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; if ADOQueryTemp.IsEmpty then begin if GetLSNo(ADOQueryCmd,YFID,'ZC','YF_Money_CR',3,1)=False then begin Application.MessageBox('取应付最大号失败!','提示',0); Exit; end; end else begin YFID:=Trim(ADOQueryTemp.fieldbyname('YFID').AsString); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from YF_Money_CR where YFID='''+Trim(YFID)+''''); Open; end; with ADOQueryCmd do begin if ADOQueryTemp.IsEmpty then Append else Edit; FieldByName('YFID').Value:=Trim(YFID); FieldByName('MainId').Value:=Trim(ClientDataSet1.fieldbyname('OrdMainId').AsString); FieldByName('CRID').Value:=StrToInt(CRID); FieldByName('Filler').Value:=Trim(DName); FieldByName('CRType').Value:='应付款登记'; FieldByName('CRFlag').Value:='应付付'; FieldByName('QtyFlag').Value:=1; FieldByName('FactoryNo').Value:=Trim(CWFactoryNo); FieldByName('FactoryName').Value:=Trim(CWFactoryName); FieldByName('HZFactoryNo').Value:=Trim(CWFactoryNo); FieldByName('HZFactoryName').Value:=Trim(CWFactoryName); FieldByName('CRTime').Value:=ClientDataSet1.fieldbyname('YFDate').Value; FieldByName('Qty').Value:=ClientDataSet1.fieldbyname('Qty').Value; if Trim(ClientDataSet1.fieldbyname('PS').AsString)<>'' then begin FieldByName('PS').Value:=ClientDataSet1.fieldbyname('PS').Value; end else begin FieldByName('PS').Value:=0; end; FieldByName('Price').Value:=ClientDataSet1.fieldbyname('Price').Value; FieldByName('Money').Value:=ClientDataSet1.fieldbyname('Money').Value; FieldByName('BBMoney').Value:=ClientDataSet1.fieldbyname('Money').Value; //FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('QtyUnit').AsString); FieldByName('YFType').Value:='自动生成'; FieldByName('HuiLv').Value:=1; FieldByName('BZType').Value:='人民币'; FieldByName('YFName').Value:=Trim(ClientDataSet1.fieldbyname('ItemName').AsString); FieldByName('PSName').Value:=Trim(ClientDataSet1.fieldbyname('PSName').AsString); FieldByName('MHID').Value:=Trim(ClientDataSet1.fieldbyname('MHID').AsString); // FieldByName('KFType').Value:='正常'; Post; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD_HZ Set YFID='''+Trim(YFID)+''''); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update YF_Money_KC Set '); sql.Add(' KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'')'); sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'' )'); sql.Add(' where CRID='+CRID); ExecSQL; end; Result:=True; end; procedure TfrmMDChkFLView.v1ToFactoryNamePropertiesEditValueChanged( Sender: TObject); var mvalue:string; begin mvalue:=TcxComboBox(Sender).EditingText; with ClientDataSet1 do begin Edit; FieldByName('ToFactoryName').Value:=mvalue; FieldByName('ToFactoryNo').Value:=TA((v1ToFactoryName.Properties as TcxComboBoxProperties).Items. Objects[(v1ToFactoryName.Properties as TcxComboBoxProperties).Items.IndexOf(Trim(mvalue))]).S; Post; end; end; procedure TfrmMDChkFLView.v72Column2PropertiesEditValueChanged( Sender: TObject); var mvalue,FName,Qty,Price,FtyQty,FtyPrice:string; begin mvalue:=TcxTextEdit(Sender).EditingText; if Trim(mvalue)='' then begin mvalue:='0'; end; FName:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName); with ClientDataSet1 do begin Edit; FieldByName(FName).Value:=mvalue; Post; end; Qty:=Trim(ClientDataSet1.fieldbyname('Qty').AsString); if Trim(Qty)='' then begin Qty:='0'; end; Price:=Trim(ClientDataSet1.fieldbyname('Price').AsString); if Trim(Price)='' then begin Price:='0'; end; FtyQty:=Trim(ClientDataSet1.fieldbyname('FtyQty').AsString); if Trim(FtyQty)='' then begin FtyQty:='0'; end; FtyPrice:=Trim(ClientDataSet1.fieldbyname('FtyPrice').AsString); if Trim(FtyPrice)='' then begin FtyPrice:='0'; end; with ClientDataSet1 do begin Edit; FieldByName('Money').Value:=StrToFloat(Qty)*StrToFloat(Price); FieldByName('FtyMoney').Value:=StrToFloat(FtyQty)*StrToFloat(FtyPrice); FieldByName('ChaEMoney').Value:=StrToFloat(Qty)*StrToFloat(Price)-StrToFloat(FtyQty)*StrToFloat(FtyPrice); Post; end; end; procedure TfrmMDChkFLView.Button2Click(Sender: TObject); var mvalue,mvalueCS:Boolean; FPS,FQty,FMoney:Double; FMDID:String; begin //mvalueCS:=ClientDataSet3.FieldByName('SSel').AsBoolean; PS.Text:='0'; FPS:=StrToFloat(PS.Text); Qty.Text:='0'; FQty:=StrToFloat(Qty.Text); Money.Text:='0'; FMoney:=StrToFloat(Money.Text); if CheckBox1.Checked=False then begin if ClientDataSet3.IsEmpty then Exit; FMDID:=Trim(ClientDataSet3.fieldbyname('MDID').AsString); ClientDataSet3.DisableControls; with ClientDataSet3 do begin First; while not Eof do begin if ClientDataSet3.FieldByName('SSel').AsBoolean=True then begin FPS:=FPS+ClientDataSet3.fieldbyname('PS').Value; FQty:=FQty+ClientDataSet3.fieldbyname('Qty').Value; FMoney:=FMoney+ClientDataSet3.fieldbyname('Money').Value; end; Next; end; end; ClientDataSet3.EnableControls; PS.Text:=FloatToStr(FPS); Qty.Text:=FloatToStr(FQty); Money.Text:=FloatToStr(FMoney); ClientDataSet3.Locate('MDID',FMDID,[]); end else begin if ClientDataSet1.IsEmpty then Exit; FMDID:=Trim(ClientDataSet1.fieldbyname('MHID').AsString); ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while not Eof do begin if ClientDataSet1.FieldByName('SSel').AsBoolean=True then begin if Trim(ClientDataSet1.fieldbyname('PS').AsString)<>'' then begin FPS:=FPS+ClientDataSet1.fieldbyname('PS').Value; end else begin FPS:=FPS+0; end; //FPS:=FPS+ClientDataSet1.fieldbyname('PS').Value; FQty:=FQty+ClientDataSet1.fieldbyname('Qty').Value; FMoney:=FMoney+ClientDataSet1.fieldbyname('Money').Value; end; Next; end; end; ClientDataSet1.EnableControls; PS.Text:=FloatToStr(FPS); Qty.Text:=FloatToStr(FQty); Money.Text:=FloatToStr(FMoney); ClientDataSet1.Locate('MHID',FMDID,[]); end; end; procedure TfrmMDChkFLView.ToolButton8Click(Sender: TObject); begin if cxTabControl2.TabIndex>1 then Exit; if ClientDataSet1.IsEmpty then Exit; BegDate.SetFocus; if ClientDataSet1.Locate('SSel',True,[])=False then begin Application.MessageBox('没有选择数据!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;OrderNo',VarArrayOf([True,Null]),[loPartialKey]) then begin Application.MessageBox('订单号不能为空!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;MHDate',VarArrayOf([True,Null]),[loPartialKey]) then begin Application.MessageBox('工厂码单日期不能为空!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;PSName',VarArrayOf([True,Null]),[loPartialKey]) then begin Application.MessageBox('工序不能为空!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;FactoryName',VarArrayOf([True,Null]),[loPartialKey]) then begin Application.MessageBox('供应商不能为空!','提示',0); Exit; end; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while ClientDataSet1.Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; with ADOQueryCmd do begin Edit; FieldByName('ORDMainid').Value:=Trim(ClientDataSet1.fieldbyname('ORDMainid').AsString); FieldByName('FactoryNo').Value:=Trim(ClientDataSet1.fieldbyname('FactoryNo').AsString); FieldByName('ToFactoryNo').Value:=Trim(ClientDataSet1.fieldbyname('ToFactoryNo').AsString); FieldByName('Status').Value:='已核对'; RTSetSaveDataCDS(ADOQueryCmd,Tv1,ClientDataSet1,'JYOrder_Main_MD_HZ',2); Post; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD_HZ Set Status=''已核对'' '); if Trim(ClientDataSet1.fieldbyname('FtyQty').AsString)<>'' then begin SQL.Add(',FtyQty='+Trim(ClientDataSet1.fieldbyname('FtyQty').AsString)); end; if Trim(ClientDataSet1.fieldbyname('FtyPrice').AsString)<>'' then begin SQL.Add(',FtyPrice='+Trim(ClientDataSet1.fieldbyname('FtyPrice').AsString)); end; if Trim(ClientDataSet1.fieldbyname('FtyMoney').AsString)<>'' then begin SQL.Add(',FtyMoney='+Trim(ClientDataSet1.fieldbyname('FtyMoney').AsString)); end; if Trim(ClientDataSet1.fieldbyname('ChaEMoney').AsString)<>'' then begin SQL.Add(',ChaEMoney='+Trim(ClientDataSet1.fieldbyname('ChaEMoney').AsString)); end; sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; if cxTabControl2.TabIndex=0 then begin ClientDataSet1.Delete; end else begin ClientDataSet1.Edit; ClientDataSet1.FieldByName('SSel').Value:=False; ClientDataSet1.Post; end; end; end; ADOQueryCmd.Connection.CommitTrans; ClientDataSet1.EnableControls; except ClientDataSet1.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('操作失败!','提示',0); end; end; procedure TfrmMDChkFLView.Button4Click(Sender: TObject); begin if cxTabControl1.TabIndex<>1 then Exit; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; if cxTabControl1.TabIndex=1 then begin if ClientDataSet3.IsEmpty=False then begin ClientDataSet3.DisableControls; with ClientDataSet3 do begin First; while Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID=Null'); sql.Add(',HCFlag=0,HCDate=Null,HCPerson=Null'); sql.Add(' where MDID='''+Trim(ClientDataSet3.fieldbyname('MDID').AsString)+''''); ExecSQL; end; ClientDataSet3.Delete; end; end; end; end; ADOQueryCmd.Connection.CommitTrans; ClientDataSet3.EnableControls; ps.Text:=''; Qty.Text:=''; Money.Text:=''; except ps.Text:=''; Qty.Text:=''; Money.Text:=''; ClientDataSet3.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('操作失败!','提示',0); end; end; procedure TfrmMDChkFLView.Button3Click(Sender: TObject); begin if cxTabControl1.TabIndex<>0 then Exit; if ClientDataSet3.IsEmpty then Exit; if ClientDataSet3.Locate('SSel',True,[])=False then begin Application.MessageBox('没有选择数据!','提示',0); Exit; end; {if Trim(ClientDataSet1.fieldbyname('OrderNo').AsString)='' then begin Application.MessageBox('订单号不能为空!','提示',0); Exit; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_HZ '); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end; if Trim(ADOQueryTemp.fieldbyname('OrderNo').AsString)='' then begin Application.MessageBox('数据未保存不能核查!','提示',0); Exit; end; } if Application.MessageBox('确定要核查吗?','提示',32+4)<>IDYES then Exit; try ADOQueryCmd.Connection.BeginTrans; if cxTabControl1.TabIndex=0 then begin if ClientDataSet3.IsEmpty=False then begin ClientDataSet3.DisableControls; with ClientDataSet3 do begin First; while Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update JYOrder_Main_MD Set MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); sql.Add(',HCFlag=1,HCDate=getdate(),HCPerson='''+Trim(DName)+''''); sql.Add(' where MDID='''+Trim(ClientDataSet3.fieldbyname('MDID').AsString)+''''); ExecSQL; end; ClientDataSet3.Delete; end; end; end; end; ADOQueryCmd.Connection.CommitTrans; ps.Text:=''; Qty.Text:=''; Money.Text:=''; ClientDataSet3.EnableControls; except ps.Text:=''; Qty.Text:=''; Money.Text:=''; ClientDataSet3.EnableControls; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('核查异常!','提示',0); end; end; procedure TfrmMDChkFLView.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin if Trim(ClientDataSet1.fieldbyname('MHId').AsString)<>FMHId then begin ps.Text:=''; Qty.Text:=''; Money.Text:=''; InitGridMD(); FMHId:=Trim(ClientDataSet1.fieldbyname('MHID').AsString); end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from Contract_Main A inner join Contract_Sub B on A.Mainid=B.Mainid'); sql.Add(' where A.ConNo='''+Trim(ClientDataSet1.fieldbyname('OrderNo').AsString)+''''); Open; end; SCreateCDS20(ADOQueryTemp,ClientDataSet2); SInitCDSData20(ADOQueryTemp,ClientDataSet2); end; procedure TfrmMDChkFLView.TBFindClick(Sender: TObject); begin if ADOQueryMain.Active=False then Exit; SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2)); SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); end; procedure TfrmMDChkFLView.orderNoChange(Sender: TObject); begin TBFind.Click; end; procedure TfrmMDChkFLView.FactoryNameChange(Sender: TObject); begin TBFind.Click; end; procedure TfrmMDChkFLView.ToolButton9Click(Sender: TObject); begin if cxTabControl2.TabIndex<>2 then Exit; if ClientDataSet1.IsEmpty then Exit; {with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end;} if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'处理中']),[loPartialKey]) then begin Application.MessageBox('数据正在处理中不能执行操作!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'处理完成']),[loPartialKey]) then begin Application.MessageBox('数据已处理完成不能执行操作!','提示',0); Exit; end; {if Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString)='处理中' then begin Application.MessageBox('数据正在处理中不能执行操作!','提示',0); Exit; end; if Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString)='处理完成' then begin Application.MessageBox('数据已处理完成不能执行操作!','提示',0); Exit; end;} if ClientDataSet1.Locate('SSel',True,[])=False then begin Application.MessageBox('没有选择数据!','提示',0); Exit; end; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while ClientDataSet1.Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('UPdate JYOrder_Main_MD_HZ Set ChkStatus=''待处理'',SSTime=Getdate(),SSPerson='''+Trim(DName)+''''); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); sql.Add('Update YF_Money_CR Set Valid=''N'' '); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update YF_Money_KC Set '); sql.Add(' KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'')'); sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'' )'); sql.Add(' where CRID=(select CRID from YF_Money_CR AA where AA.MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''')'); ExecSQL; end; Edit; FieldByName('SSel').Value:=False; FieldByName('ChkStatus').Value:='待处理'; FieldByName('SSTime').Value:=Now; Post; end; end; ClientDataSet1.EnableControls; end; procedure TfrmMDChkFLView.ToolButton10Click(Sender: TObject); begin if cxTabControl2.TabIndex<>2 then Exit; if ClientDataSet1.IsEmpty then Exit; {with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('select * from JYOrder_Main_MD_HZ where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); Open; end;} if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'处理中']),[loPartialKey]) then begin Application.MessageBox('数据正在处理中不能执行操作!','提示',0); Exit; end; if ClientDataSet1.Locate('SSel;ChkStatus',VarArrayOf([True,'处理完成']),[loPartialKey]) then begin Application.MessageBox('数据已处理完成不能执行操作!','提示',0); Exit; end; {if Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString)='处理中' then begin Application.MessageBox('数据正在处理中不能执行操作!','提示',0); Exit; end; if Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString)='处理完成' then begin Application.MessageBox('数据已处理完成不能执行操作!','提示',0); Exit; end;} if ClientDataSet1.Locate('SSel',True,[])=False then begin Application.MessageBox('没有选择数据!','提示',0); Exit; end; if Application.MessageBox('确定要执行此操作吗?','提示',32+4)<>IDYES then Exit; ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while ClientDataSet1.Locate('SSel',True,[]) do begin with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('UPdate JYOrder_Main_MD_HZ Set ChkStatus=Null,SSTime=Null,SSPerson=Null'); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); sql.Add('Update YF_Money_CR Set Valid=''Y'' '); sql.Add(' where MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''''); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update YF_Money_KC Set '); sql.Add(' KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'')'); sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'' )'); sql.Add(' where CRID=(select CRID from YF_Money_CR AA where AA.MHID='''+Trim(ClientDataSet1.fieldbyname('MHID').AsString)+''')'); ExecSQL; end; Edit; FieldByName('SSel').Value:=False; FieldByName('ChkStatus').Value:=''; FieldByName('SSTime').Value:=Null; Post; end; end; ClientDataSet1.EnableControls; end; procedure TfrmMDChkFLView.v1Column4PropertiesEditValueChanged(Sender: TObject); var mvalue,mvalueCS:Boolean; FPS,FQty,FMoney:Double; begin //mvalueCS:=ClientDataSet3.FieldByName('SSel').AsBoolean; if CheckBox1.Checked=False then exit; if Trim(PS.Text)='' then begin PS.Text:='0'; end; FPS:=StrToFloat(PS.Text); if Trim(Qty.Text)='' then begin Qty.Text:='0'; end; FQty:=StrToFloat(Qty.Text); if Trim(Money.Text)='' then begin Money.Text:='0'; end; FMoney:=StrToFloat(Money.Text); mvalue:=TcxCheckBox(Sender).EditingValue; if mvalue=True then begin if Trim(ClientDataSet1.fieldbyname('PS').AsString)<>'' then begin FPS:=FPS+ClientDataSet1.fieldbyname('PS').Value; end else begin FPS:=FPS+0; end; FQty:=FQty+ClientDataSet1.fieldbyname('Qty').Value; FMoney:=FMoney+ClientDataSet1.fieldbyname('Money').Value; end else begin if Trim(ClientDataSet1.fieldbyname('PS').AsString)<>'' then begin FPS:=FPS-ClientDataSet1.fieldbyname('PS').Value; end else begin FPS:=FPS-0; end; //FPS:=FPS-ClientDataSet1.fieldbyname('PS').Value; FQty:=FQty-ClientDataSet1.fieldbyname('Qty').Value; FMoney:=FMoney-ClientDataSet1.fieldbyname('Money').Value; end; PS.Text:=FloatToStr(FPS); Qty.Text:=FloatToStr(FQty); Money.Text:=FloatToStr(FMoney); end; procedure TfrmMDChkFLView.CheckBox1Click(Sender: TObject); begin PS.Text:=''; Qty.Text:=''; Money.Text:=''; Button2.Click; end; procedure TfrmMDChkFLView.orderNoKeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin if Trim(orderNo.Text)='' then Exit; if Length(Trim(orderNo.Text))<3 then Exit; with ADOQueryMain do begin Filtered:=False; Close; sql.Clear; sql.Add('select A.*,isnull(B.YiFuMoney,0) YiFuMoney,YingFuYMoney=isnull(B.Money,0)-isnull(B.YiFuMoney,0) '); sql.Add(',YSFKDate=(select Top 1 YC.CRTime from YF_Money_CR YC inner join YF_Money_CR_HX HX '); sql.Add(' on YC.YFID=HX.FKID where HX.YFID=B.YFID)'); sql.Add(',YSFKMoney=(select Top 1 YC.Money from YF_Money_CR YC inner join YF_Money_CR_HX HX '); sql.Add(' on YC.YFID=HX.FKID where HX.YFID=B.YFID)'); sql.Add(',KCMoney=(select KCMoney from YF_Money_KC KC where KC.CRID=B.CRID)'); sql.Add('from JYOrder_Main_MD_HZ A '); sql.Add(' left join YF_Money_CR B on A.MHID=B.MHID where 1=1'); if cxTabControl2.TabIndex=0 then begin sql.Add(' and isnull(A.Status,'''')='''' '); end else if cxTabControl2.TabIndex<3 then begin sql.Add(' and isnull(A.Status,'''')<>'''' '); end; if cxTabControl2.TabIndex=1 then begin sql.Add(' and isnull(A.DuiZhangStatus,'''')='''' '); end else if cxTabControl2.TabIndex=2 then begin sql.Add(' and isnull(A.DuiZhangStatus,'''')=''已对账'' '); end; sql.Add(' and A.OrderNo like '''+'%'+Trim(orderNo.Text)+'%'+''''); Open; end; SCreateCDS20(ADOQueryMain,ClientDataSet1); SInitCDSData20(ADOQueryMain,ClientDataSet1); end; end; end.