unit AccCloseOffBacku; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGridEh, DB, kbmMemTable,ImgList,DateUtils, Buttons, DBCtrls, ADODB,Mask, bsSkinCtrls, BusinessSkinForm; type TfrmAccCloseOffBack = class(TForm) memTblPeriod: TkbmMemTable; dsrPeriod: TDataSource; memTblPeriodPERIOD: TStringField; memTblPeriodPYEAR: TIntegerField; memTblPeriodPMONTH: TIntegerField; memTblPeriodFDAY: TDateTimeField; memTblPeriodTDAY: TDateTimeField; memTblPeriodCLOSED: TStringField; Label3: TLabel; Memo1: TMemo; memTblPeriodPeriodDsp: TStringField; EditPeriod: TEdit; bbtnExcute: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsBusinessSkinForm1: TbsBusinessSkinForm; procedure FormShow(Sender: TObject); procedure memTblPeriodCalcFields(DataSet: TDataSet); procedure bbtnExcuteClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var frmAccCloseOffBack: TfrmAccCloseOffBack; implementation uses my_sys_function, u_main; {$R *.dfm} procedure TfrmAccCloseOffBack.FormShow(Sender: TObject); var aQuery : TAdoQuery; begin aQuery:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; SQL.Add('Select * from Period'); SQL.Add('where Closed=''T'' order by period'); Open; with memTblPeriod do begin Close; EmptyTable; Filtered:=false; LoadFromDataSet(aQuery, []); Last; bbtnExcute.Enabled:=RecordCount>0; if bbtnExcute.Enabled then EditPeriod.Text:=FieldByName('PeriodDsp').AsString else EditPeriod.Text:='没有可以反结转的期间'; end; finally Close;Free; end; end; procedure TfrmAccCloseOffBack.memTblPeriodCalcFields(DataSet: TDataSet); begin with DataSet do FieldByName('PeriodDsp').AsString:= Format(' %d 年 %d 月', [FieldByName('PYear').AsInteger, FieldByName('PMonth').AsInteger]); end; procedure TfrmAccCloseOffBack.bbtnExcuteClick(Sender: TObject); var aQuery, aQuery2 : TAdoQuery; aYear, aMonth : String; tyear,tmonth:integer; begin aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; with aQuery do try frm_main.db.BeginTrans; with memTblPeriod do begin aYear:=FieldByName('PYear').AsString; aMonth:=FieldByName('PMonth').AsString; end; Close;SQL.Clear; SQL.Add('Update Period Set Closed=''F'''); SQL.Add('where Period='''+memTblPeriod.FieldByName('Period').AsString+''''); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_bank_genleg'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_cust_genleg'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_genleg'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_custbalance'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; Logininfo.offyear:=StrToInt(aYear); Logininfo.offmonth:=StrToInt(amonth); if strtoint(get_parameters_value(140,'0'))=0 then Logininfo.endday:=EncodeDate(Logininfo.offyear, Logininfo.offmonth,1)-1 else begin if Logininfo.offmonth=1 then begin tYear:=Logininfo.offyear-1; tmonth:=12; end else begin tYear:=Logininfo.offyear; tmonth:=Logininfo.offmonth-1; end; Logininfo.endday:=EncodeDate(tyear,tmonth,strtoint(get_parameters_value(140,'0'))); end; frm_main.db.CommitTrans; memTblPeriod.Delete; memTblPeriod.Last; bbtnExcute.Enabled:=memTblPeriod.RecordCount>0; if bbtnExcute.Enabled then EditPeriod.Text:=memTblPeriod.FieldByName('PeriodDsp').AsString else EditPeriod.Text:='没有可以反结转的期间'; MessageDlg('反结帐工作已经完成!', mtWarning, [mbOk], 0); finally Close; FreeAndNil(aQuery); aQuery2.Close; FreeAndNil(aQuery2); frm_main.db.RollbackTrans; end; end; end.