unit frmGetInfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls, IdAntiFreezeBase, IdAntiFreeze, ComCtrls, ExtCtrls, DB,
MemDS, DBAccess, MyAccess;
type
TProgressInfo=record
Verify_Code:string;//核对码
Accept_case_code:string;//受理号
Corp_name:string;//企业名称
Transact_State:string;//办理状态
Drug_Approve_Code:string;//药品批准文号
State_date:string;//状态开始时间
Notice_date:string;//通知时间
Notice_content:string;//通知内容
Charge_Circs:string;//收费情况
Charge_date:string;//费用收到日期
Checkout_report_date:string;//检验报告收到日期
Criterion_hodometer_date:string;//标准品回执收到日期
end;
type
TGetInfo = class(TForm)
http: TIdHTTP;
btnSearch: TButton;
IdAntiFreeze1: TIdAntiFreeze;
ProgressBar1: TProgressBar;
GroupBox1: TGroupBox;
edtVerify_Code: TLabeledEdit;
edtAccept_case_code: TLabeledEdit;
edtCorp_name: TLabeledEdit;
edtTransact_State: TLabeledEdit;
edtDrug_Approve_Code: TLabeledEdit;
edtState_date: TLabeledEdit;
edtNotice_date: TLabeledEdit;
edtNotice_content: TLabeledEdit;
edtCharge_Circs: TLabeledEdit;
edtCharge_date: TLabeledEdit;
edtCheckout_report_date: TLabeledEdit;
edtCriterion_hodometer_date: TLabeledEdit;
btnClose: TButton;
procedure httpWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure httpWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
procedure btnSearchClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
{ Private declarations }
FResultInfo:TProgressInfo;
FSuccess:boolean;
procedure DoSetEditValue;
public
{ Public declarations }
Verify_Code:string;
function CheckConnection(sURL:string):boolean;
function GetProgressInfo(sVerify_Code:string):TProgressInfo;
function SaveToDb(aMyQuery:TMyQuery):boolean;
end;
resourcestring
PostURL=’http://app1.sda.gov.cn/webportal/portal.po?UID=DWV1_WOUID_URL_6646923&&hsearchOption=clientSearch&hsearchSubOption=searchResult’;
UpdateSql=’update Corp_reg_Config set Accept_case_code=’’%s’’,Corp_name=’’%s’’,Transact_State=’’%s’’,’+
’Drug_Approve_Code=’’%s’’, State_date=’’%s’’,Notice_date=’’%s’’,Notice_content=’’%s’’,Charge_Circs=’’%s’’,’+
’Charge_date=’’%s’’,Checkout_report_date=’’%s’’,Criterion_hodometer_date=’’%s’’ ’+
’where Verify_Code=’’%s’’’;
var
GetInfo: TGetInfo;
implementation
{$R *.dfm}
{ TGetInfo }
function TGetInfo.CheckConnection(sURL: string): boolean;
begin
result:=false;
try
http.Head(sURL);
if pos(’200 OK’, http.Response.ResponseText)>0 then
result:=true;
except
end;
end;
function TGetInfo.GetProgressInfo(sVerify_Code: string): TProgressInfo;
var
sHead, sResult: TStringStream;
sResultContent:String;
Inicial,Final: Integer;
function GetValue:string; //取得 ’</SPAN>’ 之前的字符串
var
t:integer;
begin
delete(sResultContent,1,pos(’<SPAN id="Content">’,sResultContent)+18);
result:=’’;
t:=pos(’</SPAN>’,sResultContent);
result:=copy(sResultContent,1,t-1);
end;
begin
//检查地址是否有效
if not CheckConnection(PostURL) then
begin
application.MessageBox(’连接服务器失败,请检查网络是否连通!’,’失败’,MB_ICONWARNING);
exit;
end;
FSuccess:=false;
sHead := TStringStream.Create(’’);
sResult := TStringStream.Create(’’);
sHead.WriteString(’ListSelect=TBL_TABLE283&searchClient=’+sVerify_Code);
http.Request.ContentType := ’application/x-www-form-urlencoded’;
try
http.Post(PostURL, sHead, sResult)
except
http.Get(http.Response.Location, sResult);
end;
Inicial := Pos(’<TABLE><TR><TD><SPAN id="Message">’,sResult.DataString); //获得返回结果表格字符串的开头
Final : = Pos(’</TD></TR></TABLE></FORM></TD></TR> </TABLE></DIV>’,sResult.DataString); //获得结果表格的结尾
sResultContent := Copy(sResult.DataString,Inicial,Final-Inicial);
sResultContent:= Utf8Toansi(sResultContent);
if Pos(’<SPAN id="dbDescr">’,sResultContent)>0 then //如果找到
begin
with Result do
begin
Verify_Code:=sVerify_Code;//核对码
Accept_case_code:=GetValue; //受理号
Corp_name:=GetValue; //企业名称
Transact_State:=GetValue; //办理状态
Drug_Approve_Code:=GetValue; //药品批准文号
State_date:=GetValue; //状态开始时间
Notice_date:=GetValue; //通知时间
Notice_content:=GetValue; //通知内容
Charge_Circs:=GetValue; //收费情况
Charge_date:=GetValue; //费用收到日期
Checkout_report_date:=GetValue; //检验报告收到日期
Criterion_hodometer_date:=GetValue; //标准品回执收到日期
end;
FSuccess:=true;
end
else
begin
application.MessageBox(’没有找到要查询的数据’,’失败’,MB_ICONWARNING);
end;
end;
procedure TGetInfo.httpWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
ProgressBar1.Position :=0;
ProgressBar1.Max :=AWorkCountMax;
end;
procedure TGetInfo.httpWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
ProgressBar1.Position :=AWorkCount;
end;
function TGetInfo.SaveToDb(aMyQuery: TMyQuery): boolean;
begin
result:=false;
if FSuccess then
begin
with aMyQuery do
begin
close;
sql.Clear;
with FResultInfo do
sql.Text :=format(UpdateSql,[Accept_case_code,Corp_name,Transact_State,Drug_Approve_Code,State_date,
Notice_date,Notice_content,Charge_Circs,Charge_date,Checkout_report_date,
Criterion_hodometer_date,Verify_Code]);
try
Execute;
result:=true;
except
result:=false;
end;
end;
end
end;
procedure TGetInfo.DoSetEditValue;
begin
FResultInfo:=GetProgressInfo(Verify_Code);
with FResultInfo do
begin
edtVerify_Code.Text:=Verify_Code;
edtAccept_case_code.Text:=Accept_case_code;
edtCorp_name.Text:=Corp_name;
edtTransact_State.Text:=Transact_State;
edtDrug_Approve_Code.Text:=Drug_Approve_Code;
edtState_date.Text:=State_date;
edtNotice_date.Text:=Notice_date;
edtNotice_content.Text:=Notice_content;
edtCharge_Circs.Text:=Charge_Circs;
edtCharge_date.Text:=Charge_date;
edtCheckout_report_date.Text:=Checkout_report_date;
edtCriterion_hodometer_date.Text:=Criterion_hodometer_date;
end;
end;
procedure TGetInfo.btnSearchClick(Sender: TObject);
begin
Verify_Code:=’1’; //要查询的值,由外部调用者传进来。
//从服务器查询
(Sender as TButton).Enabled :=false;
try
DoSetEditValue;
finally
(Sender as TButton).Enabled :=true;
end;
{
//保存
if SaveToDb() then
begin
application.MessageBox(’保存数据完成!’,’成功’,MB_ICONINFORMATION);
close;
end
else
begin
application.MessageBox(’保存数据失败!’,’失败’,MB_ICONWARNING);
end;
}
end;
procedure TGetInfo.btnCloseClick(Sender: TObject);
begin
close;
end;
end.