📄 yytools.pas
字号:
unit yytools;
//1999.9.17.
interface
uses Sysutils, Classes, buttons, Forms, Windows, Halcn6DB, EncryptIt, inifiles, Dialogs;
const
gnOK = 0;
gnNotOK = 1;
function InitYoYo: integer; //初始化
function ysCloseApp: integer; //关闭应用程序
function ysCopyFile(s: string): integer; //复制文件
procedure ysShowAbout; //显示关于窗口
procedure ysShowHelp; //显示帮助窗口
procedure RewriteLog; //建立日志文件
procedure AppendLog(s: string); //写日志文件
procedure yiShowDB(source: string); //在电子表格中显示数据库的内容
procedure yiShowInputWindow(s: string); //显示编辑单条记录窗口
//1999.11.2.
procedure yiShowQueryWindow; //显示编辑单条记录窗口
procedure yiShowSetupWindow; //显示设置窗口
procedure yiShowStatus(s: string); //在状态栏显示信息
procedure ydOpenDB(dbType: integer); //打开数据库
procedure ydCloseDB(dbType: integer); //关闭数据库
procedure ydGetBottomID; //获得最大的编号
procedure ydAppendRecord; //追加记录
procedure ydSaveRecord; //指定存盘
procedure ydEditRecord; //修改指定的记录
procedure ydDelRecord; //指定ID删除
procedure ydCalShouRuZhiChu; //查询收入和支出
//1999.11.4.
procedure ydGenMid(s: string); //生成中间数据库
//1999.11.4
procedure ydCopyMoney2Mid; //将整个money数据库复制成为中间库
procedure ydQueryProcess; //完成查询的具体操作
function Query_TypeCondition(pCondition, pType, pSubType, pTypeValue, pSubTypeValue: string): integer;
//查询条件--金额限制判断
function Query_MoneyCondition(pCondition: string; pMoney, pMax, pMin: Double): integer;
//计算一个数据库中的记录条数
function ydRecordCount(t1: THalcyonDataSet): integer;
procedure ysDelFile(fDel: string); //删除一个指定的文件
procedure ysEncrypt(f1, f2: string); //加密一个文件
procedure ysDeCrypt(f1, f2: string); //解密一个文件
type
TYYSource = array[1..20] of string;
TYYBtn = record
YYSource: TYYSource;
YYSourceLine: integer;
end;
var
gsList: TStrings;
gsYYlist: TStrings;
gBut: TBitBtn;
ButPath, ButBMPPath: string;
gsButCaption: string;
gsButBMPFile: string;
gsButHint: string;
gnButTab: integer;
gnButTabOrder: integer;
gnPanX, gnPanY, gnPanXOff, gnPanYOff: integer;
gnYYCount: integer;
gnYYCurrent: integer;
gaYYBtn: array[1..20] of TYYBtn; //存放读入的yy语言代码
gnYPoint: integer; //记录脚本语言当前执行到第几行
gnResult: integer; //记录函数返回值
gsLogFile: string; //日志文件文件名
gnBottomID: integer; //记录数据库最后的ID
gnCurrID: integer; //当前数据库指针
gnMsg: integer; //出错代码
gcShouRu, gcZhiChu: currency; //收入和支出
// gsAct:string;//定义刚才的操作行为
gbCanEdit: boolean;
gbCanQuery: boolean;
implementation
uses Tools, JBStr, Main, uinput, uAbout, uHelp, uQuery, uSetup;
//1999.9.17. 9.23.
function InitYoYo: integer;
begin
ButPath := GetAppPath + 'Buttons\';
ButBMPPath := GetAppPAth + 'ButtonsBMP\';
gnPanXOff := 4;
gnPanYOff := 8;
gsLogFile := 'log.txt';
ReWriteLog; //建立日志文件
end;
//1999.9.17. 10.16.
//y-system 结束程序
function ysCloseApp: integer;
begin
if Application.MessageBox('请确认是否要退出。', 'M99', MB_YESNO + MB_ICONASTERISK + MB_DEFBUTTON1 + MB_APPLMODAL) = IDYES then
begin
Application.Terminate;
end;
gnResult := gnOK;
end;
//1999.10.16.
//y-system 显示关于窗口
procedure ysShowAbout;
begin
frmAbout.ShowModal;
end;
//1999.10.16.
//y-system 显示帮助窗口
procedure ysShowHelp;
begin
frmHelp.ShowModal
end;
//1999.9.21.
//复制文件
function ysCopyFile(s: string): integer;
var
s1, s2: string;
begin
try
s1 := ExtractWord(2, s, [' ']);
s2 := ExtractWord(3, s, [' ']);
CopyFile(GetAppPath + s1, GetAppPath + s2);
gnResult := gnOK;
except
gnResult := gnNotOK;
end;
end;
//1999.9.23.
//建立日志文件
procedure RewriteLog;
var
f: text;
begin
AssignFile(f, GetAppPath + gsLogFile);
ReWrite(f);
Writeln(f, '日志文件建立');
CloseFile(f);
end;
//1999.9.23.
//写日志文件
procedure AppendLog(s: string);
var
f: text;
begin
AssignFile(f, GetAppPath + gsLogFile);
Append(f);
WriteLn(f, FormatDateTime('yyyy-mm-dd hh:mm:ss', Now) + s);
CloseFile(f);
end;
//打开数据库
//1999.9.25. 10.16. 11.15.
procedure ydOpenDB(dbType: integer);
begin
try
if dbType = 0 then
begin
ysDeCrypt(GetAppPath + 'money.ebf', GetAppPath + 'money.dbf');
frmMain.tableMain.Open;
end;
if dbType = 1 then
begin
ysDeCrypt(GetAppPath + 'moneymid.ebf', GetAppPath + 'moneymid.dbf');
frmMain.tableMid.Open;
end;
if dbType = 2 then
begin
ysDeCrypt(GetAppPath + 'moneyq.ebf', GetAppPath + 'moneyq.dbf');
frmMain.tableQuery.Open;
end;
except
gnMsg := 100; //打开数据库出错
end;
end;
//关闭数据库
//1999.9.25. 10.16. 11.15.
procedure ydCloseDB(dbType: integer);
begin
if dbType = 0 then
begin
frmMain.tableMain.Close;
ysEncrypt(GetAppPath + 'money.dbf', GetAppPath + 'money.ebf');
end;
if dbType = 1 then
begin
frmMain.tableMid.Close;
ysEncrypt(GetAppPath + 'moneymid.dbf', GetAppPath + 'moneymid.ebf');
end;
if dbType = 2 then
begin
frmMain.tableQuery.Close;
ysEncrypt(GetAppPath + 'moneyq.dbf', GetAppPath + 'moneyq.ebf');
end;
end;
//1999.9.25
//获得数据库最大的ID
procedure ydGetBottomID;
begin
with frmMain do
begin
gnBottomID := 0;
ydOpenDB(0); //打开数据库
//判断是否数据库记录为空
if tableMain.RecordCount <= 0 then begin
gnBottomID := 0;
end
else begin
tableMain.last;
gnBottomID := StrToInt(frmMain.tableMain.fieldbyname('ID').value);
end;
ydCloseDB(0); //关闭数据库
end;
end;
//ydAppendRecord 追加记录
//1999.9.25. 10.12. 10.17. 11.10.
procedure ydAppendRecord;
var
i: integer;
begin
with frmMain do
begin
try
listbox1.Items.Clear;
listbox2.Items.Clear;
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入数据库字段新增记录文本文件
//如果没有记录内容,跳出
if listbox2.Items.Count = 0 then exit;
ydOpenDB(0);
tableMain.Append;
//按照字段文本文件插入记录
for i := 0 to listbox1.items.count - 1 do begin
tableMain.FieldByName(listbox1.items[i]).value := listbox2.items[i];
end;
tableMain.Post;
ydCloseDB(0); //关闭数据库
gnMsg := 302; //追加记录正确
except
gnMsg := 102; //追加记录发生错误
end;
end;
end;
//ydAppendRecord 指定ID存盘记录
//1999.9.25. 10.12.
procedure ydSaveRecord;
var
i: integer;
iID: integer;
begin
with frmMain do
begin
listbox1.Items.Clear;
listbox2.Items.Clear;
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入数据库字段新增记录文本文件
//如果没有记录内容,跳出
if listbox2.Items.Count = 0 then exit;
ydOpenDB(0);
iID := strtoint(Listbox2.items[0]);
while not tableMain.eof do
begin
if iID = StrToint(tableMain.fieldbyname('ID').value) then
begin
tableMain.edit;
//按照字段文本文件插入记录
for i := 0 to listbox1.items.count - 1 do
begin
tableMain.FieldByName(listbox1.items[i]).value := listbox2.items[i];
end;
tableMain.Post;
end;
tableMain.next;
end;
ydCloseDB(0); //关闭数据库
end;
end;
//ydDelRecord 指定ID删除
//1999.9.25. 10.17.
procedure ydDelRecord;
var
iID: integer;
begin
with frmMain do
begin
if Application.MessageBox('请确认是否要删除当前选中的记录。', 'M99', MB_YESNO + MB_ICONASTERISK + MB_DEFBUTTON1 + MB_APPLMODAL) = IDNO then
begin
gnMsg := 205; //取消删除
exit;
end;
try
listbox2.Items.Clear;
listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入数据库字段新增记录文本文件
ydOpenDB(0);
iID := strtoint(Listbox2.items[0]);
while not tableMain.eof do
begin
if iID = StrToint(tableMain.fieldbyname('ID').value) then
begin
tableMain.Delete;
end;
tableMain.next;
end;
ydCloseDB(0); //关闭数据库
gnMsg := 305; //删除操作成功
except
gnMsg := 105; //删除操作失败
end;
end;
end;
//将整个money数据库复制成为中间库
//1999.11.4
procedure ydCopyMoney2Mid;
begin
CopyFile(GetAppPath + 'Money.dbf', GetAppPath + 'MoneyMid.dbf');
end;
// yiShowDB 显示数据库的内容在表格中
//1999.9.24. 9.25. 10.12. 10.16. 10.17. 11.4. 11.9. 11.10. 11.12.
//11.16.
procedure yiShowDB(source: string);
var
i, j: integer;
s: string;
b: boolean;
s1: string;
c: integer;
m: integer;
Temp: TComponent;
begin
s1 := UpperCase(ExtractWord(2, source, [' '])); //参数表示显示在那一个电子表格中
with frmMain do
begin
//如果是主要操作,生成中间数据库的形式为根据money数据库
if s1 = 'MAIN' then
begin
pageMain.ActivePage := tabMain;
c := ydRecordCount(tableMid) + 2;
grid01.Clear;
grid01.RowCount := 0;
grid01.RowCount := c;
grid01.fixedRows := 1;
//网格标题
grid01.Cells[0, 0] := '编号';
grid01.Cells[1, 0] := '收支大类';
grid01.Cells[2, 0] := '收支细类';
grid01.Cells[3, 0] := '收支方式';
grid01.Cells[4, 0] := '收支金额';
grid01.Cells[5, 0] := '收支日期';
grid01.Cells[6, 0] := '备注';
ydGenMid('ydGenMid MONEY');
ydOpenDB(1); //打开数据库
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
i := 1;
//循环读取数据库内容
while not tableMid.Eof do
begin
for j := 1 to listbox1.items.count do
begin
s := tableMid.FieldByName(listbox1.items[j - 1]).value;
if s = 'NULL' then s := '';
if listbox1.items[j - 1] = 'SZMONEY' then
s := Format('%n', [StrToFloat(s)]);
grid01.Cells[j - 1, i] := s
end;
tableMid.Next;
inc(i);
end;
ydCloseDB(1); //关闭数据库
end;
if s1 = 'QUERY' then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -