⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.~pas

📁 家庭财账管理软件.zip 毕业设计 论文加代码
💻 ~PAS
字号:
unit main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons, FileCtrl, ComCtrls, Db, Halcn6DB, Grids,
  AppEvnts;

type
  TfrmMain = class(TForm)
    FileListYY: TFileListBox;
    PageControl1: TPageControl;
    tabSystem: TTabSheet;
    tabDB: TTabSheet;
    ListBox1: TListBox;
    ListBox2: TListBox;
    tableMain: THalcyonDataSet;
    Grid01: TStringGrid;
	 StatusBar: TStatusBar;
    ApplicationEvents1: TApplicationEvents;
    procedure FormCreate(Sender: TObject);
  private
  { Private declarations }
  public
  { Public declarations }
    procedure YYBtnClick(Sender: TObject);
	 procedure GenObject(n: integer; Sender: TObject);
	 procedure LoadYoYo(n: integer);

	 procedure ydAppendRecord;
	 procedure ydAssignDB(dbFileName: string);
	 procedure yiShowDB;
	 procedure ydOpenDB;
    procedure ydCloseDB;

	 procedure ydGetBottomID; //获得数据库最大的ID

	 procedure ydSaveRecord; //指定存盘

	 procedure ydEditRecord; //修改指定的记录

	 procedure ydDelRecord; //指定ID删除

	procedure yiShowInputWindow(s: string); //显示编辑单条记录窗口

	procedure yiShowStatus(s:string); //在状态栏显示信息


  end;

var
  frmMain: TfrmMain;


implementation

{$R *.DFM}

uses Tools, yyTools, JBStr, uinput;

//1999.9.25
//获得数据库最大的ID

procedure TfrmMain.ydGetBottomID;
begin
  gnBottomID := 0;
  ydOpenDB; //打开数据库

 //判断是否数据库记录为空
  if tableMain.RecordCount <= 0 then begin
	 gnBottomID := 0;
  end
  else begin
	 tableMain.last;
	 gnBottomID := StrToInt(tableMain.fieldbyname('ID').value);
  end;
  ydCloseDB; //关闭数据库

end;


//1999.9.17. 9.21. 9.24.
//根据yy1文件生成的按钮的事件

procedure TfrmMain.YYBtnClick(Sender: TObject);
var
  sCommand, sSource: string;
  i: integer;
  ln1: integer;
begin
  ln1 := (Sender as TBitBtn).tag; //获得现在是第几个按钮

  //开始解码循环

  i := 0;
  while i < gaYYBtn[ln1].YYSourceLine do
  begin

    gnYPoint := i + 1; //记录当前执行到第几行的指针

    sSource := gaYYBtn[ln1].YYSource[gnYPoint]; //临时记录一行yy语言

	 sCommand := GetFirstWord(sSource, [' ']);

    if sCommand = 'ysCloseApp' then
    begin
		ysCloseApp;
    end;

    if sCommand = 'ysCopyFile' then
	 begin
      ysCopyFile(sSource);
    end;


    if sCommand = 'ydAppendRecord' then
    begin
      ydAppendRecord;
	 end;

	 if sCommand = 'yiShowDB' then
	 begin
		yiShowDB;
	 end;

	 if sCommand = 'yiShowInputWindow' then
	 begin
		yiShowInputWindow(sSource);
	 end;

	 if sCommand = 'yiShowStatus' then
	 begin
		yiShowStatus(sSource);
	 end;




	 if sCommand = 'ydEditRecord' then
	 begin
		ydEditRecord;
	 end;

	 if sCommand = 'ydSaveRecord' then
	 begin
		ydSaveRecord;
	 end;

	 if sCommand = 'ydDelRecord' then
	 begin
		ydDelRecord;
	 end;


    i := i + 1;
  end;

end;


//1999.9.17. 9.21. 9.23.
//读入yy1文件,分析对象

procedure TfrmMain.LoadYoYo(n: integer);
var
  i: integer;
begin
  try
	 gsList := TStringList.Create;
	 gsList.LoadFromFile(ButPath + FileListYY.Items[n - 1]);

	 gsButCaption := gsList.Strings[0];
    gsButBMPFile := gsList.Strings[1];
    gsButHint := gsList.Strings[2];

  //第几个tab
    gnButTab := StrToInt(ExtractWord(1, gsList.Strings[3], [' ']));
    //tab上第几个按钮
    gnButTabOrder := StrToInt(ExtractWord(2, gsList.Strings[3], [' ']));

    //读入每个yy1脚本语言的源代码
    for i := 6 to gsList.Count - 1 do
    begin
      gaYYBtn[n].YYSource[i - 5] := gsList.Strings[i];
    end;
    gaYYBtn[n].YYSourceLine := gsList.Count - 6; //yy脚本语言的行数


    AppendLog('读入对象:' + gsButCaption);
  finally
    gsList.Free;
  end;
end;


//1999.9.17. 9.24.
//生成按钮对象

