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

📄 ucreateaccount.pas

📁 天涯進銷存系統
💻 PAS
字号:
unit uCreateAccount;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, jpeg, LBCtrls, DB, FileCtrl, LBMorphVCLBase,
  LBMorphButton, DBXpress, FMTBcd, SqlExpr, Gauges, DBClient;

type
  TfrmCreateAccount = class(TForm)
    Image2: TImage;
    WindowCaption: TLabel;
    SysCloseButton: TLBMorphButton;
    Panel4: TPanel;
    Panel6: TPanel;
    Panel3: TPanel;
    Panel1: TPanel;
    Image1: TImage;
    Shape24: TShape;
    Shape25: TShape;
    PriorButton: TLBButton;
    NextButton: TLBButton;
    CancelButton: TLBButton;
    Notebook: TNotebook;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    AccountCodeEdit: TLBEdit;
    AccountNameEdit: TLBEdit;
    LBLabel2: TLBLabel;
    DataPath: TLBEdit;
    LBButton3: TLBButton;
    LBLabel3: TLBLabel;
    DataName: TLBLabel;
    LBLabel4: TLBLabel;
    LBLabel5: TLBLabel;
    LBLabel6: TLBLabel;
    LBLabel7: TLBLabel;
    UserCodeEdit: TLBEdit;
    UserNameEdit: TLBEdit;
    UserPasswordEdit: TLBEdit;
    LBLabel8: TLBLabel;
    qrmm: TLBEdit;
    CreateInfo: TLBLabel;
    SQLConnection: TSQLConnection;
    SQLQuery: TSQLQuery;
    Panel2: TPanel;
    Gauge1: TGauge;
    cdsData: TClientDataSet;
    LBEdit1: TLBEdit;
    SQLConnection1: TSQLConnection;
    Label4: TLabel;
    Label5: TLabel;
    zhhao: TLBEdit;
    csmm: TLBEdit;
    procedure SysCloseButtonClick(Sender: TObject);
    procedure NextButtonClick(Sender: TObject);
    procedure PriorButtonClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure AccountCodeEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure AccountNameEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure LBButton3Click(Sender: TObject);
    procedure CancelButtonClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCreateAccount: TfrmCreateAccount;
  AppPath: string;
  isCreate : Boolean;

implementation

uses  uSelectAcc,uPublicvar;

{$R *.dfm}

procedure TfrmCreateAccount.SysCloseButtonClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmCreateAccount.NextButtonClick(Sender: TObject);
var
  SqlText: TStrings;
  s, ls,database,dbname,dbpath,logname,logpath: string;
  i,j,k,l: integer;
