unit U_SXDZInPut; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit; type TfrmSXDZInPut = class(TForm) cxGrid2: TcxGrid; Tv1: TcxGridDBTableView; v1Column2: TcxGridDBColumn; v2Column1: TcxGridDBColumn; v1Column9: TcxGridDBColumn; v2Column6: TcxGridDBColumn; cxGrid2Level1: TcxGridLevel; ToolBar1: TToolBar; TBAdd: TToolButton; TBDel: TToolButton; TBSave: TToolButton; TBClose: TToolButton; DataSource3: TDataSource; CDS_Sub: TClientDataSet; ADOQueryCmd: TADOQuery; ADOQueryMain: TADOQuery; ADOQueryTemp: TADOQuery; cxGridPopupMenu2: TcxGridPopupMenu; v1Column12: TcxGridDBColumn; v1Column14: TcxGridDBColumn; v1Column3: TcxGridDBColumn; v1Column1: TcxGridDBColumn; ToolButton1: TToolButton; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBAddClick(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBDelClick(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v2Column6PropertiesEditValueChanged(Sender: TObject); procedure ToolButton1Click(Sender: TObject); private { Private declarations } function SaveCKData():Boolean; public { Public declarations } FBCId:String; end; var frmSXDZInPut: TfrmSXDZInPut; implementation uses U_DataLink,U_RTFun,U_ClothContractListHZCX,U_ZDYHelp, U_GYSSelList,U_ContractCGJGSXSelList,U_SXDZViewSCList; {$R *.dfm} procedure TfrmSXDZInPut.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; procedure TfrmSXDZInPut.TBAddClick(Sender: TObject); begin with CDS_Sub do begin Append; FieldByName('DZDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',Now)); Post; end; end; function TfrmSXDZInPut.SaveCKData():Boolean; var FCRID,Maxno,FDZID:string; begin try ADOQueryCmd.Connection.BeginTrans; CDS_Sub.DisableControls; with CDS_Sub do begin First; while not eof do begin if Trim(CDS_Sub.fieldbyname('DZID').AsString)='' then begin if GetLSNo(ADOQueryCmd,Maxno,'SX','JYOrder_Main_MD_DuiZhang',3,1)=False then begin Result:=False; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('取纱线对账编号失败!','提示',0); Exit; end; end else begin Maxno:=Trim(CDS_Sub.fieldbyname('DZID').AsString); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(Maxno)+''''); Open; end; with ADOQueryCmd do begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_DuiZhang'); sql.Add(' where DZID='''+Trim(CDS_Sub.fieldbyname('DZID').AsString)+''''); Open; end; FDZID:=Trim(ADOQueryTemp.fieldbyname('DZID').AsString); if Trim(FDZID)='' then begin Append; FieldByName('Filler').Value:=Trim(DName); end else begin Edit; FieldByName('Editer').Value:=Trim(DName); FieldByName('EditTime').Value:=SGetServerDate(ADOQueryTemp); end; FieldByName('DZID').Value:=Trim(Maxno); FieldByName('DZType').Value:='纱线'; FieldByName('Status').Value:='待对账'; FieldByName('FactoryNo').Value:=Trim(CDS_Sub.fieldbyname('FactoryNo').AsString); RTSetSaveDataCDS(ADOQueryCmd,Tv1,CDS_Sub,'JYOrder_Main_MD_DuiZhang',2); Post; end; Edit; FieldByName('DZID').Value:=Trim(Maxno); Post; Next; end; end; CDS_Sub.EnableControls; ADOQueryCmd.Connection.CommitTrans; Result:=True; except Result:=False; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('保存异常!','提示',0); end; end; procedure TfrmSXDZInPut.TBCloseClick(Sender: TObject); begin WriteCxGrid('纱线对账录入',Tv1,'财务对账'); Close; end; procedure TfrmSXDZInPut.FormShow(Sender: TObject); begin ReadCxGrid('纱线对账录入',Tv1,'财务对账'); with ADOQueryTemp do begin Close; sql.Clear; sql.Add(' select A.* '); sql.Add(' from JYOrder_Main_MD_DuiZhang A'); sql.Add(' where DZID='''+Trim(FBCId)+''''); Open; end; SCreateCDS20(ADOQueryTemp,CDS_Sub); SInitCDSData20(ADOQueryTemp,CDS_Sub); end; procedure TfrmSXDZInPut.TBDelClick(Sender: TObject); begin if CDS_Sub.IsEmpty then Exit; if Trim(CDS_Sub.fieldbyname('DZID').AsString)<>'' then begin if Application.MessageBox('确定要删除数据吗?','提示',32+4)<>IDYES then Exit; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(CDS_Sub.fieldbyname('DZID').AsString)+''''); sql.Add(' and isnull(Status,'''')=''已入账'' '); Open; end; if ADOQueryTemp.IsEmpty=False then begin Application.MessageBox('已入账,不能删除!','提示',0); Exit; end; try ADOQueryCmd.Connection.BeginTrans; with ADOQueryCmd do begin Close; sql.Clear; sql.Add(' delete JYOrder_Main_MD_DuiZhang where DZID='''+Trim(CDS_Sub.fieldbyname('DZID').AsString)+''''); ExecSQL; end; ADOQueryCmd.Connection.CommitTrans; CDS_Sub.Delete; except ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('删除异常!','提示',0); end; end else begin CDS_Sub.Delete; end; end; procedure TfrmSXDZInPut.TBSaveClick(Sender: TObject); begin if CDS_Sub.IsEmpty then Exit; if CDS_Sub.Locate('DZDate',null,[])=True then begin Application.MessageBox('日期不能为空!','提示',0); Exit; end; if CDS_Sub.Locate('MPRTCodeName',null,[])=True then begin Application.MessageBox('品名不能为空!','提示',0); Exit; end; if CDS_Sub.Locate('FactoryName',null,[])=True then begin Application.MessageBox('供应商不能为空!','提示',0); Exit; end; if CDS_Sub.Locate('Qty',null,[])=True then begin Application.MessageBox('数量不能为空!','提示',0); Exit; end; if CDS_Sub.Locate('Price',null,[])=True then begin Application.MessageBox('单价不能为空!','提示',0); Exit; end; ToolBar1.SetFocus; if SaveCKData() then begin Application.MessageBox('保存成功!','提示',0); //ModalResult:=1; Exit; end; end; procedure TfrmSXDZInPut.v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmGYSSelList:=TfrmGYSSelList.Create(Application); with frmGYSSelList do begin if ShowModal=1 then begin with Self.CDS_Sub do begin edit; FieldByName('FactoryNo').Value:=Trim(frmGYSSelList.Order_Main.fieldbyname('ZKID').AsString) ; FieldByName('FactoryName').Value:=Trim(frmGYSSelList.Order_Main.fieldbyname('KHName').AsString); //Post; end; end; end; finally frmGYSSelList.Free; end; end; procedure TfrmSXDZInPut.v2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp:=TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag:='SXPBName'; flagname:='纱线名称'; if ShowModal=1 then begin with Self.CDS_Sub do begin Edit; FieldByName('MPRTCodeName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; end; finally frmZDYHelp.Free; end; end; procedure TfrmSXDZInPut.v2Column6PropertiesEditValueChanged( Sender: TObject); var mvalue,FName,FQty,FPrice:String; begin FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; mvalue:=TcxTextEdit(Sender).EditingText; if Trim(mvalue)='' then mvalue:='0'; with CDS_Sub do begin edit; FieldByName(FName).Value:=mvalue; //Post; end; FQty:=CDS_Sub.fieldbyname('Qty').AsString; FPrice:=CDS_Sub.fieldbyname('Price').AsString; if Trim(FQty)='' then FQty:='0'; if Trim(FPrice)='' then FPrice:='0'; with CDS_Sub do begin Edit; FieldByName('Money').Value:=StrToFloat(FQty)*StrToFloat(FPrice); //Post; end; end; procedure TfrmSXDZInPut.ToolButton1Click(Sender: TObject); begin try frmSXDZViewSCList:=TfrmSXDZViewSCList.Create(Application); with frmSXDZViewSCList do begin if ShowModal=1 then begin end; end; finally frmSXDZViewSCList.Free; end; end; end.