unit U_GYSFPInPut; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxDropDownEdit, cxCalendar, cxGridCustomPopupMenu, cxGridPopupMenu; type TfrmGYSFPInPut = class(TForm) ToolBar1: TToolBar; TBSave: TToolButton; TBClose: TToolButton; ADOTemp: TADOQuery; ADOCmd: TADOQuery; DataSource1: TDataSource; Order_Sub: TClientDataSet; DataSource2: TDataSource; ADOZDY: TADOQuery; CDS_ZDY: TClientDataSet; ADOQuery1: TADOQuery; cxGridPopupMenu1: TcxGridPopupMenu; ToolButton3: TToolButton; ToolButton4: TToolButton; ClientDataSet1: TClientDataSet; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; v1Column6: TcxGridDBColumn; v1Column9: TcxGridDBColumn; v1Column10: TcxGridDBColumn; v1Column20: TcxGridDBColumn; v1Column5: TcxGridDBColumn; v1Column18: TcxGridDBColumn; v1Column1: TcxGridDBColumn; v1Column3: TcxGridDBColumn; v1Column2: TcxGridDBColumn; v1Column12: TcxGridDBColumn; cxGrid1Level1: TcxGridLevel; v1Column4: TcxGridDBColumn; ToolButton1: TToolButton; procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); procedure v1Column3PropertiesEditValueChanged(Sender: TObject); procedure v1Column20PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); private FXS:Integer; procedure InitData(); procedure ZDYHelp(FButn:TcxButtonEdit;LType:string); function SaveData():Boolean; procedure GetMaxConNO(); { Private declarations } public PState,PCopyInt:Integer; FMainId,FConNo,FConType,FYLType:String; { Public declarations } end; var frmGYSFPInPut: TfrmGYSFPInPut; implementation uses U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_BGMXSelList; {$R *.dfm} procedure TfrmGYSFPInPut.TBCloseClick(Sender: TObject); begin Close; WriteCxGrid('供应商发票录入',Tv1,'发票管理'); end; procedure TfrmGYSFPInPut.InitData(); begin with ADOQuery1 do begin Close; SQL.Clear; sql.Add(' select A.* '); SQL.Add(' from FP_GYSNB A'); sql.Add(' where A.FMID='''+Trim(FMainId)+''''); Open; end; SCreateCDS20(ADOQuery1,Order_Sub); SInitCDSData20(ADOQuery1,Order_Sub); end; procedure TfrmGYSFPInPut.ZDYHelp(FButn:TcxButtonEdit;LType:string); begin end; procedure TfrmGYSFPInPut.FormShow(Sender: TObject); begin ReadCxGrid('供应商发票录入',Tv1,'发票管理'); InitData(); end; procedure TfrmGYSFPInPut.GetMaxConNO(); begin end; function TfrmGYSFPInPut.SaveData():Boolean; var maxno:String; begin try Result:=False; ADOCmd.Connection.BeginTrans; //保存主表 Order_Sub.DisableControls; with Order_Sub do begin First; while not Eof do begin if Trim(Order_Sub.fieldbyname('FMID').AsString)='' then begin if GetLSNo(ADOCmd,maxno,'FM','FP_GYSNB',4,1)=False then begin Order_Sub.EnableControls; ADOCmd.Connection.RollbackTrans; Application.MessageBox('取规则流水号失败!','提示',0); Exit; end; end else begin maxno:=Trim(Order_Sub.fieldbyname('FMID').AsString); end; with ADOCmd do begin Close; sql.Clear; SQL.Add('select * from FP_GYSNB where FMID='''+Trim(Order_Sub.fieldbyname('FMID').AsString)+''''); Open; end; with ADOCmd do begin if Trim(Order_Sub.fieldbyname('FMID').AsString)='' then begin Append; end else begin Edit; end; FieldByName('FMID').Value:=Trim(maxno); FieldByName('BGID').Value:=Order_Sub.fieldbyname('BGID').Value; FieldByName('BCID').Value:=Order_Sub.fieldbyname('BCID').Value; FieldByName('BFID').Value:=Order_Sub.fieldbyname('BFID').Value; FieldByName('FactoryNo').Value:=Order_Sub.fieldbyname('FactoryNo').Value; FieldByName('FMType').Value:='GYS'; RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'FP_GYSNB',0) ; if Trim(FMainId)='' then begin FieldByName('Filler').Value:=Trim(DName); end else begin FieldByName('Editer').Value:=Trim(DName); FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp); end; Post; end; with ADOCmd do begin Close; sql.Clear; sql.Add('select * from FP_GYSNB where FPNO='''+Trim(Order_Sub.fieldbyname('FPNO').AsString)+''''); sql.Add(' and isnull(FMType,'''')=''GYS'' '); Open; end; if ADOCmd.RecordCount>1 then begin Order_Sub.EnableControls; ADOCmd.Connection.RollbackTrans; Result:=False; Application.MessageBox(PChar('发票号:'+Trim(Order_Sub.fieldbyname('FPNO').AsString)+'重复!'),'',0); Exit; end; Edit; FieldByName('FMID').Value:=Trim(maxno); Next; end; end; Order_Sub.EnableControls; ADOCmd.Connection.CommitTrans; Result:=True; except Result:=False; ADOCmd.Connection.RollbackTrans; Application.MessageBox('保存失败!','提示',0); end; end; procedure TfrmGYSFPInPut.TBSaveClick(Sender: TObject); var FPPrice,PRTPrice,BCMoney,FPQty,ChaMoney:string; begin ToolBar1.SetFocus; if Order_Sub.IsEmpty then begin Application.MessageBox('明细不能为空!','提示',0); exit; end; if Order_Sub.Locate('FPNO',null,[]) then begin Application.MessageBox('发票号不能为空!','提示',0); Exit; end; if Order_Sub.Locate('FPDate',null,[]) then begin Application.MessageBox('发票日期不能为空!','提示',0); Exit; end; if Order_Sub.Locate('Qty',null,[]) then begin Application.MessageBox('数量不能为空!','提示',0); Exit; end; if Order_Sub.Locate('Price',null,[]) then begin Application.MessageBox('单价不能为空!','提示',0); Exit; end; if Order_Sub.Locate('Money',null,[]) then begin Application.MessageBox('金额不能为空!','提示',0); Exit; end; if SaveData() then begin Application.MessageBox('保存成功!','提示',0); ModalResult:=1; end; end; procedure TfrmGYSFPInPut.ToolButton3Click(Sender: TObject); var FSQDate:string; begin FSQDate:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOTemp))); try frmBGMXSelList:=TfrmBGMXSelList.Create(Application); with frmBGMXSelList do begin if ShowModal=1 then begin with frmBGMXSelList.Order_Main do begin First; while not Eof do begin if frmBGMXSelList.Order_Main.FieldByName('SSel').AsBoolean=True then begin with Self.Order_Sub do begin Append; FieldByName('BGId').Value:=frmBGMXSelList.Order_Main.FieldByName('BGId').Value; FieldByName('BCID').Value:=frmBGMXSelList.Order_Main.FieldByName('BCID').Value; FieldByName('BFID').Value:=frmBGMXSelList.Order_Main.FieldByName('BFID').Value; FieldByName('OrderNo').Value:=frmBGMXSelList.Order_Main.FieldByName('OrderNo').Value; FieldByName('BFName').Value:=frmBGMXSelList.Order_Main.FieldByName('BFName').Value; //FieldByName('GHDanWei').Value:=Trim(frmBGMXSelList.Order_Main.FieldByName('ComTaiTou').AsString); FieldByName('XHDanWei').Value:=frmBGMXSelList.Order_Main.FieldByName('FactoryName').Value; FieldByName('FactoryName').Value:=frmBGMXSelList.Order_Main.FieldByName('FactoryName').Value; FieldByName('FactoryNo').Value:=frmBGMXSelList.Order_Main.FieldByName('FactoryNo').Value; FieldByName('QtyUnit').Value:=frmBGMXSelList.Order_Main.FieldByName('BFUnit').Value; if Trim(frmBGMXSelList.Order_Main.FieldByName('BFUnit').AsString)='M' then begin FieldByName('Qty').Value:=frmBGMXSelList.Order_Main.FieldByName('BFMQty').Value; end else begin FieldByName('Qty').Value:=frmBGMXSelList.Order_Main.FieldByName('BFQty').Value; end; FieldByName('Price').Value:=frmBGMXSelList.Order_Main.FieldByName('BFPrice').Value; FieldByName('Money').Value:=FieldByName('Price').Value*FieldByName('Qty').Value; FieldByName('FPDate').Value:=FSQDate; //Post; end; end; Next; end; end; end; end; finally frmBGMXSelList.Free; end; end; procedure TfrmGYSFPInPut.ToolButton4Click(Sender: TObject); begin if Order_Sub.IsEmpty then Exit; if Trim(Order_Sub.fieldbyname('FMId').AsString)<>'' then begin if Application.MessageBox('确定要删除数据吗?','提示',32+4)<>IDYES then Exit; with ADOCmd do begin Close; sql.Clear; sql.Add('delete FP_GYSNB where FMId='''+Trim(Order_Sub.fieldbyname('FMId').AsString)+''''); ExecSQL; end; end; Order_Sub.Delete; end; procedure TfrmGYSFPInPut.v1Column3PropertiesEditValueChanged( Sender: TObject); var mvalue,FQty,FPrice,FMoney,FName:String; begin FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; mvalue:=TcxTextEdit(Sender).EditingText; if Trim(mvalue)='' then mvalue:='0'; with Order_Sub do begin Edit; FieldByName(FName).Value:=mvalue; Post; end; FQty:=Order_Sub.fieldbyname('Qty').AsString; FPrice:=Order_Sub.fieldbyname('Price').AsString; FMoney:=Order_Sub.fieldbyname('Money').AsString; if Trim(FQty)='' then FQty:='0'; if Trim(FPrice)='' then FPrice:='0'; if Trim(FMoney)='' then FMoney:='0'; if Trim(FName)<>'Money' then begin with Order_Sub do begin Edit; FieldByName('Money').Value:=StrToFloat(FQty)*StrToFloat(FPrice); Post; end; end else begin if Trim(FQty)<>'0' then begin with Order_Sub do begin Edit; FieldByName('Price').Value:=StrToFloat(FMoney)*1.000000/StrToFloat(FQty); Post; end; end else begin with Order_Sub do begin Edit; FieldByName('Price').Value:=Null; Post; end; end; end; end; procedure TfrmGYSFPInPut.v1Column20PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp:=TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag:='GSTT'; flagname:='报关单位'; V1ZdyStr1.Visible:=True; V1ZdyStr2.Visible:=True; V1ZdyStr3.Visible:=True; V1ZdyStr4.Visible:=True; V1ZdyStr1.Caption:='简称'; V1ZdyStr2.Caption:='电话'; V1ZdyStr3.Caption:='传真'; V1ZdyStr4.Caption:='地址'; frmZDYHelp.Align:=alClient; if ShowModal=1 then begin with Order_Sub do begin Edit; FieldByName('GHDanWei').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; end; finally frmZDYHelp.Free; end; end; end.