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

📄 datamodule.~pas

📁 中国移动集群网销售资料录入管理系统。 包含集群网用户录入
💻 ~PAS
字号:
unit datamodule;

interface

uses
  SysUtils, Classes, DB, ADODB;

type
  TDM = class(TDataModule)
    Conn: TADOConnection;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    install_dir: string;
    oper_code:string;
    function getmobiledesc(const sqlstr: string): string;
    function checkmobileexist(const telephone: string): boolean;
    function executesql(const sqlstr: string): boolean;
    function checkshortnumexist(const short_num, group: string): boolean;
    function getrsstring(const sqlstr: string): string;
  end;
const
  connstr = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%Sdata.mdb;Persist Security Info=False';
  sql_checkexistmobile = 'Select count(*) as expr from centre where phonenum=''%s''';
  sql_selectgroup = 'Select *  from centre where Shortnum=''%s'' and GroupName=''%s''';

var
  DM: TDM;

implementation
{$R *.dfm}

procedure TDM.DataModuleCreate(Sender: TObject);
var connstring: string;
begin
  connstring := Format(connstr, [DM.install_dir]);
  Conn.ConnectionString := connstring;
  Conn.Open;
end;

procedure TDM.DataModuleDestroy(Sender: TObject);
begin
  Conn.Close;
end;

function TDM.checkmobileexist(const telephone: string): boolean;
begin
  result := true;
  with TADOQuery.Create(nil) do try
    try
      Connection := Conn;
      SQL.Add(Format(sql_checkexistmobile, [telephone]));
      Open;
      if fields.FieldByName('expr').AsInteger > 0 then
        result := true
      else
        result := false;
    except
      on E: Exception do result := true;
    end;
  finally
    Free;
  end;
end;

function TDM.checkshortnumexist(const short_num, group: string): boolean;
begin
  result := true;
  with TADOQuery.Create(nil) do try
    try
      Connection := Conn;
      SQL.Add(Format(sql_selectgroup, [short_num, group]));
      Open;
      if not Eof then
        result := true
      else
        result := false;
    except
      on E: Exception do result := true;
    end;
  finally
    Free;
  end;
end;
function TDM.getmobiledesc(const sqlstr: string): string;
begin
  result := '';
  with TADOQuery.Create(nil) do try
    try
      Connection := Conn;
      SQL.Add(sqlstr);
      Open;
      if fields.FieldByName('expr').value <> '' then begin
        result := fields.FieldByName('expr').value;
      end
    except
      on E: Exception do result := '';
    end;
  finally
    Free;
  end;
end;

function TDM.executesql(const sqlstr: string): boolean;
begin
  result := false;
  with TADOQuery.Create(nil) do try
    try
      Conn.BeginTrans;
      Connection := Conn;
      SQL.Add(sqlstr);
      ExecSQL;
      Conn.CommitTrans;
      result := true;
    except
      on E: Exception do begin
        result := false;
        Conn.RollbackTrans;
      end;
    end;
  finally
    Free;
  end;
end;
function TDM.getrsstring(const sqlstr: string): string;
var i: Integer;
  str_tmp: TStringlist;
  line_tmp: string;
begin
  result := '';
  str_tmp := TStringlist.Create;
  with TADOQuery.Create(nil) do try
    try
      Connection := Conn;
      SQL.Add(sqlstr);
      Open;
      while not Eof do begin
        line_tmp:='';
        for i := 0 to fields.Count - 1 do begin
          if i >0 then line_tmp := line_tmp + '-';
          line_tmp := line_tmp + fields.fields[i].AsString;
        end;
        str_tmp.Add(line_tmp);
        Next;
      end;
      result := str_tmp.text;
      Close
    except
      on E: Exception do result := '';
    end;
  finally
    Free;
    str_tmp.Free; ;
  end;
end;
end.

⌨️ 快捷键说明

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