procedure TfrmMain.GenObject(n: integer; Sender: TObject);
begin
  gBut := TBitBtn.Create(self);
  gBut.Left := gnPanXOff + (gnButTabOrder - 1) * 80;
  gBut.Top := gnPanYOff;
  gBut.caption := gsButCaption;
  gBut.NumGlyphs := 2;
  gBut.Glyph.LoadFromFile(ButBMPPath + gsButBMPFile);
  gBut.Tag := n;
  gBut.Hint := gsButHint;

  if gnButTab = 0 then gBut.Parent := tabDB;
  if gnButTab = 1 then gBut.Parent := tabSystem;

  gBut.OnClick := YYBtnClick; //事件挂钩

  AppendLog('生成对象:' + gsButCaption);
end;


//窗口初始化事件
//1999.9.25. edit

procedure TfrmMain.FormCreate(Sender: TObject);
var
  i: integer;
begin
  InitYoYo; //初始化

  FileListYY.Directory := ButPath; //制定yy1文件的路径
  gnYYCount := FileListYY.Items.Count; //计算yy1文件的数量

  tableMain.DatabaseName := GetAppPath;
  ydAssignDB('money.dbf');
  ydGetBottomID;

  //按照yy1文件的数量进行循环
  for i := 1 to gnYYCount do
  begin
    gnYYCurrent := i; //当前的yy1对象是第几个
    LoadYoYo(i); //读入对象申明文件
    GenObject(i, Sender); //生成对象
  end;

end;


//ydAssignDB 数据库文件名关联
//1999.9.24. 9.25.

procedure TfrmMain.ydAssignDB(dbFileName: string);
begin
	if FileExists(GetAppPath+dbFileName)=false then
	begin
		gnErr:=101; //文件不存在
		AppendLog('指定文件:'+dbFileName+'不存在');
		Exit;
	end;

  tableMain.DatabaseName := GetAppPath;	
  tableMain.tableName := dbFileName;
end;

//ydAppendRecord 追加记录
//1999.9.25.

procedure TfrmMain.ydAppendRecord;
var
  i: integer;
begin
	try

	listbox1.Items.Clear;
	listbox2.Items.Clear;

	listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
	listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入数据库字段新增记录文本文件

	ydAssignDB('money.dbf');
	ydOpenDB;
	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; //关闭数据库
	except
		gnErr:=102;//追加记录发生错误
	end;
end;

//ydAppendRecord 指定ID存盘记录
//1999.9.25.

procedure TfrmMain.ydSaveRecord;
var
  i: integer;
  iID: integer;
begin
  listbox1.Items.Clear;
  listbox2.Items.Clear;

  listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件
  listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入数据库字段新增记录文本文件

  ydAssignDB('money.dbf');
  ydOpenDB;
  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; //关闭数据库
end;


//ydDelRecord 指定ID删除
//1999.9.25.

procedure TfrmMain.ydDelRecord;
var
  iID: integer;
begin
  listbox2.Items.Clear;

  listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入数据库字段新增记录文本文件

  ydAssignDB('money.dbf');
  ydOpenDB;
  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; //关闭数据库
end;


// yiShowDB  显示数据库的内容在表格中
//1999.9.24. 9.25.

procedure TfrmMain.yiShowDB;
var
  i, j: integer;
begin
  ydAssignDB('money.dbf');
  ydOpenDB; //打开数据库

  listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入数据库字段文本文件

  i := 1;
  //循环读取数据库内容
  while not tableMain.Eof do
  begin
	 for j := 1 to listbox1.items.count do
	 begin
		grid01.Cells[j-1, i] := tableMain.FieldByName(listbox1.items[j - 1]).value
	 end;
	 tableMain.Next;
	 inc(i);
  end;
  ydCloseDB; //关闭数据库
end;


//打开数据库
//1999.9.25.
{ DONE -oyijun : 增加防止出错的代码 }
procedure TfrmMain.ydOpenDB;
begin
	try
  tableMain.Open;
  except
	gnErr:=100; //打开数据库出错
  end;
end;


//关闭数据库
//1999.9.25.

procedure TfrmMain.ydCloseDB;
begin
  tableMain.Close;
end;


//修改指定的记录
//1999.9.25

procedure TfrmMain.ydEditRecord;
begin
 //判断是否选择了正确的记录
  if grid01.Cells[1, grid01.row] <> '' then begin
	 gnCurrID := strtoint(grid01.Cells[1, grid01.row]);
  //将记录写入到ListBox中
	 listBox2.Clear;

	 listBox2.Items.Add(grid01.Cells[1, grid01.row]);
	 listBox2.Items.Add(grid01.Cells[2, grid01.row]);
	 listBox2.Items.Add(grid01.Cells[3, grid01.row]);
	 listBox2.Items.Add(grid01.Cells[4, grid01.row]);
	 listbox2.Items.SaveToFile(GetAppPath + 'rec.txt');
  end;
end;


//显示编辑单条记录窗口
//1999.9.25.
procedure TfrmMain.yiShowInputWindow(s: string);
var
	s1:string;
begin
	s1 := ExtractWord(2, s, [' ']);
	frmInput.Caption := s1;
	frmInput.showmodal;
end;

//在状态栏显示信息
//1999.9.25.
procedure TFrmMain.yiShowStatus(s:string);
var
	i:integer;
	s1:string;
begin
	i := StrToInt(ExtractWord(2, s, [' ']));
	s1 := ExtractWord(3, s, [' ']);
	StatusBar.panels[i].text:=s1;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -