?? uadoset.pas
字號:
{
////本單元庫主要對數據庫表的操作///////////////
}
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;
///定義建立不規則窗體區域的函數////
///定義建立不規則窗體區域的函數////
////wMask:為窗體上的圖片////wColor:為圖片外的顏色;THandle:為控件
Function CreateRegion(wMask:TBitmap;wColor:TColor;hControl:THandle):HRGN;
Procedure ShowPloyForm(Bmp:TBitmap;hControl:THandle);
Procedure CloseForm(Handle:THandle);////關閉窗口////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
implementation
///實現建立區域的定義///
Function CreateRegion(wMask:TBitmap;wColor:TColor;hControl:THandle): HRGN;
var
dc, dc_c: HDC;
rgn: HRGN;
x, y: integer;
coord: TPoint;
line: boolean;
color: TColor;
begin
dc := GetWindowDC(hControl);
dc_c := CreateCompatibleDC(dc);
SelectObject(dc_c, wMask.Handle);
BeginPath(dc);
for x:=0 to wMask.Width-1 do
begin
line := false;
for y:=0 to wMask.Height-1 do
begin
color := GetPixel(dc_c, x, y);
if not (color = wColor) then
begin
if not line then
begin
line := true;
coord.x := x;
coord.y := y;
end;
end;
if (color = wColor) or (y=wMask.Height-1) then
begin
if line then
begin
line := false;
MoveToEx(dc, coord.x, coord.y, nil);
LineTo(dc, coord.x, y);
LineTo(dc, coord.x+1 , y);
LineTo(dc, coord.x+1 , coord.y);
CloseFigure(dc);
end;
end;
end;
end;
EndPath(dc);
rgn := PathToRegion(dc);
ReleaseDC(hControl, dc);
Result := rgn;
end;
////實現區域形狀的顯示///
procedure ShowPloyForm(bmp:Tbitmap;Hcontrol:Thandle);
var
w1:Tbitmap;
w2:Tcolor;
Rgn:Hrgn;
begin
w1:=TBitmap.Create;
w1.Assign(bmp);
w2:=w1.Canvas.Pixels[0,0];
rgn := CreateRegion(w1,w2,hcontrol);
if rgn<>0 then
begin
SetWindowRgn(Hcontrol, rgn, true);
end;
w1.Free;
end;
//////實現關閉窗口////////
Procedure CloseForm(Handle:Thandle);
begin
DefWindowProc(handle,WM_SYSCOMMAND,SC_CLOSE,0);
end;
/////關閉數據集/////////////////////////
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;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -