📄 unit_wh.pas
字号:
unit Unit_WH;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, IniFiles, FileCtrl;
type
TForm_WH = class(TForm)
BitBtn_close: TBitBtn;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
BitBtn_BF: TBitBtn;
BitBtn_HF: TBitBtn;
CheckBox_ZD: TCheckBox;
CheckBox_HF: TCheckBox;
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
Panel2: TPanel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
BitBtn_QL: TBitBtn;
Label11: TLabel;
TabSheet3: TTabSheet;
Panel3: TPanel;
Label12: TLabel;
Bevel1: TBevel;
BitBtn_DC: TBitBtn;
BitBtn_DR: TBitBtn;
Memo1: TMemo;
BitBtn_Open: TBitBtn;
OpenDialog1: TOpenDialog;
RadioButton_txt: TRadioButton;
RadioButton_xls: TRadioButton;
Label13: TLabel;
procedure BitBtn_closeClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn_BFClick(Sender: TObject);
procedure BitBtn_HFClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn_QLClick(Sender: TObject);
procedure BitBtn_DCClick(Sender: TObject);
procedure BitBtn_OpenClick(Sender: TObject);
procedure BitBtn_DRClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
filepath : String;
end;
var
Form_WH: TForm_WH;
implementation
uses jia;
{$R *.dfm}
procedure TForm_WH.BitBtn_closeClick(Sender: TObject);
begin
Close;
end;
procedure TForm_WH.FormShow(Sender: TObject);
var
myinifile : TIniFile;
begin
PageControl1.ActivePageIndex := 0;
filepath :=ExtractFilePath(Paramstr(0));
myinifile :=Tinifile.Create(filepath+'data\Home.dft');
try
DirectoryListBox1.Directory := myinifile.ReadString('数据库','Bakpath',filepath+'\Bak');
CheckBox_ZD.Checked := myinifile.ReadBool('数据库','自动备份',False);
finally
myinifile.Destroy;
end;
DriveComboBox1.Drive := DirectoryListBox1.Drive;
end;
procedure TForm_WH.BitBtn_BFClick(Sender: TObject);
var
myinifile : TInifile;
begin //备份数据
myinifile :=Tinifile.Create(filepath+'data\Home.dft');
try
myinifile.WriteString('数据库','Bakpath',Label6.Caption);
finally
myinifile.Destroy;
end;
DriveComboBox1.Drive := DirectoryListBox1.Drive;
Form1.Table1.Active := False;
if Form1.filecopy(filepath+'data\Home.dft',Label6.Caption+'\Home.dft.bak')
and Form1.filecopy(filepath+'data\Home.dat',Label6.Caption+'\Home.dat.bak')
and Form1.filecopy(filepath+'data\Home.DBF',Label6.Caption+'\Home.DBF.bak')
and Form1.filecopy(filepath+'data\Home.MDX',Label6.Caption+'\Home.MDX.bak') then
showmessage('手动备份数据成功!');
Form1.Table1.Active := True;
end;
procedure TForm_WH.BitBtn_HFClick(Sender: TObject);
begin
Form1.Table1.Active := False;
if CheckBox_HF.Checked then
begin
if Form1.filecopy(filepath+'Bak\Home.dft.000',filepath+'data\Home.dft')
and Form1.filecopy(filepath+'Bak\Home.dat.000',filepath+'data\Home.dat')
and Form1.filecopy(filepath+'Bak\Home.DBF.000',filepath+'data\Home.DBF')
and Form1.filecopy(filepath+'Bak\Home.MDX.000',filepath+'data\Home.MDX') then
showmessage('自动备份的数据恢复成功!');
end
else
begin
if Form1.filecopy(Label6.Caption+'\Home.dft.bak',filepath+'data\Home.dft')
and Form1.filecopy(Label6.Caption+'\Home.dat.bak',filepath+'data\Home.dat')
and Form1.filecopy(Label6.Caption+'\Home.DBF.bak',filepath+'data\Home.DBF')
and Form1.filecopy(Label6.Caption+'\Home.MDX.bak',filepath+'data\Home.MDX') then
showmessage('手动备份的数据恢复成功!');
end;
Form1.Table1.Active := True;
end;
procedure TForm_WH.FormClose(Sender: TObject; var Action: TCloseAction);
var
myinifile : TIniFile;
begin
myinifile :=Tinifile.Create(filepath+'data\Home.dft');
try
myinifile.WriteBool('数据库','自动备份',CheckBox_ZD.Checked);
finally
myinifile.Destroy;
end;
Form1.TreeView1.SetFocus;
end;
procedure TForm_WH.BitBtn_QLClick(Sender: TObject);
var
T,Y : String;
F :Double;
I : Integer;
mynode : TTreeNode;
begin //清理陈旧数据
T:= DateToStr(Date);
Y:= Copy(T,1,4);
Y:= IntToStr(StrToInt(Y)-2);
Form1.SDate := StrToDate(Y+'-1-1');
Form1.EDate := StrToDate(Y+'-12-31');
Form1.chaxun;
if Form1.Table1.RecordCount <> 0 then
begin
Form1.DBGrid1.DataSource.Enabled := False;
for i:=0 to Form1.TreeView1.Items.Count -1 do
begin
mynode := Form1.TreeView1.Items[i];
if mynode.Level = 1 then
begin
Form1.Table1.Filter := '(type1='+#39+mynode.Parent.Text+#39+')and(type2='+#39+mynode.Text+#39+')and(Memo<>'+#39+'属于统计记录'+#39+')';
Form1.Table1.Filtered := True;
F:= Form1.TableMoneyJS;
if (F <> 0) and (F < 99999999) then
begin
Form1.Table1.Edit;
Form1.Table1.AppendRecord([StrtoDate(Y+'-1-1'),'管理员',mynode.Parent.Text,mynode.Text,'其它',F,'其它','属于统计记录']);
Form1.Table1.First;
while not Form1.Table1.Eof do
Form1.Table1.Delete;
end;
end;
end;
Form1.DBGrid1.DataSource.Enabled := True;
ShowMessage('前年的记录记录已处理!');
end
else
ShowMessage('前年的记录记录没有找到!');
end;
procedure TForm_WH.BitBtn_DCClick(Sender: TObject);
var
I: Integer;
Str: String;
StrList: TStringList;//用于存储数据的字符列表
begin //导出数据到excel表
StrList := TStringList.Create;
Str := '日期'+#9+'姓名'+#9+'分区'+#9+'分类'+#9+'项目'+#9+'地址'+#9+'金额'+#9+'详细描述'+#9;
StrList.Add(Str);
try
with Form1.Table1 do
begin
First;
while not Eof do
begin
Str := '';
for I := 0 to FieldCount-1 do
Str := Str + Fields[I].AsString + #9; //关键是错在这儿
StrList.Add(Str);
Next;
end;
if RadioButton_xls.Checked then
Str := 'Home.xls'
else
Str := 'Home.txt';
StrList.SaveToFile(filepath+Str);
MessageBox(Application.Handle,PChar('导出完毕!'+#13+'地址:'+filepath+Str),'系统',MB_OK);
end;
StrList.Free;
except
StrList.Free;
end;
end;
procedure TForm_WH.BitBtn_OpenClick(Sender: TObject);
begin
OpenDialog1.InitialDir := filepath;
if OpenDialog1.Execute then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
BitBtn_DR.Enabled := True;
end;
end;
procedure TForm_WH.BitBtn_DRClick(Sender: TObject);
var
str,S1,S2,S3,S4,S5,S6,S7,S8,S : String;
I,J,n : Integer;
T: Boolean;
begin
try
n := 0;
for I:=0 to Memo1.Lines.Count -1 do
begin
str := Memo1.Lines[i];
if copy(Str,Length(Str),1) = #9 then Str := copy(Str,1,Length(Str)-1);
S1:='';S2:='';S3:='';S4:='';S5:='';S6:='';S7:='';S8:='';
for J:=1 to Length(str) do
begin
S := Copy(str,j,1);
if s = #9 then
begin
S1 := S2;
S2 := S3;
S3 := S4;
S4 := S5;
S5 := S6;
S6 := S7;
S7 := S8;
S8 := '';
end
else
S8 := S8+S;
end;
if S8 = '' then S8 :='...';
if (S1<>'')and(S2<>'')and(S3<>'')and(S4<>'')and(S5<>'')and(S6<>'')and(S7<>'')then
begin
T := True;
for j:=1 to length(S1) do
if not (S1[j] in ['1','2','3','4','5','6','7','8','9','0','-']) then T := False;
if T then
begin
Form1.Table1.Edit;
Form1.Table1.SetFields([StrToDate(S1),S2,S3,S4,S5,StrToFloat(S6),S7,S8]);
Form1.Table1.Post;
n := n+1;
end;
end;
end;
BitBtn_DR.Enabled := False;
MessageBox(Application.Handle,PChar('共导入'+intToStr(n)+'条记录'),'系统',MB_OK);
except
MessageBox(Application.Handle,'格式错误!','系统',MB_OK);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -