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

📄 systemdm.pas

📁 这个是个简单的关于出票申请的处理
💻 PAS
字号:
unit SystemDM;

interface

uses
  Windows, Forms,SysUtils, Classes, DB, ADODB, IniFiles,Dialogs;

type
  TDMSystem = class(TDataModule)
    ConnMain: TADOConnection;
    Qry_Temp: TADOQuery;
    Qry_Info: TADOQuery;
    procedure DataModuleCreate(Sender: TObject);
  private
    FConnectFlag: boolean;
    FWorkName: string;
    FWorkPwd: string;
    FWorkAuthStr: string;
    FWorkRole: string;
    FWorkId: string;
    { Private declarations }
  public
    { Public declarations }
    property WorkId :string read FWorkId write FWorkId;               //登录工号
    property WorkPwd :string read FWorkPwd write FWorkPwd;            //登录工号的口令
    property WorkAuthStr :string read FWorkAuthStr write FWorkAuthStr;//登录工号的权限字串
    property WorkRole :string read FWorkRole write FWorkRole;         //登录工号的权限角色
    property WorkName  :string read FWorkName write FWorkName;        //登录工号的名称

    property ConnectFlag: boolean read FConnectFlag; //系统数据模块连接标志
    function SQL_Querys(ADataset: TAdoQuery; Sql_Str: string): boolean;
    function SQL_Exec(ADataset: TAdoQuery; Sql_Str: string; Commit: boolean = true): boolean;
    function GetServerTime: TDateTime;
    function CallLogin:boolean;  //系统登录
    function isConnectionDB: Boolean;
  end;

  function ReadIni(const Section, Ident, Default: string): string;
var
  DMSystem: TDMSystem;

implementation
uses
  systemPH, systemLoginFM;
{$R *.dfm}
function ReadIni(const Section, Ident, Default: string): string;
var
  tempIni:TIniFile;
  STemp:String;
begin
  tempIni:=nil;
  sTemp:=ExtractFileName(Application.ExeName);
  if pos('.',sTemp)>0 then
    sTemp:=copy(sTemp,1,pos('.',sTemp))+'ini';
  sTemp:=ExtractFilePath(Application.ExeName)+sTemp;
  try
    tempIni := TIniFile.Create(sTemp);
    result := tempIni.ReadString(Section,Ident,Default);
  finally
    tempIni.Free;
  end;
end;

function TDMSystem.CallLogin: boolean;
begin
  Result:=False;
  try
    Application.CreateForm(Tfrm_Login,frm_Login);
    if Assigned(frm_Login) then
    begin
      frm_Login.ShowModal;
      Result:= frm_Login.BLogin;
    end;
  finally
     FreeAndNil(frm_Login);
  end;
end;

procedure TDMSystem.DataModuleCreate(Sender: TObject);
var
  ConnStr: string;
begin
  try
    ConnStr := 'Provider=SQLOLEDB.1;Password=' + SystemConst_DBLoginPwd +
               ';Persist Security Info=False;User ID=' + SystemConst_DBLoginName +
               ';Initial Catalog=' + SystemConst_DataBaseName + ';Data Source=' + SystemConst_ServerName;
    ConnMain.ConnectionString := ConnStr;
    ConnMain.Connected := true;
    if ConnMain.Connected then FConnectFlag := True;
  except
    FConnectFlag := False;
  end;

  Qry_Temp.Connection := ConnMain;
  Qry_Info.Connection := ConnMain;
end;

function TDMSystem.GetServerTime: TDateTime;
begin
 with TADOQuery.Create(nil)do
 try
   Connection := ConnMain;
   Sql.Text := 'Select GetDate() As ServerTime';
   Open;
   Result := FieldByName('ServerTime').asDateTime;
 finally
  Free;
 end
end;

function TDMSystem.isConnectionDB: Boolean;
begin
  try
    Result := True;
    if not ConnMain.Connected then
    begin
      SendMessage(Application.MainForm.Handle, DM_CONNECTDB, 0, 0);
      Result := False;
    end;
  except
  end;

end;

function TDMSystem.SQL_Exec(ADataset: TAdoQuery; Sql_Str: string;
  Commit: boolean): boolean;
begin
  result := false;
  if Assigned(ADataset) then
  begin
    with ADataset do
    begin
      Close; SQL.Clear; SQL.Add(SQL_Str);
      if Commit then connMain.BeginTrans;
      try
        ExecSQL;
        if Commit then connMain.CommitTrans;
        result := true;
      except on E:Exception do
      begin
        if Commit then connMain.RollbackTrans;
        ConnMain.Connected := False;
        SendMessage(Application.MainForm.Handle, DM_CONNECTDB, 0, 0);
       // ShowMessage(E.Message);
      end;
      end;
    end;
  end;
end;

function TDMSystem.SQL_Querys(ADataset: TAdoQuery;
  Sql_Str: string): boolean;
begin
  result := false;
  if Assigned(ADataset) then
  begin
    with ADataset do
    begin
      Close; SQL.Clear; SQL.Add(SQL_Str);
      try
        //Prepare;
        Open; First;
        if not IsEmpty then
          result := true;
      except on E:Exception do
      begin
        ConnMain.Connected := False;
        SendMessage(Application.MainForm.Handle, DM_CONNECTDB, 0, 0);
      //  ShowMessage(E.Message);
      end;
      end;
    end;
  end;
end;

end.

⌨️ 快捷键说明

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