begin
  case Notebook.PageIndex of
  0:
    begin
      if Trim(AccountCodeEdit.Text)='' then
      begin
        Application.MessageBox('请输入帐套编号。','提示信息', $30);
        AccountCodeEdit.SetFocus;
        Exit;
      end;
      if Pos(':', AccountCodeEdit.Text)>0 then
      begin
        Application.MessageBox('对不起,帐套编号不可包含字符“:”。','提示信息', $30);
        AccountCodeEdit.SetFocus;
        Exit;
      end;
      if Trim(AccountNameEdit.Text)='' then
      begin
        Application.MessageBox('请输入帐套名称。','提示信息', $30);
        AccountNameEdit.SetFocus;
        Exit;
      end;
      cdsData.Data:=frmSelectAcc.AccCds.Data;
      if cdsData.Locate('Code', Trim(AccountCodeEdit.Text), [loPartialKey]) then
      begin
        Application.MessageBox('此帐套编号已存在,请重新输入。','提示信息', $30);
        AccountCodeEdit.SetFocus;
        Exit; 
      end;
      PriorButton.Enabled:=True;
      database:=LBEdit1.Text;
      DataPath.Text:=AppPath+'DATABASE\';
    end;
  1:
    begin
      if not DirectoryExists(PChar(DataPath.Text)) then
         if not CreateDir(PChar(DataPath.Text)) then
         begin
           Application.MessageBox(PChar('创建数据库目录“'+DataPath.Text+'”不成功。'),
                                        '提示信息', $30);
           Exit;
         end;  
    end;
  2:
    begin
      if Trim(UserCodeEdit.Text)='' then
      begin
        Application.MessageBox('请输入管理员编号。','提示信息', $30);
        UserCodeEdit.SetFocus;
        Exit;
      end;
      if Trim(UserNameEdit.Text)='' then
      begin
        Application.MessageBox('请输入服务器登陆帐号。','提示信息', $30);
        UserNameEdit.SetFocus;
        Exit;
      end;
      if Trim(zhhao.Text)='' then
      begin
        Application.MessageBox('请输入初始帐号。','提示信息', $30);
        zhhao.SetFocus;
        Exit;
      end;
      if Trim(csmm.Text)<>Trim(qrmm.Text) then
      begin
        Application.MessageBox('管理员密码输入不正确,请重新输入。','提示信息', $30);
        UserPasswordEdit.Clear;
        csmm.Clear;
        UserPasswordEdit.SetFocus;
        Exit; 
      end;
      try
          SQLConnection1.Connected:=False;
          SQLConnection1.ConnectionName:='SQLServerConnection';
          SQLConnection1.DriverName:='sqlserver';
          SQLConnection1.Params.Clear;
          SQLConnection1.Params.Values['HostName']:=computer;
          SQLConnection1.Params.Values['Database']:='master';
          SQLConnection1.Params.Values['User_Name']:=UserCodeEdit.Text;
          SQLConnection1.Params.Values['Password']:=UserPasswordEdit.Text;
          SQLConnection1.Connected:=True;
      except
          showmessage('服务器帐号或密码输入错误');
          exit;
      end;
          SQLConnection1.close;
      end;
  3:
    begin
      CreateInfo.Caption:='正在创建帐套,请稍后......';
      database:=trim(LBEdit1.Text);
      dbname:=database+'_data';
      logname:=database+'_log';
      dbpath:=DataPath.Text+dbname+'.mdf';
      logpath:=DataPath.Text+logname+'.ldf';
      PriorButton.Enabled:=False;
      NextButton.Enabled:=False;
      CancelButton.Enabled:=False;
      Panel2.Visible:=True;
      if fileexists(dbpath) or fileexists(logpath) then
         begin
         showmessage('该数据库文件已经存在!请选用其它名称');
         exit;
         end;
      try
        begin
          SQLConnection.Connected:=False;
          SQLConnection.ConnectionName:='SQLServerConnection';
          SQLConnection.DriverName:='sqlserver';
          SQLConnection.Params.Clear;
          SQLConnection.Params.Values['HostName']:=cserver;
          SQLConnection.Params.Values['Database']:=cdbname;
          SQLConnection.Params.Values['User_Name']:=cuser;
          SQLConnection.Params.Values['Password']:=cpassword;
          SQLConnection.Connected:=True;
          sqlquery.Close;
          sqlquery.SQL.Text:='exec sp_tianyacreatedb '+''''+database+''''+','+''''+dbname+''''+
          ','+''''+dbpath+''''+','+''''+logname+''''+','+''''+logpath+'''';
          sqlquery.ExecSQL;
          sqlquery.Close;
          SQLConnection.Connected:=False;
          SQLConnection.ConnectionName:='SQLServerConnection';
          SQLConnection.DriverName:='sqlserver';
          SQLConnection.Params.Clear;
          SQLConnection.Params.Values['HostName']:=cserver;
          SQLConnection.Params.Values['Database']:=database;
          SQLConnection.Params.Values['User_Name']:=cuser;
          SQLConnection.Params.Values['Password']:=cpassword;
          SQLConnection.Connected:=True;
        end;
      except
        CreateInfo.Caption:='请按“下一步”开始创建帐套......';
        Application.MessageBox('连接数据库错误。','错误信息',$30);
        PriorButton.Enabled:=True;
        NextButton.Enabled:=True;
        CancelButton.Enabled:=True;
        Panel2.Visible:=False;
        Exit;
      end;
      if not FileExists('Table') then
      begin
        CreateInfo.Caption:='请按“下一步”开始创建帐套......';
        Application.MessageBox('没有找到所需的文件,请重新安装系统。','错误信息',$10);
        PriorButton.Enabled:=True;
        NextButton.Enabled:=True;
        CancelButton.Enabled:=True;
        Panel2.Visible:=False;
        Exit;
      end;
      try
        SqlText:=TStringList.Create;
        SqlText.LoadFromFile('Table');
        i:=SqlText.Count;
        k:=i div 100;
        l:=0;
        for j:=0 to i-1 do
        begin
          ls:=Sqltext.Strings[j];
          s:=s+ls;
          if Pos(';', ls)>0 then
          begin
            SQLQuery.Close;
            SQLQuery.Sql.Text:=s;
            SQLQuery.ExecSql;
            s:='';
          end;
          l:=l+1;
          if l=k then
          begin
            Gauge1.Progress:=Gauge1.Progress+1;
            l:=0; 
          end
        end;
        SqlText.Free;
        s:='';
        for i:=1 to 44 do
        begin
          s:=s+'1';
        end;
        SQLQuery.Close;
        SQLQuery.Sql.Text:='insert into Userkey values('+
                           #39+zhhao.Text+#39+','+
                           #39+UserNameEdit.Text+#39+','+
                           #39+csmm.Text+#39+
                           ','+#39+'1'+#39+', '+#39+s+#39+')';
        SQLQuery.ExecSql;
        with  frmSelectAcc.AccCds do
        begin
          Append;
          Fieldbyname('Code').asstring:=Trim(AccountCodeEdit.Text);
          Fieldbyname('Name').asstring:=Trim(AccountNameEdit.Text);
          Fieldbyname('CreateDate').AsDateTime:=Now;
          Fieldbyname('USERNAME').asstring:=Trim(UserCodeEdit.Text);
          Fieldbyname('PASSWORD').asstring:=Trim(UserPasswordEdit.Text);
          Fieldbyname('DataPath').asstring:=DataPath.Text+DataName.Caption;
          Fieldbyname('computer').AsString:=computer;
          Fieldbyname('dbname').AsString:=database;
          ApplyUpdates(-1);
          CancelButton.Enabled:=True;
          CancelButton.Caption:='完成';
          CreateInfo.Caption:='创建帐套已完成。';
          isCreate:=True;
          Panel2.Visible:=False;
          Update;
          Application.MessageBox('创建帐套成功。','提示信息', $30);
          frmCreateAccount.Close;
        end;
      except
        CreateInfo.Caption:='请按“下一步”开始创建帐套......';
        Application.MessageBox('创建帐套不成功,请确定数据库文件是否存在。','错误信息',$10);
        PriorButton.Enabled:=True;
        NextButton.Enabled:=True;
        CancelButton.Enabled:=True;
        Panel2.Visible:=False;
        DeleteFile(DataPath.Text+DataName.Caption);
        Exit;
      end;
    end;
  end;
  if Notebook.PageIndex<3 then
  Notebook.PageIndex:=Notebook.PageIndex+1;
