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

📄 uadoset.~pas

📁 这是delphi7.0开发的人力资源培训考核软件
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
{
  ////本单元库主要对数据库表的操作///////////////
  
 }
unit uADOSet;

interface
uses
    Windows,
    Classes,
    Messages,
    SysUtils,
    Variants,
    DB,
    AdoDb,
    Grids,
    Graphics,
    Controls,
    Forms,
    Dialogs,
    StdCtrls,
    ExtCtrls,
    IniFiles,
    EasyGrid,
    uGlobal,
    ComCtrls;
 /////////定义数据操作函数//////////////////
 /////定义一些操作数据库的函数/////
    //*iFlag连接的是本地数据库(1:Access)还是Sqlserver数据库(2:)
    //*DbName代表是数据库的名字////
    Function ConnectToDatabase(iFlag:integer):string;////定义连接数据库的字符串///
    ////将某一个字段的内容填充到一个控件中////////////////////////////////
    ////**TV控件名称////////////////////////
    ////**TableName表名/////////////////////
    ////**FieldName字段名称//////////////////
    procedure FillControl(AdoQuery:TAdoQuery;Tv:TControl;TableName:string;FieldName:string);
    ////将符合条件某一个字段的内容填充到一个控件中////////////////////////////////
    ////**ctrl控件名称////////////////////////
    ////**TableName表名/////////////////////
    ////**FieldName字段名称//////////////////
    ////**paramValues////为参数列表//////////
    procedure FillCtrlParam(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList;ctrl:TControl;FieldName:string);
    ////从\plugins\connectString.ini配置文件中得到数据库名称///////////////////
    ////**iFlag=1得到本地数据库//////////////////////
    ////**iFlag=2得到服务器端的数据库////////////////
    Function GetConnectString(iFlag:integer;Section:string;Keyword:string):string;
    ////判断符合条件的记录是否存在//////////////////////
    //Function setParamsCount(params:TStringList):TStringList;
    ////**strSql为查询语句如:select * from  tablename where  Field1=:param1  and  Field2=:param2////
    ////**params为查询语句中参数的个数////////////////////
    ////**paramValues为赋值给字段的参数的值////////////////
    Function isRecordExist(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList):Boolean;
    ////得到符合条件的记录的个数//////////////////////////
    ////**strSql为查询语句如:select * from  tablename where  Field1=:param1  and  Field2=:param2////
    ////**params为查询语句中参数的个数////////////////////
    ////**paramValues为赋值给字段的参数的值////////////////
    Function getRecordCount(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList):integer;
    /////定义显示记录函数///////////////////////////////
    ////根据表中唯一ID得到某一字段值////////////////////////
    ////**FieldName要得到值 的字段名////////////////////////
    Function getFieldValue(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList;FieldName:string):variant;
    ////将符合条件的记录显示记录集///////////////////////////
    procedure BindToGrid(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList;Ctrl:TControl);
    procedure BindToGrid1(AdoQuery:TAdoQuery;strSql:string;Ctrl:TControl);
    ////进行存盘操作//////////////////////////////////////////
    procedure SaveRecord(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
    /////做数据表进行更新操作//////////////////////////////////
    procedure UpdateRecord(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
    /////对数据表进行删除操作//////////////////////////////////
    procedure DelRecord(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
    /////建立结果集//////////////////////////////////////////////
    procedure getAdoResult(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
    /////得到字段列表然后存储在TStrings中/////////////////////////////////////////////
    Function getFieldList(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList;FieldName:string):TStringList;
    /////设置得到数据库名称的标志//////////////////////////////////////////////////////
    procedure setDBFlag(Value:string);
    /////得到符合条件的记录数据并存储到TString列表中/////////////////////////////////
    Function getValueList(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList):TStringList;
    /////关闭数据集/////////////////////////
    procedure CloseQueryS(AdoQuery:TAdoQuery);
    ////判断是否为数字//////////////
    Function isDigit(ch:Char):Boolean;
    ///定义建立不规则窗体区域的函数////

//////////////////////////////////////////////////////////////////////////////////////////////////////////
implementation


/////关闭数据集/////////////////////////
procedure CloseQueryS(AdoQuery:TAdoQuery);
begin
   AdoQuery.Close;
end;////
////判断是否为数字//////////////
Function isDigit(ch:char):Boolean;
begin
    result:=ch in ['0'..'9'];
end;
/////////////////////////////////
Function getValueList(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList):TStringList;
var
    ValueList:TStringList;
    i:integer;
begin
    ValueList:=TStringList.Create;
    try
      with Adoquery  do
      begin
         ConnectionString:=ConnectToDatabase(2);
         try
           close;
         except
           on E:exception do
           begin
              exit;
           end;
         end;
         sql.clear;
         ///strSql:='SELECT * FROM    '+TableName+'   WHERE  '+FieldName+'=:'+FieldName;
         Sql.Text:=strSql;
         if paramValues.Count<>0 then
         begin
            for i:=0 to  paramValues.count-1 do
            begin
                Parameters[i].value:=paramValues[i];
            end;
         end
         else
         begin
         end;
         prepared;
         Open;
         if RecordCount<>0 then
         begin
            ValueList.Clear;
            while not eof do
            begin
                 for i:=0 to FieldDefList.Count-1 do
                 begin
                     ValueList.Add(FieldByName(FieldDefList[i].Name).asstring);
                 end;//for
                 next;
            end;//while

            ///ValueList.Add('aaaa');
         end;////
        end;//with
        Result:=ValueList;
     Finally
        AdoQuery.Close; 
     end;
end;////
/////设置得到数据库名称的标志//////////////////////////////////////////////////////
procedure setDBFlag(Value:string);
begin
    iDBFlag:=Value;
end;////
/////得到字段列表然后存储在TStrings中/////////////////////////////////////////////
Function getFieldList(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList;FieldName:string):TStringList;
var
    i:integer;
    tmp_FieldList:TStringList;
begin
    tmp_FieldList:=TStringList.Create;
    try
      with Adoquery  do
      begin
         ConnectionString:=ConnectToDatabase(2);
         try
           close;
         except
           on E:exception do
           begin
              exit;
           end;
         end;
         sql.clear;
         ///strSql:='SELECT * FROM    '+TableName+'   WHERE  '+FieldName+'=:'+FieldName;
         Sql.Text:=strSql;
         if paramValues.Count<>0 then
         begin
            for i:=0 to  paramValues.count-1 do
            begin
                Parameters[i].value:=paramValues[i];
            end;
         end
         else
         begin
         end;
         prepared;
         Open;
         if RecordCount<>0 then
         begin
            tmp_FieldList.Clear;
            while not eof do
            begin
                 tmp_FieldList.Add(FieldByName(FieldName).AsVariant);
                 next;
            end;//while
         end;//if
      end; //with
      result:=tmp_FieldList;
    Finally
       AdoQuery.Close;
    end;
end;//////
//////形成数据集////////////////////////////////////////////
procedure getAdoResult(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
var
   //Tmp_AdoQuery:TAdoQuery;
   i:integer;
begin
   //Tmp_AdoQuery:=TAdoQuery.Create(nil);
   try
      with AdoQuery do
      begin
         ConnectionString:=ConnectToDatabase(2);
         try
            close;
         except
            ON E:Exception do
            begin
               exit;
            end;
         end;
         sql.clear;
         ///strSql:='SELECT * FROM    '+TableName+'   WHERE  '+FieldName+'=:'+FieldName;
         Sql.Text:=strSql;
         if paramValues.Count<>0 then
         begin
            for i:=0 to  paramValues.count-1 do
            begin
                Parameters[i].value:=paramValues[i];
            end;
         end
         else
         begin

         end;////
         prepared;
         Open;
      end;////
      //result:=Tmp_AdoQuery;
    Finally

    end;
end;////
/////做数据表进行更新操作//////////////////////////////////
procedure DelRecord(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
var
    i:integer;
begin
     try
       with AdoQuery do
       begin
            ConnectionString:=ConnectToDatabase(2);
            try
               close;
            except
               ON E:exception do
               begin
                  exit;
               end;
            end;
            sql.clear;
            sql.Text:=strSql;
            if paramValues.Count<>0 then
            begin
               for i:=0 to  paramValues.count-1 do
               begin
                   Parameters[i].value:=paramValues[i];
               end;
            end
            else
            begin

            end;
            prepared;
            ExeCSql;
        end;//with
     Finally
        AdoQuery.Close;
     end;
end;////
/////做数据表进行更新操作//////////////////////////////////
procedure UpdateRecord(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList);
var
    i:integer;
begin
    with AdoQuery do
    begin
        try
            ConnectionString:=ConnectToDatabase(2);
            close;
            sql.clear;
            sql.Text:=strSql;
            if paramValues.Count<>0 then
            begin
               for i:=0 to  paramValues.count-1 do
               begin
                   Parameters[i].value:=paramValues[i];
               end;
            end
            else
            begin
               
            end;////
            prepared;
            ExeCSql;
        Finally
            AdoQuery.Close;
        end;
    end;//with

⌨️ 快捷键说明

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