📄 yytools.pas
字号:
begin
if gbCanQuery = false then exit;
c := ydRecordCount(tableQuery) + 1;
if c = 1 then
begin
Application.MessageBox('没有找到相应的记录。', 'Money', MB_OK + MB_ICONEXCLAMATION + MB_DEFBUTTON1 + MB_APPLMODAL);
exit;
end;
pageMain.ActivePage := tabQuery;
gridQuery.Clear;
gridQUERY.RowCount := 0;
gridQUERY.RowCount := c;
gridQUERY.fixedrows := 1;
//网格标题
gridQUERY.Cells[0, 0] := '编号';
gridQUERY.Cells[1, 0] := '收支大类';
gridQUERY.Cells[2, 0] := '收支细类';
gridQUERY.Cells[3, 0] := '收支方式';
gridQUERY.Cells[4, 0] := '收支金额';
gridQUERY.Cells[5, 0] := '收支日期';
gridQUERY.Cells[6, 0] := '备注';
ydOpenDB(2); //打开数据库
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
i := 1;
//循环读取数据库内容
while not tableQuery.Eof do
begin
for j := 1 to listbox1.items.count do
begin
s := tableQuery.FieldByName(listbox1.items[j - 1]).value;
if s = 'NULL' then s := '';
if listbox1.items[j - 1] = 'SZMONEY' then
s := Format('%n', [StrToFloat(s)]);
gridQuery.Cells[j - 1, i] := s
end;
tableQuery.Next;
inc(i);
end;
ydCloseDB(2); //关闭数据库
end;
end;
end;
//修改指定的记录
//1999.9.25 11.10.
procedure ydEditRecord;
var
i: integer;
begin
gbCanEdit := true;
with frmMain do
begin
//判断是否选择了正确的记录
if grid01.Cells[0, grid01.row] <> '' then
begin
gnCurrID := strtoint(grid01.Cells[0, grid01.row]);
//将记录写入到ListBox中
listBox2.Clear;
for i := 0 to listbox1.Items.Count - 1 do
listbox2.Items.Add(grid01.Cells[i, grid01.row]);
listbox2.Items.SaveToFile(GetAppPath + 'rec.txt');
end
else
gbCanEdit := false;
end;
end;
//显示编辑单条记录窗口
//1999.9.25. 11.10.
procedure yiShowInputWindow(s: string);
var
s1: string;
begin
if gbCanEdit = false then exit;
s1 := ExtractWord(2, s, [' ']);
frmInput.Caption := s1;
frmInput.showmodal;
end;
//显示查询窗口
//edit 1999.11.2.
procedure yiShowQueryWindow;
var
s1: string;
begin
frmQuery.showmodal;
end;
//在状态栏显示信息
//1999.9.25. 10.11. 10.16. 10.17. 11.13.
procedure yiShowStatus(s: string);
var
i, j: integer;
s1, s2: string;
begin
i := StrToInt(ExtractWord(2, s, [' ']));
s1 := ExtractWord(3, s, [' ']);
//显示 收入和支出 状态
if s1 = 'SHOURUZHICHU' then
begin
ydCalShouRuZhiChu;
s1 := '收入:' + Format('%n', [gcShouRu]) + ' 支出:' + Format('%n', [gcZhiChu]);
s1 := s1 + ' 平衡:' + Format('%n', [gcShouRu + gcZhiChu]);
end;
//显示操作执行结果的信息
if i = 1 then
begin
j := gnMsg div 100;
case j of
3: s2 := '成功';
2: s2 := '取消';
1: s2 := '失败';
end;
s1 := s1 + ':' + s2;
end;
frmMain.StatusBar.panels[i].text := s1;
end;
//查询收入和支出
//1999.10.11. 10.16.
procedure ydCalShouRuZhiChu;
var
s: string;
begin
with frmMain do
begin
ydOpenDB(1); //打开中间数据库
gcShouRu := 0; gcZhiChu := 0;
while not tableMid.eof do
begin
s := tableMid.FieldbyName('SZTYPE').value;
if s = '收入' then
begin
gcShouRu := gcShouRu + tableMid.FieldbyName('SZMONEY').value;
end;
if s = '支出' then
begin
gcZhiChu := gcZhiChu + tableMid.FieldbyName('SZMONEY').value;
end;
tableMid.Next;
end;
ydCloseDB(1);
end;
end;
//生成中间数据库
//1999.10.16. 11.9. 11.16. 11.17.
procedure ydGenMid(s: string);
var
s1: string;
iniFile: TiniFile;
lnShouZhi: integer;
lsShouZhi: string;
lnSort: integer;
begin
with frmMain do
begin
s1 := UpperCase(ExtractWord(2, s, [' '])); //参数表示生成中间数据库的方法
if s1 = 'NEW' then ysCopyFile('ysCopyFile MoneyBAK.ebf MoneyMid.ebf');
if s1 = 'MONEY' then
begin
iniFile := TiniFile.create(GetAppPath + 'money99.ini');
//获得显示收支的类型
lnShouZhi := iniFile.ReadInteger('Show', 'ShouZhi', 0);
//获得排序类型
lnShouZhi := iniFile.ReadInteger('Show', 'Sort', 0);
iniFile.free;
//全部显示
if lnShouZhi = 0 then
begin
ysCopyFile('ysCopyFile Money.ebf MoneyMid.ebf');
exit;
end;
//只显示收入
if lnShouZhi = 1 then lsShouZhi := '收入';
//只显示支出
if lnShouZhi = 2 then lsShouZHi := '支出';
if (lnShouZhi = 1) or (lnShouZhi = 2) then
begin
//生成一个新的中间数据库
ysCopyFile('ysCopyFile MoneyBAK.ebf MoneyMid.ebf');
ydOpenDB(0);
ydOpenDB(1);
while not tableMain.eof do
begin
if tableMainSZType.value = lsShouZhi then
begin
tableMid.Append;
tableMidID.value := tableMainID.value;
tableMidSZTYPE.value := tableMainSZTYPE.value;
tableMidSZSUB.value := tableMainSZSUB.value;
tableMidSZMONEY.value := tableMainSZMONEY.value;
tableMidSZFS.value := tableMainSZFS.value;
tableMidSZDATE.value := tableMainSZDATE.value;
tableMidSZMEM.value := tableMainSZMEM.value;
tableMid.Post;
end;
tableMain.Next;
end;
ydCloseDB(0);
ydCloseDB(1);
end;
//不排序
if lnSort = 0 then
begin
end;
//按照日期进行排序
if lnSort = 1 then
begin
//对中间数据库进行操作
ydOpenDB(1);
tableMid.SortTo(GetAppPath + 'money_s', 'SZDATE', SortUp);
ydCloseDB(1);
ysEncrypt(GetAppPath + 'money_s.dbf', GetAppPath + 'money_s.ebf');
CopyFile(GetAppPath + 'money_s.ebf', GetAppPath + 'moneymid.ebf');
ysDelFile(GetAppPath + 'money_s.ebf');
end;
end;
end;
end;
//查询条件--收支限制
function Query_TypeCondition(pCondition, pType, pSubType, pTypeValue, pSubTypeValue: string): integer;
begin
Query_TypeCondition := 0;
//假如查询条件是全部收支
if pCondition = 'ALL' then begin
if pType = pTypeValue then begin
Query_TypeCondition := 1;
exit
end
else begin
Query_TypeCondition := 0;
exit
end;
end
//假如查询条件是某种收支
else begin
if (pType = pTypeValue) and (pSubType = pSubTypeValue) then begin
Query_TypeCondition := 1;
exit
end
else begin
Query_TypeCondition := 0;
exit
end;
end;
Query_TypeCondition := 0;
end;
//查询条件--金额限制判断
function Query_MoneyCondition(pCondition: string; pMoney, pMax, pMin: Double): integer;
begin
Query_MoneyCondition := 0;
//假如有金额限制
if pCondition = '1' then begin
if (pMoney >= pMin) and (pMoney <= pMax) then
Query_MoneyCondition := 1
else
Query_MoneyCondition := 0;
end
//假如没有金额限制
else begin
Query_MoneyCondition := 1;
end;
end;
//完成具体的查询操作
//1999.11.2. 11.12.
procedure ydQueryProcess; //完成查询的具体操作
var
iRecNum: integer;
iI: integer;
gQueryTJ: array[1..8] of string;
i: integer;
begin
//将条件输出
with frmMain do
begin
lstQuery.items.loadfromfile(GetAppPath + '\dat\Query.txt');
//如果是取消出来的,则跳出。
if lstQuery.Items.Count = 0 then exit;
for iI := 1 to 8 do
begin
gQueryTJ[iI] := lstQuery.items[iI - 1]
end;
//生成空的中间数据库
copyfile(Getapppath + 'moneybak.ebf', GetAppPath + 'moneyQ.ebf');
iRecNum := ydRecordCount(tableMain);
//打开数据库
if tableMain.Active = false then
ydOpenDB(0);
if tableQuery.Active = false then
ydOpenDB(2);
tableMain.First;
tableQuery.First;
//判断要显示的记录数目
if iRecNum = 0 then
begin
tableMain.close;
tableQuery.close;
exit;
end
else
begin
tableMain.first;
tableQuery.Edit;
for iI := 1 to iRecNum do
begin
if (tableMainSZDATE.value >= gQueryTJ[1]) and (tableMainSZDATE.value <= gQueryTJ[2]) then
begin
if Query_TypeCondition(gQueryTJ[8], tableMainSZType.Value, tableMainSZSub.Value, gQueryTJ[3], gQueryTJ[4]) = 1 then
begin
if Query_MoneyCondition(gQueryTJ[5], tableMainSZMoney.value, strtofloat(gQueryTJ[7]), strtofloat(gQueryTJ[6])) = 1 then
begin
tableQuery.Append;
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
for i := 0 to listbox1.items.count - 1 do
begin
tableQuery.FieldByName(listbox1.Items[i]).value := tableMain.FieldByName(listbox1.Items[i]).value
end;
tableQuery.Post;
tableMain.next;
end
else
tableMain.next;
end
else
tableMain.next;
end
else
tableMain.next;
end; //for
end; //else
ydCloseDB(0);
ydCloseDB(2);
end;
end;
//1999.11.15.
function ydRecordCount(t1: THalcyonDataSet): integer;
var
i: integer;
begin
with frmMain do
begin
if t1 = tableMain then
ysDeCrypt(GetAppPath + 'money.ebf', GetAppPath + 'money.dbf');
if t1 = tableMid then
ysDeCrypt(GetAppPath + 'moneymid.ebf', GetAppPath + 'moneymid.dbf');
if t1 = tableQuery then
ysDeCrypt(GetAppPath + 'moneyq.ebf', GetAppPath + 'moneyq.dbf');
i := 0;
with T1 do
begin
Open;
First;
while not EOF do
begin
Next;
i := i + 1;
end;
Close;
Result := i;
end;
if t1 = tableMain then
ysEnCrypt(GetAppPath + 'money.dbf', GetAppPath + 'money.ebf');
if t1 = tableMid then
ysEnCrypt(GetAppPath + 'moneymid.dbf', GetAppPath + 'moneymid.ebf');
if t1 = tableQuery then
ysEnCrypt(GetAppPath + 'moneyq.dbf', GetAppPath + 'moneyq.ebf');
end;
end;
//1999.11.15.
procedure ysDelFile(fDel: string);
var
f: file;
begin
Assign(f, fDel);
Erase(f);
end;
//1999.11.15.
procedure ysEncrypt(f1, f2: string);
begin
EncryptFile(f1, f2, 5719);
ysDelFile(f1);
end;
//1999.11.15.
procedure ysDeCrypt(f1, f2: string);
begin
DecryptFile(f1, f2, 5719);
end;
//显示设置窗口
procedure yiShowSetupWindow;
begin
frmSetup.ShowModal;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -