📄 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 + -