end;

procedure TfrmCreateAccount.PriorButtonClick(Sender: TObject);
begin
  if Notebook.PageIndex>0 then
    Notebook.PageIndex:=Notebook.PageIndex-1
  else
    PriorButton.Enabled:=False;
end;

procedure TfrmCreateAccount.FormShow(Sender: TObject);
begin
  Notebook.PageIndex:=0;
  AppPath:=ExtractFileDir(Application.Exename);
  if Length(AppPath)>3 then AppPath:=AppPath+'\';
  isCreate:=False;
end;

procedure TfrmCreateAccount.AccountCodeEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key=13 then  Perform(WM_NEXTDLGCTL,0,0);
end;

procedure TfrmCreateAccount.AccountNameEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key=13 then  NextButtonClick(Sender);
end;

procedure TfrmCreateAccount.LBButton3Click(Sender: TObject);
var
  S: string;
begin
  S := '';
  if SelectDirectory('选择目录', '', S) then
  begin
    if Length(S)>3 then S:=S+'\';
    DataPath.Text:=S;
  end;  
end;

procedure TfrmCreateAccount.CancelButtonClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmCreateAccount.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if not isCreate then
    if Application.MessageBox('没有完成帐套的创建,是否要退出?','提示信息', $24)=idNo then
       CanClose:=False;
end;

procedure TfrmCreateAccount.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=27 then Close;
  if (key=13) and (Notebook.PageIndex=3) then
     NextButtonClick(Sender);
end;

procedure TfrmCreateAccount.Image2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Handle, wm_SysCommand ,$F012, 0);
end;

end.

⌨️ 快捷键说明

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