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

📄 jia.pas

📁 这是一套小型家庭理财软件delphi源代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit jia;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, DBTables, CustomizeDlg, ExtCtrls, Menus,
  ComCtrls, DBCtrls, ToolWin, StdCtrls, Mask, Buttons, IniFiles, jpeg,
  ImgList, Aligrid, ShellAPI;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    Table1: TTable;
    StatusBar1: TStatusBar;
    Panel1: TPanel;
    DBGrid1: TDBGrid;
    ImageList1: TImageList;
    Panel_DateUp: TPanel;
    Splitter1: TSplitter;
    Panel2: TPanel;
    ToolBar1: TToolBar;
    SpeedButton_tianjia: TSpeedButton;
    SpeedButton_bianji: TSpeedButton;
    SpeedButton_chaxun: TSpeedButton;
    SpeedButton_zt_cx: TSpeedButton;
    SpeedButton_jt_cx: TSpeedButton;
    SpeedButton_mt_cx: TSpeedButton;
    SpeedButton_tongji: TSpeedButton;
    SpeedButton_guanli: TSpeedButton;
    SpeedButton_weihu: TSpeedButton;
    SpeedButton_Exit: TSpeedButton;
    Panel3: TPanel;
    TreeView1: TTreeView;
    Panel4: TPanel;
    StringAlignGrid1: TStringAlignGrid;
    procedure SpeedButton_spot_tjClick(Sender: TObject);
    procedure BitBtn_jt_cxClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TreeView1DblClick(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure SpeedButton_bianjiClick(Sender: TObject);
    procedure SpeedButton_ExitClick(Sender: TObject);
    procedure SpeedButton_tianjiaClick(Sender: TObject);
    procedure TreeView1KeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton_chaxunClick(Sender: TObject);
    procedure SpeedButton_jt_cxClick(Sender: TObject);
    procedure SpeedButton_zt_cxClick(Sender: TObject);
    procedure SpeedButton_mt_cxClick(Sender: TObject);
    procedure SpeedButton_tongjiClick(Sender: TObject);
    procedure SpeedButton_guanliClick(Sender: TObject);
    procedure StringAlignGrid1DblClick(Sender: TObject);
    procedure StringAlignGrid1Click(Sender: TObject);
    procedure SpeedButton_weihuClick(Sender: TObject);
  private
    { Private declarations }
  public
    SDate,EDate: TDate;
    NameQX,Name : String;
    doing : Boolean;
    function FileCopy(source,dest: String): Boolean;
    function TableMoneyJS : Extended;
    function SetMMax(Y:Integer;M:integer) : Integer;
    function Mi(Name,Mima : String) : String;
    function chaxun : Integer;
    procedure ShowRiLi(nian,yue,ri : String);
    procedure all_cx;
    procedure quanxian;
    { Public declarations }
  end;



var
  Form1: TForm1;


implementation

uses Unit_TJ, Unit_CX, Unit_TU, Unit_GL, Unit_M, Unit_WH;


{$R *.dfm}

procedure TForm1.quanxian;
begin

end;

function TForm1.FileCopy(source,dest: String): Boolean;
var
  fSrc,fDst,len: Integer;
  size: Longint;
  buffer: packed array [0..2047] of Byte;
begin
  Result := False; { Assume that it WONT work }
  if source <> dest then begin
    fSrc := FileOpen(source,fmOpenRead);
    if fSrc >= 0 then begin
      size := FileSeek(fSrc,0,2);
      FileSeek(fSrc,0,0);
      fDst := FileCreate(dest);
      if fDst >= 0 then begin
        while size > 0 do begin
          len := FileRead(fSrc,buffer,sizeof(buffer));
          FileWrite(fDst,buffer,len);
          size := size - len;
        end;
        FileSetDate(fDst,FileGetDate(fSrc));
        FileClose(fDst);
        FileSetAttr(dest,FileGetAttr(source));
        Result := True;
      end;
      FileClose(fSrc);
    end;
  end;
end;

procedure TForm1.ShowRiLi(nian,yue,ri : String);
var
  MyDate : TDate;
  dow,j,i,MMax : integer;
begin
  //显示日期

  MyDate := StrToDate(nian+'-'+yue+'-'+'1');
  dow := DayOfWeek(MyDate)-1;
  j := 1;
  MMax := SetMMax(StrToInt(nian),StrToInt(yue));
  for i:=1 to MMax do
  begin
    StringAlignGrid1.Cells[dow,j] := IntToStr(i);

    if i = StrToInt(ri) then
      StringAlignGrid1.CellFont[dow,j].Style := [fsBold];

    if dow > 5 then
    begin
      dow := 0;
      j:= j+1;
    end
    else
     dow := dow+1;
  end;
end;

function TForm1.chaxun : Integer;
begin
  Table1.IndexName :='DATE';
  Table1.SetRange([SDate],[EDate]);
  Table1.ApplyRange;
  Table1.Filtered := False;  //   去过滤

  Result :=Trunc(EDate) - Trunc(SDate);   //返回天数
  Result := Result +1;
end;

function TForm1.SetMMax(Y:Integer;M:integer) : Integer;
begin
  if m in [1,3,5,7,8,10,12] then
    Result := 31
  else
    if m in [4,6,9,11] then
      Result := 30
    else
    begin
      if y mod 400 =0 then
        Result :=29
      else
        if (y mod 4 = 0) and (y mod 100 <>0) then
          Result := 29
        else
          Result := 28;
    end;
end;

function TForm1.TableMoneyJS : Extended;
begin
  Panel_DateUp.Show;
  Panel_DateUp.Update;
  Result :=0;
  DBGrid1.DataSource.Enabled := False;
  Table1.First;
  while not Table1.Eof do
  begin
     if Table1.FieldValues['money'] <> null then
       Result := Result + Table1.FieldValues['money'];
     Table1.Next;
  end;

  Result := Round(Result*10)/10;

  StatusBar1.Panels.Items[0].Text := '  总计:' + FloatToStr(Result) + ' 元';
  StatusBar1.Panels[1].Text := '记录范围:'+DateToStr(SDate)+' 至 '+DateToStr(EDate);

  DBGrid1.DataSource.Enabled := True;

  Panel_DateUp.Visible := False;
end;

function TForm1.Mi(Name,Mima : String) : String;
var
  S : String;
  n,i,T : integer;
  C1,C2 : Char;
  W : Word;
begin
    Result := '';
    if (Mima = '')or(Name = '') then
      exit;

    S := 'F&SHome2.01FengYaHui';  //更改密码算法就改这个常量就可以了
    Mima := Mima+Name;
    n := Length(Mima);
    for i:=1 to Length(S) do
    begin
      C2 := S[i];
      if n>=i then
      begin
        C1 := Mima[i];
        W :=ord(C1)*ord(C2);
      end
      else
      begin
        T := i;
        repeat
          T := T-n;
        until T <= n;
        C1 := Mima[T];
        W := (ord(C1)) Mod (ord(C2))-i;
      end;

      while W < 65 do
        W:=65-w+65;
      while W > 90 do
        W:=W-24;
      Result := Result + Chr(W);
    end;
end;

procedure TForm1.SpeedButton_spot_tjClick(Sender: TObject);
var
  S,MessageStr: String;
  T: Boolean;
  i: Integer;
begin
     MessageStr :=inputBox('请输入','请输入地点:','');
     S:= MessageStr;
     MessageStr :='';

     if S<>'' then
     begin
        T:= True;
        for i:=0 to Form_TJ.ComboBox_spot_tj.Items.Count -1 do
            if S = Form_TJ.ComboBox_spot_tj.Items[i] then
             begin
               T := False;
               Break;
             end;

        if T then
        begin
           Form_TJ.ComboBox_spot_tj.Items.Add(S);
           Form_TJ.ComboBox_spot_tj.ItemIndex :=Form_TJ.ComboBox_spot_tj.Items.Count -1;
        end;
     end;

end;

procedure TForm1.BitBtn_jt_cxClick(Sender: TObject);
begin   //查询今天记录
  Table1.IndexName :='DATE';
  Table1.SetRange([date],[date]);
  Table1.ApplyRange;

end;

procedure TForm1.all_cx;
begin//查询全部记录
  Table1.IndexName :='DATE';
  Table1.SetRange([],[]);
  Table1.ApplyRange;

end;

procedure TForm1.FormShow(Sender: TObject);
var
   myinifile:Tinifile;
   filepath,m,y,t,nian,yue,tian: String;
   n,i,MMax: integer;
   mynode : TTreeNode;
   Form_M : TForm_M;
   NewProcedure : Boolean;
begin
  doing := False;
  Name := '';
  Form_M:= TForm_M.Create(Application);
  Form_M.Caption := Form1.Caption;
  try
    Form_M.ShowModal;
  finally
    Form_M.Free;
  end;

  if not doing  then
  begin
    Close;
    exit;
  end;

  Panel3.Width := 156;

  filepath :=ExtractFilePath(Paramstr(0));
  myinifile :=Tinifile.Create(filepath+'data\Home.dft');
  try
    if myinifile.ReadBool('数据库','自动备份',False) then
      if not DirectoryExists(filepath+'Bak') then
        CreateDir(filepath+'Bak')
      else
      begin
        filecopy(filepath+'data\Home.dft',filepath+'Bak\Home.dft.000');
        filecopy(filepath+'data\Home.dat',filepath+'Bak\Home.dat.000');
        filecopy(filepath+'data\Home.DBF',filepath+'Bak\Home.DBF.000');
        filecopy(filepath+'data\Home.MDX',filepath+'Bak\Home.MDX.000');
      end;

    Form_GL.Edit_j1.Text := myinifile.ReadString('自定义键','name1','昨天');
    Form_GL.Edit_j11.Text := myinifile.ReadString('自定义键','spot1','');
    Form_GL.Edit_j2.Text := myinifile.ReadString('自定义键','name2','今天');
    Form_GL.Edit_j22.Text := myinifile.ReadString('自定义键','spot2','');
    Form_GL.Edit_j3.Text := myinifile.ReadString('自定义键','name3','明天');
    Form_GL.Edit_j33.Text := myinifile.ReadString('自定义键','spot3','');
    SpeedButton_zt_cx.Caption := Form_GL.Edit_j1.Text;
    SpeedButton_jt_cx.Caption := Form_GL.Edit_j2.Text;
    SpeedButton_mt_cx.Caption := Form_GL.Edit_j3.Text;
    n:= myinifile.ReadInteger('spot','n',1);
    for i:=1 to n do
      Form_GL.ListBox_spot.items.Add(myinifile.ReadString('spot',IntToStr(i-1),'公交车'));

    Table1.DatabaseName := filepath+'data';
    Table1.TableName := myinifile.ReadString('数据库','name','HOME');
  finally
    myinifile.Destroy;
  end;


  NewProcedure := False;
  if not DirectoryExists(filepath+'data') then
  begin
    NewProcedure := True;
    showmessage('数据库文件找不到!重新创建数据库');
    CreateDir(filepath+'data');
    CreateDir(filepath+'Bak');
    Table1.Active := False;
    Table1.DatabaseName := filepath+'data';
    Table1.TableType := ttDBase;
    Table1.TableName := 'HOME';
    Table1.FieldDefs.Clear;
    Table1.FieldDefs.Add('DATE',ftDate,0,True);
    Table1.FieldDefs.Add('NAME',ftString,8,True);
    Table1.FieldDefs.Add('TYPE1',ftString,12,True);
    Table1.FieldDefs.Add('TYPE2',ftString,12,True);
    Table1.FieldDefs.Add('TYPE3',ftString,12,True);
    Table1.FieldDefs.Add('MONEY',ftFloat,0,True);
    Table1.FieldDefs.Add('SPOT',ftString,12,True);
    Table1.FieldDefs.Add('MEMO',ftString,20,True);
    Table1.IndexDefs.Clear;
    Table1.IndexDefs.Add('DATE','DATE',[ixExpression]);
    Table1.IndexDefs.Add('NAME','NAME',[ixExpression]);
    Table1.IndexDefs.Add('TYPE1','TYPE1',[ixExpression]);
    Table1.IndexDefs.Add('TYPE2','TYPE2',[ixExpression]);
    Table1.IndexDefs.Add('TYPE3','TYPE3',[ixExpression]);
    Table1.IndexDefs.Add('SPOT','SPOT',[ixExpression]);
    Table1.IndexDefs.Add('MEMO','MEMO',[ixExpression]);

    Table1.CreateTable;
  end
  else
    Form_GL.TreeView1.LoadFromFile(filepath+'data\Home.dat');

  Table1.Active :=True;

  for i:=0 to Form_GL.TreeView1.Items.Count-1 do
  begin
     mynode := Form_GL.TreeView1.Items[i];
     if mynode.Level =2 then
        mynode.ImageIndex :=2;
     if mynode.Level =1 then
        mynode.ImageIndex :=1;
     if mynode.level = 0 then
        mynode.ImageIndex :=0;
  end;

  for i:=0 to TreeView1.Items.Count -1 do
  begin
    MyNode := TreeView1.Items[i];
    if MyNode.Level = 0 then
      Form_GL.ComboBox_type1.Items.Add(MyNode.TExt)
  end;

  TreeView1.Items := Form_GL.TreeView1.Items;

  StatusBar1.Panels[3].Text := '登陆时间:'+ DateTimeToStr(now);

  //显示日期表格
  StringAlignGrid1.Cells[0,0] := '日';

⌨️ 快捷键说明

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