📄 unitprocessquery.~pas
字号:
unit UnitProcessQuery;
interface
uses
Classes {$IFDEF MSWINDOWS} ,Variants,ActiveX,Windows {$ENDIF},DB, ADODB,SysUtils,SPComm,Dialogs,Forms;
type
QueryDatabase = class(TThread)
private
ParamSet:boolean;
testin :integer;
FromPhoneNum:string;
ProductID:string;
QueryDate:string;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
procedure SetName;
function Checkdatabase(ProductID:string): Boolean;
function UpdateQuery(ProductID:string;QueryDate:string;queryPhone:string): string;
function ReplayQuery(FromPhoneNumber:string;ProductID:string;QueryDate:string): Boolean;
function UpdateErrorQuery(ProductID:string;QueryDate:string;queryPhone:string): string;
protected
procedure Execute; override;
public
procedure Setparams(PhoneNumber:string;ID:string;Date:string;MainQuery:TADOQuery);
constructor create;
end;
implementation
uses XiSms,unitIrdacomm;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure QueryDatabase.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{$IFDEF MSWINDOWS}
type
TThreadNameInfo = record
FType: LongWord; // must be 0x1000
FName: PChar; // pointer to name (in user address space)
FThreadID: LongWord; // thread ID (-1 indicates caller thread)
FFlags: LongWord; // reserved for future use, must be zero
end;
{$ENDIF}
{ QueryDatabase }
procedure QueryDatabase.SetName;
{$IFDEF MSWINDOWS}
var
ThreadNameInfo: TThreadNameInfo;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
ThreadNameInfo.FType := $1000;
ThreadNameInfo.FName := 'QueryDatabaseThread';
ThreadNameInfo.FThreadID := $FFFFFFFF;
ThreadNameInfo.FFlags := 0;
try
RaiseException( $406D1388, 0, sizeof(ThreadNameInfo) div sizeof(LongWord), @ThreadNameInfo );
except
end;
{$ENDIF}
end;
procedure QueryDatabase.Execute;
begin
SetName;
CoInitialize(nil);
FreeOnTerminate:=true;
if ParamSet then
begin
ReplayQuery(FromPhoneNum,ProductID,QueryDate);
end;
{ Place thread code here }
end;
procedure QueryDatabase.Setparams(PhoneNumber:string;ID:string;Date:string;MainQuery:TADOQuery);
var
teststr:string;
begin
ParamSet:=true;
teststr:= PhoneNumber;
FromPhoneNum:=PhoneNumber;
ProductID:=ID;
QueryDate:=Date;
ADOQuery1:=MainQuery;
end;
constructor QueryDatabase.Create;
begin
inherited Create(true);
ParamSet:=false;
{ ADOConnection1:=TADOConnection.Create(Application);
ADOQuery1:=TADOQuery.Create(Application);
if ADOConnection1.Connected then //若已连接,则断开连接
ADOConnection1.Connected:=false;
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+MainForm.FilePath+'ClientInfo.mdb;Persist Security Info=False';
ADOQuery1.Connection:=ADOConnection1; }
end;
function QueryDatabase.Checkdatabase(ProductID:string):boolean;
begin
if ProductID='' then
result:=false;
if ADOQuery1.Active then
ADOQuery1.Active:=false;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * from ClientInfo');
ADOQuery1.SQL.Add('Where ClientProductorID=:MyClientProductorID');
ADOQuery1.Parameters.ParamByName('MyClientProductorID').Value:=ProductID;
//ADOQuery1.ExecSQL;
ADOQUery1.Open;
if (ADOQuery1.RecordCount=0) then
begin
result:=false;
end
else
result:=True;
end;
function QueryDatabase.UpdateQuery(ProductID:string;QueryDate:string;queryPhone:string): string;
var
Str:string;
DateTemp,DateTemp1 :TDateTime;
begin
if QueryDate=''then
DateTemp:=now
else
DateTemp:= strtoDateTime(QueryDate);
if ADOQuery1.Active then
ADOQuery1.Active:=false;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * from ClientInfo');
ADOQuery1.SQL.Add('Where ClientProductorID=:MyClientProductorID');
ADOQuery1.Parameters.ParamByName('MyClientProductorID').Value:=ProductID;
//ADOQuery1.ExecSQL;
ADOQUery1.Open;
if VarIsNull(ADOQUery1['ClientQueryDate']) then
str:= 'this is the first time you query '+DateTimetostr(now)
else
Str:='last query time is '+DateTimetostr(ADOQUery1['ClientQueryDate']);
if ADOQuery1.Active then
ADOQuery1.Active:=false;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Update ClientInfo');
ADOQuery1.SQL.Add('Set ClientQueryDate=:MyClientQueryDate,QueryTelephone=:MyQueryTelephone');
ADOQuery1.SQL.Add('Where ClientProductorID=:MyClientProductorID');
ADOQuery1.Parameters.ParamByName('MyClientQueryDate').Value:=DateTemp;
ADOQuery1.Parameters.ParamByName('MyQueryTelephone').Value:=queryPhone;
ADOQuery1.Parameters.ParamByName('MyClientProductorID').Value:=ProductID;
ADOQUery1.ExecSQL;
result:=Str;
end;
function QueryDatabase.UpdateErrorQuery(ProductID:string;QueryDate:string;queryPhone:string): string;
var
Str:string;
DateTemp,DateTemp1 :TDateTime;
begin
if QueryDate=''then
DateTemp:=now
else
DateTemp:= strtoDateTime(QueryDate);
Str:='faild';
if ADOQuery1.Active then
ADOQuery1.Active:=false;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into errorTable(ErrorQueryProductID,ErrorQueryPhone,ErrorQueryTime)');
ADOQuery1.SQL.Add('Values(:MyErrorQueryProductID,:MyErrorQueryPhone,:MyErrorQueryTime)');
ADOQuery1.Parameters.ParamByName('MyErrorQueryProductID').Value:=ProductID;
ADOQuery1.Parameters.ParamByName('MyErrorQueryPhone').Value:=queryPhone;
ADOQuery1.Parameters.ParamByName('MyErrorQueryTime').Value:=DateTemp;
ADOQUery1.ExecSQL;
result:=Str;
end;
function QueryDatabase.ReplayQuery(FromPhoneNumber:string;ProductID:string;QueryDate:string): Boolean;
var
returnsms ,str:string;
begin
if(length(ProductID)=18)then
begin
if(Checkdatabase(ProductID)) then
begin
returnsms:='Success';
str:=UpdateQuery(ProductID,QueryDate,FromPhoneNumber);
returnsms:=returnsms+' '+str;
end
else
begin
returnsms:='failed';
UpdateErrorQuery(ProductID,QueryDate,FromPhoneNumber);
end;
end
else
begin
returnsms := 'failed , the num of ProductID is not correct';
UpdateErrorQuery(ProductID,QueryDate,FromPhoneNumber);
end;
if FromPhoneNumber ='' then
result:=false;
if mainform.ReturnResult then
begin
if not SendSMS(FromPhoneNumber, str, True, false,false) then
result:=false
else
result:=true;
end
else
result:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -