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

📄 openunit.pas

📁 很好用的一个票据管理系统
💻 PAS
字号:
unit OpenUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls;

type
  TOpenform = class(TForm)
    Panel1: TPanel;
    Image1: TImage;
    ComboBox1: TComboBox;
    Image2: TImage;
    Edit1: TEdit;
    Image3: TImage;
    DateTimePicker1: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label4: TLabel;
    Label5: TLabel;
    ComboBox2: TComboBox;
    Image4: TImage;
    Image5: TImage;
    ComboBox3: TComboBox;
    procedure combobox1new;
    procedure combobox2new;
    procedure combobox3new;
    procedure FileCopy(Const sourcefilename,targetfilename:String);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure formcreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure formshow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    loginok:boolean;
   date:string;

  end;

var
  Openform: TOpenform;

implementation
uses dm,CreateUnit1, createdata,MainUnit;
{$R *.dfm}
procedure topenform.combobox1new;
begin
   dmdata.ADOTable_dh.Active:=true;
   dmdata.ADOTable_dh.First;
   while not dmdata.ADOTable_dh.eof do
   begin
     combobox1.Items.Add('['+dmdata.ADOTable_dh['cacc']+']'+dmdata.ADOTable_dh['cacc_name']);
     dmdata.ADOTable_dh.Next;
   end;
   combobox1.ItemIndex:=0;
end;
procedure topenform.combobox2new;
var
 s,i,unm:integer;
 cacc,str:string;
