📄 uinput.pas
字号:
{
说明:
opendb
closedb
writeDataToTXTFile
}
unit uinput;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, DBTables, ComCtrls, ExtCtrls, Mask, ToolEdit,
CurrEdit;
type
Tfrminput = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ListBox1: TListBox;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
DT1: TDateTimePicker;
Edit1: TCurrencyEdit;
Edit2: TEdit;
cmdNewSub: TBitBtn;
//将数据写入文本文件中
function WriteDataToTXTFile: integer;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
//根据收入和支出改变收支细类的显示
procedure ShowSZSub(pSZ: integer);
procedure cmdNewSubClick(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frminput: Tfrminput;
implementation
{$R *.DFM}
uses Tools, yytools;
//将数据写入文本文件中
function Tfrminput.WriteDataToTXTFile: integer;
var
s1: string;
begin
//清空列表框
listbox1.Clear;
s1 := edit1.text;
WriteDataToTXTFile := 0;
if combobox1.text = '支出' then
begin
if strtofloat(s1) > 0 then
begin
s1 := '-' + s1;
end;
end
else
if strtofloat(s1) < 0 then
begin
WriteDataToTXTFile:=1;
showmessage('收入金额不能为负数!')
end;
begin
end;
if frmInput.Caption = '新增' then begin
gnBottomID := gnBottomID + 1;
//写入记录的ID值
listbox1.items.Add(inttostr(gnBottomID))
end
else if frmInput.Caption = '修改' then begin
listbox1.items.Add(inttostr(gnCurrID));
end;
//数据写入listbox中
listbox1.Items.Add(combobox1.text);
listbox1.Items.Add(combobox2.text);
listbox1.Items.Add(combobox3.text);
listbox1.Items.Add(s1);
listbox1.Items.Add(FormatDateTime('yyyy-mm-dd', Dt1.date));
if length(Edit2.text) = 0 then edit2.text := 'NULL';
listBox1.Items.Add(Edit2.Text);
//记录写入文本文件中
listbox1.Items.SaveToFile(GetAppPath + 'rec.txt');
end;
procedure Tfrminput.BitBtn1Click(Sender: TObject);
begin
//将数据写入文本文件中
if WriteDataToTXTFile=0 then begin
//关闭窗口
frminput.close;
end;
end;
procedure Tfrminput.BitBtn2Click(Sender: TObject);
begin
//清空列表框
listbox1.Clear;
listbox1.Items.SaveToFile(GetAppPath + 'rec.txt');
frminput.close;
end;
//根据收入和支出改变收支细类的显示
procedure Tfrminput.ShowSZSub(pSZ: integer);
begin
if pSZ = 0 then begin
combobox2.Items.LoadFromFile(GetApppath + 'dat\sr.dat');
combobox2.ItemIndex := 0;
end
else begin
combobox2.Items.LoadFromFile(GetApppath + 'dat\zc.dat');
combobox2.ItemIndex := 0;
end;
end;
procedure Tfrminput.FormShow(Sender: TObject);
begin
combobox3.Items.LoadFromFile(GetApppath + 'dat\fs.dat');
if frmInput.Caption = '修改' then begin
listbox1.Items.LoadFromFile(GetAppPath + 'rec.txt');
combobox1.ItemIndex := combobox1.Items.Indexof(listbox1.Items[1]);
if listbox1.Items[1] = '收入' then
combobox2.Items.LoadFromFile(GetAppPath + '\dat\sr.dat')
else
combobox2.Items.LoadFromFile(GetAppPath + '\dat\zc.dat');
combobox2.ItemIndex := combobox2.Items.Indexof(listbox1.Items[2]);
combobox3.ItemIndex := combobox3.Items.Indexof(listbox1.Items[3]);
edit1.Text := listbox1.Items[4];
DT1.DateTime := strtodatetime(listbox1.items[5]);
Edit2.Text := listbox1.Items[6];
end
else if frmInput.Caption = '新增' then begin
DT1.DateTime := Now;
combobox1.Text := '';
combobox2.Text := '';
edit1.text := '';
edit2.text := '';
//收入和支出的缺省值
combobox1.ItemIndex := 0;
ShowSZSub(0);
combobox3.Itemindex := 0;
end;
end;
procedure Tfrminput.cmdNewSubClick(Sender: TObject);
var
sNewSub: string;
begin
//输入新的细类
sNewSub := inputbox('新细类', '请输入新的收支细类', '');
if (trim(sNewSub) <> '') and (combobox2.Items.IndexOf(sNewSub) = -1) then begin
combobox2.Items.Add(sNewSub);
if combobox1.itemindex = 0 then begin
combobox2.Items.SaveToFile(GetApppath + 'dat\sr.dat');
end
else begin
combobox2.Items.SaveToFile(GetApppath + 'dat\zc.dat');
end;
end;
end;
procedure Tfrminput.ComboBox1Change(Sender: TObject);
begin
ShowSZSub(combobox1.itemindex);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -