unit u_ch_genleg_start; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, Grids, DBGridEh, ComCtrls, bsSkinTabs, StdCtrls, Mask, wwdbedit, Wwdotdot, Wwdbcomb, DB, kbmMemTable, ADODB; type Tfrm_ch_genleg_start = class(TForm) bsSkinPanel1: TbsSkinPanel; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet5: TbsSkinTabSheet; DBGridEhGenleg: TDBGridEh; bsSkinTabSheet4: TbsSkinTabSheet; DBGridEhBank: TDBGridEh; bsSkinPanel4: TbsSkinPanel; Label1: TLabel; Label6: TLabel; Label7: TLabel; cbYear: TwwDBComboBox; cbmonth: TwwDBComboBox; bsSkinButton3: TbsSkinButton; bsSkinButton1: TbsSkinButton; t_ch_genleg: TkbmMemTable; t_ch_genlegField: TFloatField; t_ch_genlegField2: TFloatField; t_ch_genlegField3: TFloatField; t_ch_genlegUSD: TFloatField; t_ch_genlegUSD2: TFloatField; t_ch_genlegUSD3: TFloatField; t_ch_bank_genleg: TkbmMemTable; FloatField1: TFloatField; FloatField2: TFloatField; FloatField3: TFloatField; FloatField4: TFloatField; FloatField5: TFloatField; FloatField6: TFloatField; t_ch_bank_genlegField: TStringField; t_ch_bank_genlegField2: TStringField; t_ch_bank_genlegBANK: TStringField; t_ch_genleg1: TDataSource; t_ch_bank_genleg1: TDataSource; t_ch_genleg_n: TADOQuery; t_ch_genlegDSDesigner: TIntegerField; t_ch_genlegDSDesigner2: TSmallintField; t_ch_genlegDSDesigner3: TBCDField; t_ch_genlegDSDesigner4: TBCDField; t_ch_genlegDSDesigner5: TBCDField; t_ch_genlegDSDesigner6: TBCDField; t_ch_genlegDSDesigner7: TBCDField; t_ch_genlegDSDesigner8: TBCDField; BCDField1: TBCDField; BCDField2: TBCDField; BCDField3: TBCDField; t_ch_genlegUSD4: TBCDField; t_ch_genlegUSD5: TBCDField; t_ch_genlegUSD6: TBCDField; t_ch_genlegDSDesigner9: TBCDField; t_ch_genlegDSDesigner10: TBCDField; t_ch_genlegDSDesigner11: TBCDField; t_ch_genlegUSD7: TBCDField; t_ch_genlegUSD8: TBCDField; t_ch_genlegUSD9: TBCDField; t_ch_bank_genleg_n: TADOQuery; t_ch_bank_genlegDSDesigner: TIntegerField; t_ch_bank_genlegDSDesigner2: TSmallintField; t_ch_bank_genlegDSDesigner3: TStringField; t_ch_bank_genlegDSDesigner4: TStringField; t_ch_bank_genlegDSDesigner5: TBCDField; t_ch_bank_genlegDSDesigner6: TBCDField; t_ch_bank_genlegDSDesigner7: TBCDField; t_ch_bank_genlegDSDesigner8: TBCDField; t_ch_bank_genlegDSDesigner9: TBCDField; t_ch_bank_genlegDSDesigner10: TBCDField; t_ch_bank_genlegUSD: TBCDField; t_ch_bank_genlegUSD2: TBCDField; t_ch_bank_genlegUSD3: TBCDField; t_ch_bank_genlegUSD4: TBCDField; t_ch_bank_genlegUSD5: TBCDField; t_ch_bank_genlegUSD6: TBCDField; StringField1: TStringField; t_ch_bank_genlegDSDesigner11: TBCDField; t_ch_bank_genlegDSDesigner12: TBCDField; t_ch_bank_genlegDSDesigner13: TBCDField; t_ch_bank_genlegUSD7: TBCDField; t_ch_bank_genlegUSD8: TBCDField; t_ch_bank_genlegUSD9: TBCDField; t_ch_genlegRMB: TFloatField; t_ch_genlegRMB2: TFloatField; t_ch_genlegRMB3: TFloatField; t_ch_bank_genlegRMB: TFloatField; t_ch_bank_genlegRMB2: TFloatField; t_ch_bank_genlegRMB3: TFloatField; t_ch_bank_genleg_nRMB: TBCDField; t_ch_bank_genleg_nRMB2: TBCDField; t_ch_bank_genleg_nRMB3: TBCDField; t_ch_bank_genleg_nRMB4: TBCDField; t_ch_bank_genleg_nRMB5: TBCDField; t_ch_bank_genleg_nRMB6: TBCDField; t_ch_genleg_nRMB: TBCDField; t_ch_genleg_nRMB2: TBCDField; t_ch_genleg_nRMB3: TBCDField; t_ch_genleg_nRMB4: TBCDField; t_ch_genleg_nRMB5: TBCDField; t_ch_genleg_nRMB6: TBCDField; procedure t_ch_genlegFieldChange(Sender: TField); procedure t_ch_genlegUSDChange(Sender: TField); procedure t_ch_genlegAfterInsert(DataSet: TDataSet); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure t_ch_bank_genleg_nAfterInsert(DataSet: TDataSet); procedure t_ch_genlegRMBChange(Sender: TField); private { Private declarations } public { Public declarations } end; var frm_ch_genleg_start: Tfrm_ch_genleg_start; implementation uses u_main, u_data_share, my_sys_function; {$R *.dfm} procedure Tfrm_ch_genleg_start.t_ch_genlegFieldChange(Sender: TField); begin Sender.DataSet.FieldByName('累计余额').Asfloat:=Sender.DataSet.FieldByName('累计借方').Asfloat-Sender.DataSet.FieldByName('累计贷方').Asfloat; end; procedure Tfrm_ch_genleg_start.t_ch_genlegUSDChange(Sender: TField); begin Sender.DataSet.FieldByName('USD累计余额').Asfloat:=Sender.DataSet.FieldByName('USD累计借方').Asfloat-Sender.DataSet.FieldByName('USD累计贷方').Asfloat; end; procedure Tfrm_ch_genleg_start.t_ch_genlegAfterInsert(DataSet: TDataSet); begin DataSet.FieldByName('累计借方').Asfloat:=0.00; DataSet.FieldByName('累计贷方').Asfloat:=0.00; DataSet.FieldByName('累计余额').Asfloat:=0.00; DataSet.FieldByName('USD累计借方').Asfloat:=0.00; DataSet.FieldByName('USD累计贷方').Asfloat:=0.00; DataSet.FieldByName('USD累计余额').Asfloat:=0.00; DataSet.FieldByName('RMB累计借方').Asfloat:=0.00; DataSet.FieldByName('RMB累计贷方').Asfloat:=0.00; DataSet.FieldByName('RMB累计余额').Asfloat:=0.00; end; procedure Tfrm_ch_genleg_start.FormShow(Sender: TObject); begin t_ch_genleg.open; t_ch_bank_genleg.open; t_ch_genleg.Insert; t_ch_genleg.post; frm_data_share.t_sys_bank.First; while not frm_data_share.t_sys_bank.eof do begin t_ch_bank_genleg.Insert; t_ch_bank_genleg.fieldbyname('银行代码').AsString:=frm_data_share.t_sys_bank.fieldbyname('代码').AsString; t_ch_bank_genleg.fieldbyname('银行名称').AsString:=frm_data_share.t_sys_bank.fieldbyname('银行名称').AsString; t_ch_bank_genleg.post; frm_data_share.t_sys_bank.next; end; cbYear.ItemIndex:=cbYear.Items.IndexOf(inttostr(Logininfo.offyear)); cbmonth.ItemIndex:=cbmonth.Items.IndexOf(inttostr(Logininfo.offmonth)); end; procedure Tfrm_ch_genleg_start.bsSkinButton1Click(Sender: TObject); begin close; end; procedure Tfrm_ch_genleg_start.bsSkinButton3Click(Sender: TObject); var aQuery:TAdoQuery; begin if (cbYear.text='') or (cbMonth.text='') then begin showmessage('初始年、月不能为空!'); exit; end; if MessageDlg('确实要初始化,总账数据吗?',mtWarning,[mbyes,mbno],0)=mrno then exit; aQuery:=CreateAdoQuery; try frm_main.db.BeginTrans; try with aQuery do begin Close;SQL.Clear; SQL.Add('update period set closed=''T'' where period<='''+cbYear.Text+cbmonth.text+''''); ExecSQL; Close;SQL.Clear; SQL.Add('update period set closed=''F'' where period>'''+cbYear.Text+cbmonth.text+''''); ExecSQL; Close;SQL.Clear; SQL.Add('delete from t_ch_genleg'); ExecSQL; Close;SQL.Clear; SQL.Add('delete from t_ch_bank_genleg'); ExecSQL; end; t_ch_genleg_n.open; t_ch_bank_genleg_n.open; if not t_ch_genleg.IsEmpty then begin t_ch_genleg_n.Insert; t_ch_genleg_n.FieldByName('年').AsInteger:=strtoint(cbYear.text); t_ch_genleg_n.FieldByName('月').AsInteger:=strtoint(cbmonth.text); t_ch_genleg_n['累计借方']:=t_ch_genleg['累计借方']; t_ch_genleg_n['累计贷方']:=t_ch_genleg['累计贷方']; t_ch_genleg_n['累计余额']:=t_ch_genleg['累计余额']; t_ch_genleg_n['USD累计借方']:=t_ch_genleg['USD累计借方']; t_ch_genleg_n['USD累计贷方']:=t_ch_genleg['USD累计贷方']; t_ch_genleg_n['USD累计余额']:=t_ch_genleg['USD累计余额']; t_ch_genleg_n['RMB累计借方']:=t_ch_genleg['RMB累计借方']; t_ch_genleg_n['RMB累计贷方']:=t_ch_genleg['RMB累计贷方']; t_ch_genleg_n['RMB累计余额']:=t_ch_genleg['RMB累计余额']; t_ch_genleg_n.post; end; if not t_ch_bank_genleg.IsEmpty then begin t_ch_bank_genleg.First; while not t_ch_bank_genleg.Eof do begin t_ch_bank_genleg_n.Insert; t_ch_bank_genleg_n.FieldByName('年').AsInteger:=strtoint(cbYear.text); t_ch_bank_genleg_n.FieldByName('月').AsInteger:=strtoint(cbmonth.text); t_ch_bank_genleg_n['银行代码']:=t_ch_bank_genleg['银行代码']; t_ch_bank_genleg_n['银行名称']:=t_ch_bank_genleg['银行名称']; t_ch_bank_genleg_n['累计借方']:=t_ch_bank_genleg['累计借方']; t_ch_bank_genleg_n['累计贷方']:=t_ch_bank_genleg['累计贷方']; t_ch_bank_genleg_n['累计余额']:=t_ch_bank_genleg['累计余额']; t_ch_bank_genleg_n['USD累计借方']:=t_ch_bank_genleg['USD累计借方']; t_ch_bank_genleg_n['USD累计贷方']:=t_ch_bank_genleg['USD累计贷方']; t_ch_bank_genleg_n['USD累计余额']:=t_ch_bank_genleg['USD累计余额']; t_ch_bank_genleg_n['RMB累计借方']:=t_ch_bank_genleg['RMB累计借方']; t_ch_bank_genleg_n['RMB累计贷方']:=t_ch_bank_genleg['RMB累计贷方']; t_ch_bank_genleg_n['RMB累计余额']:=t_ch_bank_genleg['RMB累计余额']; t_ch_bank_genleg_n.post; t_ch_bank_genleg.Next; end; end; Logininfo.offyear:=StrToInt(cbYear.Text); Logininfo.offmonth:=StrToInt(cbmonth.text); frm_main.db.CommitTrans; showmessage('初始化完毕!'); except frm_main.db.RollbackTrans; showmessage('初始化过程中出错!'); end; finally freeandnil(aQuery); end; end; procedure Tfrm_ch_genleg_start.t_ch_bank_genleg_nAfterInsert( DataSet: TDataSet); begin DataSet.FieldByName('本月借方').Asfloat:=0.00; DataSet.FieldByName('本月贷方').Asfloat:=0.00; DataSet.FieldByName('本月余额').Asfloat:=0.00; DataSet.FieldByName('USD本月借方').Asfloat:=0.00; DataSet.FieldByName('USD本月贷方').Asfloat:=0.00; DataSet.FieldByName('USD本月余额').Asfloat:=0.00; DataSet.FieldByName('RMB本月借方').Asfloat:=0.00; DataSet.FieldByName('RMB本月贷方').Asfloat:=0.00; DataSet.FieldByName('RMB本月余额').Asfloat:=0.00; end; procedure Tfrm_ch_genleg_start.t_ch_genlegRMBChange(Sender: TField); begin Sender.DataSet.FieldByName('RMB累计余额').Asfloat:=Sender.DataSet.FieldByName('RMB累计借方').Asfloat-Sender.DataSet.FieldByName('RMB累计贷方').Asfloat; end; end.