begin
  if combobox1.Text= '' then
    exit;
  s:=length(trim(combobox1.Text));
  str:=copy(trim(combobox1.Text),2,s-1);
  i:=pos(']',trim(str));
  cacc:=copy(trim(str),1,i-1);
  dmdata.ADOTable_year.Active:=true;
  dmdata.ADOTable_year.Filtered:= false;
  dmdata.ADOTable_year.Filter:='accountNum = '''+cacc+'''';
  dmdata.ADOTable_year.Filtered:=true;
  unm:=0;
  dmdata.ADOTable_year.First;
   while not dmdata.ADOTable_year.eof do
   begin
     combobox2.Items.Add(dmdata.ADOTable_year['iyear']);
     dmdata.ADOTable_year.Next;
     unm:=unm + 1;
   end;
   combobox2.ItemIndex:=unm-1;
end;
procedure Topenform.combobox3new;
var
 s,i:integer;
 cacc,str:string;
begin
  if combobox1.Text= '' then
    exit;
  s:=length(trim(combobox1.Text));
  str:=copy(trim(combobox1.Text),2,s-1);
  i:=pos(']',trim(str));
  cacc:=copy(trim(str),1,i-1);
  dmdata.ADOTable_User.Active:=true;
  dmdata.ADOTable_User.Filtered:= false;
  dmdata.ADOTable_User.Filter:='Qx = '''+cacc+'''';
  dmdata.ADOTable_User.Filtered:=true;
  dmdata.ADOTable_User.First;
   while not dmdata.ADOTable_User.eof do
   begin
     combobox3.Items.Add(dmdata.ADOTable_User['name']);
     dmdata.ADOTable_User.Next;
   end;
   combobox3.ItemIndex:=0;
end;
procedure TOpenForm.FileCopy(Const sourcefilename,targetfilename:string);
var
 S,T:TFileStream;
begin
  s:=TFileStream.Create(sourcefilename,fmOpenRead);
  try
    t:=TFileStream.Create(Targetfilename,fmopenWrite or fmCreate);
    try
      t.CopyFrom(s,s.Size);
    finally
      t.Free;
    end;
  finally
    s.Free;
  end;
end;
procedure TOpenform.BitBtn2Click(Sender: TObject);
begin
  loginok:=false;

end;

procedure TOpenform.BitBtn1Click(Sender: TObject);
var
 l,s,i,j,ID,NewID,g_period_id:integer;
 Cstring,cacc,str,str1,stryear,dir,dir1,dir2,dirfile1,dirfile2,dbegin,dend,path:string;
 yy,mm,dd:word;
begin
  if combobox1.Text= '' then
    exit;
  s:=length(trim(combobox1.Text));
  str1:=copy(trim(combobox1.Text),2,s-1);
  i:=pos(']',trim(str1));
  cacc:=copy(trim(str1),1,i-1);
  j:=pos('-',trim(datetostr(datetimepicker1.Date)));
  stryear:=copy(trim(datetostr(datetimepicker1.Date)),1,j-1);
  with dmdata.CreateHDADOQuery do
  begin
    close;
    sql.Clear;
    sql.Add('select * from g_account where (cAcc=:a)' );
    parameters.ParamByName('a').Value:=trim(cacc);
    open;
    if fieldByName('dbegin').AsDateTime >Datetimepicker1.Date then
    begin
       showmessage('你所选择的日期小于建账日期');
       exit;
    end;
    dm.DMData.pjlen:=fieldByName('pjlen').AsInteger;
    dm.DMData.pjlenstr:='0';
    for l:=1 to dm.DMData.pjlen-1 do
    begin
      dm.DMData.pjlenstr:=dm.DMData.pjlenstr+'0';
    end;
    //showmessage(dm.DMData.pjlenstr);
  end;
  with dmdata.CreateHDADOQuery do
  begin
    close;
    sql.Clear;
    sql.Add('select MAX(iYear) AS matyear from g_account1 where (AccountNum=:a)' );
    parameters.ParamByName('a').Value:=trim(cacc);
    open;
    if fieldByName('matyear').AsInteger < strtoint(stryear)-1  then
    begin
       showmessage('你所选择的日期已隔年');
       exit;
    end;
  end;
  with dmdata.CreateHDADOQuery do
  begin
    close;
    sql.Clear;
    sql.Add('select * from g_account1 where (AccountNum=:a) and (iYear=:b)' );
    parameters.ParamByName('a').Value:=trim(cacc);
    parameters.ParamByName('b').Value:=strtoint(trim(stryear));
    open;
    if RecordCount > 0 then
    begin
      if trim(combobox2.Text) <> stryear then
      begin
        showmessage('请查看登陆日期与账套年份是否相符');
        exit;
      end;
     if (length(combobox3.Text)>0) and (length(edit1.text)>0)then
     begin
      with dmdata.OpenUserADOQuery do
      try
      close;
      sql.Clear;
      sql.Add('select * from T_User where (name=:a)and (passwd=:b)');
      parameters.ParamByName('a').Value:=trim(combobox3.Text);
      parameters.ParamByName('b').Value:=trim(edit1.Text);
      open;
      if RecordCount > 0 then
      begin
        date:=datetostr(dateTimepicker1.date);
        with dmdata.OpenZtADOQuery do
        begin
          close;
          sql.Clear;
          sql.Add('Select * from g_account1 where  (AccountNum = :a) and (iyear = :b)');
          parameters.ParamByName('a').Value:=cacc;
          parameters.ParamByName('b').Value:=strtoint(trim(combobox2.Text));
          open;
          dir:=trim(fieldByName('FullpathName').AsString);
          newid:= fieldByName('ID').AsInteger;
        end;
        //Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\FPGLXT\Zt001\Pjdb.mdb;Persist Security Info=False
        CString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
        CString:=CString+dir;
        str:=';Persist Security Info=False';
        CString:=CString+str;
        DMData.ADOConnectiondata.Connected := false;
        DMData.ADOConnectiondata.ConnectionString := cstring;
        try
         DMData.ADOConnectiondata.Connected := true;
           //启动与数据库服务器的连接
        except        //抛出异常
         Application.MessageBox('与数据库服务器连接未成功,请重新配置','警告对话框',MB_OK);
        end;
        loginok:=true;
        end
        else
        begin
         loginok:=false;
         showmessage('请确认登录的用户名和密码是否正确!');
         edit1.SelectAll;
        end;
        finally
        free;
        end;
        close;
       end
       else
       begin
        showmessage('请输入登录用户名和密码!');
        exit;
        edit1.SelectAll;
       end;
       inherited;
       dmdata.ADOTable_T_user.Active:=true;
       dmdata.ADOTable_T_user.First;
       dmdata.ADOTable_T_user.Edit;
       dmdata.ADOTable_T_user['DH']:=trim(combobox1.Text);
       dmdata.ADOTable_T_user['name']:=trim(combobox3.Text);
       dmdata.ADOTable_T_user['date']:=datetimepicker1.date;
       dmdata.ADOTable_T_user.Post;
    end
    else
    begin
    if (length(combobox3.Text)>0) and (length(edit1.text)>0)then
    begin
      if MessageDlg('确认要创建年度账吗?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
      begin
      with dmdata.CreateHDADOQuery do
      begin
        close;
        sql.Clear;
        sql.Add('insert into g_account1(accountNum,iyear,fullpathname) values(:a,:b,:c)');
        parameters.ParamByName('a').Value:=cacc;
        parameters.ParamByName('b').Value:=strtoint(stryear);
        parameters.ParamByName('c').Value:=trim(ExtractFileDir(Application.ExeName)+'\Zt'+cacc+'\'+stryear+'\pjdb.mdb');
        execsql;
      end;
    with dmdata.CreateHDADOQuery do
    begin
     close;
     sql.Clear;
     sql.Add('Select * from g_account1 where  (AccountNum = :a) and (iyear = :b)');
     parameters.ParamByName('a').Value:=cacc;
     parameters.ParamByName('b').Value:=strtoint(stryear);
     open;
     newid:= fieldByName('ID').AsInteger;
    end;
    with dmdata.CreateHDADOQuery do
    begin
     close;
     sql.Clear;
     sql.Add('Select * from g_account1 where  (AccountNum = :a) and (iyear = :b)');
     parameters.ParamByName('a').Value:=cacc;
     parameters.ParamByName('b').Value:=strtoint(stryear)-1;
     open;
     id:= fieldByName('ID').AsInteger;
    end;
    with dmdata.CreateHDADOQuery do
    begin
     close;
     sql.Clear;
     sql.Add('Select * from g_period where  (iacc_id = :a)');
     parameters.ParamByName('a').Value:=id;
     open;
     First;
     while not eof do
     begin
       g_period_id:=fieldByName('id').AsInteger;
       decodedate(fieldByName('dbegin').AsDateTime,yy,mm,dd);
       dbegin:=inttostr(yy+1)+'-'+inttostr(mm)+'-'+inttostr(dd);
       decodedate(fieldByName('dend').AsDateTime,yy,mm,dd);
       dend:= inttostr(yy+1)+'-'+inttostr(mm)+'-'+inttostr(dd);
       with dmdata.CreateYearADOQuery do
       begin
         close;
         sql.Clear;
         sql.Add('insert into g_period values(:a,:b,:c,:d,:e,:f)');
         parameters.ParamByName('a').Value:=newid;
         parameters.ParamByName('b').Value:=strtoint(stryear);
         parameters.ParamByName('c').Value:= g_period_id;
         parameters.ParamByName('d').Value:=strtodate(dbegin);
         parameters.ParamByName('e').Value:=strtodate(dend);
         parameters.ParamByName('f').Value:=0;
         execsql;
       end;
     next;
     end;
    end;
   end;
   dir1:= ExtractFileDir(Application.ExeName);
   dir2:= trim(ExtractFileDir(Application.ExeName)+'\Zt'+cacc+'\'+stryear);
   ForceDirectories(dir2);
   dirfile1:=dir1+'\Pjdb.mdb';
   dirfile2:=dir2+'\pjdb.mdb';
   FileCopy(dirfile1,dirfile2);
  //dmdata.ADOConnectionSet.Connected := false;
  //Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\FPGLXT\Zt010\Pjdb.mdb;Persist Security Info=False
  CString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
  CString:=CString+dir2;
  str:='\Pjdb.mdb;Persist Security Info=False';
  CString:=CString+str;
  DMData.ADOConnectiondata.Connected := false;
  DMData.ADOConnectiondata.ConnectionString := cstring;
  try
    DMData.ADOConnectiondata.Connected := true;
           //启动与数据库服务器的连接
  except        //抛出异常
    Application.MessageBox('与数据库服务器连接未成功,请重新配置','警告对话框',MB_OK);
  end;
  loginok:=true;
  inherited;
       dmdata.ADOTable_T_user.Active:=true;
       dmdata.ADOTable_T_user.First;
       dmdata.ADOTable_T_user.Edit;
       dmdata.ADOTable_T_user['DH']:=trim(combobox1.Text);
       dmdata.ADOTable_T_user['name']:=trim(combobox3.Text);
       dmdata.ADOTable_T_user['date']:=datetimepicker1.date;
       dmdata.ADOTable_T_user.Post;
 end
 else
 begin
 loginok:=false;
 showmessage('请确认登录的用户名和密码是否正确!');
 edit1.SelectAll;
 end;
 end;
 end;
 decodedate(datetimepicker1.Date,yy,mm,dd);
 with dmdata.qsjzADOQuery do
 begin
   close;
   sql.Clear;
   sql.Add('select * from g_period where (iyear = :a) and (id = :b)and(iacc_id =:c)');
   parameters.ParamByName('a').Value :=yy;
   parameters.ParamByName('b').Value :=mm;
   parameters.ParamByName('c').Value :=Newid;
   open;
 end;
 path:=trim(ExtractFileDir(Application.ExeName)+'\Zt'+cacc+'\'+inttostr(strtoint(stryear)-1)+'\pjdb.mdb');
 //Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\FPGLXT\Zt001\2007\Pjdb.mdb;Persist Security Info=False
 dmdata.qqjjADOQuery.Active :=false;
 dmdata.qqjjADOQuery.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+path+';Persist Security Info=False';
 
end;

procedure TOpenform.formcreate(Sender: TObject);
begin
 datetimepicker1.Date:=now;
 combobox1new;
 combobox2new;
 combobox3new;

end;

procedure TOpenform.ComboBox1Change(Sender: TObject);
begin
  combobox2.Clear;
  Combobox2new;
  combobox3.Clear;
  combobox3new;
end;

procedure TOpenform.formshow(Sender: TObject);
begin
  edit1.SetFocus;
end;

end.

⌨️ 快捷键说明

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