📄 main.~pas
字号:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, ExtCtrls, DBCtrls, Grids, DBGrids, Menus, StdCtrls,
ComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet4: TTabSheet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
Table1: TTable;
Database1: TDatabase;
MainMenu1: TMainMenu;
F1: TMenuItem;
X1: TMenuItem;
S1: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
H1: TMenuItem;
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
TreeView1: TTreeView;
GroupBox1: TGroupBox;
ComboBox1: TComboBox;
Edit2: TEdit;
Label3: TLabel;
Label4: TLabel;
Button2: TButton;
Button3: TButton;
DBGrid2: TDBGrid;
DataSource2: TDataSource;
Table2: TTable;
Edit3: TEdit;
Label5: TLabel;
DBNavigator2: TDBNavigator;
Label6: TLabel;
Label7: TLabel;
Edit5: TEdit;
Label8: TLabel;
DBGrid3: TDBGrid;
DBNavigator3: TDBNavigator;
Button4: TButton;
Button5: TButton;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
Edit4: TEdit;
Label9: TLabel;
DBGrid4: TDBGrid;
DBNavigator4: TDBNavigator;
Edit6: TEdit;
Label10: TLabel;
Edit7: TEdit;
Table3: TTable;
DataSource3: TDataSource;
GroupBox2: TGroupBox;
StatusBar1: TStatusBar;
Label13: TLabel;
Edit10: TEdit;
DBGrid5: TDBGrid;
DBNavigator5: TDBNavigator;
Button6: TButton;
Label14: TLabel;
Edit11: TEdit;
Button7: TButton;
Edit12: TEdit;
Label15: TLabel;
Label16: TLabel;
Label11: TLabel;
Label12: TLabel;
Edit8: TEdit;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Edit9: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure X1Click(Sender: TObject);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure Button4Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
count,count1,count2,count3,count4: double;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
mynode,tmpnode: TTreenode;
year,month,day: word;
now2: Tdatetime;
begin
table1.Active:=true;
if table3.Active=false then
begin
table3.Active:=true;
end;
if table2.Active=false then
begin
table2.Active:=true;
end;
with treeview1 do
begin
while (not (table3.Eof)) do
begin
mynode:=items.Add(nil,table3.fieldbyname('usertype').AsString);
mynode.ImageIndex:=0;
mynode.SelectedIndex:=0;
with table2 do
begin
if Active=true then
begin
Active:=false;
end;
Filter :='usertype='+''''+table3.fieldbyname('usertype').AsString+'''';
Filtered := True;
active := True; //激活Table控件
while not eof do
begin
tmpnode:=items.AddChild(mynode,fieldbyname('username').AsString);
tmpnode.ImageIndex:=1;
tmpnode.SelectedIndex:=1;
next;
end;
end;
table3.Next;
end;
end;
now2:=date();
decodedate(now2,year,month,day);
edit8.Text :=inttostr(year)+'年'+inttostr(month)+'月'+inttostr(day)+'日';
if table3.Active=false then
begin
table3.Active:=true;
end;
table3.First;
while not table3.Eof do
begin
combobox1.Items.Add(table3.fieldbyname('usertype').AsString);
table3.Next;
end;
combobox2.Items.Add('收入');
combobox2.Items.Add('支出');
combobox3.Items.Add('清帐');
combobox3.Items.Add('债务');
combobox3.Items.Add('债权');
table2.Last;
if table2.FieldByName('id').AsString='' then
begin
edit3.Text:=inttostr(1);
end
else
begin
edit3.Text:=inttostr(strtoint(table2.FieldByName('id').AsString)+1);
end;
table1.Last;
if table1.FieldByName('id').AsString='' then
begin
edit4.Text:=inttostr(1);
end
else
begin
edit4.Text:=inttostr(strtoint(table1.FieldByName('id').AsString)+1);
end;
table3.Last;
if table3.FieldByName('id').AsString='' then
begin
edit11.Text:=inttostr(1);
end
else
begin
edit11.Text:=inttostr(strtoint(table3.FieldByName('id').AsString)+1);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if (not (edit2.Text='')) or (combobox1.Items[combobox1.ItemIndex]='')then
begin
table2.Append;
table2.Last;
table2.Insert;
table2.FieldByName('id').AsString:=edit3.Text;
table2.FieldByName('username').AsString:=edit2.Text;
table2.FieldByName('usertype').AsString:=combobox1.Items[combobox1.ItemIndex];
table2.Post;
edit2.Text:='';
edit2.Focused;
edit3.Text:=inttostr(strtoint(table2.FieldByName('id').AsString)+1);
end
else
begin
groupbox1.Caption:='编号不能为空';
end;
end;
procedure TForm1.X1Click(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
count:=0;
count1:=0;
count2:=0;
count3:=0;
count4:=0;
Table2.Filter:='username= '+''''+treeview1.Selected.Text+'''';
Table2.Filtered:=true;
edit6.Text:=treeview1.Selected.Text;
Table1.Filter:='username= '+''''+treeview1.Selected.Text+'''';
Table1.Filtered:=true;
edit2.Text:=treeview1.Selected.Text;
table1.First;
while not table1.Eof do
begin
if table1.FieldByName('option').AsString='收入' then
begin //计算收入总额
count1:=count1+strtofloat(table1.FieldByName('money').AsString);
end;
if table1.FieldByName('option').AsString='支出' then
begin //计算支出总额
count2:=count2+strtofloat(table1.FieldByName('money').AsString);
end;
if table1.FieldByName('moneystat').AsString='债务' then
begin //计算债务总额
count3:=count3+strtofloat(table1.FieldByName('money').AsString);
end;
if table1.FieldByName('moneystat').AsString='债权' then
begin //计算债权总额
count4:=count4+strtofloat(table1.FieldByName('money').AsString);
end;
//count:=count+strtofloat(table1.FieldByName('money').AsString);
table1.Next;
end;
count:=count3-count4;
if count>0 then
begin
edit14.Text:='债务';//清欠状态
edit15.Text:=floattostr(count);//清欠数额
end
else if count=0 then
begin
edit14.Text:='清帐';//清欠状态
edit15.Text:=floattostr(count);//清欠数额
end
else
begin
edit14.Text:='债权';//清欠状态
edit15.Text:=floattostr(-count);//清欠数额
end;
edit9.Text:=floattostr(count1);//收入总额
edit13.Text:=floattostr(count2);//支出总额
//edit14.Text:=floattostr(count3);//清欠状态
//edit15.Text:=floattostr(count4);//清欠数额
end;
procedure TForm1.Button4Click(Sender: TObject);
var
now2: Tdatetime;
year,month,day: word;
begin
if (not (edit2.Text='')) or (combobox1.Items[combobox1.ItemIndex]='')then
begin
if (combobox2.Items[combobox2.ItemIndex]='支出') and (combobox3.Items[combobox3.ItemIndex]='债权')then
begin
showmessage('你们家买别人东西还能自己还能收钱呀?真是的!');
end
else if (combobox2.Items[combobox2.ItemIndex]='收入') and (combobox3.Items[combobox3.ItemIndex]='债务')then
begin
showmessage('你们家卖别人东西还能自己还能欠帐呀?真是的!');
end
else
begin
table1.Append;
table1.Last;
table1.Insert;
table1.FieldByName('id').AsString:=edit4.Text;
table1.FieldByName('username').AsString:=edit6.Text;
table1.FieldByName('option').AsString:=combobox2.Items[combobox2.ItemIndex];
table1.FieldByName('optime').AsString:=edit8.Text;
table1.FieldByName('money').AsString:=edit5.Text;
table1.FieldByName('moneystat').AsString:=combobox3.Items[combobox3.ItemIndex];
table1.FieldByName('bak').AsString:=edit12.Text;
table1.Post;
edit2.Text:='';
edit2.Focused;
edit4.Text:=inttostr(strtoint(table1.FieldByName('id').AsString)+1);
table1.First;
while not table1.Eof do
begin
count:=count+strtofloat(table1.FieldByName('money').AsString);
table1.Next;
end;
edit9.Text:=floattostr(count);
end;
end
else
begin
groupbox1.Caption:='编号不能为空';
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
table3.Append;
table3.Last;
table3.Insert;
table3.FieldByName('id').AsString:=edit11.Text;
table3.FieldByName('usertype').AsString:=edit10.Text;
table3.Post;
edit10.Text:='';
edit10.Focused;
edit11.Text:=inttostr(strtoint(table3.FieldByName('id').AsString)+1);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -