📄 newmonth_f.pas
字号:
unit NewMonth_F;
interface
uses
Windows,
ShellApi, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ExtCtrls;
type
TF_NewMonth = class(TForm)
Memo1: TMemo;
Bt_Ok: TButton;
E_Year: TEdit;
Bt_Cancel: TButton;
Label1: TLabel;
E_Month: TEdit;
Label2: TLabel;
Label3: TLabel;
Label5: TLabel;
E_OK: TEdit;
Panel: TPanel;
procedure Bt_OkClick(Sender: TObject);
procedure Bt_CancelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
F_NewMonth: TF_NewMonth;
implementation
uses Variants, CommSmdljf, Proc_Dm, Msg_F, Comm, Login_F, Main_F, Table_DM;
{$R *.DFM}
procedure TF_NewMonth.Bt_OkClick(Sender: TObject);
var
GbakParam: string;
DBName, BakDBName, BakGDBName:String;
Error: Integer;
CopyOK: boolean;
begin
if E_OK.Text <> 'OK' Then
Begin
MessageBox(Handle, '确实要进行月底结帐处理请在输入框输入 OK 再按确定键','系统提示',MB_OK);
Exit;
End;
DBName := F_Login.E_DBName.Text;//参数当前使用的数据库名
BakDBName := gRootPath+'SMDLJF'+CurrentYear+CurrentMonth+'.GBK';//备份库文件名
BakGDBName := gRootPath+'SMDLJF'+CurrentYear+CurrentMonth+'.GDB';//当月数据库名
GbakParam := '-b -user sysdba -password masterkey '
+ DBName + ' '//当前使用的数据库名
+ BakDBName;
If F_Login.E_Server.Text <> '' Then//用户输入了服务器
Begin
If Application.MessageBox('您必须先手工备份数据库然后结帐,您确认要现在结帐吗?','系统警告',MB_YESNO) <> IDYES Then
Exit;
End
Else
Begin
If FileExists(BakGDBName) then
Begin
MessageBox(Handle,PChar('文件 '+BakGDBName+' 已经存在, 这个月你已做了一次备份'),'系统提示',0);
Exit;
End;
P_OpenMessageBox('系统提示','正在备份数据数据库,请稍候...');
CopyOK := CopyFile(PChar(DBName), PChar(BakGDBName), false);//直接拷贝数据库文件
Error := GetLastError();
P_CloseMessageBox();//关闭消息窗口
If Not CopyOK Then
Begin
MessageBox(Handle,PChar('拷贝数据库文件时出现错误. 错误号是: '+IntToStr(Error)
+ #13#10
+'系统执行的函数是: CopyFile('+DBName+','+BakGDBName+')'),
'系统警告',0);
Exit;
End;
End;
P_OpenMessageBox('系统提示','正在生成下月数据,请稍候...');
Error := ShellExecute(Handle,'Open',PChar(gRootPath+'gbak'),PChar(GbakParam),Nil,SW_HIDE);
P_CloseMessageBox();//关闭消息窗口
If (Error <= 32) then
Begin
MessageBox(Handle,PChar('结帐时出现错误. 错误号是: '+IntToStr(Error)
+ #13#10
+'系统执行的命令是: GBAK '+GbakParam),
'系统警告',0);
Exit;
End;
//数据备份成功才做新月份的工作
P_NewMonth();//做新月开始应做的工作
P_CloseMessageBox();//关闭消息窗口
MessageBox(Handle,PChar('数据已备份到当前目录下的文件'
+ BakDBName
+ ', 请注意保存此文件'),
'系统提示',0);
Close();
end;
procedure TF_NewMonth.Bt_CancelClick(Sender: TObject);
begin
Close();
end;
procedure TF_NewMonth.FormShow(Sender: TObject);
var
AccountDate: String;
LastDate: TDateTime;
Year, Month, Day:Word;
Msg:String;
begin
P_GetCurrentYearMonth(CurrentYear, CurrentMonth);
E_Year.Text := CurrentYear;
E_Month.Text := CurrentMonth;
E_Ok.Text := '';
with DM_Table,Query Do
Begin
Active := False;
SQL.Text := 'select max(f_date) f_Date from tb_ammeter_detail';
Query.Open();
If Query['f_Date'] <> NULL Then//检查上备份日期
Begin
LastDate := StrToDate(Query['f_Date']);
DecodeDate(LastDate, Year, Month, Day);
If Month = 12 Then//当前月份应为
Begin
Inc(Year);
Month := 1;
End
Else
Inc(Month);
If (Year <> StrToInt(CurrentYear)) Or (Month <> StrToInt(CurrentMonth)) Then
Begin
Msg := Format('系统应结帐时间为%d年%d月, 现在为%s年%s月,请核实!!',[Year,Month,CurrentYear,CurrentMonth]);
Application.MessageBox(PChar(Msg),'系统警告',MB_OK);
End;
End;
Active := false;
SQL.Clear();
AccountDate := CurrentMonth + '-1' + '-' + CurrentYear;
SQL.Add('Select Count(*) As Cnt From Tb_Ammeter_Detail Where F_Date >= '+ QuotedStr(AccountDate) );
Try
Open();
if Query['Cnt'] > 0 Then
Application.MessageBox('当前月份的数据已作过结帐处理','请核实',MB_OK);
Finally
Active := false;
End;
End;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -