抓取程序

  1 unit ThdBDSFMatch;
  2 
  3 interface
  4 
  5 uses
  6   Classes,MyAccess,SysUtils,DateUtils, IdHTTP,StrUtils,IniFiles;
  7 
  8 type
  9   TBDSFMatchThd = class(TThread)
 10   private
 11     mcMain: TMyConnection;
 12     mqMain: TMyQuery;
 13     iBDSFType : Integer;
 14     Pause:Boolean;
 15     iBdsfInv : integer;
 16 
 17     hsl_Match : Thashedstringlist;
 18     //
 19     function CatchMatch: Boolean;
 20     function GetBDSFMatch : Boolean ;
 21     //
 22     function SaveData: Boolean;
 23 
 24   public
 25     procedure Execute; override;
 26     constructor Create(iType:integer;Finterval:integer);
 27     destructor Destroy; override;
 28     procedure SetPause(const aIsPause: Boolean); 
 29   end ;
 30 
 31 implementation
 32 uses
 33   PubDefine,FrmMain;
 34 var
 35   BDSFMatchList : array of TBDSFMatch ;
 36 
 37 
 38 { TBDSFMatchThd }
 39 
 40 constructor TBDSFMatchThd.Create(iType: integer;Finterval:integer);
 41 begin
 42   inherited Create(True);
 43   iBDSFType := iType;
 44   iBdsfInv := Finterval;
 45 
 46   hsl_Match := Thashedstringlist.Create;
 47   //
 48   FreeOnTerminate := True;
 49   mcMain := TMyConnection.Create(nil);
 50   mcMain.Server := ConnectionConfig.Server;
 51   mcMain.Username := ConnectionConfig.Username;
 52   mcMain.Password := ConnectionConfig.Password;
 53   mcMain.Port := ConnectionConfig.Port;
 54   mcMain.Database := ConnectionConfig.Database;
 55   mcMain.Options.UseUnicode := True;
 56   mcMain.LoginPrompt := False;
 57   try
 58      mcMain.Connect;
 59   except on ex:Exception do
 60     begin
 61       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
 62       Exit;
 63     end;
 64   end;
 65   mqMain := TMyQuery.Create(nil);
 66   mqMain.Connection := mcMain;
 67   if iBDSFType = 0 then
 68     SetPause(True)
 69   else
 70     SetPause(false);
 71   Self.Resume;
 72 end;
 73 
 74 procedure TBDSFMatchThd.Execute;
 75 var
 76   bPauseStatus: Boolean;
 77   dtTemp: TDateTime;
 78   iNum : Integer;
 79 begin
 80   bPauseStatus := Pause;
 81   iNum := 0;
 82   while (iNum < 4 ) and (not Terminated) do   
 83   begin
 84     if iBDSFType = 0 then
 85     begin
 86       iNum := 1;
 87       Sleep(iBdsfInv);
 88     end
 89     else
 90       iNum := iNum + 1;
 91     //
 92     BDSFMatchRunTime := Now;
 93     if not Pause then                             //如果没有收到暂停信息
 94     begin
 95       if bPauseStatus <> Pause then
 96       begin
 97         MainForm.LogInfo('抓取线程***北单胜负过关对阵***已启动', True);
 98         bPauseStatus := Pause;
 99       end;
100       MainForm.IsBDSFMatchCatching := True;
101       if CatchMatch then                                   //抓取成功
102       begin
103         MainForm.LogInfo('北单胜负过关对阵抓取成功,等待下一次抓取', True);
104         dtTemp := Now;
105         while not Pause do
106         begin
107           Sleep(500);
108           if SecondsBetween(Now, dtTemp) > iBdsfInv then Break;
109         end;
110       end
111       else begin
112         MainForm.LogInfo('抓取北单胜负过关对阵失败,等待重试', True);
113         Sleep(RETRY_INV);
114       end;
115     end
116     else begin                                 //如果暂停抓取
117       if bPauseStatus <> Pause then
118       begin
119         MainForm.LogInfo('抓取线程***北单胜负过关对阵***已暂停', True);
120         bPauseStatus := Pause;
121       end;
122       MainForm.IsBDSFMatchCatching := False;
123       Sleep(500);
124     end;
125   end;
126 end;
127 
128 function TBDSFMatchThd.CatchMatch: Boolean;
129 begin
130   Result := False;
131   MainForm.LogInfo('开始抓取北单胜负过关对阵', True);
132   SetLength(BDSFMatchList, 0);
133   if not GetBDSFMatch then
134   begin
135     Exit;
136   end;
137   Result := SaveData;
138 end;
139 
140 function TBDSFMatchThd.GetBDSFMatch: Boolean;
141 var
142     idServer: TIdHTTP;
143     sResponse :string;
144     i,Pos1, Pos2: Integer;
145     Term ,RaceName,HomeTeam,VisitingTeam,StatusStr: string ;
146     MatchNo : Integer ;
147     Handicap :Double;
148     StartDate : TDateTime;
149     SellMatchCount , TotalMatchCount, StopMatchCount ,status: Integer;
150 begin
151   Result := False ;
152   idServer := TIdHTTP.Create(nil);
153   idServer.ConnectTimeout:=15000;
154   idServer.ReadTimeout:=15000;
155   try
156     try
157       try     //2015-02-05 liping.chen
158         if trim(MainForm.BDSFMatchAddress) = '' then Exit;
159         sResponse := UTF8Decode(idServer.Get(MainForm.BDSFMatchAddress));
160       except on E : Exception do
161         begin
162           MainForm.LogInfo('idServer.Get获取北单胜负对阵失败'+ E.Message, True);
163           Exit;
164         end;
165       end;
166       if MainForm.IsSaveFile then
167       begin
168         if MainForm.SaveFile(sResponse,'FileBDSFDZDate') then
169         begin
170           MainForm.LogInfo('保存北单胜负对阵页面成功', True);
171         end;
172       end;
173       //------------------可以修改为不用截短-直接移位取[取赛果]---------
174       //彩期
175       pos1 := posex('<no>',sResponse,1);
176       sResponse := copy(sResponse,pos1+length('<no>'),Length(sResponse)-Length('<no>')-pos1+1);
177       pos2 := posex('</no>',sResponse,1);
178       Term :=  copy(sResponse,2,pos2-2) ;
179       Term := FormatDateTime('Y',now) + Term ;
180       // 销售中场次数
181       pos1 :=  posex('<selling>',sResponse,1);
182       sResponse := copy(sResponse,pos1+length('<selling>'),Length(sResponse)-Length('<selling>')-pos1+1);
183       pos2 := posex('</selling>',sResponse,1);
184       SellMatchCount := StrToInt(Copy(sResponse,1,pos2-1));
185       // 停止销售场次数
186       pos1 :=  posex('<stopsell>',sResponse,1);
187       sResponse := copy(sResponse,pos1+length('<stopsell>'),Length(sResponse)-Length('<stopsell>')-pos1+1);
188       pos2 := posex('</stopsell>',sResponse,1);
189       StopMatchCount := StrToInt(Copy(sResponse,1,pos2-1));
190       TotalMatchCount := SellMatchCount+ StopMatchCount ;
191       // 截取场次信息字符
192       pos1 :=  posex('<matchelem>',sResponse,1);
193       sResponse := Copy(sResponse,pos1+length('<matchelem>'),Length(sResponse)-Length('<matchelem>')-pos1+1);
194       SetLength(BDSFMatchList,TotalMatchCount);   
195       for i := 0 to TotalMatchCount-1 do
196       begin
197         // 场次序号
198         pos1 := posex('<no>',sResponse,1);
199         sResponse := Copy(sResponse,pos1+length('<no>'),Length(sResponse)-Length('<no>')-pos1+1);
200         pos2 := posex('</no>',sResponse,1);
201         MatchNo:= StrToInt(Copy(sResponse,1 ,pos2-1)) ;//
202         //   主队
203         pos1 :=  posex('<host>',sResponse,1);
204         sResponse := Copy(sResponse,pos1+length('<host>'),Length(sResponse)-Length('<host>')-pos1+1);
205         pos2 := posex('</host>',sResponse,1);
206         HomeTeam := Copy(sResponse,1 ,pos2-1 ) ;
207         //  客队
208         pos1 :=  posex('<guest>',sResponse,1);
209         sResponse := Copy(sResponse,pos1+length('<guest>'),Length(sResponse)-Length('<guest>')-pos1+1);
210         pos2 := posex('</guest>',sResponse,1);
211         VisitingTeam := Copy(sResponse,1 ,pos2-1 );
212         // 开赛时间
213         pos1 := posex('<endTime>',sResponse,1);
214         sResponse := Copy(sResponse,pos1+length('<endTime>'),Length(sResponse)-Length('<endTime>')-pos1+1);
215         pos2 := posex('</endTime>',sResponse,1) ;
216         StartDate := TranDrawDateEx(Copy(sResponse,1,pos2-1));
217         //  让分
218         pos1 :=  posex('<handicap>',sResponse,1);
219         sResponse := Copy(sResponse,pos1+length('<handicap>'),Length(sResponse)-Length('<handicap>')-pos1+1);
220         pos2 := posex('</handicap>',sResponse,1);
221         Handicap := StrToFloat(Copy(sResponse,1 ,pos2-1 )) ;
222         // 赛事
223         pos1 :=  posex('<leagueName>',sResponse,1);
224         sResponse := Copy(sResponse,pos1+length('<leagueName>'),Length(sResponse)-Length('<leagueName>')-pos1+1);
225         pos2 := posex('</leagueName>',sResponse,1);
226         RaceName := Copy(sResponse,1 ,pos2-1 ) ;
227         // 状态
228         pos1 := posex('<matchandstate>',sResponse,1);
229         sResponse := Copy(sResponse,pos1+length('<matchandstate>'),Length(sResponse)-Length('<matchandstate>')-pos1+1);
230         pos2 := posex('</matchandstate>',sResponse,1) ;
231         StatusStr :=Copy(sResponse,1,pos2-1);
232         if  StatusStr= '销售中' then
233         begin
234           status := 1;
235         end else
236           status := 2;
237         BDSFMatchList[i].TERM := term ;
238         BDSFMatchList[i].Status := status;
239         BDSFMatchList[i].StartDate := StartDate ;
240         BDSFMatchList[i].RaceName := RaceName ;
241         BDSFMatchList[i].HomeTeam := HomeTeam ;
242         BDSFMatchList[i].VisitingTeam := VisitingTeam ;
243         BDSFMatchList[i].MatchNo := MatchNo ;
244         BDSFMatchList[i].Handicap := Handicap ;
245       end;
246       Result:=True;
247     except on E: Exception do
248       begin
249        MainForm.LogInfo('抓取北单胜负过关对阵出错!'+ E.Message, True);
250        Exit;
251       end;
252     end;
253   finally
254     idServer.Free;
255   end;
256 end;
257 
258 function TBDSFMatchThd.SaveData: Boolean;
259 var
260   i,iRepeat, iBDSFMatchCount, iReturnCode: Integer;
261   sSQLString: string;
262   iLotMacthId : Integer;
263   sMatchRet,sTmp : string;
264   BDSFCount,iNoChangeNum : Integer;
265 begin
266   Result := False;
267   BDSFCount:=0;
268   iNoChangeNum:=0;
269   iBDSFMatchCount := Length(BDSFMatchList);
270   if iBDSFMatchCount<=0 then
271   begin
272     MainForm.LogInfo('准备写入北单胜负过关 对阵的场数为0 ', True);
273     Exit;
274   end;
275   MainForm.LogInfo('准备写入北单胜负过关对阵彩期:'+BDSFMatchList[0].TERM+'' +inttostr(iBDSFMatchCount)+'', True);
276 ///////////////////////////////////////北单胜负过关对阵//////////////////////////////
277   try
278     if hsl_Match.Count > 1000 then
279       hsl_Match.Clear;
280     for i := 0 to iBDSFMatchCount - 1 do
281     begin
282       //
283       // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
284       iLotMacthId := 35 * 10000 + BDSFMatchList[i].MatchNo;
285       sMatchRet := trim(BDSFMatchList[i].TERM) +
286                    '^' + IntToStr(BDSFMatchList[i].MatchNo) +
287                    '^' + BDSFMatchList[i].RaceName +
288                    '^' + IntToStr(BDSFMatchList[i].Status) +
289                    '^' + DateTimeToStr(BDSFMatchList[i].StartDate) +
290                    '^' + trim(BDSFMatchList[i].HomeTeam) +
291                    '^' + Trim(BDSFMatchList[i].VisitingTeam) +
292                    '^' + FloatToStr(BDSFMatchList[i].Handicap);
293       // 判断hashed是否存在
294       sTmp := trim(hsl_Match.Values[IntToStr(iLotMacthId)]);
295       if sTmp = '' then
296         hsl_Match.Add(IntToStr(iLotMacthId) + '=' + sMatchRet)
297       else
298       begin
299         if sTmp = Trim(sMatchRet) then
300         begin
301           //MainForm.LogInfo('【北单胜负赛程】无变更:' + sMatchRet, True);
302           inc(iNoChangeNum);
303           Continue;   // 退出
304         end
305         else
306           hsl_Match.Values[IntToStr(iLotMacthId)] := Trim(sMatchRet);
307       end;
308       // ---------------------------------------------------------------------
309       sSQLString := 'CALL P_MATCH_BD_SF_INSERT ('
310            + QuotedStr(BDSFMatchList[i].TERM)
311            + ',' + QuotedStr(IntToStr(BDSFMatchList[i].MatchNo))
312            + ',' + QuotedStr(BDSFMatchList[i].RaceName)
313            + ',' + QuotedStr(IntToStr(BDSFMatchList[i].Status))
314            + ',' + QuotedStr(DateTimeToStr(BDSFMatchList[i].StartDate))
315            + ',' + QuotedStr(BDSFMatchList[i].HomeTeam)
316            + ',' + QuotedStr(BDSFMatchList[i].VisitingTeam)
317            + ',' + QuotedStr(FloatToStr(BDSFMatchList[i].Handicap));
318            sSQLString := sSQLString +',@a); select @a;';
319 
320       iRepeat:=0;
321       while True do
322       begin
323         try    //2015-02-05 liping.chen
324           mqMain.Close;
325           mqMain.SQL.Text := sSQLString;
326           mqMain.Execute;
327           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
328           mqMain.Close;
329           Break;
330         except on E : Exception do
331           begin
332             inc(iRepeat);
333             MainForm.LogInfo('北单胜负对阵'+BDSFMatchList[i].TERM +' '+IntToStr(BDSFMatchList[i].MatchNo)+'场次写入失败!第'+IntToStr(iRepeat)+''+E.Message, True);
334             mqMain.Close;
335             if iRepeat=2 then
336             begin
337               hsl_Match.Values[IntToStr(iLotMacthId)] :='';
338               Break;
339             end;
340           end;
341         end;
342       end;
343       if iRepeat=2 then
344       begin
345         Continue;
346       end;
347 
348       if iReturnCode = 1 then              //数据验证失败
349       begin
350         MainForm.LogInfo('写入北单胜负过关对阵失败,原因:数据验证失败'+BDSFMatchList[i].TERM +' '+IntToStr(BDSFMatchList[i].MatchNo) , True);
351         hsl_Match.Values[IntToStr(iLotMacthId)] :='';
352         Continue;
353       end else if iReturnCode = 100 then
354       begin
355         MainForm.LogInfo('写入北单胜负过关对阵失败,原因:未知错误'+BDSFMatchList[i].TERM +' '+IntToStr(BDSFMatchList[i].MatchNo) , True);
356         hsl_Match.Values[IntToStr(iLotMacthId)] :='';
357         Continue;
358       end;
359       BDSFCount := BDSFCount + 1;
360     end;
361     if BDSFCount>0 then
362     begin
363       // 更新北单胜负截止时间
364       try
365          mqMain.Close;
366          sSQLString := ' CALL P_BDSF_TERM_UPDATE() '  ;
367          mqMain.SQL.Text := sSQLString ;
368          mqMain.Execute ;
369          mqMain.Close;
370       except on E: Exception do
371         MainForm.LogInfo('更新北单胜负过关截止时间出错!'+ E.Message, True);
372       end;
373     end;
374     MainForm.LogInfo('已写入北单胜负对阵'+IntToStr(BDSFCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
375     result := true;
376   except on E : Exception do
377     begin
378       MainForm.LogInfo('写入北单胜负过关对阵失败,原因:' + E.Message, True);
379       Exit;
380     end;
381   end;
382 end;
383 procedure TBDSFMatchThd.SetPause(const aIsPause: Boolean);
384 begin
385   Pause := aIsPause;
386 end;
387 destructor TBDSFMatchThd.Destroy;
388 begin
389   if Assigned(mcMain) then mcMain.Free;
390   if Assigned(mqMain) then mqMain.Free;
391   if Assigned(hsl_Match) then hsl_Match.Free;
392   inherited;
393 end;
394 end.
北单胜负赛程线程单元

 

  1 unit ThdBDSFResult;
  2 
  3 interface
  4 
  5 uses
  6   Classes,MyAccess,SysUtils,DateUtils, IdHTTP,StrUtils,IniFiles;
  7 
  8 type
  9   TBDSFResultThd = class(TThread)
 10   private
 11     mcMain: TMyConnection;
 12     mqMain: TMyQuery;
 13     iBDSFType : Integer;
 14     Pause:Boolean;
 15     iBdsfInv : integer;
 16     hsl_Result : Thashedstringlist;
 17     //
 18     function CatchMatch: Boolean;
 19     function GetBDSFResult : Boolean ;
 20     //
 21     function SaveData: Boolean;
 22     function GetMatchId(MacheNo:Integer;Term :string; var MatchId :string):Boolean;
 23   public
 24     procedure Execute; override;
 25     constructor Create(iType:integer;Finterval:integer);
 26     destructor Destroy; override;
 27     procedure SetPause(const aIsPause: Boolean);
 28   end ;
 29 
 30 implementation
 31 uses
 32   PubDefine,FrmMain;
 33 var
 34   DBSFResultList : array of TBDResult;
 35 
 36 { TBDSFResultThd }
 37 
 38 constructor TBDSFResultThd.Create(iType: integer;Finterval:integer);
 39 begin
 40   inherited Create(True);
 41   iBDSFType := iType;
 42   iBdsfInv := Finterval;
 43   //
 44   hsl_Result := Thashedstringlist.Create;
 45 
 46   FreeOnTerminate := True;
 47   mcMain := TMyConnection.Create(nil);
 48   mcMain.Server := ConnectionConfig.Server;
 49   mcMain.Username := ConnectionConfig.Username;
 50   mcMain.Password := ConnectionConfig.Password;
 51   mcMain.Port := ConnectionConfig.Port;
 52   mcMain.Database := ConnectionConfig.Database;
 53   mcMain.Options.UseUnicode := True;
 54   mcMain.LoginPrompt := False;
 55   try
 56      mcMain.Connect;
 57   except on ex:Exception do
 58     begin
 59       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
 60       Exit;
 61     end;
 62   end;
 63   mqMain := TMyQuery.Create(nil);
 64   mqMain.Connection := mcMain;
 65   if iBDSFType = 0 then
 66     SetPause(True)
 67   else
 68     SetPause(false);
 69   Self.Resume;
 70 end;
 71 
 72 procedure TBDSFResultThd.Execute;
 73 var
 74   bPauseStatus: Boolean;
 75   dtTemp: TDateTime;
 76   iNum : Integer;
 77 begin
 78   bPauseStatus := Pause;
 79   iNum := 0;
 80   while (iNum < 4 ) and (not Terminated) do   //线程.Terminate时确保可以结束线程。
 81   begin
 82     if iBDSFType = 0 then
 83     begin
 84       iNum := 1;
 85       Sleep(iBdsfInv);
 86     end
 87     else
 88       iNum := iNum + 1;
 89     //
 90     BDSFResultRunTime := Now;
 91     if not Pause then                             //如果没有收到暂停信息
 92     begin
 93       if bPauseStatus <> Pause then
 94       begin
 95         MainForm.LogInfo('抓取线程***北单胜负赛果***已启动', True);
 96         bPauseStatus := Pause;
 97       end;
 98       MainForm.IsBDSFResultCatching := True;
 99       if CatchMatch then                                   //抓取成功
100       begin
101         MainForm.LogInfo('北单胜负赛果抓取成功,等待下一次抓取', True);
102         dtTemp := Now;
103         while not Pause do
104         begin
105           Sleep(500);
106           if SecondsBetween(Now, dtTemp) >iBdsfInv then Break;  
107         end;
108       end
109       else begin
110         MainForm.LogInfo('抓取北单胜负赛果失败,等待重试', True);
111         Sleep(RETRY_INV);
112       end;
113     end
114     else begin                                 //如果暂停抓取
115       if bPauseStatus <> Pause then
116       begin
117         MainForm.LogInfo('抓取线程***北单胜负赛果***已暂停', True);
118         bPauseStatus := Pause;
119       end;
120       MainForm.IsBDSFResultCatching := False;
121       Sleep(500);
122     end;
123   end;
124 end;
125 
126 function TBDSFResultThd.CatchMatch: Boolean;
127 begin
128   Result := False;
129   MainForm.LogInfo('开始抓取北单胜负赛果', True);
130   SetLength(DBSFResultList, 0);
131   if not GetBDSFResult then Exit;
132   Result := SaveData;  //  暂时屏蔽
133 end;
134 
135 function TBDSFResultThd.GetBDSFResult: Boolean;
136 var
137   idServer: TIdHTTP;
138   sResponse,sYear,sMonth,sDrawNo :string;
139   i,Pos1, Pos2: Integer;
140   Term,MatchResult,StatusStr,Urltmp : string ;
141   TotalMatchCount,MatchNo : Integer ;
142   SP: Double ;
143 begin
144   Result := False ;
145   idServer := TIdHTTP.Create(nil);
146   idServer.ConnectTimeout:=15000;
147   idServer.ReadTimeout:=15000;
148   try
149     try
150       try
151         //http://www.bjlot.com/ssm/sf/report.shtml从里面分析可知取当前年信息的地址 /data/270/control/drawyearlist.js
152         //取当前年[为了得到取当前月信息的地址]  //jsonString={"drawyears":[{"year":"2014"}]}
153         sResponse := UTF8Decode(idServer.Get(MainForm.BDSFResultAddress+'/data/270/control/drawyearlist.js'));
154         pos1 := posex('year":"',sResponse,1);
155         pos2 := posex('"}',sResponse,1);
156         sYear :=  copy(sResponse,pos1+length('year":"'),pos2-pos1-length('year":"')) ;
157         //取当前月[为了得到取当前彩期信息的地址] // jsonString={"monthlist":[{"month":"07"},{"month":"06"},...
158         sResponse := UTF8Decode(idServer.Get(MainForm.BDSFResultAddress+'/data/270/control/'+sYear+'.js'));
159         pos1 := posex('month":"',sResponse,1);
160         pos2 := posex('"}',sResponse,1);
161         sMonth :=  copy(sResponse,pos1+length('month":"'),pos2-pos1-length('month":"')) ;
162 
163         //取当前彩期 // jsonString={"drawnolist":[{"drawno":"40704"},{"drawno":"40703"},....
164         sResponse := UTF8Decode(idServer.Get(MainForm.BDSFResultAddress+'/data/270/control/drawnolist_'+sYear+sMonth+'.js'));
165         pos1 := posex('drawno":"',sResponse,1);
166         pos2 := posex('"}',sResponse,1);
167         sDrawNo :=  copy(sResponse,pos1+length('drawno":"'),pos2-pos1-length('drawno":"')) ;
168 
169         // 取当前彩期赛果数据
170         Urltmp:=MainForm.BDSFResultAddress+'/data/270/draw/'+sYear+'/'+sDrawNo+'.js';
171         sResponse := UTF8Decode(idServer.Get(Urltmp));
172         MainForm.EdtBDSF.Text:=Urltmp;
173       except on E : Exception do
174         begin
175           MainForm.LogInfo('idServer.Get获取北单赛果失败'+ E.Message, True);
176           Exit;
177         end;
178       end;
179 
180       //赛果场次总数
181       Pos1 := 0;
182       TotalMatchCount:=0;
183       Pos1:= PosEx('Competitions', sResponse, Pos1+1);
184       if (Pos1 = 0)  then
185       begin
186         MainForm.LogInfo('获取北单赛果时出错,找不到标识字符串Competitions ', True);
187         MainForm.LogInfo(sResponse, False);
188         Exit;
189       end;
190       while Pos1<> 0 do                            //循环算总场次
191       begin
192         Inc(TotalMatchCount);
193         Pos1:= PosEx('Competitions', sResponse, Pos1+1);
194       end;
195       //彩期[存入数据库的彩期格式]40704-->140704
196       Term := copy(sDrawNo,2,Length(sDrawNo)-1);   //0704
197       Term := FormatDateTime('Y',now) + Term ;     //140704
198 
199       if MainForm.IsSaveFile then
200       begin
201         Urltmp:='获取地址为:'+Urltmp+#13#10+'赛果彩期为'+Term+',共有'+inttostr(TotalMatchCount)+'场比赛结果。';
202         if MainForm.SaveFile(Urltmp+sResponse,'FileBDSFDate') then
203         begin
204           MainForm.LogInfo('保存北单胜负赛果页面成功', True);
205         end;
206       end;
207 
208       Pos1:=1;   //移位取信息,不用截短,这样更快捷   //以pos1为基准,pos1不断往后移
209       SetLength(DBSFResultList,TotalMatchCount);
210       for i := 0 to TotalMatchCount-1 do
211       begin
212         // 场次序号
213         pos1 := posex('matchno":"',sResponse,Pos1);
214         pos2 := posex('",',sResponse,Pos1) ;
215         MatchNo:= StrToInt(Copy(sResponse,pos1+length('matchno":"'),pos2-pos1-length('matchno":"')));//
216         // 赛果
217         pos1 := posex('result":"',sResponse,pos1);
218         pos2 := posex('",',sResponse,Pos1) ;
219         StatusStr :=Copy(sResponse,pos1+length('result":"'),pos2-pos1-length('result":"'));
220         if  StatusStr= '' then
221           MatchRESULT := '3'
222         else if StatusStr= '' then
223           MatchRESULT := '0';
224         //SP值
225         pos1 :=  posex('spvalue":"',sResponse,pos1);
226         pos2 := posex('",',sResponse,Pos1) ;
227         SP :=StrToFloat(Copy(sResponse,pos1+length('spvalue":"'),pos2-pos1-length('spvalue":"')));
228 
229         DBSFResultList[i].TERM := term ;
230         DBSFResultList[i].SCORE :='0:0';
231         DBSFResultList[i].MatchRESULT := MatchRESULT ;
232         DBSFResultList[i].SP := SP;
233         DBSFResultList[i].SingleBonus :=0;
234         DBSFResultList[i].MatchNo := MatchNo ;
235       end;
236       Result:=True;
237     except on E: Exception do
238       begin
239         MainForm.LogInfo('抓取北单胜负赛果出错!'+ E.Message, True);
240         Exit;
241       end;
242     end;
243   finally
244     idServer.Free;
245   end;
246 end;
247 
248 function TBDSFResultThd.SaveData: Boolean;
249 var
250   i,j,iBDSFResltCount, iReturnCode: Integer;
251   sSQLString: string;
252   MatchId : string ;
253   ResulCount,iNoChangeNum: Integer ;
254   iLotMacthId : Integer;
255   sMatchRet,sTmp : string;
256 begin
257   Result := False;
258   ResulCount := 0 ;
259   iNoChangeNum:=0;
260   iBDSFResltCount := Length(DBSFResultList);
261   if iBDSFResltCount<=0 then
262   begin
263     MainForm.LogInfo('准备写入北单胜负赛果的场数为 0 ', True);
264     Exit;
265   end;
266   MainForm.LogInfo('准备写入北单胜负赛果彩期为:'+DBSFResultList[0].TERM+'' + IntToStr(iBDSFResltCount) + '条数据。', True);
267   try
268     if hsl_Result.Count > 1000 then
269       hsl_Result.Clear;
270     for i := 0 to iBDSFResltCount - 1 do
271     begin
272       try
273         j := 0   ;
274         while j < 2 do
275         begin
276           if GetMatchId(DBSFResultList[i].MatchNo,DBSFResultList[i].TERM,MatchId) then
277            j :=2
278           else
279           begin
280             j:= j+ 1;
281             MainForm.LogInfo('获取北单胜负场次ID出错!第 '+IntToStr(j)+'', True);
282             Sleep(500);  //获取不到,稍后再获取,
283           end;
284         end;
285         if  trim(MatchId) = '' then
286         begin
287           MainForm.LogInfo('北单胜负对阵没有此场次   彩期:'+DBSFResultList[i].TERM +' 序号:'+ IntToStr(DBSFResultList[i].MatchNo), True);
288           continue;
289         end;
290       except on e:Exception do
291         begin
292           MainForm.LogInfo('准备北单数据时失败,原因:' + e.Message + ''+DBSFResultList[i].TERM +' '+ MatchId , True);
293           Continue;
294         end;
295       end;
296       // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
297       iLotMacthId := 35 * 10000 + StrToInt(matchid);
298       sMatchRet := IntToStr(DBSFResultList[i].MatchNo) +
299                    '^' + trim(MatchId)+
300                    '^' + Trim(DBSFResultList[i].SCORE) +
301                    '^' + Trim(DBSFResultList[i].MatchRESULT) +
302                    '^' + Trim(FloatTostr(DBSFResultList[i].SP)) +
303                    '^' + Trim(FloatTostr(DBSFResultList[i].SingleBonus));
304       // 判断hashed是否存在
305       sTmp := trim(hsl_Result.Values[IntToStr(iLotMacthId)]);
306       if sTmp = '' then
307         hsl_Result.Add(IntToStr(iLotMacthId) + '=' + sMatchRet)
308       else
309       begin
310         if sTmp = Trim(sMatchRet) then
311         begin
312           //MainForm.LogInfo('【北单胜负赛果】无变更:' + sMatchRet, True);
313           Inc(iNoChangeNum);
314           Continue;
315         end
316         else
317           hsl_Result.Values[IntToStr(iLotMacthId)] := Trim(sMatchRet);
318       end;
319       // -------------------------------------------------------------------------
320       try
321         sSQLString := 'CALL P_M_RESULT_BDSF_INS('
322              +  QuotedStr(IntToStr(35))
323              + ',' + QuotedStr(MatchId)               //  彩种35表示北单胜负过关
324              + ',' + QuotedStr(DBSFResultList[i].SCORE)
325              + ',' + QuotedStr(DBSFResultList[i].MatchRESULT)
326              + ',' + QuotedStr(FloatTostr(DBSFResultList[i].SP))
327              + ',' + QuotedStr(FloatTostr(DBSFResultList[i].SingleBonus));
328 
329              sSQLString := sSQLString +',@a); select @a;';
330         mqMain.Close;
331         mqMain.SQL.Text := sSQLString;
332         mqMain.Execute;
333         iReturnCode := mqMain.Fields.Fields[0].AsInteger;
334         mqMain.Close;
335       except on E:Exception do
336         begin
337           mqMain.Close;
338           MainForm.LogInfo('写入北单胜负彩果失败,原因:' + e.Message + ''+DBSFResultList[i].TERM +' '+ MatchId , True);
339           hsl_Result.Values[IntToStr(iLotMacthId)] :='';
340           Continue;
341         end;
342       end;
343       if iReturnCode = 1 then              //数据验证失败
344       begin
345         MainForm.LogInfo('写入北单胜负彩果失败,原因:数据验证失败'+DBSFResultList[i].TERM +' '+MatchId , True);
346         hsl_Result.Values[IntToStr(iLotMacthId)] :='';
347         Continue;
348       end else if iReturnCode = 100 then
349       begin
350         MainForm.LogInfo('写入北单胜负彩果失败,原因:未知错误'+DBSFResultList[i].TERM +' '+ MatchId , True);
351         hsl_Result.Values[IntToStr(iLotMacthId)] :='';
352        Continue;
353       end;
354       ResulCount := ResulCount +1 ;
355     end;
356     MainForm.LogInfo('已写入北单胜负赛果'+IntToStr(ResulCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
357     result := true;
358   except on E : Exception do
359     begin
360       MainForm.LogInfo('写入北单胜负过关赛果失败,原因:' + E.Message, True);
361       Exit;
362     end;
363   end;
364 end;
365 
366 function TBDSFResultThd.GetMatchId(MacheNo: Integer; Term: string; var MatchId: string): Boolean;
367 var
368   sSQLString : string ;
369 begin
370   result := false ;
371   try
372     sSQLString := ' SELECT ID FROM LOTTERY_MATCH_BDSF WHERE  TERM = '     // ''120914''
373              +  QuotedStr(Term)
374              + ' AND MATCH_NO= ' + inttostr(macheNo);
375     mqMain.Close;
376     mqMain.SQL.Text := sSQLString;
377     mqMain.Execute;
378     //
379     MatchId := mqMain.Fields.Fields[0].AsString;
380     mqMain.Close;
381     result := true;
382   except on e:Exception do
383     begin
384       MainForm.LogInfo('获取北单胜负场次ID出错! 原因:'+E.Message, True);
385       Exit;
386     end;
387   end;
388 end;
389 
390 procedure TBDSFResultThd.SetPause(const aIsPause: Boolean);
391 begin
392   Pause := aIsPause;
393 end;
394 
395 destructor TBDSFResultThd.Destroy;
396 begin
397   if Assigned(mcMain) then mcMain.Free;
398   if Assigned(mqMain) then mqMain.Free;
399   if Assigned(hsl_Result) then hsl_Result.Free;
400   inherited;
401 end;
402 end.
北单胜负赛果线程单元

 

  1 unit ThdBDMatch;
  2 
  3 interface
  4 
  5 uses
  6   Classes, ShDocVw, MyAccess, SysUtils, PubDefine, DateUtils, IdHTTP,
  7   StrUtils,IniFiles;
  8 
  9   type
 10      TBDMatchThd = class(TThread)
 11 
 12   private
 13      Pause: Boolean;
 14      mcMain: TMyConnection;
 15      mqMain: TMyQuery;
 16      iBDType : Integer;
 17      hsl_Match :Thashedstringlist;
 18      //
 19      function CatchMatch: Boolean;
 20      function GetBDMatch : Boolean ;
 21      //
 22      function SaveData: Boolean;
 23   protected
 24 
 25   public
 26     iBdInv : integer;
 27 
 28     constructor Create(iType:integer;Finterval:integer);
 29     procedure Execute; override;
 30     destructor Destroy; override;
 31     procedure SetPause(const aIsPause: Boolean);
 32   end ;
 33 
 34 implementation
 35 
 36 uses FrmMain; //, UAddLogThread; //2014-12-15 liping.chen 该线程目前没有使用,不需要引用,
 37                                  //【该线程自动创建并挂起,AddLogThread.Terminate无法正确释放】
 38 var
 39   BDMatchList : array of TBDMatch ;
 40 
 41 
 42 { TBDMatchResult }
 43 
 44 function TBDMatchThd.CatchMatch: Boolean;
 45 begin
 46 
 47   Result := False;
 48   MainForm.LogInfo('开始抓取北单对阵', True);
 49   SetLength(BDMatchList, 0);
 50   if not GetBDMatch then Exit;
 51   Result := SaveData;
 52 end;
 53 
 54 constructor TBDMatchThd.Create(iType : integer;Finterval:integer);
 55 begin
 56   inherited Create(True);
 57   iBDType := iType;
 58   iBdInv := Finterval;
 59 
 60   hsl_Match := Thashedstringlist.Create;
 61   //
 62   FreeOnTerminate := True;
 63   mcMain := TMyConnection.Create(nil);
 64   mcMain.Server := ConnectionConfig.Server;
 65   mcMain.Username := ConnectionConfig.Username;
 66   mcMain.Password := ConnectionConfig.Password;
 67   mcMain.Port := ConnectionConfig.Port;
 68   mcMain.Database := ConnectionConfig.Database;
 69   mcMain.Options.UseUnicode := True;
 70   mcMain.LoginPrompt := False;
 71   try
 72     mcMain.Connect;
 73   except on ex:Exception do
 74     begin
 75       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
 76       Exit;
 77     end;
 78   end;
 79   mqMain := TMyQuery.Create(nil);
 80   mqMain.Connection := mcMain;
 81   if iBDType = 0 then
 82     SetPause(True)
 83   else
 84     SetPause(false);
 85   Self.Resume;
 86 end;
 87 
 88 destructor TBDMatchThd.Destroy;
 89 begin
 90   if Assigned(mcMain) then mcMain.Free;
 91   if Assigned(mqMain) then mqMain.Free;
 92   if Assigned(hsl_Match) then hsl_Match.Free;
 93   inherited;
 94 end;
 95 
 96 procedure TBDMatchThd.Execute;
 97 var
 98   bPauseStatus: Boolean;
 99   dtTemp: TDateTime;
100   iNum : Integer;
101 begin
102   { Place thread code here }
103   bPauseStatus := Pause;
104   iNum := 0;
105   while (iNum < 4 ) and (not Terminated) do   //线程.Terminate时确保可以结束线程。
106   begin
107     if iBDType = 0 then
108     begin
109       iNum := 1;
110       Sleep(iBdInv);
111     end
112     else
113       iNum := iNum + 1;
114     //
115     BDMatchRunTime := Now;
116     if not Pause then                          //如果没有收到暂停信息
117     begin
118       if bPauseStatus <> Pause then
119       begin
120         MainForm.LogInfo('抓取线程***北单对阵***已启动', True);
121         bPauseStatus := Pause;
122       end;
123       MainForm.IsBDMatchCatching := True;
124       if CatchMatch then                    //如果抓取成功
125       begin
126         MainForm.LogInfo('北单对阵抓取成功,等待下一次抓取', True);
127         dtTemp := Now;
128         while not Pause do
129         begin
130           Sleep(500);
131           if SecondsBetween(Now, dtTemp) > MainForm.BDMatchGetInv then Break;
132         end;
133       end
134       else begin
135         MainForm.LogInfo('抓取北单对阵失败,等待重试', True);
136         Sleep(RETRY_INV);
137       end;
138     end
139     else begin                                 //如果暂停抓取
140       if bPauseStatus <> Pause then
141       begin
142         MainForm.LogInfo('抓取线程***北单对阵***已暂停', True);
143         bPauseStatus := Pause;
144       end;
145       MainForm.IsBDMatchCatching := False;
146       Sleep(500);
147     end;
148   end;
149 
150 end;
151 
152 function TBDMatchThd.GetBDMatch : Boolean;
153 var
154   idServer: TIdHTTP;
155   i, Pos1, Pos2: Integer;
156   sResponse : string;
157   Term ,RaceName,HomeTeam,VisitingTeam,StatusStr: string ;
158   MatchNo ,Handicap: Integer ;
159   StartDate : TDateTime;
160   SellMatchCount , TotalMatchCount, StopMatchCount ,status: Integer;
161 begin
162   Result := False ;
163   idServer := TIdHTTP.Create(nil);
164   idServer.ConnectTimeout:=15000;
165   idServer.ReadTimeout:=15000;
166   try
167     try
168       try      //2015-02-05 liping.chen
169         sResponse := UTF8Decode(idServer.Get(MainForm.BDMatchAddress));
170       except on E : Exception do
171         begin
172           MainForm.LogInfo('idServer.Get获取北单对阵失败'+ E.Message, True);
173           Exit;
174         end;
175       end;
176       if MainForm.IsSaveFile then
177       begin
178         if MainForm.SaveFile(sResponse,'FileBDDZDate') then
179         begin
180           MainForm.LogInfo('保存北单对阵页面成功', True);
181         end;
182       end;
183       //------------------可以修改为不用截短-直接移位取[取赛果]---------
184       //彩期
185       pos1 := posex('<no>',sResponse,1);
186       sResponse := copy(sResponse,pos1+length('<no>'),Length(sResponse)-Length('<no>')-pos1+1);
187       pos2 := posex('</no>',sResponse,1);
188       Term :=  copy(sResponse,2,pos2-2) ;
189       Term := FormatDateTime('Y',now) + Term ;
190       // 销售中场次数
191       pos1 :=  posex('<selling>',sResponse,1);
192       sResponse := copy(sResponse,pos1+length('<selling>'),Length(sResponse)-Length('<selling>')-pos1+1);
193       pos2 := posex('</selling>',sResponse,1);
194       SellMatchCount := StrToInt(Copy(sResponse,1,pos2-1));
195       // 停止销售场次数
196       pos1 :=  posex('<stopsell>',sResponse,1);
197       sResponse := copy(sResponse,pos1+length('<stopsell>'),Length(sResponse)-Length('<stopsell>')-pos1+1);
198       pos2 := posex('</stopsell>',sResponse,1);
199       StopMatchCount := StrToInt(Copy(sResponse,1,pos2-1));
200       TotalMatchCount := SellMatchCount+ StopMatchCount ;
201       // 截取场次信息字符
202       pos1 :=  posex('<matchelem>',sResponse,1);
203       sResponse := Copy(sResponse,pos1+length('<matchelem>'),Length(sResponse)-Length('<matchelem>')-pos1+1);
204       SetLength(BDMatchList,TotalMatchCount);
205       for i := 0 to TotalMatchCount-1 do
206       begin
207         // 场次序号
208         pos1 := posex('<no>',sResponse,1);
209         sResponse := Copy(sResponse,pos1+length('<no>'),Length(sResponse)-Length('<no>')-pos1+1);
210         pos2 := posex('</no>',sResponse,1);
211         MatchNo:= StrToInt(Copy(sResponse,1 ,pos2-1)) ;//
212         //   主队
213         pos1 :=  posex('<host>',sResponse,1);
214         sResponse := Copy(sResponse,pos1+length('<host>'),Length(sResponse)-Length('<host>')-pos1+1);
215         pos2 := posex('</host>',sResponse,1);
216         HomeTeam := Copy(sResponse,1 ,pos2-1 ) ;
217         //  客队
218         pos1 :=  posex('<guest>',sResponse,1);
219         sResponse := Copy(sResponse,pos1+length('<guest>'),Length(sResponse)-Length('<guest>')-pos1+1);
220         pos2 := posex('</guest>',sResponse,1);
221         VisitingTeam := Copy(sResponse,1 ,pos2-1 );
222         // 开赛时间
223         pos1 := posex('<endTime>',sResponse,1);
224         sResponse := Copy(sResponse,pos1+length('<endTime>'),Length(sResponse)-Length('<endTime>')-pos1+1);
225         pos2 := posex('</endTime>',sResponse,1) ;
226         StartDate := TranDrawDateEx(Copy(sResponse,1,pos2-1));
227         //  让分
228         pos1 :=  posex('<handicap>',sResponse,1);
229         sResponse := Copy(sResponse,pos1+length('<handicap>'),Length(sResponse)-Length('<handicap>')-pos1+1);
230         pos2 := posex('</handicap>',sResponse,1);
231         Handicap := StrToInt(Copy(sResponse,1 ,pos2-1 )) ;
232         // 赛事
233         pos1 :=  posex('<leagueName>',sResponse,1);
234         sResponse := Copy(sResponse,pos1+length('<leagueName>'),Length(sResponse)-Length('<leagueName>')-pos1+1);
235         pos2 := posex('</leagueName>',sResponse,1);
236         RaceName := Copy(sResponse,1 ,pos2-1 ) ;
237         // 状态
238         pos1 := posex('<matchandstate>',sResponse,1);
239         sResponse := Copy(sResponse,pos1+length('<matchandstate>'),Length(sResponse)-Length('<matchandstate>')-pos1+1);
240         pos2 := posex('</matchandstate>',sResponse,1) ;
241         StatusStr :=Copy(sResponse,1,pos2-1);
242         if  StatusStr= '销售中' then
243         begin
244           status := 1;
245         end else
246           status := 2;
247         BDMatchList[i].TERM := term ;
248         BDMatchList[i].Status := status;
249         BDMatchList[i].StartDate := StartDate ;
250         BDMatchList[i].RaceName := RaceName ;
251         BDMatchList[i].HomeTeam := HomeTeam ;
252         BDMatchList[i].VisitingTeam := VisitingTeam ;
253         BDMatchList[i].MatchNo := MatchNo ;
254         BDMatchList[i].Handicap := Handicap ;
255       end;
256       //*********************************************************
257      { for i := 0 to TotalMatchCount-1 do
258       begin
259         // 开赛时间
260         pos1 := posex('title="',sResponse,1);
261         sResponse := Copy(sResponse,pos1+length('title="'),Length(sResponse)-Length('title="')-pos1);
262         pos2 := posex('" name1',sResponse,1) ;
263         StartDate := TranDrawDateEx(Copy(sResponse,1,pos2-1));
264         // 状态
265         pos1 := posex('name2="',sResponse,1);
266         sResponse := Copy(sResponse,pos1+length('name2="'),Length(sResponse)-Length('name2="')-pos1);
267         pos2 := posex('" name3',sResponse,1) ;
268         StatusStr :=Copy(sResponse,1,pos2-1);
269         if  StatusStr= '销售中' then
270         begin
271           status := 1;
272         end else
273           status := 2;
274         // 场次序号
275         pos1 := posex('"number_tab">',sResponse,1);
276         sResponse := Copy(sResponse,pos1+length('"number_tab">'),Length(sResponse)-Length('"number_tab">')-pos1);
277         pos2 := posex('</span>',sResponse,1);
278         MatchNo:= StrToInt(Copy(sResponse,1 ,pos2-1)) ;
279         // 赛事
280         pos1 :=  posex('td_'+inttostr(MatchNo)+'_null_b">',sResponse,1);
281         sResponse := Copy(sResponse,pos1+length('td_'+inttostr(MatchNo)+'_null_b">'),Length(sResponse)-Length('td_'+inttostr(MatchNo)+'_null_b">')-pos1);
282         pos2 := posex('</td>',sResponse,1);
283         RaceName := Copy(sResponse,1 ,pos2-1 ) ;
284         //   主队
285         pos1 :=  posex('td_'+inttostr(MatchNo)+'_null_d">',sResponse,1);
286         sResponse := Copy(sResponse,pos1+length('td_'+inttostr(MatchNo)+'_null_d">'),Length(sResponse)-Length('td_'+inttostr(MatchNo)+'_null_d">')-pos1);
287         pos2 := posex('</td>',sResponse,1);
288         HomeTeam := Copy(sResponse,1 ,pos2-1 ) ;
289         //  让分
290         pos1 :=  posex('td_'+inttostr(MatchNo)+'_null_e">',sResponse,1);
291         sResponse := Copy(sResponse,pos1+length('td_'+inttostr(MatchNo)+'_null_e">'),Length(sResponse)-Length('td_'+inttostr(MatchNo)+'_null_e">')-pos1);
292         pos2 := posex('</td>',sResponse,1);
293         Handicap := StrToInt(Copy(sResponse,1 ,pos2-1 )) ;
294         //  客队
295         pos1 :=  posex('td_'+inttostr(MatchNo)+'_null_f">',sResponse,1);
296         sResponse := Copy(sResponse,pos1+length('td_'+inttostr(MatchNo)+'_null_f">'),Length(sResponse)-Length('td_'+inttostr(MatchNo)+'_null_f">')-pos1);
297         pos2 := posex('</td>',sResponse,1);
298         VisitingTeam := Copy(sResponse,1 ,pos2-1 );
299         //
300         BDMatchList[i].TERM := term ;
301         BDMatchList[i].Status := status;
302         BDMatchList[i].StartDate := StartDate ;
303         BDMatchList[i].RaceName := RaceName ;
304         BDMatchList[i].HomeTeam := HomeTeam ;
305         BDMatchList[i].VisitingTeam := VisitingTeam ;
306         BDMatchList[i].MatchNo := MatchNo ;
307         BDMatchList[i].Handicap := Handicap ;
308         //
309         pos1 :=  posex('number_tab',sResponse,1);
310         pos2 :=  posex('<tbody',sResponse,1);
311         if pos1> pos2 then
312         begin
313           sResponse := Copy(sResponse,pos2+length('<tbody'),Length(sResponse)-Length('<tbody')-pos2);
314         end ; 
315        end; }
316       Result := True;
317     except on E: Exception do
318       begin
319         MainForm.LogInfo('抓取北单对阵出错!'+ E.Message, True);
320         Exit;
321       end;
322     end;
323   finally
324     idServer.Free;
325   end;
326 end;
327 
328 function TBDMatchThd.SaveData: Boolean;
329 var
330   i,iRepeat, iBDMatchCount, iReturnCode: Integer;
331   sSQLString: string;
332   sLotMacthId : string;
333   sMatchRet,sTmp : string;
334   BDCount,iNoChangeNum : Integer;
335 begin
336   Result := False;
337   BDCount:=0;
338   iNoChangeNum:=0;
339   iBDMatchCount := Length(BDMatchList);
340   if iBDMatchCount<=0 then
341   begin
342     MainForm.LogInfo('准备写入北单对阵的场数为0 ', True);
343     Exit;
344   end;
345   if hsl_Match.Count > 1000 then
346     hsl_Match.Clear;
347   //============================北单对阵============================
348   try
349     MainForm.LogInfo('准备写入北单对阵彩期:'+BDMatchList[0].TERM +''+inttostr(iBDMatchCount)+'', True);
350     for i := 0 to iBDMatchCount - 1 do
351     begin
352       // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
353       sLotMacthId := BDMatchList[i].TERM + '-' + IntToStr(BDMatchList[i].MatchNo);
354       sMatchRet := trim(BDMatchList[i].TERM)
355                    + '^' + IntToStr(BDMatchList[i].MatchNo)
356                    + '^' + trim(BDMatchList[i].RaceName)
357                    + '^' + IntToStr(BDMatchList[i].Status)
358                    + '^' + DateTimeToStr(BDMatchList[i].StartDate)
359                    + '^' + trim(BDMatchList[i].HomeTeam)
360                    + '^' + trim(BDMatchList[i].VisitingTeam)
361                    + '^' + FloatToStr(BDMatchList[i].Handicap);
362       // 判断hashed是否存在
363       sTmp := trim(hsl_Match.Values[trim(sLotMacthId)]);
364       if sTmp = '' then
365         hsl_Match.Add(trim(sLotMacthId) + '=' + sMatchRet)
366       else
367       begin
368         if sTmp = Trim(sMatchRet) then
369         begin
370           //MainForm.LogInfo('【北单赛程】无变更:' + sMatchRet, True);
371           Inc(iNoChangeNum);
372           Continue;   // 退出
373         end
374         else
375           hsl_Match.Values[trim(sLotMacthId)] := Trim(sMatchRet);
376       end;
377       // ---------------------------------------------------------------------
378       //sSQLString := 'SET NAMES GB2312;'  ;
379       sSQLString := 'CALL P_INSERT_BD_MATCH('
380            + QuotedStr(BDMatchList[i].TERM)
381            + ',' + QuotedStr(IntToStr(BDMatchList[i].MatchNo))
382            + ',' + QuotedStr(BDMatchList[i].RaceName)
383            + ',' + QuotedStr(IntToStr(BDMatchList[i].Status))
384            + ',' + QuotedStr(DateTimeToStr(BDMatchList[i].StartDate))
385            + ',' + QuotedStr(BDMatchList[i].HomeTeam)
386            + ',' + QuotedStr(BDMatchList[i].VisitingTeam)
387            + ',' + QuotedStr(FloatToStr(BDMatchList[i].Handicap));
388            sSQLString := sSQLString +',@a); select @a;';
389 
390       iRepeat:=0;
391       while True do   //2015-02-05 liping.chen
392       begin
393         try
394           mqMain.Close;
395           mqMain.SQL.Text := sSQLString;
396           mqMain.Execute;
397           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
398           mqMain.Close;
399           Break;
400         except on E : Exception do
401           begin
402             inc(iRepeat);
403             MainForm.LogInfo('北单对阵'+BDMatchList[i].TERM +' '+IntToStr(BDMatchList[i].MatchNo)+'场次写入失败!第'+IntToStr(iRepeat)+''+ E.Message, True);
404             mqMain.Close;
405             if iRepeat=2 then
406             begin
407               hsl_Match.Values[trim(sLotMacthId)] :='';
408               Break;
409             end;
410           end;
411         end;
412       end;
413       if iRepeat=2 then
414       begin
415         Continue;
416       end;
417 
418       if iReturnCode = 1 then              //数据验证失败
419       begin
420         MainForm.LogInfo('写入北单对阵失败,原因:数据验证失败'+BDMatchList[i].TERM +' '+IntToStr(BDMatchList[i].MatchNo) , True);
421         hsl_Match.Values[trim(sLotMacthId)] :='';
422         Continue;
423       end else if iReturnCode = 100 then
424       begin
425         MainForm.LogInfo('写入北单对阵失败,原因:未知错误'+BDMatchList[i].TERM +' '+IntToStr(BDMatchList[i].MatchNo) , True);
426         hsl_Match.Values[trim(sLotMacthId)] :='';
427         Continue;
428       end;
429       BDCount := BDCount + 1;
430     end;
431     if BDCount>0 then
432     begin
433       // 更新北单截止时间
434       try
435          mqMain.Close;
436          sSQLString := ' CALL P_UPDATE_BD_LOTTERY_TERM() '  ;
437          mqMain.SQL.Text := sSQLString ;
438          mqMain.Execute ;
439       except on E : Exception do
440         MainForm.LogInfo('更新北单截止时间出错!'+ E.Message, True);
441       end;
442     end;
443     MainForm.LogInfo('已写入北单对阵'+IntToStr(BDCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
444     result := true;
445   except on E : Exception do
446     begin
447       MainForm.LogInfo('写入北单对阵失败,原因:' + E.Message, True);
448       Exit;
449     end;
450   end;
451 
452 
453 end;
454 
455 procedure TBDMatchThd.SetPause(const aIsPause: Boolean);
456 begin
457    Pause := aIsPause;
458 end;
459 
460 end.
北单赛程线程

 

  1 {*******************************************************************************
  2   Copyright (C), 2011-2015, aicaipiao
  3   File name: ThdBDResult.pas
  4   Author:
  5   Version: 1.0
  6   Date:
  7   Description: 投注接口
  8   Others:
  9   Function List:
 10   History:
 11    1. Date: 2013-1-13
 12         Author: rulinzhang
 13         Modification:  北单赛果页面变动
 14 *******************************************************************************}
 15 unit ThdBDResult;
 16 
 17 interface
 18 
 19 uses
 20   Classes, ShDocVw, MyAccess, SysUtils, PubDefine, DateUtils, IdHTTP,Forms, ActiveX,
 21   StrUtils,Windows,WinInet,IniFiles;
 22 
 23 
 24   type
 25     TDBResultDetail = array of TBDResult;
 26     TPtResult=^TDBResultDetail;
 27 
 28     TDoNavigatorProc = procedure(var aurl : string);   //指针函数
 29     TParseProc = procedure(var Content: string);
 30     TCatchStatus = (csStart, csNavigator, csParse,csNavigatorError, csComplete);
 31 
 32 
 33 type
 34      TBDResultThd = class(TThread)
 35 
 36   private
 37      Pause: Boolean;
 38      mcMain: TMyConnection;
 39      mqMain: TMyQuery;
 40      iBDType : Integer;
 41 
 42      FNavigatorProc: TDoNavigatorProc;   //打开页面
 43      FParseProc: TParseProc;       //获取分析内容
 44      CatchStatus: TCatchStatus;    // 抓取状态
 45 
 46      hsl_Result : Thashedstringlist;
 47      //
 48      function   CatchMatch: Boolean;
 49      function   GetResult(Aurl:string ; var ResultList : TDBResultDetail): Boolean ;
 50      //
 51      function   SaveData: Boolean;
 52      procedure  SaveDataDetail(Msg : string ; LotteryType : Integer ;ResultList : TDBResultDetail);
 53      function   GetMatchId(MacheNo : Integer; Term : string  ; var MatchId :string) : Boolean;
 54 
 55      procedure  SetBDResultLength(var APtResult : TPtResult ; Alength : Integer);    // 给结构体初始化长度
 56   protected
 57     procedure DoNavigator;  //传参,指定抓取网址,对应unit FrmMain的私有函数DoNavigator。
 58     procedure DoParse;      //var传参(抓取得到的内容);条件判断是否包含想要的内容。
 59 
 60   public
 61      Content : string;
 62      LoadAurl : string ;
 63      iBdInv : Integer;
 64 
 65      constructor Create(ANavigatorProc: TDoNavigatorProc; AParseProc: TParseProc;iType:integer;Finterval:integer);
 66      procedure Execute; override;
 67      destructor Destroy; override;
 68      procedure SetPause(const aIsPause: Boolean);
 69     procedure DeleteIECache ;
 70     // function EmptyDirectory(TheDirectory:String;Recursive:Boolean):Boolean; // 清空IE临时文件
 71 
 72   end ;
 73 
 74 implementation
 75 
 76 uses FrmMain;
 77 
 78 var
 79    BDSPFResultList : TDBResultDetail ;       //胜平负
 80    BDSXPDSSResultList : TDBResultDetail ;    // 单场上下盘单双
 81    BDZJQSResultList : TDBResultDetail ;      //  单场总进球数
 82    BDDCBFResultList : TDBResultDetail ;      // 单场比分
 83    BDBQCSPFResultList : TDBResultDetail ;   // 单场半场胜负平
 84    IsLoadUrl : Boolean ;
 85    TempFile : string; 
 86 
 87 
 88 { TBDMResultThd }
 89 
 90 function TBDResultThd.CatchMatch: Boolean;
 91 begin
 92   Result := False;
 93   case iBDType of
 94     30 : begin
 95       MainForm.LogInfo('开始抓取北单胜平负赛果', True);
 96       if not GetResult(MainForm.BDResultSPFAddress,BDSPFResultList)  then
 97         MainForm.LogInfo('获取北单胜平负赛果出错,等待重试!', True);
 98     end;
 99     31 : begin
100       MainForm.LogInfo('开始抓取北单总进球数赛果', True);
101       if not GetResult(MainForm.BDResultZJQSAddress,BDZJQSResultList)  then
102         MainForm.LogInfo('获取北单总进球数赛果出错,等待重试!', True);
103     end;
104     32 : begin
105       MainForm.LogInfo('开始抓取半全场胜平负赛果', True);
106       if not GetResult(MainForm.BDResultBQCSPFAddress,BDBQCSPFResultList)  then
107         MainForm.LogInfo('获取北单半全场胜平负赛果出错,等待重试!', True);
108     end;
109     33 : begin
110       MainForm.LogInfo('开始抓取上下盘单双数赛果', True);
111       if not GetResult(MainForm.BDResultSXPDSSAddress,BDSXPDSSResultList)  then
112         MainForm.LogInfo('获取北单上下盘单双数赛果出错,等待重试!', True);
113     end;
114     34 : begin
115       MainForm.LogInfo('开始抓取单场比分赛果', True);
116       if not GetResult(MainForm.BDResultDCBFAddress,BDDCBFResultList)  then
117         MainForm.LogInfo('获取北单单场比分赛果出错,等待重试!', True);
118     end;
119     0 : begin
120       if Pause then Exit;
121       MainForm.LogInfo('开始抓取北单胜平负赛果', True);
122       if not GetResult(MainForm.BDResultSPFAddress,BDSPFResultList)  then
123         MainForm.LogInfo('获取北单胜平负赛果出错,等待重试!', True);
124       if Pause then Exit;
125       //
126       MainForm.LogInfo('开始抓取北单总进球数赛果', True);
127       if not GetResult(MainForm.BDResultZJQSAddress,BDZJQSResultList)  then
128         MainForm.LogInfo('获取北单总进球数赛果出错,等待重试!', True);
129       if Pause then Exit;
130       //
131       MainForm.LogInfo('开始抓取半全场胜平负赛果', True);
132       if not GetResult(MainForm.BDResultBQCSPFAddress,BDBQCSPFResultList)  then
133         MainForm.LogInfo('获取北单半全场胜平负赛果出错,等待重试!', True);
134       if Pause then Exit;
135       //
136       MainForm.LogInfo('开始抓取上下盘单双数赛果', True);
137       if not GetResult(MainForm.BDResultSXPDSSAddress,BDSXPDSSResultList)  then
138         MainForm.LogInfo('获取北单上下盘单双数赛果出错,等待重试!', True);
139       if Pause then Exit;
140       //
141       MainForm.LogInfo('开始抓取单场比分赛果', True);
142       if not GetResult(MainForm.BDResultDCBFAddress,BDDCBFResultList)  then
143         MainForm.LogInfo('获取北单单场比分赛果出错,等待重试!', True);
144     end;
145     else
146       Exit;
147   end;
148   if Pause then Exit;
149   Result := SaveData;
150 end;
151 
152 constructor TBDResultThd.Create(ANavigatorProc: TDoNavigatorProc; AParseProc: TParseProc;iType:integer;Finterval:integer);
153 begin
154   inherited Create(True);
155   iBDType := iType;
156   iBdInv := Finterval;
157 
158   hsl_Result := Thashedstringlist.Create;
159   // TempFile := 'C:\Users\jianglong\AppData\Local\Microsoft\Windows\Temporary Internet Files';
160   TempFile := 'C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\' ;
161   FreeOnTerminate := True;
162 
163   mcMain := TMyConnection.Create(nil);
164   mcMain.Server := ConnectionConfig.Server;
165   mcMain.Username := ConnectionConfig.Username;
166   mcMain.Password := ConnectionConfig.Password;
167   mcMain.Port := ConnectionConfig.Port;
168   mcMain.Database := ConnectionConfig.Database;
169   mcMain.Options.UseUnicode := True;
170   mcMain.LoginPrompt := False;
171   try
172     mcMain.Connect;
173   except on ex:Exception do
174     begin
175       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
176       Exit;
177     end;
178   end;
179   mqMain := TMyQuery.Create(nil);
180   mqMain.Connection := mcMain;
181   if iBDType = 0 then
182     SetPause(True)
183   else
184     SetPause(false);
185   FNavigatorProc := ANavigatorProc ;
186   FParseProc := AParseProc;
187   Self.Resume;
188 
189 end;
190 
191 
192 destructor TBDResultThd.Destroy;
193 begin
194   if Assigned(mcMain) then mcMain.Free;
195   if Assigned(mqMain) then mqMain.Free;
196   if Assigned(hsl_Result) then hsl_Result.Free;
197   inherited;
198 end;
199 
200 procedure TBDResultThd.DoNavigator;
201 begin
202   CatchStatus := csNavigator;
203   FNavigatorProc(LoadAurl);
204 end;
205 
206 procedure TBDResultThd.DoParse;
207 var
208   tmpContent: string;
209   pos1 : Integer ;
210 begin
211   CatchStatus := csParse;
212   FParseProc(tmpContent);
213   //用'=changci>'来判断是否抓取成功
214   if Pos('=changci>', Content) > 0 then
215     CatchStatus := csComplete;
216   Content := tmpContent;
217   //
218   pos1 := posex('无法显示网页',Content,1);
219   if  pos1 >0 then
220   begin
221      MainForm.LogInfo('打开网页出错!' , True);
222      CatchStatus := csNavigatorError ;
223      Content := '' ;
224      Exit;
225   end;
226   //
227   pos1 := posex('取消操作',Content,1);
228   if  pos1 >0 then
229   begin
230      MainForm.LogInfo('打开网页出错!'  , True);
231      CatchStatus := csNavigatorError ;
232      Content := '' ;
233      Exit;
234   end;
235 end;
236 
237 procedure TBDResultThd.DeleteIECache;
238 var
239    lpEntryInfo: PInternetCacheEntryInfo;
240    hCacheDir: LongWord;
241    dwEntrySize: LongWord;
242 begin
243   dwEntrySize := 0;
244   FindFirstUrlCacheEntry(nil,TInternetCacheEntryInfo(nil^),dwEntrySize);//第一个参数可以指定类型
245   GetMem(lpEntryInfo, dwEntrySize);
246   if dwEntrySize > 0 then
247     lpEntryInfo^.dwStructSize := dwEntrySize;
248   //
249   hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
250   if hCacheDir <> 0 then
251   begin
252     repeat
253        DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
254        FreeMem(lpEntryInfo, dwEntrySize);
255        dwEntrySize := 0;
256        FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
257        GetMem(lpEntryInfo, dwEntrySize);
258       if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
259     until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize);
260   end;
261    FreeMem(lpEntryInfo, dwEntrySize);
262    FindCloseUrlCache(hCacheDir);
263 end;
264 
265 
266 
267 {
268  // 清空IE 临时文件
269 function TBDResultThd.EmptyDirectory(TheDirectory:String;Recursive:Boolean):Boolean;
270 var
271   SearchRec : TSearchRec;
272   Res : Integer;
273 begin
274   Res := FindFirst(TheDirectory + '*.*', faAnyFile, SearchRec);
275   try
276     while Res = 0 do
277     begin
278       if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
279       begin
280         if ((SearchRec.Attr and faDirectory) > 0) and Recursive then
281         begin
282           EmptyDirectory(TheDirectory + SearchRec.Name, True);
283           RemoveDirectory(PChar(TheDirectory + SearchRec.Name));
284         end else
285         begin
286           DeleteFile(PChar(TheDirectory + SearchRec.Name))
287         end;
288       end;
289       Res := FindNext(SearchRec);
290     end;
291     Result := True;
292   finally
293    // FindClose(SearchRec);
294   end;
295 end;
296 
297 }
298 procedure TBDResultThd.Execute;
299 var
300   bPauseStatus: Boolean;
301   dtTemp: TDateTime;
302   iNum : Integer;
303 begin
304   { Place thread code here }
305   bPauseStatus := Pause;
306   iNum := 0;
307   while (iNum < 4 ) and (not Terminated) do   //线程.Terminate时确保可以结束线程。
308   begin
309     if iBDType = 0 then
310     begin
311       iNum := 1;
312       Sleep(iBdInv);
313     end
314     else
315     begin
316       iNum := iNum + 1;
317       Sleep(500);
318     end;
319     BDResultRunTime := now;                    //2013-04-28 监控变量
320     if not Pause then                          //如果没有收到暂停信息
321     begin
322       if bPauseStatus <> Pause then
323       begin
324         MainForm.LogInfo('抓取线程***北单赛果***已启动', True);
325         bPauseStatus := Pause;
326       end;
327       MainForm.IsBDResultCatching := True;
328       if CatchMatch then                    //如果抓取成功
329       begin
330         MainForm.LogInfo('北单赛果抓取成功,等待下一次抓取', True);
331         DeleteIECache ;
332         WINEXEC(PChar('ipconfig /flushdns'),SW_SHOWNORMAL);
333         MainForm.LogInfo('清空IE缓存成功!',True);
334         dtTemp := Now;
335         while not Pause do
336         begin
337           Sleep(500);
338           if SecondsBetween(Now, dtTemp) > MainForm.BDResultGetInv then Break;
339         end;
340       end
341       else begin
342         MainForm.LogInfo('抓取北单赛果失败,等待重试', True);
343         if not Pause then Sleep(RETRY_INV);
344       end;
345     end
346     else begin                                 //如果暂停抓取
347       if bPauseStatus <> Pause then
348       begin
349         MainForm.LogInfo('抓取线程***北单赛果***已暂停', True);
350         bPauseStatus := Pause;
351       end;
352       MainForm.IsBDResultCatching := False;
353     end;
354   end;
355 end;
356 
357 function TBDResultThd.GetMatchId(macheNo: Integer; Term: string ; var MatchId :string ): Boolean ;
358 var
359   sSQLString : string ;
360 begin
361   result := false ;
362   try
363     sSQLString := ' SELECT ID FROM LOTTERY_MATCH_BD WHERE  TERM = '     // ''120914''
364              +  QuotedStr(Term)
365              + ' AND MATCH_NO= ' + inttostr(macheNo);
366     mqMain.Close;
367     mqMain.SQL.Text := sSQLString;
368     mqMain.Execute;
369     //
370     MatchId := mqMain.Fields.Fields[0].AsString;
371     mqMain.Close;
372     result := true;
373   except on e:Exception do
374     begin
375       MainForm.LogInfo('获取北单场次ID出错!原因:'+E.Message, True);
376       Exit;
377     end;
378   end;
379 end;
380 
381 function TBDResultThd.GetResult(Aurl:string ; var ResultList : TDBResultDetail): Boolean ;
382 var
383   term : string;
384   ptResult : TPtResult;
385   sResponse  : string;
386   TatolMatchCount : integer ;
387   i,j,pos1,pos2: Integer;
388   MatchNo : Integer ;
389   SCORE,MatchResult : string ;
390   SP,SingleBonus : Double ;
391   dtTemp : TDateTime;
392 begin
393   Result  := false ;
394   ptResult := @ResultList ;
395   SetBDResultLength(ptResult,0) ;
396   IsLoadUrl := False ;
397   LoadAurl :=  Aurl;
398   dtTemp := Now;
399 
400   while not  IsLoadUrl do
401   begin
402     if Pause then   //2015-04-08 liping.chen
403     begin
404       CatchStatus := csStart;
405       Exit;
406     end;
407 
408     case CatchStatus of
409     csStart:
410       begin
411 
412         try
413           MainForm.LogInfo('访问北单页面为:' +LoadAurl ,True);
414           Synchronize(DoNavigator);
415           Sleep(200);
416         except on e: Exception do
417           MainForm.LogInfo('获取北单URL出错!' + e.Message , True);
418         end;
419       end;
420     csNavigator, csParse:
421       begin
422         try
423           Synchronize(DoParse);
424         except on e: Exception do
425           begin
426            MainForm.LogInfo('加载北单页面出错!' + e.Message , True);
427             CatchStatus := csStart;
428             Exit;
429            end;
430         end;
431         IF MinutesBetween(Now, dtTemp) > 10  then
432         begin
433           MainForm.LogInfo('获取北单页面超时!', True);
434           DeleteIECache ;
435           WINEXEC(PChar('ipconfig /flushdns'),SW_SHOWNORMAL);
436           MainForm.LogInfo('清空IE缓存成功!',True);
437           CatchStatus := csStart;
438           Content := '' ;
439           Exit;
440         end;
441       end;
442     csNavigatorError :
443       begin
444         CatchStatus := csStart;
445         Content := '' ;
446         Exit;
447       end;
448       csComplete: //解析完了
449       begin
450        //dosomething
451        CatchStatus := csStart;
452        sResponse :=  Content  ;           
453      //  MainForm.LogInfo(Content, True);
454        IsLoadUrl := True;
455        Content := '' ;
456       end;
457     end;
458   end;
459 
460   try
461     try
462       if MainForm.IsSaveFile then
463       begin
464         if Aurl = MainForm.BDResultSPFAddress then
465         begin
466           if MainForm.SaveFile(sResponse,'FileBDSPFDate') then
467           begin
468             MainForm.LogInfo('保存北单胜平负页面成功', True);
469           end;
470         end ;
471         //
472         if Aurl =MainForm.BDResultZJQSAddress then
473         begin
474           if MainForm.SaveFile(sResponse,'FileBDZJQSDate') then
475           begin
476             MainForm.LogInfo('保存北单总进球数赛果页面成功', True);
477           end;
478         end ;
479         //
480         if Aurl =MainForm.BDResultBQCSPFAddress then
481         begin
482           if MainForm.SaveFile(sResponse,'FileBDBQCSPFDate') then
483           begin
484             MainForm.LogInfo('保存北单半全场胜平负赛果页面成功', True);
485           end;
486         end ;
487         //
488         if Aurl =MainForm.BDResultSXPDSSAddress then
489         begin
490           if MainForm.SaveFile(sResponse,'FileBDSXPDSSDate') then
491           begin
492             MainForm.LogInfo('保存北单上下盘单双数赛果页面成功', True);
493           end;
494         end ;
495         //
496         if Aurl =MainForm.BDResultDCBFAddress then
497         begin
498           if MainForm.SaveFile(sResponse,'FileBDDCBFDate') then
499           begin
500             MainForm.LogInfo('保存单场比分赛果页面成功', True);
501           end;
502         end ;
503       end;
504 
505        // 2013-01-13 rulinzhang 北单赛果页面变动
506        // pos1 := PosEx('月',sResponse,1);
507        // sResponse := Copy(sResponse,pos1+Length('月'),Length(sResponse)-length('月')-pos1);
508        //pos1 := PosEx('</OPTION></SELECT> 月',sResponse,1);
509        //sResponse := Copy(sResponse,pos1+Length('</OPTION></SELECT> 月'),Length(sResponse)-length('</OPTION></SELECT> 月')-pos1);
510        //
511 //       pos1 := posex('selected>',sResponse,1);
512 //       sResponse := Copy(sResponse,pos1+Length('selected>'),Length(sResponse)-length('selected>')-pos1);
513 //       pos2 :=  Posex('<',sResponse,1);
514 //       term := Copy(sResponse,2,pos2-2);
515 //       Term := FormatDateTime('Y',now) + Term ;
516        //
517               // 2013-01-31 rulinzhang update
518        //pos1 := posex('allNoNum>',sResponse,1);
519        //sResponse := Copy(sResponse,pos1+Length('allNoNum>'),Length(sResponse)-length('allNoNum>')-pos1);
520 
521        //彩期        // 2014-12-08 liping.chen 北单赛果页面变动
522       pos1 := Posex('drawNo',sResponse,1);
523       pos1 := posex('>',sResponse,pos1);
524       pos1 := posex('>',sResponse,pos1+1); //若与上一句查找相同字符,后面pos1要加上1  pos1+1
525       pos2 :=  Posex('<',sResponse,pos1);
526       term := Copy(sResponse,pos1+2,pos2-pos1-2);
527       Term := FormatDateTime('Y',now) + Term ;
528       //总场次数
529       pos1 := posex('allNoNum',sResponse,pos1);
530       pos1 :=  Posex('>',sResponse,pos1);
531       pos2 :=  Posex('<',sResponse,pos1);
532       TatolMatchCount := StrToInt(Copy(sResponse,pos1 + 1,pos2-pos1-1));
533       //******************************
534       SetBDResultLength(ptResult,TatolMatchCount) ;
535       for  i := 0 to TatolMatchCount-1 do
536       begin
537         // 场次序号
538         pos1 := posex('changci><SPAN>',sResponse,Pos1); 
539         pos2 := posex('</SPAN>',sResponse,Pos1) ;
540         MatchNo:= StrToInt(Copy(sResponse,pos1+length('changci><SPAN>'),pos2-pos1-length('changci><SPAN>')));//
541         // 赛果
542         for j := 0 to 5 do
543         begin
544           pos1 := posex('<TD',sResponse,pos1+1);
545         end;
546         pos2 := posex('</TD>',sResponse,Pos1) ;
547         MatchResult :=Copy(sResponse,pos1+4,pos2-pos1-4); //<TD>3</TD> 因此处pos1后为'</TD>',所以+4,-4
548         // SP
549         pos1 := posex('<TD>',sResponse,Pos1+1);
550         pos2 := posex('</TD>',sResponse,Pos1) ;
551         SP := StrToFloat(Copy(sResponse,pos1+length('<TD>'),pos2-pos1-length('<TD>')));//
552         ResultList[i].TERM := term ;
553         ResultList[i].SCORE :='0:0' ;
554         ResultList[i].MatchRESULT := MatchRESULT ;
555         ResultList[i].SP := SP ;
556         ResultList[i].SingleBonus :=0 ;
557         ResultList[i].MatchNo := MatchNo ;
558       end;
559       Result := True ;
560     except  on E: Exception do
561        begin
562          MainForm.LogInfo('抓取北单赛果出错!'+ E.Message, True);
563          Exit;
564        end;
565     end;
566   finally
567      // MainForm.WebBrowser1.stop;
568   end ;
569 end;
570 
571 
572 function TBDResultThd.SaveData: Boolean;
573 begin
574   Result := False;
575   try
576     SaveDataDetail('单场胜平负赛果',30,BDSPFResultList) ;
577     SaveDataDetail('单场上下盘单双赛果',31,BDSXPDSSResultList) ;
578     SaveDataDetail('单场总进球数赛果',32,BDZJQSResultList) ;
579     SaveDataDetail('单场比分赛果',33,BDDCBFResultList) ;
580     SaveDataDetail('单场半场胜负平赛果',34,BDBQCSPFResultList) ;
581     Result := True;
582   except on E: Exception do
583     begin
584       MainForm.LogInfo('写入北单赛果出错'+ E.Message, True);
585     Exit;
586     end;
587   end
588 end;
589 
590 procedure TBDResultThd.SaveDataDetail(Msg: string; LotteryType: Integer;
591   ResultList: TDBResultDetail);
592 var
593   i, iBDResltCount, iReturnCode: Integer;
594   sSQLString: string;
595   MatchId : string ;
596   MatchResult : string ;
597   MatchSore : string ;
598   ResulCount,iNoChangeNum : Integer ;
599   j : integer ;
600   iLotMacthId : Integer;
601   sMatchRet,sTmp : string;
602 begin
603   iBDResltCount := Length(ResultList);
604   ResulCount := 0 ;
605   iNoChangeNum:=0;
606   if iBDResltCount<=0 then
607   begin
608     MainForm.LogInfo('准备写入的'+Msg+'的场数为 0 ', True);
609     Exit;
610   end;
611   MainForm.LogInfo('准备写入'+Msg+' 彩期为'+ResultList[0].TERM+''+IntToStr(iBDResltCount) + '条数据' , True);
612   //============================北单赛果============================
613   if hsl_Result.Count > 2500 then
614     hsl_Result.Clear;
615   for i := 0 to iBDResltCount - 1 do
616   begin
617     try
618       j := 0;
619       while j<3 do
620       begin
621         if GetMatchId(ResultList[i].MatchNo,ResultList[i].TERM,MatchId) then
622          j  := 3
623         else
624         begin
625           j:= j+ 1;
626           MainForm.LogInfo('获取北单场次ID出错!第 '+IntToStr(j)+'', True);
627           Sleep(500);
628         end;
629       end;
630       //
631       if  trim(MatchId) = '' then
632       begin
633         MainForm.LogInfo('北单对阵没有此场次   彩期:'+ResultList[i].TERM +' 序号:'+ IntToStr(ResultList[i].MatchNo), True);
634         continue;
635       end;
636       // 格式转换
637       MatchResult := ResultList[i].MatchResult;
638       MatchResult := StringReplace(MatchResult,'-',':',[rfReplaceAll]);
639       MatchResult := StringReplace(MatchResult,'胜其它','9:0',[rfReplaceAll]);
640       MatchResult := StringReplace(MatchResult,'平其它','9:9',[rfReplaceAll]);
641       MatchResult := StringReplace(MatchResult,'负其它','0:9',[rfReplaceAll]);
642       //
643       MatchResult := StringReplace(MatchResult,'上单','11',[rfReplaceAll]);
644       MatchResult := StringReplace(MatchResult,'上双','12',[rfReplaceAll]);
645       MatchResult := StringReplace(MatchResult,'下单','21',[rfReplaceAll]);
646       MatchResult := StringReplace(MatchResult,'下双','22',[rfReplaceAll]);
647       //
648       MatchSore := ResultList[i].SCORE;
649       MatchSore := StringReplace(MatchSore,'-:-','*',[rfReplaceAll]);
650     except on e:Exception do
651       begin
652         MainForm.LogInfo('准备北单数据时失败,原因:' + e.Message + ''+ResultList[i].TERM +' '+ MatchId , True);
653         Continue;
654       end;
655     end;
656     // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
657     iLotMacthId := LotteryType * 10000 + StrToInt(matchid);
658     sMatchRet := IntToStr(LotteryType)
659                  + '^' + trim(MatchId)
660                  + '^' + trim(MatchSore)
661                  + '^' + trim(MatchResult)
662                  + '^' + FloatTostr(ResultList[i].SP)
663                  + '^' + FloatTostr(ResultList[i].SingleBonus);
664     // 判断hashed是否存在
665     sTmp := trim(hsl_Result.Values[IntToStr(iLotMacthId)]);
666     if sTmp = '' then
667       hsl_Result.Add(IntToStr(iLotMacthId) + '=' + sMatchRet)
668     else
669     begin
670       if sTmp = Trim(sMatchRet) then
671       begin
672         //MainForm.LogInfo('【北单赛果】无变更:' + sMatchRet, True);
673         Inc(iNoChangeNum);
674         Continue;
675       end
676       else
677         hsl_Result.Values[IntToStr(iLotMacthId)] := Trim(sMatchRet);
678     end;
679     // -------------------------------------------------------------------------
680     sSQLString := 'CALL P_INSERT_BD_RESULT('
681          + QuotedStr(IntToStr(LotteryType))
682          + ',' + QuotedStr(MatchId)
683          + ',' + QuotedStr(MatchSore)
684          + ',' + QuotedStr(MatchResult)
685          + ',' + QuotedStr(FloatTostr(ResultList[i].SP))
686          + ',' + QuotedStr(FloatTostr(ResultList[i].SingleBonus));
687          sSQLString := sSQLString +',@a); select @a;';
688 
689     try
690       mqMain.Close;
691       //  sSQLString :=  sSQLString + ' SET NAMES GB2312; ' ;
692       mqMain.SQL.Text := sSQLString;
693       mqMain.Execute;
694       iReturnCode := mqMain.Fields.Fields[0].AsInteger;
695       mqMain.Close;
696     except on E:Exception do
697       begin
698         mqMain.Close;
699         MainForm.LogInfo('写入北单'+ Msg +'失败,原因:' + E.Message + ''+ResultList[i].TERM +' '+ MatchId , True);
700         hsl_Result.Values[IntToStr(iLotMacthId)] :='';
701         Continue;
702       end;
703     end;
704     if iReturnCode = 1 then              //数据验证失败
705     begin
706       MainForm.LogInfo('写入北单赛果'+Msg+'失败,原因:数据验证失败'+ResultList[i].TERM +' '+MatchId , True);
707       hsl_Result.Values[IntToStr(iLotMacthId)] :='';
708       Continue;
709     end else if iReturnCode = 100 then
710     begin
711       MainForm.LogInfo('写入北单'+ Msg +'失败,原因:未知错误'+ResultList[i].TERM +' '+ MatchId , True);
712       hsl_Result.Values[IntToStr(iLotMacthId)] :='';
713      Continue;
714     end;
715     ResulCount := ResulCount +1 ;
716   end;
717   //2015-02-05 liping.chen
718   MainForm.LogInfo('已写入'+Msg+IntToStr(ResulCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
719 end;
720 
721 procedure TBDResultThd.SetBDResultLength(var APtResult : TPtResult ; Alength : Integer);
722 begin
723   setlength(APtResult^,Alength);
724 end;
725 
726 procedure TBDResultThd.SetPause(const aIsPause: Boolean);
727 begin
728   Pause := aIsPause;
729 end;
730 
731 
732 initialization
733   CoInitialize(nil);
734 
735 finalization
736   CoUninitialize;
737 
738 end.
北单赛果线程

 

   1 {*******************************************************************************
   2   Copyright (C), 2011-2015, aicaipiao
   3   File name: 所在单元
   4   Author: rulinzhang
   5   Version: 版本
   6   Date: 日期
   7   Description: 基本描述
   8   Others:
   9   Function List:
  10   History:
  11    7. Date: 2015-03-23
  12         Author: liping.chen
  13         Modification: 竞篮让分和预设总分页面改版,和竞足让分改版一样。
  14         [右键-查看源代码,看不出所需数据了,找到Json格式的数据源],尽量少改动原有函数;
  15    6. Date: 2015-01-21
  16         Author: liping.chen
  17         Modification: 设置SET NAMES GB2312优化
  18                       竞篮让分、预设总分 取消 分多次抓取网页。
  19    5. Date: 2015-01-13
  20         Author: liping.chen
  21         Modification: 竞彩赛程全部单过关修改为全可投注
  22    4. Date: 2014-12-15
  23         Author: liping.chen
  24         Modification: 竞篮竞足赛程单过关状态修改,竞足取消原停赛函数
  25                       P_STOP_MATCH_FLAG存储过程在本线程不再使用
  26                       竞足让分默认为0
  27    3. Date: 2013-05-17
  28         Author: rulinzhang
  29         Modification: 针对竞彩新玩法胜平负
  30    2. Date: 2013-04-09
  31         Author: rulinzhang
  32         Modification: 针对混合过关,无法保存场次问题的处理
  33    1. Date: 2013-03-13
  34         Author: rulinzhang
  35         Modification: 获取场次唯一码的地址有误。原为.com ,现改为.cn
  36 *******************************************************************************}
  37 unit ThdJCMatch;
  38 
  39 interface
  40 
  41 uses              
  42   Dialogs,Classes, MyAccess, PubDefine, SysUtils, XMLDoc, XMLIntf, IniFiles,IdHTTP,
  43   ActiveX, oxmldom, xmldom, DateUtils,StrUtils;
  44 
  45 type
  46   TJCMatchThd = class(TThread)
  47   private
  48     { Private declarations }
  49     Pause: Boolean;                                                                                
  50     mcMain: TMyConnection;
  51     mqMain: TMyQuery;
  52     LTypeList: THashedStringList;
  53     iJCType : Integer;
  54 
  55     function CatchMatch: Boolean;
  56     function GetBBMatch: Boolean;
  57  //   function GetBBSales: Boolean;
  58     function GetBBGivenScore(MatchID,HomeTeam,Response : string):Real ;             // 篮球让分
  59     function GetBBPresetScore(MatchID ,AwayTeam,Response:string):Real ;    // 篮球预设总分
  60     function GetFBMatch: Boolean;
  61     function GetFBGivenScore:Boolean ;  // 足球让分
  62   //  function GetFBSales: Boolean;
  63   //  function GetFBGoalLine :Boolean;
  64     function GetStopMatch : Boolean ;    //2014-12-15 liping.chen 已经不使用
  65     function SaveData: Boolean;
  66     function SaveDateStopMatch : Boolean ; //2014-12-15 liping.chen 已经不使用
  67     function GetLotteryType(aTypeName: string): string;
  68     function GetMatchNo(BusinessDate: string;MatchTime: string): string ;
  69     function TranMatchDateEx(const aMatchDate: string): TDateTime;
  70 
  71   protected
  72 
  73   public
  74     iJcInv : Integer;
  75     hsl_Match : THashedStringList;
  76 
  77     constructor Create(iType:integer;Finterval:integer);
  78     procedure Execute; override;
  79     destructor Destroy; override;
  80     procedure SetPause(const aIsPause: Boolean);
  81   end;
  82 
  83 implementation
  84 
  85 uses FrmMain;
  86 
  87 var
  88   BBMatchList, FBMatchList   : array of TMatch;
  89   FBStopMatchList  : TStringList;
  90 
  91 { Important: Methods and properties of objects in visual components can only be
  92   used in a method called using Synchronize, for example,
  93 
  94       Synchronize(UpdateCaption);
  95 
  96   and UpdateCaption could look like,
  97 
  98     procedure JCMatchThd.UpdateCaption;
  99     begin
 100       Form1.Caption := 'Updated in a thread';
 101     end; }
 102 
 103 { JCMatchThd }
 104 
 105 // 日期转换
 106 function TJCMatchThd.TranMatchDateEx(const aMatchDate: string): TDateTime;
 107 var
 108   FS:TFormatSettings;
 109   sTemp: string;
 110   aYear : string ;
 111 begin
 112   FS.ShortDateFormat := 'yyyy-mm-dd';
 113   FS.LongTimeFormat := 'hh:mm:ss';
 114   FS.DateSeparator := '-';
 115   FS.TimeSeparator := ':';
 116   aYear := Copy(FormatDateTime('yyyy',Date),0,2);
 117   sTemp := aMatchDate;
 118 
 119   sTemp := aYear+ sTemp + ':00';
 120   Result := StrToDateTimeDef(sTemp, MinDateTime, FS);
 121 end;
 122 
 123 //  推算发布时间 方法
 124 function TJCMatchThd.GetMatchNo(BusinessDate: string;MatchTime: string): string ;
 125 var
 126   WeekList : THashedStringList ;
 127   BusinessInt,MatchTimeInt : Integer ;
 128   DayDiff : Integer ;
 129   MatchTimeTemp : TDateTime ;
 130 begin
 131   WeekList := THashedStringList.Create ;
 132   try
 133     // 周转换
 134     WeekList.Add('周一=1');
 135     WeekList.Add('周二=2');
 136     WeekList.Add('周三=3');
 137     WeekList.Add('周四=4');
 138     WeekList.Add('周五=5');
 139     WeekList.Add('周六=6');
 140     WeekList.Add('周日=7');
 141     //
 142     BusinessInt := StrToInt(WeekList.Values[BusinessDate]);
 143     MatchTimeTemp := TranMatchDateEx(MatchTime);
 144     //  MatchTimeTemp := TranDrawDate()
 145     // MatchTimeTemp  := StrToDateTime(MatchTime)  ;
 146 
 147     MatchTimeInt := DayOfTheWeek(MatchTimeTemp);
 148     if   BusinessInt >  MatchTimeInt then
 149     begin
 150       DayDiff := 7-BusinessInt + MatchTimeInt;
 151     end else
 152     begin
 153       DayDiff :=  MatchTimeInt - BusinessInt ;
 154     end;
 155     // 返回处理
 156     Result :=  FormatDateTime('yymmdd',MatchTimeTemp - DayDiff);
 157     // 2013-05-17 rulinzhang 未做异常处理
 158   finally
 159     WeekList.Free;
 160   end;
 161 end;
 162 
 163 function TJCMatchThd.CatchMatch: Boolean;
 164 begin
 165   Result := False;
 166   // 此stringlist 会在如下那个函数中运行
 167   FBStopMatchList :=  TStringList.Create ;
 168   try
 169     MainForm.LogInfo('开始抓取竞彩对阵', True);
 170     // 初始化列表
 171     SetLength(BBMatchList, 0);
 172     SetLength(FBMatchList, 0);
 173     //
 174     case iJCType of
 175       0 :begin
 176         if not GetBBMatch then
 177         begin
 178           MainForm.LogInfo('获取竞彩篮球对阵出错,等待重试!', True);
 179           // AddErrorSmsLog(9,'【获取竞彩篮球对阵出错】');
 180           // Exit;
 181         end;
 182         if not GetFBMatch then
 183         begin
 184           MainForm.LogInfo('获取竞彩足球对阵出错,等待重试!', True);
 185           // AddErrorSmsLog(9,'【获取竞彩足球对阵出错】' );
 186           //  Exit;
 187         end;
 188       end;
 189       4 :begin
 190         if not GetBBMatch then
 191         begin
 192           MainForm.LogInfo('获取竞彩篮球对阵出错,等待重试!', True);
 193           // AddErrorSmsLog(9,'【获取竞彩篮球对阵出错】');
 194           // Exit;
 195         end;
 196       end;
 197       7 : begin
 198         if not GetFBMatch then
 199         begin
 200           MainForm.LogInfo('获取竞彩足球对阵出错,等待重试!', True);
 201           // AddErrorSmsLog(9,'【获取竞彩足球对阵出错】' );
 202           //  Exit;
 203         end;
 204       end;
 205     end;
 206     {if not GetBBSales then
 207     begin
 208       MainForm.LogInfo('获取竞彩篮球开售情况出错,等待重试!', True);
 209     //  Exit;
 210     end;
 211     if not GetFBSales then
 212     begin
 213       MainForm.LogInfo('获取竞彩足球开售情况出错,等待重试!', True);
 214     //  Exit;
 215     end;}
 216     // 保存数据
 217     Result := SaveData;
 218 
 219     {case iJCType of    //2014-12-15 liping.chen 不需要了
 220       0,7 : begin
 221         if not GetStopMatch then
 222         begin
 223           MainForm.LogInfo('获取竞彩足球停赛情况出错,等待重试!', True);
 224           Exit;
 225         end;
 226         //
 227         if not SaveDateStopMatch then
 228         begin
 229           MainForm.LogInfo('更新竞足停赛和单关过关开售状态出错,等待重试!', True);
 230           Exit
 231         end;
 232       end;
 233     end;  }
 234   finally
 235      FBStopMatchList.Free ;
 236   end;
 237 end;
 238 
 239 constructor TJCMatchThd.Create(iType:integer;Finterval:integer);
 240 begin
 241   inherited Create(True);
 242   FreeOnTerminate := True;
 243   iJCType := iType;
 244   iJcInv := Finterval;
 245   hsl_Match := THashedStringList.Create;
 246   // 1 数据连接池
 247   mcMain := TMyConnection.Create(nil);
 248   mcMain.Server := ConnectionConfig.Server;
 249   mcMain.Username := ConnectionConfig.Username;
 250   mcMain.Password := ConnectionConfig.Password;
 251   mcMain.Port := ConnectionConfig.Port;
 252   mcMain.Database := ConnectionConfig.Database;
 253   mcMain.LoginPrompt := False;
 254   try
 255     mcMain.Connect;
 256   except on ex:Exception do
 257     begin
 258       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
 259       Exit;
 260     end;
 261   end;
 262   // 2 查询连接
 263   mqMain := TMyQuery.Create(nil);
 264   mqMain.Connection := mcMain;
 265   // 3 彩种列表  暂时没有使用
 266   LTypeList := THashedStringList.Create;
 267   LTypeList.Add('MNL=45');
 268   LTypeList.Add('HDC=46');
 269   LTypeList.Add('WNM=47');
 270   LTypeList.Add('HILO=48');
 271 
 272   // 4 线程设定
 273   if iJCType = 0 then
 274     SetPause(True)
 275   else
 276     SetPause(false);
 277   CoInitialize(nil);
 278   Self.Resume;
 279 end;
 280 
 281 destructor TJCMatchThd.Destroy;
 282 begin
 283   if Assigned(mcMain) then mcMain.Free;
 284   if Assigned(mqMain) then mqMain.Free;
 285   if Assigned(LTypeList) then LTypeList.Free;
 286   if Assigned(hsl_Match) then hsl_Match.Free;
 287   CoUninitialize;
 288   inherited;
 289 end;
 290 
 291 procedure TJCMatchThd.Execute;
 292 var
 293   bPauseStatus: Boolean;
 294   dtTemp: TDateTime;
 295   iNum : Integer;// 执行次数
 296 begin
 297   { Place thread code here }
 298   bPauseStatus := Pause;
 299   iNum := 0;
 300   while (iNum < 4 ) and (not Terminated) do   //线程.Terminate时确保可以结束线程。
 301   begin
 302     if iJCType = 0 then
 303     begin
 304       iNum := 1;
 305       Sleep(iJcInv);
 306     end
 307     else
 308     begin
 309       iNum := iNum + 1;
 310       Sleep(500);
 311     end;
 312     //
 313     JcMtchRunTime := Now;                      //2013-04-28 监控变量
 314     if not Pause then                          //如果没有收到暂停信息
 315     begin
 316       if MainForm.IsCatchJCMatch then         //如果需要抓取
 317       begin
 318         if bPauseStatus <> Pause then
 319         begin
 320           MainForm.LogInfo('抓取线程***竞彩对阵***已启动', True);
 321           bPauseStatus := Pause;
 322         end;
 323         MainForm.IsJCMatchCatching := True;
 324         if CatchMatch then                    //如果抓取成功
 325         begin
 326           MainForm.LogInfo('竞彩对阵抓取成功,等待下一次抓取', True);
 327           dtTemp := Now;
 328           while not Pause do
 329           begin
 330             Sleep(500);
 331             if SecondsBetween(Now, dtTemp) > MainForm.JCMatchGetInv then Break;
 332           end;
 333         end
 334         else begin
 335           MainForm.LogInfo('抓取竞彩对阵失败,等待重试', True);
 336           Sleep(RETRY_INV);
 337         end;
 338       end
 339       else begin
 340         if bPauseStatus <> Pause then
 341         begin
 342           MainForm.LogInfo('抓取线程***竞彩对阵***已启动,但设置为不抓取', True);
 343           bPauseStatus := Pause;
 344         end;
 345         Sleep(200);
 346       end;
 347     end
 348     else begin                                 //如果暂停抓取
 349       if bPauseStatus <> Pause then
 350       begin
 351         MainForm.LogInfo('抓取线程***竞彩对阵***已暂停', True);
 352         bPauseStatus := Pause;
 353       end;
 354       MainForm.IsJCMatchCatching := False;
 355       Sleep(500);
 356     end;
 357   end;
 358 end;
 359 
 360 function TJCMatchThd.GetBBMatch: Boolean;
 361 var
 362   ipos1 ,ipos2 ,ipos3 : integer;
 363   idHttp : TIdHTTP ;
 364   //Url,
 365   sResponse,MatchNO,ID : string ;
 366   HomeTeam , awayTeam : string ;
 367   GivenScore ,PresetScore : Real;
 368   matchtime : string ;
 369   StrLog,SaleStatus : string ;
 370   SaleType  : string ;
 371   SaleList : THashedStringList ;
 372   LotteryType : THashedStringList ;
 373   WeekStr,WeekStrNo : string ;
 374   MatchCount ,SaleCount,LotteFlag: Integer ;  
 375   //SingleMultipleStr,LotteryStr : string ;
 376   iUrlLen :Integer;
 377   sResponsePreset,sResponseGiven :string;
 378 begin
 379   {
 380    ID: string;               //获取到的比赛ID
 381     MatchIndex: string;       //场次编码,格式为:110217-301
 382     MatchTime: TDateTime;     //比赛时间
 383     Sales: array of TSales;   //开售状态
 384     HomeTeam: string;         //主队名
 385     AwayTeam: string;         //客队名
 386     GivenScore: Real;         //让分让球
 387     PresetScore: Real;        //预设总分
 388     }
 389   Result := False ;
 390   SaleList := THashedStringList.Create ;
 391   LotteryType :=  THashedStringList.Create ;
 392   idHttp := TIdHTTP.Create(nil);
 393   idHttp.ConnectTimeout:=15000;
 394   idHttp.ReadTimeout:=15000;
 395   try
 396     try
 397       // Url := 'http://info.sporttery.com/basketball/match_list.php';
 398       try   //2015-02-05 liping.chen
 399         MainForm.LogInfo('正在获取竞篮对阵数据', True);
 400         sResponse := idHttp.Get(MainForm.BBMatchAddress) ;
 401       except on E : Exception do
 402         begin
 403           MainForm.LogInfo('idHttp.Get获取竞篮对阵数据失败 '+ E.Message, True);
 404           Exit;
 405         end;
 406       end;
 407       // 1 是否保存文件
 408       if MainForm.IsSaveFile then
 409       begin
 410         if MainForm.SaveFile(sResponse,'FileLQDZDate') then
 411           MainForm.LogInfo('保存竞彩篮球对阵页面成功', True);
 412       end;
 413 
 414       //========================================
 415       try
 416         MainForm.LogInfo('正在获取篮球对阵预设总分情况', True);
 417         sResponsePreset := idhttp.Get(MainForm.BBPresetScoreAddress);
 418       except on E : Exception do
 419         begin
 420           MainForm.LogInfo('idHttp.Get获取篮球对阵预设总分情况失败 '+ E.Message, True);
 421           Exit;
 422         end;
 423       end;
 424       //
 425       if MainForm.IsSaveFile then
 426       begin
 427         if MainForm.SaveFile(sResponsePreset,'FileLQYSZFDate') then
 428           MainForm.LogInfo('保存竞彩篮球对阵预设总分页面成功', True);
 429       end;
 430       //-------------------------------------------
 431       try
 432         MainForm.LogInfo('正在获取篮球对阵让分情况', True);
 433         sResponseGiven := idhttp.Get(MainForm.BBGivenScoreAddress);
 434       except on E : Exception do
 435         begin
 436           MainForm.LogInfo('idHttp.Get获取篮球对阵让分情况失败 '+ E.Message, True);
 437           Exit;
 438         end;
 439       end;
 440       if MainForm.IsSaveFile then
 441       begin
 442         if MainForm.SaveFile(sResponseGiven,'FileLQRFDate') then
 443         begin
 444           MainForm.LogInfo('保存竞彩篮球对阵让分页面成功', True);
 445         end;
 446       end;
 447       //=========================================
 448       // 2 开始解析数据
 449       // 2013-12-19 RULINZHANG add   缩小处理范围
 450       iPos1 := Pos('search_form', sResponse);
 451       if iPos1 = 0 then
 452         iPos1 := Pos('SEARCH_FORM', sResponse);
 453       sResponse := Copy(sResponse,iPos1,Length(sResponse) - iPos1 - 50);
 454       iPos2 := Pos('</form>', sResponse);
 455       if iPos2 = 0 then
 456         iPos2 := Pos('</FORM>', sResponse);
 457       sResponse := Copy(sResponse,1,iPos2 + 50);   //去掉末端,而已
 458       //
 459       StrLog := '<th class="txc forange">';
 460       ipos1 := PosEx(StrLog,sResponse) ;
 461       if (iPos1 = 0)then
 462       begin
 463         MainForm.LogInfo('获取竞篮对阵时出错,找不到标识字符串'+StrLog, True);
 464         Exit;
 465       end;
 466       MatchCount := 0 ;
 467       while ipos1 > 0 do
 468       begin
 469         SetLength(BBMatchList,Length(BBMatchList)+1);
 470         GivenScore :=0 ;  //让分清零
 471         PresetScore :=0; // 预设总分清零
 472 
 473         // 2.1 场次编号
 474         iPos1 := Posex('<td width="80">', sResponse,iPos1);
 475         sResponse := Copy(sResponse,ipos1+Length('<td width="80">') ,Length(sResponse)-Length('<td width="80">')-iPos1+1) ;
 476         ipos2  := PosEx('<',sResponse);
 477         WeekStr :=  Copy(sResponse,0,ipos2-1) ;
 478         MatchNO := rightstr(WeekStr,3);
 479         WeekStrNo  := LeftStr(WeekStr,2);
 480         // 2.2 官方编号
 481         ipos2  := PosEx('http://info.sporttery.cn/basketball/info/bk_match_mnl.php?m=',sResponse);
 482         iUrlLen := Length('http://info.sporttery.cn/basketball/info/bk_match_mnl.php?m=');
 483         sResponse := Copy(sResponse,ipos2+ iUrlLen,Length(sResponse)-ipos2- iUrlLen + 1);
 484         ipos3  := PosEx('''',sResponse);
 485         ID :=  Copy(sResponse,0,ipos3-1);
 486         // 2.3 客队
 487         ipos2  := PosEx('>',sResponse);
 488         sResponse := Copy(sResponse,ipos2+ Length('>'),Length(sResponse)-ipos2-Length('>')+1);
 489         ipos3  := PosEx('<strong>',sResponse);
 490         awayTeam  :=  Trim(Copy(sResponse,0,ipos3-1));
 491         // 2.4 主队
 492         ipos2  := PosEx('</strong>',sResponse);
 493         sResponse := Copy(sResponse,ipos2+ Length('</strong>'),Length(sResponse)-ipos2-Length('</strong>')+1);
 494         ipos3  := PosEx('</a>',sResponse);
 495         HomeTeam :=  Copy(sResponse,0,ipos3-1);
 496         // 2.5 截至时间
 497         ipos1  := Pos('<td',sResponse);
 498         ipos2  := Posex('>',sResponse,ipos1);
 499         sResponse := Copy(sResponse,ipos2+ Length('>'),Length(sResponse)-ipos2-Length('>')+1);
 500         ipos3  := PosEx('</td>',sResponse);
 501         matchtime   :=  Copy(sResponse,3,ipos3-3); //更改前格式>14-11-28 02:14<  更改后格式>2014-12-13 02:59<
 502         // 2.6 场次官方编码
 503         MatchNO := GetMatchNo(WeekStrNo,matchtime)+'-'+MatchNO;
 504         
 505         // 2.7 销售情况  // 销售类型   单关过关
 506         ipos2  := PosEx('>',sResponse,ipos3+6);
 507         sResponse := Copy(sResponse,ipos2+ Length('>'),Length(sResponse)-ipos2-Length('>')+1);
 508         ipos3  := PosEx('</td>',sResponse);
 509         SaleStatus  :=  Copy(sResponse,0,ipos3-1);
 510         if SaleStatus ='已开售' then     //开售才去抓取 让分 和预设总分 目前竞篮开售和未开售都一起存入数据库。
 511         begin
 512           // 2.8 让分
 513           GivenScore := GetBBGivenScore(ID,HomeTeam,sResponseGiven) ;
 514           // 2.9 预设总分
 515           PresetScore := GetBBPresetScore(ID,HomeTeam,sResponsePreset);
 516 
 517           for LotteFlag :=45  to 48 do     //循环 移位取信息,不截短,
 518           begin
 519             SetLength(BBMatchList[MatchCount].Sales,Length(BBMatchList[MatchCount].Sales)+1) ;
 520 
 521             BBMatchList[MatchCount].Sales[LotteFlag-45].LotteryType := IntToStr(LotteFlag);
 522             BBMatchList[MatchCount].Sales[LotteFlag-45].IsDGSale :=True; // False; //2015-01-13 liping.chen 全部修改为可投注
 523             BBMatchList[MatchCount].Sales[LotteFlag-45].IsGGSale:=True;  // False ;
 524 
 525 
 526 
 527 
 528 
 529             {SaleType :=''; //销售类型 每次清空
 530 
 531             iPos1 := posex('"_blank"><div class="',sResponse,iPos1+10);  //iPos1+10 为了让字符串向前截取
 532             iPos2 := posex('"></div>',sResponse,iPos1) ;
 533             SaleType :=Copy(sResponse,iPos1+length('"_blank"><div class="'),iPos2-iPos1-length('"_blank"><div class="'));
 534             if LotteFlag=47 then
 535             begin
 536               BBMatchList[MatchCount].Sales[LotteFlag-45].LotteryType:='48'; //对应彩种大小分  //Sales[LotteFlag-45]为了下标从0开始
 537             end
 538             else if LotteFlag=48 then
 539             begin
 540               BBMatchList[MatchCount].Sales[LotteFlag-45].LotteryType:='47'; //对应彩种胜分差
 541             end
 542             else
 543               BBMatchList[MatchCount].Sales[LotteFlag-45].LotteryType:=IntToStr(LotteFlag); //彩种
 544 
 545             case Pos(SaleType,'*kong*dan*closed*') of
 546               2:begin
 547                  BBMatchList[MatchCount].Sales[LotteFlag-45].IsDGSale:=False;
 548                  BBMatchList[MatchCount].Sales[LotteFlag-45].IsGGSale:=True;
 549                end  ;
 550               7:begin
 551                  BBMatchList[MatchCount].Sales[LotteFlag-45].IsDGSale:=True;
 552                  BBMatchList[MatchCount].Sales[LotteFlag-45].IsGGSale:=True;
 553                end;
 554               11:begin   //closed 为未开售此玩法
 555                  BBMatchList[MatchCount].Sales[LotteFlag-45].IsDGSale:=False;
 556                  BBMatchList[MatchCount].Sales[LotteFlag-45].IsGGSale:=False;
 557               end;
 558             end; }
 559           end;
 560         end
 561         else if SaleStatus ='&nbsp;' then  //2015-02-05 liping.chen 竞篮赛程页面变更修改
 562         begin
 563           SaleCount := 0 ;
 564           for LotteFlag:=45 to 48 do
 565           begin
 566             SetLength(BBMatchList[MatchCount].Sales,Length(BBMatchList[MatchCount].Sales)+1) ;
 567             BBMatchList[MatchCount].Sales[SaleCount].LotteryType := IntToStr(LotteFlag);
 568             BBMatchList[MatchCount].Sales[SaleCount].IsDGSale :=True; // False; //2015-01-13 liping.chen 全部修改为可投注
 569             BBMatchList[MatchCount].Sales[SaleCount].IsGGSale:=True;  // False ;
 570             SaleCount := SaleCount + 1;
 571           end;
 572         end;
 573 
 574         // 2.11 场次信息存储
 575         BBMatchList[MatchCount].ID := ID;
 576         BBMatchList[MatchCount].MatchIndex := MatchNO;
 577         // BBMatchList[MatchCount].MatchTime :=  StrToDateTime(matchtime);
 578         BBMatchList[MatchCount].MatchTime := TranMatchDateEx(matchtime);
 579         BBMatchList[MatchCount].HomeTeam := HomeTeam ;
 580         BBMatchList[MatchCount].AwayTeam := awayTeam ;
 581         BBMatchList[MatchCount].GivenScore := GivenScore ;
 582         BBMatchList[MatchCount].PresetScore := PresetScore ;
 583         
 584         // 场次数加 1
 585         MatchCount :=   MatchCount + 1 ;
 586         iPos1 := Posex('<td width="80">', sResponse,iPos3);    //这句很重要,判断是否还有场次未抓取完。
 587       end;
 588 
 589       Result := True ;
 590     except on e: Exception do
 591       begin
 592         MainForm.LogInfo('获取竞彩篮球对阵出错,原因:' + E.Message, True);
 593         Result := False;
 594         Exit;
 595       end;
 596     end;
 597   finally
 598     SaleList.Free;
 599     LotteryType.free;
 600     idHttp.Free;
 601   end;
 602 end;
 603 
 604 {
 605 function TJCMatchThd.GetBBMatch: Boolean;
 606 var
 607   ResponseXML: TXMLDocument;
 608   RXMLRoot: IXMLNode;
 609   RXMLList: IXMLNodeList;
 610   DateStr: string;
 611   i, j, k, NodeCount, MatchListIndex: Integer;
 612   FS:TFormatSettings;
 613 begin
 614   try
 615     Result := True;
 616     FS.ShortDateFormat := 'yyyy-mm-dd';
 617     FS.LongTimeFormat := 'hh:mm:ss';
 618     FS.DateSeparator := '-';
 619     FS.TimeSeparator := ':';
 620     MainForm.LogInfo('正在获取竞彩篮球对阵数据', True);
 621     try
 622       ResponseXML := TXMLDocument.Create(MainForm);
 623       ResponseXML.DOMVendor := GetDomVendor(oxmldom.SOpenXML);
 624       ResponseXML.LoadFromFile(MainForm.BBMatchAddress + IntToStr(Random(1000)));
 625      // ResponseXML.LoadFromFile(MainForm.BBMatchAddress);
 626       RXMLRoot := ResponseXML.DocumentElement;
 627 
 628       if MainForm.IsSaveFile then
 629       begin
 630          if not DirectoryExists('fieleLQDZDate') then
 631          CreateDir('fieleLQDZDate') ;
 632          ResponseXML.SaveToFile('fieleLQDZDate\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
 633       end;
 634       RXMLList := RXMLRoot.ChildNodes;
 635       NodeCount := RXMLList.Count;
 636       for i := 0 to NodeCount - 1 do
 637       begin
 638         if RXMLList[i].NodeName <> 'Match' then Continue;
 639         SetLength(BBMatchList, Length(BBMatchList) + 1);
 640         MatchListIndex := Length(BBMatchList) - 1;
 641         BBMatchList[MatchListIndex].ID := RXMLList[i].Attributes['ID'];
 642         for j := 0 to RXMLList[i].ChildNodes.Count -1 do
 643         begin
 644           if (RXMLList[i].ChildNodes.Nodes[j].NodeName = 'HomeTeam') then
 645           begin
 646             for k := 0 to RXMLList[i].ChildNodes.Nodes[j].ChildNodes.Count - 1 do
 647             begin
 648               if RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].Attributes['lang'] = 'zh-cn' then
 649               begin
 650                 BBMatchList[MatchListIndex].HomeTeam := RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].NodeValue;
 651                 Break;
 652               end;
 653             end;
 654           end
 655           else if (RXMLList[i].ChildNodes.Nodes[j].NodeName = 'AwayTeam') then
 656           begin
 657             for k := 0 to RXMLList[i].ChildNodes.Nodes[j].ChildNodes.Count - 1 do
 658             begin
 659               if RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].Attributes['lang'] = 'zh-cn' then
 660               begin
 661                 BBMatchList[MatchListIndex].AwayTeam := RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].NodeValue;
 662                 Break;
 663               end;
 664             end;
 665           end
 666           else Continue;
 667         end;
 668         DateStr := Copy(RXMLList[i].ChildValues['BusinessDate'], 3, 8);
 669         DateStr := StringReplace(DateStr, '-', '', [rfIgnoreCase, rfReplaceAll]);
 670         BBMatchList[MatchListIndex].MatchIndex := DateStr + '-' + Copy(RXMLList[i].Attributes['num'], 2, 3);
 671         BBMatchList[MatchListIndex].MatchTime := StrToDateTime(RXMLList[i].ChildValues['MatchDate'] + ' ' + RXMLList[i].ChildValues['MatchTime'], FS);
 672       end;
 673     except on E : Exception do
 674       begin
 675         MainForm.LogInfo('获取竞彩篮球对阵出错,原因:' + E.Message, True);
 676         Result := False;
 677         Exit;
 678       end;
 679     end;
 680   finally
 681     ResponseXML.Free;
 682   end;
 683 end;
 684 
 685 }
 686 
 687 function TJCMatchThd.GetFBMatch: Boolean;
 688 var
 689   ipos1 ,ipos2 ,ipos3 : integer;
 690   idHttp : TIdHTTP ;
 691   MatchNO,ID : string ;
 692   HomeTeam , awayTeam : string ;
 693   GivenScore : Real;
 694   GivenScoreStr : string ;
 695   matchtime : string ;
 696   StrLog ,SaleStatus, SaleType : string ;
 697 
 698   WeekStr,weekStrNo : string ;
 699   MatchCount : Integer ;
 700   sResponse : AnsiString ;
 701   iUrlLen ,LotteFlag : Integer;
 702 begin
 703   idHttp := TIdHTTP.Create(nil) ;
 704   idHttp.ConnectTimeout:=15000;
 705   idHttp.ReadTimeout:=15000;
 706   try
 707     Result := True;
 708     try
 709       StrLog := '<td class="td1"' ;
 710       //  Url := 'http://info.sporttery.cn/football/match_list.php';
 711       try     //2015-02-05 liping.chen
 712         MainForm.LogInfo('正在获取竞彩足球对阵数据', True);
 713         sResponse  :=  idHttp.Get(MainForm.FBMatchAddress);
 714       except on E : Exception do
 715         begin
 716           MainForm.LogInfo('idHttp.Get获取竞彩足球对阵数据失败 '+ E.Message, True);
 717           Exit;
 718         end;
 719       end;
 720       if MainForm.IsSaveFile then
 721       begin
 722         if MainForm.SaveFile(sResponse,'FileZQDZDate') then
 723           MainForm.LogInfo('保存竞彩足球对阵页面成功', True);
 724       end;
 725 
 726      { //2014-12-15 liping.chen
 727       //获取受注赛程 总场数,可用for循环获取每场信息; 但目前用【while ipos1 >0 do】 方式
 728       iPos1 := Pos('查询结果:有',sResponse) ;
 729       iPos1 := PosRightEx('>',sResponse,ipos1);
 730       iPos2 := PosRightEx('</b>',sResponse,ipos1);
 731       iMatchCount := StrToIntDef((Copy(sResponse,iPos1+Length(CountStr),ipos2-iPos1-Length(CountStr))),-1);
 732       if iMatchCount =-1 then
 733       begin
 734          MainForm.LogInfo('获取页面有误,页面内容为:' + sResponse , True);
 735          Exit;
 736       end; }
 737 
 738       // 开始获取信息
 739       ipos1:=1;
 740       ipos1 := PosEx(StrLog,sResponse,ipos1);
 741       if (iPos1 = 0)then
 742       begin
 743         MainForm.LogInfo('获取竞足对阵时出错,找不到标识字符串'+StrLog, True);
 744         Exit;
 745       end;
 746       MatchCount := 0 ;
 747       while ipos1 >0 do
 748       begin
 749         SetLength(FBMatchList,Length(FBMatchList)+1) ;
 750         // 场次编号
 751         ipos1  := PosEx('>',sResponse,ipos1);
 752         ipos2  := PosEx('</td>',sResponse,ipos1 );
 753         weekStrNo :=  Copy(sResponse,ipos1+1,ipos2-ipos1-1) ;
 754         MatchNO := rightstr(weekStrNo,3);
 755         WeekStr := LeftStr(weekStrNo,2) ;
 756         //  官方编号
 757         ipos1  := PosEx('<a href="http://info.sporttery.cn/football/info/fb_match_info.php?m=',sResponse,ipos2);
 758         iUrlLen := Length('<a href="http://info.sporttery.cn/football/info/fb_match_info.php?m=');
 759         ipos2  := PosEx('" style=',sResponse,ipos1);
 760         ID :=  Copy(sResponse,ipos1+iUrlLen,ipos2-ipos1-iUrlLen);
 761         //  主队
 762         ipos1  := PosEx('>',sResponse,ipos2);
 763         ipos2  := PosEx(' VS ',sResponse,ipos1);
 764         HomeTeam  :=  Trim(Copy(sResponse,ipos1+1,ipos2-ipos1-1));
 765         // 客队
 766         ipos1 :=ipos2+Length(' VS ');
 767         ipos2  := PosEx('</a>',sResponse,ipos1);
 768         awayTeam  :=  Copy(sResponse,ipos1,ipos2-ipos1);
 769         // 取时间 合成场次编号
 770         ipos1  := PosEx('<td',sResponse,ipos2);
 771         ipos1  := PosEx('>',sResponse,ipos1);
 772         ipos2  := PosEx('</td>',sResponse,ipos1);
 773         matchtime  :=  Trim(Copy(sResponse,ipos1+3,ipos2-ipos1-3));
 774         // matchtime := StringReplace(matchtime,'-','/',[rfReplaceAll]) ;
 775         MatchNO := GetMatchNo(WeekStr,matchtime)+'-'+MatchNO;
 776         //销售情况
 777         ipos1  := PosEx('</td>',sResponse,ipos2+6);
 778         ipos1  := PosEx('>',sResponse,ipos1+6);
 779         ipos2  := PosEx('</td>',sResponse,ipos1);
 780         SaleStatus  :=  Copy(sResponse,ipos1+1,ipos2-ipos1-1);
 781         //
 782         if SaleStatus ='已开售' then  //2014-12-15 liping.chen
 783         begin
 784           SetLength(FBMatchList[MatchCount].Sales,Length(FBMatchList[MatchCount].Sales)+5) ;
 785           for LotteFlag:=69 to 73 do
 786           begin
 787             if LotteFlag=69 then
 788             begin
 789               FBMatchList[MatchCount].Sales[LotteFlag-69].LotteryType :='77'; //对应彩种 胜平负
 790             end
 791             else
 792               FBMatchList[MatchCount].Sales[LotteFlag-69].LotteryType :=IntToStr(LotteFlag); //彩种
 793 
 794             FBMatchList[MatchCount].Sales[LotteFlag-69].IsDGSale := True; // False; //2015-01-13 liping.chen 全部修改为可投注
 795             FBMatchList[MatchCount].Sales[LotteFlag-69].IsGGSale :=True; // False; //2015-01-13 liping.chen 全部修改为可投注
 796           end;
 797 
 798 
 799          { for LotteFlag :=69  to 73 do
 800           begin
 801             SaleType :=''; //销售类型 每次清空
 802             iPos1 := posex('"_blank"><div class="',sResponse,iPos1+10);  //iPos1+10 为了让字符串向前截取
 803             iPos2 := posex('"></div>',sResponse,iPos1) ;
 804             SaleType :=Copy(sResponse,iPos1+length('"_blank"><div class="'),iPos2-iPos1-length('"_blank"><div class="'));
 805             if LotteFlag=69 then
 806             begin
 807               FBMatchList[MatchCount].Sales[LotteFlag-69].LotteryType:='77'; //对应彩种 胜平负
 808             end                                                            //Sales[Lottery-69]为了下标从0开始
 809             else
 810               FBMatchList[MatchCount].Sales[LotteFlag-69].LotteryType:=IntToStr(LotteFlag); //彩种
 811 
 812             case Pos(SaleType,'*kong*dan*closed*') of
 813               2:begin
 814                  FBMatchList[MatchCount].Sales[LotteFlag-69].IsDGSale:=False;
 815                  FBMatchList[MatchCount].Sales[LotteFlag-69].IsGGSale:=True;
 816                end  ;
 817               7:begin
 818                  FBMatchList[MatchCount].Sales[LotteFlag-69].IsDGSale:=True;
 819                  FBMatchList[MatchCount].Sales[LotteFlag-69].IsGGSale:=True;
 820                end;
 821               11:begin   //closed 为未开售此玩法
 822                  FBMatchList[MatchCount].Sales[LotteFlag-69].IsDGSale:=False;
 823                  FBMatchList[MatchCount].Sales[LotteFlag-69].IsGGSale:=False;
 824               end;
 825             end;
 826           end; }
 827         end
 828         else //if SaleStatus ='' then
 829         begin
 830           SetLength(FBMatchList[MatchCount].Sales,Length(FBMatchList[MatchCount].Sales)+5) ;
 831           for LotteFlag:=69 to 73 do
 832           begin
 833             if LotteFlag=69 then
 834             begin
 835               FBMatchList[MatchCount].Sales[LotteFlag-69].LotteryType :='77'; //对应彩种 胜平负
 836             end
 837             else
 838               FBMatchList[MatchCount].Sales[LotteFlag-69].LotteryType :=IntToStr(LotteFlag); //彩种
 839 
 840             FBMatchList[MatchCount].Sales[LotteFlag-69].IsDGSale :=True; // False; //2015-01-13 liping.chen 全部修改为可投注
 841             FBMatchList[MatchCount].Sales[LotteFlag-69].IsGGSale :=True; // False; //2015-01-13 liping.chen 全部修改为可投注
 842           end;
 843         end;
 844 
 845         FBMatchList[MatchCount].ID := ID;
 846         FBMatchList[MatchCount].MatchIndex := MatchNO;
 847         FBMatchList[MatchCount].HomeTeam := HomeTeam ;
 848         FBMatchList[MatchCount].AwayTeam := awayTeam ;
 849         FBMatchList[MatchCount].GivenScore :=0;
 850         // FBMatchList[MatchCount].MatchTime := StrToDateTime(matchtime) ;
 851         FBMatchList[MatchCount].MatchTime := TranMatchDateEx(matchtime) ;
 852         //
 853         MatchCount := MatchCount +1 ;
 854         sResponse :=  Copy(sResponse,ipos2,length(sResponse)-ipos2) ;  //添加截短
 855         ipos1 := PosEx(StrLog,sResponse,1);
 856       end;
 857       if GetFBGivenScore then   //让分  一次性抓完
 858       begin
 859         MainForm.LogInfo('抓取竞足对阵让分成功', True);
 860       end;
 861 
 862       //*******************以下为测试代码
 863      { sResponse:='';
 864       for ipos1 :=0  to Length(FBMatchList)-1 do
 865       begin
 866         sResponse:=sResponse
 867             + ',' + QuotedStr(FBMatchList[ipos1].ID)
 868             + ',' + QuotedStr(FBMatchList[ipos1].MatchIndex)
 869             + ',' + QuotedStr(DateTimeToStr(FBMatchList[ipos1].MatchTime))
 870             + ',' + QuotedStr(FBMatchList[ipos1].HomeTeam)
 871             + ',' + QuotedStr(FBMatchList[ipos1].AwayTeam)
 872             + #13#10 ;
 873       end;
 874       MainForm.SaveFile(sResponse,'mytest'); }
 875       //************************
 876     except on E:Exception do
 877       begin
 878          MainForm.LogInfo('获取竞彩足球对阵出错,原因:' + E.Message, True);
 879          Result := False;
 880          Exit;
 881       end;
 882     end;
 883   finally
 884     idHttp.Free ;
 885   end;
 886 end;
 887 
 888 
 889 
 890 {
 891 function TJCMatchThd.GetFBMatch: Boolean;
 892 var
 893   ResponseXML: TXMLDocument;
 894   RXMLRoot: IXMLNode;
 895   RXMLList: IXMLNodeList;
 896   DateStr: string;
 897   i, j, k, NodeCount, MatchListIndex: Integer;
 898   FS: TFormatSettings;
 899 begin
 900   try
 901     Result := True;
 902     FS.ShortDateFormat := 'yyyy-mm-dd';
 903     FS.LongTimeFormat := 'hh:mm:ss';
 904     FS.DateSeparator := '-';
 905     FS.TimeSeparator := ':';
 906     MainForm.LogInfo('正在获取竞彩足球对阵数据', True);
 907     try
 908       ResponseXML := TXMLDocument.Create(MainForm);
 909       ResponseXML.DOMVendor := GetDomVendor(oxmldom.SOpenXML);
 910 
 911      // ResponseXML.LoadFromFile(MainForm.FBMatchAddress);
 912       ResponseXML.LoadFromFile(MainForm.FBMatchAddress + IntToStr(Random(1000)));
 913     //  ResponseXML.LoadFromFile(MainForm.FBMatchAddress);
 914       RXMLRoot := ResponseXML.DocumentElement;
 915 
 916       if MainForm.IsSaveFile then
 917       begin
 918          if not DirectoryExists('fieleZQDZDate') then
 919          CreateDir('fieleZQDZDate') ;
 920          ResponseXML.SaveToFile('fieleZQDZDate\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
 921       end;
 922 
 923 
 924       RXMLList := RXMLRoot.ChildNodes;
 925       NodeCount := RXMLList.Count;
 926       for i := 0 to NodeCount - 1 do
 927       begin
 928         if RXMLList[i].NodeName <> 'Match' then Continue;
 929         SetLength(FBMatchList, Length(FBMatchList) + 1);
 930         MatchListIndex := Length(FBMatchList) - 1;
 931         FBMatchList[MatchListIndex].ID := RXMLList[i].Attributes['ID'];
 932         for j := 0 to RXMLList[i].ChildNodes.Count -1 do
 933         begin
 934           if (RXMLList[i].ChildNodes.Nodes[j].NodeName = 'HomeTeam') then
 935           begin
 936             for k := 0 to RXMLList[i].ChildNodes.Nodes[j].ChildNodes.Count - 1 do
 937             begin
 938               if RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].Attributes['lang'] = 'zh-cn' then
 939               begin
 940                 FBMatchList[MatchListIndex].HomeTeam := RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].NodeValue;
 941                 Break;
 942               end;
 943             end;
 944           end
 945           else if (RXMLList[i].ChildNodes.Nodes[j].NodeName = 'AwayTeam') then
 946           begin
 947             for k := 0 to RXMLList[i].ChildNodes.Nodes[j].ChildNodes.Count - 1 do
 948             begin
 949               if RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].Attributes['lang'] = 'zh-cn' then
 950               begin
 951                 FBMatchList[MatchListIndex].AwayTeam := RXMLList[i].ChildNodes.Nodes[j].ChildNodes[k].NodeValue;
 952                 Break;
 953               end;
 954             end;
 955           end
 956           else Continue;
 957         end;
 958         DateStr := Copy(RXMLList[i].ChildValues['BusinessDate'], 3, 8);
 959         DateStr := StringReplace(DateStr, '-', '', [rfIgnoreCase, rfReplaceAll]);
 960         FBMatchList[MatchListIndex].MatchIndex := DateStr + '-' + Copy(RXMLList[i].Attributes['num'], 2, 3);
 961         FBMatchList[MatchListIndex].MatchTime := StrToDateTime(RXMLList[i].ChildValues['MatchDate'] + ' ' + RXMLList[i].ChildValues['MatchTime'], FS);
 962       end;
 963 
 964     except on E : Exception do
 965       begin
 966         MainForm.LogInfo('获取竞彩足球对阵出错,原因:' + E.Message, True);
 967         Result := False;
 968         Exit;
 969       end;
 970     end;
 971   finally
 972     ResponseXML.Free;
 973   end;
 974 end;
 975 
 976 }
 977 
 978 {
 979 篮球销售情况
 980 function TJCMatchThd.GetBBSales: Boolean;
 981 var
 982   ResponseXML: TXMLDocument;
 983   RXMLRoot: IXMLNode;
 984   RXMLList: IXMLNodeList;
 985   DateStr: string;
 986   i, j, k, NodeCount, MatchCount, MatchListIndex: Integer;
 987 begin
 988   try
 989     Result := True;
 990     MainForm.LogInfo('正在获取竞彩篮球开售数据', True);
 991     try
 992       ResponseXML := TXMLDocument.Create(MainForm);
 993       ResponseXML.DOMVendor := GetDomVendor(oxmldom.SOpenXML);
 994     //  ResponseXML.LoadFromFile(MainForm.BBSalesAddress + IntToStr(Random(1000)));
 995      // ResponseXML.LoadFromFile(MainForm.BBSalesAddress);
 996       RXMLRoot := ResponseXML.DocumentElement;
 997       RXMLList := RXMLRoot.ChildNodes;
 998 
 999       if MainForm.IsSaveFile then
1000       begin
1001         if not DirectoryExists('fieleLQXSDate') then
1002         CreateDir('fieleLQXSDate') ;
1003         ResponseXML.SaveToFile('fieleLQXSDate\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
1004       end;
1005 
1006       NodeCount := RXMLList.Count;
1007       MatchCount := Length(BBMatchList);
1008       for i := 0 to NodeCount - 1 do
1009       begin
1010         if RXMLList[i].NodeName <> 'Match' then Continue;
1011         for j := 0 to MatchCount - 1 do
1012         begin
1013           if RXMLList[i].Attributes['ID'] <> BBMatchList[j].ID then Continue;
1014           SetLength(BBMatchList[j].Sales, RXMLList[i].ChildNodes.Count);
1015           for k := 0 to RXMLList[i].ChildNodes.Count - 1 do
1016           begin
1017             BBMatchList[j].Sales[k].LotteryType := RXMLList[i].ChildNodes[k].Attributes['code'];
1018             if RXMLList[i].ChildNodes[k].Attributes['code'] = 'HDC'
1019               then BBMatchList[j].GivenScore := RXMLList[i].ChildNodes[k].ChildValues['GoalLine']
1020             else if RXMLList[i].ChildNodes[k].Attributes['code'] = 'HILO'
1021               then BBMatchList[j].PresetScore := RXMLList[i].ChildNodes[k].ChildValues['GoalLine'];
1022             BBMatchList[j].Sales[k].IsDGSale := RXMLList[i].ChildNodes[k].ChildNodes[0].ChildValues['Single'];
1023             BBMatchList[j].Sales[k].IsGGSale := RXMLList[i].ChildNodes[k].ChildNodes[0].ChildValues['Allup'];
1024           end;
1025           Break;
1026         end;
1027       end;
1028     except on E : Exception do
1029       begin
1030         MainForm.LogInfo('获取竞彩篮球开售情况出错,原因:' + E.Message, True);
1031         Result := False;
1032         Exit;
1033       end;
1034     end;
1035   finally
1036     ResponseXML.Free;
1037   end;
1038 end;
1039 }
1040 
1041 
1042 {
1043 //获取 足球销售情况
1044 function TJCMatchThd.GetFBSales: Boolean;
1045 var
1046   ResponseXML: TXMLDocument;
1047   RXMLRoot: IXMLNode;
1048   RXMLList: IXMLNodeList;
1049   DateStr: string;
1050   i, j, k, NodeCount, MatchCount, MatchListIndex: Integer;
1051 
1052 begin
1053   try
1054     Result := True;
1055     MainForm.LogInfo('正在获取竞彩足球开售数据', True);
1056     try
1057       if not   GetFBGoalLine then Exit ;
1058 
1059       ResponseXML := TXMLDocument.Create(MainForm);
1060       ResponseXML.DOMVendor := GetDomVendor(oxmldom.SOpenXML);
1061       //ResponseXML.LoadFromFile(MainForm.FBSalesAddress);
1062      // ResponseXML.LoadFromFile(MainForm.FBSalesAddress + IntToStr(Random(1000)));
1063      // ResponseXML.LoadFromFile(MainForm.FBSalesAddress);
1064       RXMLRoot := ResponseXML.DocumentElement;
1065       RXMLList := RXMLRoot.ChildNodes;
1066 
1067       if MainForm.IsSaveFile then
1068       begin
1069         if not DirectoryExists('fieleZQXSDate') then
1070         CreateDir('fieleZQXSDate') ;
1071         ResponseXML.SaveToFile('fieleZQXSDate\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
1072       end;
1073 
1074       NodeCount := RXMLList.Count;
1075       MatchCount := Length(FBMatchList);
1076       for i := 0 to NodeCount - 1 do
1077       begin
1078         if RXMLList[i].NodeName <> 'Match' then Continue;
1079         for j := 0 to MatchCount - 1 do
1080         begin
1081           if RXMLList[i].Attributes['ID'] <> FBMatchList[j].ID then Continue;
1082           SetLength(FBMatchList[j].Sales, RXMLList[i].ChildNodes.Count);
1083 
1084 
1085           for k := 0 to RXMLList[i].ChildNodes.Count - 1 do
1086           begin
1087             if RXMLList[i].ChildNodes[k].Attributes['code'] <> 'HHAD' then
1088             begin
1089               FBMatchList[j].Sales[k].LotteryType := RXMLList[i].ChildNodes[k].Attributes['code'];
1090               FBMatchList[j].Sales[k].IsDGSale := RXMLList[i].ChildNodes[k].ChildNodes[0].ChildValues['Single'];
1091               FBMatchList[j].Sales[k].IsGGSale := RXMLList[i].ChildNodes[k].ChildNodes[0].ChildValues['Allup'];
1092             end;
1093           end;
1094 
1095 
1096 //          for k := 0 to RXMLList[i].ChildNodes.Count - 1 do
1097 //          begin
1098 //              FBMatchList[j].Sales[k].LotteryType := RXMLList[i].ChildNodes[k].Attributes['code'];
1099 //              if RXMLList[i].ChildNodes[k].Attributes['code'] = 'HHAD'
1100 //                then FBMatchList[j].GivenScore := RXMLList[i].ChildNodes[k].ChildValues['GoalLine'];
1101 //              FBMatchList[j].Sales[k].IsDGSale := RXMLList[i].ChildNodes[k].ChildNodes[0].ChildValues['Single'];
1102 //              FBMatchList[j].Sales[k].IsGGSale := RXMLList[i].ChildNodes[k].ChildNodes[0].ChildValues['Allup'];
1103 //          end;
1104 
1105 
1106           Break;
1107         end;
1108       end;
1109     except on E : Exception do
1110       begin
1111         MainForm.LogInfo('获取竞彩足球开售情况出错,原因:' + E.Message, True);
1112         Result := False;
1113         Exit;
1114       end;
1115     end;
1116   finally
1117     ResponseXML.Free;
1118   end;
1119 end;
1120 }
1121 
1122 
1123 
1124 // 竞彩让分抓取
1125 {
1126 function TJCMatchThd.GetFBGoalLine:Boolean;
1127 var
1128   ResponseXML: TXMLDocument;
1129   RXMLRoot: IXMLNode;
1130   RXMLList: IXMLNodeList;
1131   DateStr: string;
1132   i,j,NodeCount, MatchCount,MatchListIndex: Integer;
1133 begin
1134   try
1135     Result := True;
1136     MainForm.LogInfo('正在获取竞彩足球让分数据', True);
1137     try
1138       ResponseXML := TXMLDocument.Create(MainForm);
1139 
1140       ResponseXML.DOMVendor := GetDomVendor(oxmldom.SOpenXML);
1141     //  ResponseXML.LoadFromFile(MainForm.FBGoalLineAddress);
1142       ResponseXML.LoadFromFile(MainForm.FBGoalLineAddress + IntToStr(Random(1000)));
1143    //   ResponseXML.LoadFromFile(MainForm.FBGoalLineAddress);
1144 
1145       RXMLRoot := ResponseXML.DocumentElement;
1146 
1147       if MainForm.IsSaveFile then
1148       begin
1149         if not DirectoryExists('fieleZQRFDate') then
1150         CreateDir('fieleZQRFDate') ;
1151         ResponseXML.SaveToFile('fieleZQRFDate\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
1152       end;
1153       
1154       //ResponseXML.SaveToFile('D:\FBXMLData\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
1155 
1156 
1157 //      if not DirectoryExists('fieleRFDate') then
1158 //        CreateDir('fieleRFDate');
1159 //        ResponseXML.SaveToFile('fieleRFDate\' + FormatDateTime('yy-mm-dd-hh-mm-ss',Now)+ '.xml');
1160 
1161 
1162       RXMLList := RXMLRoot.ChildNodes;
1163       NodeCount := RXMLList.Count;
1164       MatchCount := Length(FBMatchList);
1165 
1166 //      for i := 0 to NodeCount - 1 do
1167 //      begin
1168 //        if RXMLList[i].NodeName <> 'Match' then Continue;
1169 //
1170 //        if RXMLList[i].Attributes['ID'] <> ID then Continue;
1171 //        LotteryType := RXMLList[i].ChildNodes[0].Attributes['code'];
1172 //        GivenScore  := RXMLList[i].ChildNodes[0].ChildValues['GoalLine'];
1173 //        IsDGSale    := RXMLList[i].ChildNodes[0].ChildNodes[1].ChildValues['Single'];
1174 //        IsGGSale    := RXMLList[i].ChildNodes[0].ChildNodes[1].ChildValues['Allup'];
1175 //        Break;
1176 //        end;
1177 
1178 
1179       for i := 0 to NodeCount - 1 do
1180       begin
1181         if RXMLList[i].NodeName <> 'Match' then Continue;
1182         for j := 0 to MatchCount - 1 do
1183         begin
1184           if RXMLList[i].Attributes['ID'] <> FBMatchList[j].ID then Continue;
1185 
1186            SetLength(FBMatchList[j].Sales,1);
1187 
1188            FBMatchList[j].Sales[0].LotteryType := RXMLList[i].ChildNodes[0].Attributes['code'];
1189            FBMatchList[j].GivenScore := RXMLList[i].ChildNodes[0].ChildValues['GoalLine'];
1190            FBMatchList[j].Sales[0].IsDGSale := RXMLList[i].ChildNodes[0].ChildNodes[1].ChildValues['Single'];
1191            FBMatchList[j].Sales[0].IsGGSale := RXMLList[i].ChildNodes[0].ChildNodes[1].ChildValues['Allup'];
1192           Break;
1193         end;
1194       end;
1195 
1196     except on E : Exception do
1197       begin
1198         MainForm.LogInfo('获取竞彩足球让分情况出错,原因:' + E.Message, True);
1199         Result := False;
1200         Exit;
1201       end;
1202     end;
1203   finally
1204     ResponseXML.Free;
1205   end;
1206 end;
1207 
1208  }
1209 
1210 
1211 function TJCMatchThd.SaveData: Boolean;
1212 var
1213   i, j,SucCount , iBBMatchCount, iFBMatchCount, iSalesCount, iReturnCode: Integer;
1214   sSQLString, sDGSales, sGGSales: string;
1215   insFlag : Boolean;  // 针对混合过关场次的问题
1216   sLotMacthId : string;
1217   sMatchRet,sTmp : string;
1218   iNoChangeNum:Integer;
1219 begin
1220   Result := False;
1221   i:=1;
1222   iNoChangeNum:=0;
1223   while True do      //2015-02-05 liping.chen  设置失败时 允许多次设置,直到成功。
1224   begin
1225     try
1226       mqMain.Close;
1227       //sSQLString := 'TRUNCATE TABLE TRANSIT_LOTTERY_MATCH; SET NAMES GB2312;';
1228       sSQLString := ' SET NAMES GB2312;';
1229       mqMain.SQL.Text := sSQLString;
1230       mqMain.Execute;
1231       Break;
1232     except on E : Exception do
1233       begin
1234         MainForm.LogInfo('执行SET NAMES GB2312异常第'+IntToStr(i)+'次! ', True);
1235         inc(i);
1236         if i=4 then
1237           Exit;   //词句必须,若未设置完成,就会存进乱码,
1238         Sleep(50);
1239       end;
1240     end;
1241   end;
1242 
1243   iBBMatchCount := Length(BBMatchList);
1244   iFBMatchCount := Length(FBMatchList);
1245   if hsl_Match.Count > 1500 then
1246     hsl_Match.Clear;
1247 
1248   //============================篮彩============================
1249   try
1250     MainForm.LogInfo('准备写入竞篮对阵 共' +inttostr(iBBMatchCount)+'', True);
1251     SucCount := 0 ;
1252     for i := 0 to iBBMatchCount - 1 do
1253     begin
1254       iSalesCount := Length(BBMatchList[i].Sales);
1255       // 2013-04-09 rulinzhang 第一次需要保存
1256       insFlag := true;
1257       for j := 0 to iSalesCount - 1 do
1258       begin
1259         //if (not BBMatchList[i].Sales[j].IsDGSale) and (not BBMatchList[i].Sales[j].IsGGSale) then Continue;  //2014-12-15 liping.chen
1260         if BBMatchList[i].Sales[j].IsDGSale then sDGSales := '1'
1261           else sDGSales := '0';
1262         if BBMatchList[i].Sales[j].IsGGSale then sGGSales := '1'
1263           else sGGSales := '0';
1264         // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
1265         sLotMacthId := 'LQ' + '-' + BBMatchList[i].Sales[j].LotteryType + '-' + BBMatchList[i].ID;
1266         sMatchRet := BBMatchList[i].Sales[j].LotteryType
1267                       + '^' + BBMatchList[i].ID
1268                       + '^' + BBMatchList[i].MatchIndex
1269                       + '^' + DateTimeToStr(BBMatchList[i].MatchTime)
1270                       + '^' + sDGSales
1271                       + '^' + sGGSales
1272                       + '^' + BBMatchList[i].HomeTeam
1273                       + '^' + BBMatchList[i].AwayTeam
1274                       + '^' + FloatToStr(BBMatchList[i].GivenScore)
1275                       + '^' + FloatToStr(BBMatchList[i].PresetScore);
1276         // 判断hashed是否存在
1277         sTmp := trim(hsl_Match.Values[trim(sLotMacthId)]);
1278         if sTmp = '' then
1279           hsl_Match.Add(trim(sLotMacthId) + '=' + sMatchRet)
1280         else
1281         begin
1282           if sTmp = Trim(sMatchRet) then
1283           begin
1284             //MainForm.LogInfo('【竞篮赛程】无变更:' + sMatchRet, True);
1285             inc(iNoChangeNum);
1286             Continue;   // 退出
1287           end
1288           else
1289             hsl_Match.Values[trim(sLotMacthId)] := Trim(sMatchRet);
1290         end;
1291         // ---------------------------------------------------------------------
1292         sSQLString := 'CALL P_TRANSIT_LOTTERY_MATCH('
1293             + BBMatchList[i].Sales[j].LotteryType
1294             + ',' + QuotedStr(BBMatchList[i].ID)
1295             + ',' + QuotedStr(BBMatchList[i].MatchIndex)
1296             + ',' + QuotedStr(DateTimeToStr(BBMatchList[i].MatchTime))
1297             + ',' + sDGSales
1298             + ',' + sGGSales
1299             + ',' + QuotedStr(BBMatchList[i].HomeTeam)
1300             + ',' + QuotedStr(BBMatchList[i].AwayTeam);
1301 
1302         if BBMatchList[i].Sales[j].LotteryType = '46' then        //让分胜负
1303           sSQLString := sSQLString + ',' + FloatToStr(BBMatchList[i].GivenScore)+',null'
1304         else if BBMatchList[i].Sales[j].LotteryType = '48' then   //大小分
1305           sSQLString := sSQLString + ',null,' + FloatToStr(BBMatchList[i].PresetScore)
1306         else
1307           sSQLString := sSQLString + ',null,null';
1308         sSQLString := sSQLString +',@a); select @a;';
1309 
1310         try
1311           mqMain.Close;
1312           mqMain.SQL.Text := sSQLString;
1313           mqMain.Execute;
1314           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1315           mqMain.Close;
1316         except on E : Exception do
1317           begin
1318             MainForm.LogInfo('竞篮对阵'+BBMatchList[i].MatchIndex+'场次写入失败! '+ E.Message, True);
1319             hsl_Match.Values[trim(sLotMacthId)] :='';
1320             mqMain.Close;
1321           end;
1322         end;
1323 
1324         if iReturnCode = 1 then              //数据验证失败
1325         begin
1326           MainForm.LogInfo('写入竞篮对阵失败,原因:数据验证失败', True);
1327           hsl_Match.Values[trim(sLotMacthId)] :='';
1328           //Exit;
1329         end
1330         else if iReturnCode = 100 then
1331         begin
1332           MainForm.LogInfo('写入竞篮对阵失败,原因:未知错误', True);
1333           hsl_Match.Values[trim(sLotMacthId)] :='';
1334           //Exit;
1335         end;
1336 
1337       end;
1338       // 独立处理竞篮混合过关
1339       if insFlag then       // 此时已经可以撤销该标志了
1340       begin
1341         // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
1342         sLotMacthId := 'LQ' + '-49-' + BBMatchList[i].ID;
1343         sMatchRet :=  IntToStr(49)
1344                       + '^' + BBMatchList[i].ID
1345                       + '^' + BBMatchList[i].MatchIndex
1346                       + '^' + DateTimeToStr(BBMatchList[i].MatchTime)
1347                       + '^' + '1'
1348                       + '^' + '1'
1349                       + '^' + BBMatchList[i].HomeTeam
1350                       + '^' + BBMatchList[i].AwayTeam;
1351         // 判断hashed是否存在
1352         sTmp := trim(hsl_Match.Values[trim(sLotMacthId)]);
1353         if sTmp = '' then
1354           hsl_Match.Add(trim(sLotMacthId) + '=' + sMatchRet)
1355         else
1356         begin
1357           if sTmp = Trim(sMatchRet) then
1358           begin
1359             //MainForm.LogInfo('【竞篮赛程】无变更:' + sMatchRet, True);
1360             Continue;   // 退出
1361           end
1362           else
1363             hsl_Match.Values[trim(sLotMacthId)] := Trim(sMatchRet);
1364         end;
1365         // ---------------------------------------------------------------------
1366         sSQLString := 'CALL P_TRANSIT_LOTTERY_MATCH(49'
1367           + ',' + QuotedStr(BBMatchList[i].ID)
1368           + ',' + QuotedStr(BBMatchList[i].MatchIndex)
1369           + ',' + QuotedStr(DateTimeToStr(BBMatchList[i].MatchTime))
1370           + ',' + '1'                                               //2014-12-15 liping.chen 固定为1
1371           + ',' + '1'
1372           + ',' + QuotedStr(BBMatchList[i].HomeTeam)
1373           + ',' + QuotedStr(BBMatchList[i].AwayTeam);
1374         sSQLString := sSQLString + ',null';
1375         sSQLString := sSQLString + ',null';
1376         sSQLString := sSQLString +',@a); select @a;';
1377         try
1378           mqMain.Close;
1379           mqMain.SQL.Text := sSQLString;
1380           mqMain.Execute;
1381           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1382           mqMain.Close;
1383           if iReturnCode = 1 then              //数据验证失败
1384           begin
1385             MainForm.LogInfo('写入竞篮混合对阵失败 49,原因:数据验证失败', True);
1386             hsl_Match.Values[trim(sLotMacthId)] :='';
1387            // Exit;
1388           end
1389           else if iReturnCode = 100 then
1390           begin
1391             MainForm.LogInfo('写入竞篮混合对阵失败 49,原因:未知错误', True);
1392             hsl_Match.Values[trim(sLotMacthId)] :='';
1393            // Exit;
1394           end;
1395           insFlag := false;
1396         except on E : Exception do
1397           begin
1398             MainForm.LogInfo('写入竞篮混合'+sLotMacthId+'异常!'+E.Message, True);
1399             // 若捕获,说明该场次没有存储成功,清空哈希对应的值
1400             hsl_Match.Values[trim(sLotMacthId)] :='';
1401           end;
1402         end;
1403       end;
1404       SucCount := SucCount + 1 ;
1405     end;
1406 
1407     iNoChangeNum:=iNoChangeNum div 4; //一场次存储彩种45、46、47、48 时 iNoChangeNum都累加了。
1408     MainForm.LogInfo('已写入竞篮对阵'+IntToStr(SucCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
1409   except on E : Exception do
1410     MainForm.LogInfo('已写入竞彩篮球对阵失败!'+E.Message, True);
1411   end;
1412 
1413   //============================足彩============================
1414   try
1415     SucCount := 0 ;
1416     iNoChangeNum:=0;
1417     MainForm.LogInfo('准备写入竞足对阵 共' +inttostr(iFBMatchCount)+'', True);
1418     for i := 0 to iFBMatchCount - 1 do
1419     begin
1420       iSalesCount := Length(FBMatchList[i].Sales);
1421       insFlag := True;
1422       for j := 0 to iSalesCount - 1 do            //2014-12-15 liping.chen
1423       begin
1424         //if (not FBMatchList[i].Sales[j].IsDGSale) and (not FBMatchList[i].Sales[j].IsGGSale) then Continue;
1425         if FBMatchList[i].Sales[j].IsDGSale then sDGSales := '1'
1426           else sDGSales := '0';
1427         if FBMatchList[i].Sales[j].IsGGSale then sGGSales := '1'
1428           else sGGSales := '0';
1429         // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
1430         sLotMacthId := 'ZQ' + '-' + FBMatchList[i].Sales[j].LotteryType + '-' + FBMatchList[i].ID;
1431         sMatchRet := FBMatchList[i].Sales[j].LotteryType
1432                     + '^' + trim(FBMatchList[i].ID)
1433                     + '^' + trim(FBMatchList[i].MatchIndex)
1434                     + '^' + DateTimeToStr(FBMatchList[i].MatchTime)
1435                     + '^' + sDGSales
1436                     + '^' + sGGSales
1437                     + '^' + trim(FBMatchList[i].HomeTeam)
1438                     + '^' + trim(FBMatchList[i].AwayTeam)
1439                     + '^' + FloatToStr(FBMatchList[i].GivenScore);
1440         // 判断hashed是否存在
1441         sTmp := trim(hsl_Match.Values[trim(sLotMacthId)]);
1442         if sTmp = '' then
1443           hsl_Match.Add(trim(sLotMacthId) + '=' + sMatchRet)
1444         else
1445         begin
1446           if sTmp = Trim(sMatchRet) then
1447           begin
1448             //MainForm.LogInfo('【竞足赛程】无变更:' + sMatchRet, True);
1449             inc(iNoChangeNum);
1450             Continue;   // 退出
1451           end
1452           else
1453             hsl_Match.Values[trim(sLotMacthId)] := Trim(sMatchRet);
1454         end;
1455         // ---------------------------------------------------------------------
1456         sSQLString := 'CALL P_TRANSIT_LOTTERY_MATCH('
1457             + FBMatchList[i].Sales[j].LotteryType
1458             + ',' + QuotedStr(FBMatchList[i].ID)
1459             + ',' + QuotedStr(FBMatchList[i].MatchIndex)
1460             + ',' + QuotedStr(DateTimeToStr(FBMatchList[i].MatchTime))
1461             + ',' + sDGSales
1462             + ',' + sGGSales
1463             + ',' + QuotedStr(FBMatchList[i].HomeTeam)
1464             + ',' + QuotedStr(FBMatchList[i].AwayTeam);
1465 
1466         if FBMatchList[i].Sales[j].LotteryType = '70' then    //让分胜平负
1467           sSQLString := sSQLString + ',' + FloatToStr(FBMatchList[i].GivenScore)
1468         else
1469           sSQLString := sSQLString + ',null';
1470         sSQLString := sSQLString +',null,@a); select @a;';
1471 
1472         try
1473           mqMain.Close;
1474           mqMain.SQL.Text := sSQLString;
1475           mqMain.Execute;
1476           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1477           mqMain.Close;
1478         except on E : Exception do
1479           begin
1480             MainForm.LogInfo('竞足对阵'+FBMatchList[i].MatchIndex+'场次写入失败!'+ E.Message, True);
1481             hsl_Match.Values[trim(sLotMacthId)] :='';
1482             mqMain.Close;
1483           end;
1484         end;
1485 
1486         if iReturnCode = 1 then              //数据验证失败
1487         begin
1488           MainForm.LogInfo('写入竞足对阵失败,原因:数据验证失败', True);
1489           hsl_Match.Values[trim(sLotMacthId)] :='';
1490           //Exit;
1491         end
1492         else if iReturnCode = 100 then
1493         begin
1494           MainForm.LogInfo('写入竞足对阵失败,原因:未知错误', True);
1495           hsl_Match.Values[trim(sLotMacthId)] :='';
1496           //Exit;
1497         end;
1498       end;
1499 
1500       // 独立处理足球混合过关
1501       if insFlag then
1502       begin
1503         // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
1504         sLotMacthId := 'ZQ' + '-76-' + FBMatchList[i].ID;
1505         sMatchRet := IntToStr(76)
1506                     + '^' + trim(FBMatchList[i].ID)
1507                     + '^' + trim(FBMatchList[i].MatchIndex)
1508                     + '^' + DateTimeToStr(FBMatchList[i].MatchTime)
1509                     + '^' + '1'
1510                     + '^' + '1'
1511                     + '^' + trim(FBMatchList[i].HomeTeam)
1512                     + '^' + trim(FBMatchList[i].AwayTeam);
1513         // 判断hashed是否存在
1514         sTmp := trim(hsl_Match.Values[trim(sLotMacthId)]);
1515         if sTmp = '' then
1516           hsl_Match.Add(trim(sLotMacthId) + '=' + sMatchRet)
1517         else
1518         begin
1519           if sTmp = Trim(sMatchRet) then
1520           begin
1521             //MainForm.LogInfo('【竞足赛程】无变更:' + sMatchRet, True);
1522             Continue;   // 退出
1523           end
1524           else
1525             hsl_Match.Values[trim(sLotMacthId)] := Trim(sMatchRet);
1526         end;
1527         // ---------------------------------------------------------------------
1528         sSQLString := 'CALL P_TRANSIT_LOTTERY_MATCH('
1529           + IntToStr(76)
1530           + ',' + QuotedStr(FBMatchList[i].ID)
1531           + ',' + QuotedStr(FBMatchList[i].MatchIndex)
1532           + ',' + QuotedStr(DateTimeToStr(FBMatchList[i].MatchTime))
1533           + ',' + '1'
1534           + ',' + '1'
1535           + ',' + QuotedStr(FBMatchList[i].HomeTeam)
1536           + ',' + QuotedStr(FBMatchList[i].AwayTeam);
1537         //让分胜平负
1538         sSQLString := sSQLString + ',' + FloatToStr(FBMatchList[i].GivenScore);
1539         sSQLString := sSQLString +',null,@a); select @a;';
1540         try
1541           mqMain.Close;
1542           mqMain.SQL.Text := sSQLString;
1543           mqMain.Execute;
1544           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1545           mqMain.Close;
1546           if iReturnCode = 1 then              //数据验证失败
1547           begin
1548             MainForm.LogInfo('写入竞足混合对阵失败 76,原因:数据验证失败', True);
1549             hsl_Match.Values[trim(sLotMacthId)] :='';
1550             //Exit;
1551           end
1552           else if iReturnCode = 100 then
1553           begin
1554             MainForm.LogInfo('写入竞足混合对阵失败 76,原因:未知错误', True);
1555             hsl_Match.Values[trim(sLotMacthId)] :='';
1556             //Exit;
1557           end;
1558           insFlag := False;
1559         except on E : Exception do
1560           begin
1561             MainForm.LogInfo('写入竞足混合'+sLotMacthId+'异常!'+E.Message, True);
1562             hsl_Match.Values[trim(sLotMacthId)] :='';
1563           end;
1564         end;
1565       end;
1566       SucCount :=  SucCount + 1 ;
1567     end;
1568 
1569     iNoChangeNum:=iNoChangeNum div 5; //一场次存储彩种70,71,72,73,77 时 iNoChangeNum都累加了。
1570     MainForm.LogInfo('已写入竞足对阵'+IntToStr(SucCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
1571   except on E : Exception do
1572     MainForm.LogInfo('写入竞彩对阵失败,原因:' + E.Message, True);
1573   end;
1574 
1575 //////////////////////////////////////////////////////////////////////////
1576   try
1577     sSQLString := 'CALL P_UPDATE_LOTTERY_MATCH';
1578     mqMain.Close;
1579     mqMain.SQL.Text := sSQLString;
1580     mqMain.Execute;
1581     mqMain.Close;
1582     //
1583     MainForm.LogInfo('写入更新竞彩对阵成功', True);
1584     Result := True;
1585   except on E : Exception do
1586     begin
1587       MainForm.LogInfo('写入更新竞彩对阵失败,原因:' + E.Message, True);
1588       Result := False;
1589      // Exit;
1590     end;
1591   end;
1592 end;
1593 
1594 function TJCMatchThd.GetLotteryType(aTypeName: string): string;
1595 begin
1596   Result := LTypeList.Values[aTypeName];
1597 end;
1598 
1599 procedure TJCMatchThd.SetPause(const aIsPause: Boolean);
1600 begin
1601   Pause := aIsPause;
1602 end;
1603 
1604 function TJCMatchThd.GetStopMatch: Boolean;
1605 var
1606   idServer: TIdHTTP;
1607   i, j,iPos1, iPos2, iMatchCount: Integer;
1608   sResponse ,URLStr ,CountStr, IsNotStr: string;
1609   StarMatchList : TStringList;
1610 begin
1611   Result := False ;
1612   StarMatchList := TStringList.Create;
1613   idServer := TIdHTTP.Create(nil);
1614   try
1615     CountStr := 'match_counts(' ;
1616     URLStr := 'http://info.sporttery.cn/football/info/fb_match_info.php?m=';
1617     try
1618       //sResponse := idServer.Get('http://info.sporttery.cn/football/match_list.php');
1619       sResponse := idServer.Get(MainForm.FBSMResultAddress);
1620       iPos1 := Pos(CountStr,sResponse) ;
1621       iPos2 := PosEx(''')',sResponse,ipos1+1);
1622       iMatchCount := StrToIntDef((Copy(sResponse,iPos1+Length(CountStr)+1,ipos2-iPos1-Length(CountStr)-1)),-1);
1623 
1624       if iMatchCount =-1 then
1625       begin
1626          MainForm.LogInfo('获取页面有误,页面内容为:' + sResponse , True);
1627          Exit;
1628       end;
1629 
1630       if iMatchCount > 0 then
1631       begin
1632         for  i :=0 to iMatchCount*2 -1 do
1633         begin
1634           iPos1 := Pos(URLStr, sResponse);
1635           sResponse := Copy(sResponse,iPos1+Length(URLStr),Length(sResponse)-iPos1-Length(URLStr)-1) ;
1636           iPos2 := Pos('" ',sResponse) ;
1637           IsNotStr :=   Copy(sResponse,0,iPos2-1) ;
1638           if Pos('=',IsNotStr)= 0 then
1639           begin
1640              StarMatchList.Add(Copy(sResponse,0,iPos2-1));
1641           end;
1642         end;
1643       end;
1644 
1645       for j := 0 to Length(FBMatchList)-1 do
1646       begin
1647         if  (StarMatchList.IndexOf(FBMatchList[j].ID) < 0) then
1648         begin
1649            FBStopMatchList.Add(FBMatchList[j].ID);
1650         end;
1651       end;
1652       //
1653       MainForm.LogInfo('抓取停赛数据成功', True);
1654       Result := True ;
1655     except on E : Exception do
1656       begin
1657         MainForm.LogInfo('抓取停赛数据失败 原因:' + E.Message, True);
1658         Exit;
1659       end;
1660     end;
1661   finally
1662     if idServer <> nil then idServer.Free;
1663     StarMatchList.Free;
1664   end;
1665 end;
1666 
1667 function TJCMatchThd.SaveDateStopMatch: Boolean;
1668 var
1669   k, iFBMatchCount  : integer ;
1670   StopMatchNo,sSQLString : string ;
1671 begin
1672   //////////////////////////////写入竞彩足球停赛数据///////////////////////////////
1673   Result := False ;
1674   try
1675     iFBMatchCount :=  Length(FBMatchList);
1676     for k := 0 to iFBMatchCount -1 do
1677     begin
1678       if (FBStopMatchList.IndexOf(FBMatchList[k].ID) >= 0) then
1679       begin
1680          StopMatchNo :=  StopMatchNo + ','  + FBMatchList[k].ID ;
1681       end;
1682     end;
1683     //
1684     StopMatchNo := Copy(StopMatchNo,2,Length(StopMatchNo)-1);
1685     StopMatchNo := QuotedStr(StringReplace(StopMatchNo,',','*',[rfReplaceAll]));
1686     //
1687     if StopMatchNo <> '' then
1688     begin
1689       sSQLString := ' CALL P_STOP_MATCH_FLAG( '+ StopMatchNo + ' ) ;' ;
1690       mqMain.Close;
1691       mqMain.SQL.Text := sSQLString;
1692       mqMain.Execute;
1693     end;
1694     MainForm.LogInfo('已写入竞彩足球停赛数据', True);
1695     result := True ;
1696   except on  e: Exception do
1697     begin
1698       MainForm.LogInfo('抓取停赛数据失败 原因:' + E.Message, True);
1699       Exit;
1700     end;
1701   end;
1702 end;
1703 
1704 // 获取篮球让分情况
1705 function TJCMatchThd.GetBBGivenScore(MatchID,HomeTeam,Response: string): Real;
1706 var
1707   idhttp : TIdHTTP ;
1708   //Response,
1709   RFStr,sGivenSco : string ;
1710   ipos2, ipos3 : Integer ;
1711 begin
1712   Result := 0;
1713   sGivenSco:='"fixedodds":"';  //让分所在标识
1714   //2015-03-23 liping.chen 竞篮让分页面改版, 参数HomeTeam暂时保留,
1715   //idhttp := TIdHTTP.Create(nil);
1716   try
1717     try
1718       //2015-01-21 liping.chen 取消分多次频繁抓取网页。
1719      { MainForm.LogInfo('抓取篮球对阵让分情况', True);
1720 
1721       Response := idhttp.Get(MainForm.BBGivenScoreAddress);
1722 
1723       if MainForm.IsSaveFile then
1724       begin
1725         if MainForm.SaveFile(Response,'FileLQRFDate') then
1726         begin
1727           MainForm.LogInfo('保存竞彩篮球对阵让分页面成功', True);
1728         end;
1729       end;  }
1730 
1731       ipos2 := PosEx(MatchID,Response);
1732       if ipos2>0 then
1733       begin
1734         Response := Copy(Response,ipos2 + Length(MatchID),Length(Response)-ipos2-Length(MatchID)-1);
1735         ipos3:=PosEx(sGivenSco,Response);
1736         if ipos3>0 then
1737         begin
1738           ipos2:=PosEx('",',Response,ipos3+length(sGivenSco));
1739           RFStr:=Copy(Response,ipos3+length(sGivenSco),ipos2-ipos3-length(sGivenSco));
1740           if RFStr<>'' then
1741             Result:=StrToFloat(RFStr);
1742         end
1743         else
1744           MainForm.LogInfo('该ID场次已开售但查找让分标示位失败,请检查' , True);
1745       end
1746       else
1747         MainForm.LogInfo('该ID场次已开售但让分Json中查找ID标示位失败,请检查' , True);
1748 
1749       //-----------------------暂时保留
1750      { ipos2   :=  PosEx(HomeTeam,Response);
1751 
1752       Response :=   Copy(Response,ipos2 + Length(HomeTeam),Length(Response)-ipos2-Length(HomeTeam)-1);
1753       ipos3  :=  PosEx('</a>',Response);
1754 
1755       RFStr := Copy(Response,0,ipos3-1) ;
1756 
1757       ipos2 := PosEx('(',RFStr);
1758       if ipos2 > 0 then
1759       begin
1760         ipos3 := PosEx(')',RFStr);
1761         RFStr := StringReplace(Copy(RFStr,ipos2+1,ipos3-ipos2-1),'+','',[rfReplaceAll]);
1762         Result := StrToFloat(RFStr) ;
1763       end else
1764       begin
1765         //MainForm.LogInfo('抓取篮球对阵让分失败 ', True);
1766         Result := 0 ;
1767       end;   }
1768     except on E: Exception do
1769       begin
1770          MainForm.LogInfo('抓取篮球对阵让分失败 原因:' + E.Message, True);
1771          Result := 0;
1772          Exit;
1773       end;
1774     end;
1775   finally
1776     //idhttp.Free;
1777   end;
1778 
1779 end;
1780 
1781 
1782 // 获取篮球预设总分
1783 function TJCMatchThd.GetBBPresetScore(MatchID ,AwayTeam,Response : string): Real;
1784 var
1785   idhttp : TIdHTTP ;
1786   //Response,
1787   YSZFStr,sGivenSco : string ;
1788   ipos2, ipos3 : Integer ;
1789 begin
1790   //idhttp := TIdHTTP.Create(nil);
1791   Result := 0;
1792   sGivenSco:='"fixedodds":"';  //让分所在标识
1793   //2015-03-23 liping.chen 竞篮让分页面改版, 参数HomeTeam暂时保留,
1794   try
1795     try
1796       //2015-01-21 liping.chen 取消分多次频繁抓取网页。
1797      { MainForm.LogInfo('抓取篮球对阵预设总分情况', True);
1798       Response := idhttp.Get(MainForm.BBPresetScoreAddress);
1799       //
1800       if MainForm.IsSaveFile then
1801       begin
1802         if MainForm.SaveFile(Response,'FileLQYSZFDate') then
1803         begin
1804           MainForm.LogInfo('保存竞彩篮球对阵预设总分页面成功', True);
1805         end;
1806 
1807       end;  }
1808 
1809       ipos2 := PosEx(MatchID,Response);
1810       if ipos2>0 then
1811       begin
1812         Response := Copy(Response,ipos2 + Length(MatchID),Length(Response)-ipos2-Length(MatchID)-1);
1813         ipos3:=PosEx(sGivenSco,Response);
1814         if ipos3>0 then
1815         begin
1816           ipos2:=PosEx('",',Response,ipos3+length(sGivenSco));
1817           YSZFStr:=Copy(Response,ipos3+length(sGivenSco),ipos2-ipos3-length(sGivenSco));
1818           if YSZFStr<>'' then
1819             Result:=StrToFloat(YSZFStr);
1820         end
1821         else
1822           MainForm.LogInfo('该ID场次已开售但查找预设总分标示位失败,请检查' , True);
1823       end
1824       else
1825         MainForm.LogInfo('该ID场次已开售但预设总分Json中查找ID标示位失败,请检查' , True);
1826 
1827       //-------------------------
1828       {ipos3 :=  PosEx(awayTeam,Response);
1829       Response := Copy(Response,ipos3 + Length(awayTeam),Length(Response)-ipos3-Length(awayTeam)-1);
1830       ipos2  :=  PosEx('</a>',Response);
1831       if ipos2 <> 1  then
1832       begin
1833          Result := StrToFloat(copy(Response,0,ipos2-1));
1834       end else
1835       begin
1836         Result := 0;
1837       end; }
1838     except on E: Exception do
1839       begin
1840          MainForm.LogInfo('抓取篮球对阵预设总分失败 原因:' + E.Message, True);
1841          Exit;
1842       end;
1843     end;
1844   finally
1845     //idhttp.Free;
1846   end;
1847 end;
1848 
1849 function TJCMatchThd.GetFBGivenScore: Boolean;
1850 var
1851   idhttp : TIdHTTP ;
1852   sResponse,sID,RFStr : string ;
1853   ipos1, ipos2,i : Integer ;
1854   StrLog,sGivenSco : string ;
1855   iFlagNum1,iFlagNum2:Integer;
1856 begin
1857   Result := False ;
1858   idhttp := TIdHTTP.Create(nil);
1859   idhttp.ConnectTimeout:=15000;    //2015-02-05 liping.chen
1860   idhttp.ReadTimeout:=15000;
1861   StrLog:=':{"id":"';   //每场开始标识
1862   sGivenSco:='"fixedodds":"';  //让分所在标识
1863   try
1864     try
1865       //从http://info.sporttery.cn/football/hhad_list.php 网页分析一下 数据源网址:
1866       //完整url:=http://i.sporttery.cn/odds_calculator/get_odds?i_format=json&i_callback=getDat&poolcode[]=hhad&poolcode[]=had&_=1418712667
1867       //url:=http://i.sporttery.cn/odds_calculator/get_odds?i_format=json&i_callback=getDat&poolcode[]=hhad 本例非让球的数据不取
1868       try
1869         MainForm.LogInfo('正在获取竞足对阵让分情况', True);
1870         sResponse := idhttp.Get(MainForm.FBGoalLineAddress);
1871       except on E : Exception do
1872         begin
1873           MainForm.LogInfo('idhttp.Get获取竞足对阵让分情况失败 '+ E.Message, True);
1874           Exit;
1875         end;
1876       end;
1877       if MainForm.IsSaveFile then
1878       begin
1879         if MainForm.SaveFile(sResponse,'FileZQRFDate') then
1880         begin
1881           MainForm.LogInfo('保存竞足对阵让分页面成功', True);
1882         end;
1883       end;
1884       //-------------------------  //20150226  添加易发现错误的判断机制 ID标示数要和让分标示数要相同
1885       iPos1 := 0;
1886       iFlagNum1:=0;
1887       iPos1:= Pos(StrLog, sResponse);
1888       while iPos1<> 0 do
1889       begin
1890         Inc(iFlagNum1);
1891         iPos1:= PosEx(StrLog, sResponse, iPos1+1);
1892       end;
1893       iPos1 := 0;
1894       iFlagNum2:=0;
1895       iPos1:= Pos(sGivenSco, sResponse);
1896       while iPos1<> 0 do
1897       begin
1898         Inc(iFlagNum2);
1899         iPos1:= PosEx(sGivenSco, sResponse, iPos1+1);
1900       end;
1901       if iFlagNum1<>iFlagNum2 then
1902       begin
1903         MainForm.LogInfo('获取竞足对阵让分时出错,ID与让分的标识数目不相同,请检查', True);
1904         Exit;
1905       end;
1906       //------------------------
1907 
1908       //ipos1 := Pos('"id":"',sResponse);   //新变动 "id":"改为  :{"id":"
1909       iPos1 := 0;
1910       ipos1 := Pos(StrLog,sResponse);
1911       if (iPos1 = 0)then
1912       begin
1913         MainForm.LogInfo('获取竞足对阵让分时出错,找不到标识字符串'+StrLog, True);
1914         Exit;
1915       end;
1916 
1917 
1918       while ipos1 >0 do
1919       begin
1920         //官方编号
1921         ipos2:=PosEx('"',sResponse,ipos1+length(StrLog));
1922         sID:= Copy(sResponse,ipos1+length(StrLog),ipos2-ipos1-length(StrLog));
1923         //让分
1924         ipos1:=PosEx(sGivenSco,sResponse,ipos2);
1925         ipos2:=PosEx('",',sResponse,ipos1+length(sGivenSco));
1926         RFStr:=Copy(sResponse,ipos1+length(sGivenSco),ipos2-ipos1-length(sGivenSco));
1927         for i := 0 to Length(FBMatchList)-1 do
1928         begin
1929           if (FBMatchList[i].ID = sID) and (RFStr<>'') then
1930           begin
1931             FBMatchList[i].GivenScore := StrToInt(RFStr);
1932             Break;
1933           end;
1934         end;
1935         sResponse := Copy(sResponse,iPos2,Length(sResponse) - iPos2 +1);  //添加截短
1936         ipos1 := PosEx(StrLog,sResponse,1);
1937       end;
1938       Result:=True;
1939     except on E: Exception do
1940       begin
1941          MainForm.LogInfo('抓取竞足对阵让分失败 原因:' + E.Message, True);
1942          Result :=False;
1943          Exit;
1944       end;
1945     end;
1946   finally
1947     idhttp.Free;
1948   end;
1949 end;
1950 
1951 end.
竞彩赛程
   1 unit ThdJCResult;
   2 
   3 interface
   4 
   5 uses
   6   Classes, ShDocVw, MyAccess, SysUtils, PubDefine, DateUtils, IdHTTP,
   7   StrUtils,IniFiles;
   8 
   9 const
  10   GETCOUNTSTART = '查询结果:有';
  11   GETCOUNTEND = '场赛事符合条件';
  12   FBDETAILURL = 'pool_result.php?id=';
  13 
  14 type
  15   TJCResultThd = class(TThread)
  16   private
  17     { Private declarations }
  18     Pause: Boolean;
  19     mcMain: TMyConnection;
  20     mqMain: TMyQuery;
  21     iJCType : integer;
  22 
  23     function CatchResult: Boolean;
  24     function GetBBResult: Boolean;
  25     function GetFBResult: Boolean;
  26     function SaveData: Boolean;
  27     function ParseBBTable(aTableStr: string): Boolean;
  28     function ParseFBTable(aTableStr: string): Boolean;
  29     function GetBBDetail: Boolean;
  30     function GetFBDetail: Boolean;
  31   protected
  32 
  33   public
  34     iJcInv : Integer;
  35     hsl_Result : THashedstringlist;
  36 
  37     constructor Create(iType :integer;Finterval:integer);
  38     procedure Execute; override;
  39     destructor Destroy; override;
  40     procedure SetPause(const aIsPause: Boolean);
  41   end;
  42 
  43 implementation
  44 
  45 uses FrmMain;
  46 
  47 var
  48   BBList: array of TBBMatchResult;
  49   FBList: array of TFBMatchResult;
  50 
  51 { Important: Methods and properties of objects in visual components can only be
  52   used in a method called using Synchronize, for example,
  53 
  54       Synchronize(UpdateCaption);
  55 
  56   and UpdateCaption could look like,
  57 
  58     procedure TJCResultThd.UpdateCaption;
  59     begin
  60       Form1.Caption := 'Updated in a thread';
  61     end; }
  62 
  63 { TJCResultThd }
  64 
  65 function TJCResultThd.CatchResult: Boolean;
  66 begin
  67   Result := False;
  68   MainForm.LogInfo('开始抓取竞彩赛果', True);
  69   SetLength(BBList, 0);
  70   SetLength(FBList, 0);
  71   case iJCType of
  72     0 : begin
  73       MainForm.LogInfo('获取竞彩篮球赛果页面信息开始',True);
  74       if not GetBBResult then
  75         MainForm.LogInfo('获取竞彩篮球赛果出错,等待重试!', True);
  76       MainForm.LogInfo('获取竞彩篮球赛果页面信息结束',True);
  77       //
  78       MainForm.LogInfo('获取竞彩足球赛果页面信息开始',True);
  79       if not GetFBResult then
  80         MainForm.LogInfo('获取竞彩足球赛果出错,等待重试!', True);
  81       MainForm.LogInfo('获取竞彩足球赛果页面信息结束',True);
  82     end;
  83     70 : begin
  84       MainForm.LogInfo('获取竞彩足球赛果页面信息开始',True);
  85       if not GetFBResult then
  86         MainForm.LogInfo('获取竞彩足球赛果出错,等待重试!', True);
  87       MainForm.LogInfo('获取竞彩足球赛果页面信息结束',True);
  88     end;
  89     45 : begin
  90       MainForm.LogInfo('获取竞彩篮球赛果页面信息开始',True);
  91       if not GetBBResult then
  92         MainForm.LogInfo('获取竞彩篮球赛果出错,等待重试!', True);
  93       MainForm.LogInfo('获取竞彩篮球赛果页面信息结束',True);
  94     end;
  95   end;
  96   // 保存赛果
  97   Result := SaveData;
  98 end;
  99 
 100 constructor TJCResultThd.Create(iType :integer;Finterval:integer);
 101 begin
 102   inherited Create(True);
 103   iJCType := iType;
 104   iJcInv := Finterval;
 105   FreeOnTerminate := True;
 106 
 107   hsl_Result := THashedstringlist.Create;
 108   //
 109   mcMain := TMyConnection.Create(nil);
 110   mcMain.Server := ConnectionConfig.Server;
 111   mcMain.Username := ConnectionConfig.Username;
 112   mcMain.Password := ConnectionConfig.Password;
 113   mcMain.Port := ConnectionConfig.Port;
 114   mcMain.Database := ConnectionConfig.Database;
 115   mcMain.LoginPrompt := False;
 116   try
 117     mcMain.Connect;
 118   except on ex:Exception do
 119     begin
 120       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
 121       Exit;
 122     end;
 123   end;
 124   mqMain := TMyQuery.Create(nil);
 125   mqMain.Connection := mcMain;
 126   //
 127   if iJCType = 0 then
 128     SetPause(True)
 129   else
 130     SetPause(false);
 131   Self.Resume;
 132 end;
 133 
 134 destructor TJCResultThd.Destroy;
 135 begin
 136   if Assigned(mcMain) then mcMain.Free;
 137   if Assigned(mqMain) then mqMain.Free;
 138   if Assigned(hsl_Result) then hsl_Result.Free;
 139   inherited;
 140 end;
 141 
 142 procedure TJCResultThd.Execute;
 143 var
 144   bPauseStatus: Boolean;
 145   dtTemp: TDateTime;
 146   ReDoCount : Integer ;
 147   iNum : Integer;// 执行次数
 148 begin
 149   { Place thread code here }
 150   ReDoCount := 0 ;
 151   bPauseStatus := Pause;
 152   iNum := 0;
 153   while (iNum < 4 ) and (not Terminated) do   //线程.Terminate时确保可以结束线程。
 154   begin
 155     if iJCType = 0 then
 156     begin
 157       iNum := 1;
 158       Sleep(500);
 159     end
 160     else
 161       iNum := iNum + 1;
 162     //
 163     JcResultRunTime := Now;                    //2013-04-28 监控变量
 164     if not Pause then                          //如果没有收到暂停信息
 165     begin
 166       if MainForm.IsCatchJCResult then         //如果需要抓取
 167       begin
 168         if bPauseStatus <> Pause then
 169         begin
 170           MainForm.LogInfo('抓取线程***竞彩赛果***已启动', True);
 171           bPauseStatus := Pause;
 172         end;
 173         MainForm.IsJCResultCatching := True;
 174         if CatchResult then                    //如果抓取成功
 175         begin
 176           MainForm.LogInfo('竞彩赛果抓取成功,等待下一次抓取', True);
 177           dtTemp := Now;
 178           while not Pause do
 179           begin
 180             Sleep(500);
 181             if SecondsBetween(Now, dtTemp) > MainForm.JCResultGetInv then Break;
 182           end;
 183         end else begin
 184 
 185           ReDoCount := ReDoCount +1 ;
 186           MainForm.LogInfo('重试次数'+ IntToStr(ReDoCount),True);
 187           dtTemp := Now ;
 188           if ReDoCount mod 3 = 0 then
 189           begin
 190              while not Pause do
 191              begin
 192                Sleep(500);
 193                if SecondsBetween(Now, dtTemp) > MainForm.JCResultGetInv then Break;    // 抓取3次不成功 则重新退出抓取避免频繁获取官网屏蔽网址
 194              end;
 195           end;
 196           MainForm.LogInfo('抓取竞彩赛果失败,等待重试', True);
 197           Sleep(RETRY_INV);
 198         end;
 199       end
 200       else begin
 201         if bPauseStatus <> Pause then
 202         begin
 203           MainForm.LogInfo('抓取线程***竞彩赛果***已启动,但设置为不抓取', True);
 204           bPauseStatus := Pause;
 205         end;
 206         Sleep(200);
 207       end;
 208     end
 209     else begin                                 //如果暂停抓取
 210       if bPauseStatus <> Pause then
 211       begin
 212         MainForm.LogInfo('抓取线程***竞彩赛果***已暂停', True);
 213         bPauseStatus := Pause;
 214       end;
 215       MainForm.IsJCResultCatching := False;
 216       Sleep(500);
 217     end;
 218   end;
 219 end;
 220 
 221 function TJCResultThd.GetBBResult: Boolean;
 222 var
 223   idServer: TIdHTTP;
 224   iPos1, iPos2, iMatchCount: Integer;
 225   sResponse, sTable: string;
 226 begin
 227   Result := False;
 228   idServer := TIdHTTP.Create(nil);
 229   idServer.ConnectTimeout:=15000;   //2015-02-05 liping.chen 增加连接和读取超时属性值
 230   idServer.ReadTimeout:=15000;
 231   try
 232     try
 233       try
 234         MainForm.LogInfo('正在获取竞彩篮球赛果', True);
 235         sResponse := idServer.Get(MainForm.BBResultAddress);
 236       except on E : Exception do
 237         begin
 238           MainForm.LogInfo('idServer.Get获取竞彩篮球赛果失败'+ E.Message, True);
 239           Exit;
 240         end;
 241       end;
 242       if MainForm.IsSaveFile then
 243       begin
 244         if MainForm.SaveFile(sResponse,'FileLQSGDate') then
 245         begin
 246           MainForm.LogInfo('保存竞彩篮球赛果页面成功', True);
 247         end;
 248       end;
 249 
 250       //  MainForm.LogInfo('读取页面信息成功!', True);
 251       // 2013-12-19 rulinzhang add
 252       {iPos1 := Pos('<form', sResponse);
 253       if iPos1 = 0 then
 254         iPos1 := Pos('<FORM', sResponse);
 255       sResponse := Copy(sResponse,iPos1 + 10,Length(sResponse) - iPos1 - 11); }
 256       iPos1 := Pos('<form', sResponse);
 257       if iPos1 = 0 then
 258         iPos1 := Pos('<FORM', sResponse);
 259       sResponse := Copy(sResponse,iPos1,Length(sResponse) - iPos1);
 260       //
 261       iPos2 := Pos('</form>', sResponse);
 262       if iPos2 = 0 then
 263         iPos2 := Pos('</FORM', sResponse);
 264       //sResponse := Copy(sResponse,1,Length(sResponse) - iPos2 - 10);
 265       sResponse := Copy(sResponse,1,iPos2 + 50);    //2014-01-14 guoqiang.xu
 266       //
 267       iPos1 := Pos(GETCOUNTSTART, sResponse);
 268       iPos2 := Pos(GETCOUNTEND, sResponse);
 269       if (iPos1 = 0) or (iPos2 = 0) then
 270       begin
 271         MainForm.LogInfo('获取篮彩赛果时出错,找不到标识字符串', True);
 272         MainForm.LogInfo(sResponse, False);
 273         Exit;
 274       end;
 275       iMatchCount := StrToIntDef(Copy(sResponse, iPos1 + 12, iPos2 - iPos1 - 12), -1);
 276       if iMatchCount = -1 then
 277       begin
 278         MainForm.LogInfo('获取篮彩赛果时出错,找不到场次数量', True);
 279         MainForm.LogInfo(sResponse, False);
 280         Exit;
 281       end
 282       else if iMatchCount = 0 then
 283       begin
 284         MainForm.LogInfo('篮彩无最新赛果', True);
 285         Result := True;
 286         Exit;
 287       end;
 288       iPos1 := Pos('<table', sResponse);
 289       iPos2 := Pos('</table>', sResponse);
 290       sTable := Copy(sResponse, iPos1, iPos2 - iPos1);
 291       iPos1 := Pos('开奖结果', sTable);
 292       if iPos1 = 0 then
 293       begin
 294         MainForm.LogInfo('获取篮彩赛果时出错,找不到开奖信息', True);
 295         MainForm.LogInfo(sTable, False);
 296         Exit;
 297       end;
 298       iPos1 := PosEx('<tr', sTable, iPos1 + 1);
 299       iPos1 := PosEx('<tr', sTable, iPos1 + 1);
 300       sTable := Copy(sTable, iPos1, Length(sTable) - iPos1 + 1);
 301       if not ParseBBTable(sTable) then Exit;
 302       //if not GetBBDetail then Exit;   //2014/10/21体彩中心取消单场浮动投注,不需要抓取
 303       Result := True;
 304     except on E : Exception do
 305       begin
 306         MainForm.LogInfo('获取篮彩赛果时出错,原因:' + E.Message, True);
 307         Exit;
 308       end;
 309     end;
 310   finally
 311      idServer.Free;
 312   end;
 313 end;
 314 
 315 function TJCResultThd.GetBBDetail: Boolean;
 316 var
 317   idServer: TIdHTTP;
 318   i, iMatchIndex, iPos1, iPos2: Integer;
 319   sWholeURL, sResponse, sTable, sBonus: string;
 320   cBonus: Currency;
 321   Handicap ,PrestScore : Currency ;
 322 begin
 323   Result := False;
 324   idServer := TIdHTTP.Create(nil);
 325   try
 326     idServer.ReadTimeout := 20000 ;
 327     idServer.ConnectTimeout := 20000 ;
 328     MainForm.LogInfo('开始获取竞彩篮球详细赛果', True);
 329     try
 330       iMatchIndex := Length(BBList);
 331       for i := 0 to iMatchIndex - 1 do
 332       begin
 333         if BBList[i].Status <> '已完成' then Continue;            //未完成的比赛不抓取
 334         sWholeURL := MainForm.BBDlResultAddress + BBList[i].ID;
 335         try
 336           sResponse := idServer.Get(sWholeURL);
 337         except on e: Exception do
 338           begin
 339             MainForm.LogInfo('抓取竞彩篮球详细赛果时错误,场次为'+ QuotedStr(BBList[i].ID) +' 错误详情' + e.Message, True);
 340             Continue;
 341           end;
 342         end;
 343         // 2013-12-19 rulinzhang add
 344         {iPos1 := Pos('<form', sResponse);
 345         if iPos1 = 0 then
 346           iPos1 := Pos('<FORM', sResponse);
 347         sResponse := Copy(sResponse,iPos1 + 10,Length(sResponse) - iPos1 - 11);
 348         iPos1 := Pos('<form', sResponse);
 349         if iPos1 = 0 then
 350           iPos1 := Pos('<FORM', sResponse);
 351         sResponse := Copy(sResponse,iPos1,Length(sResponse) - iPos1);
 352         //
 353         iPos2 := Pos('</form>', sResponse);
 354         if iPos2 = 0 then
 355           iPos2 := Pos('</FORM', sResponse);
 356         sResponse := Copy(sResponse,1,Length(sResponse) - iPos2 - 10); }
 357         //
 358         iPos1 := Pos('单场浮动奖金', sResponse);
 359         if iPos1 = 0 then
 360         begin
 361           MainForm.LogInfo('抓取竞彩篮球详细赛果时出错,找不到匹配符号', True);
 362           MainForm.LogInfo('匹配符号:' + sResponse, False);
 363           Exit;
 364         end;
 365       //  iPos1 := Pos('<table', sResponse);
 366       //   iPos2 := PosEx('</table>', sResponse, iPos1 + 1);
 367       //  sTable := Copy(sResponse, iPos1, iPos2 - iPos1 + 8);
 368 
 369        sTable := Copy(sResponse,iPos1 ,Length(sResponse)-iPos1);
 370   /////////////////////抓取篮彩胜负的SP////////////////////////////////
 371 
 372         iPos1 := Pos('胜负', sTable);
 373         if iPos1 = 0 then
 374         begin
 375           MainForm.LogInfo('抓取竞彩篮球详细赛果时出错,找不到胜负匹配符号', True);
 376           MainForm.LogInfo('匹配符号:' + sTable, False);
 377           Exit;
 378         end;
 379         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 380         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 381         iPos1 := PosEx('>', sTable, iPos1 + 1);
 382         iPos2 := PosEx('</td>', sTable, iPos1 + 1);
 383         sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
 384         if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
 385         else begin
 386           cBonus := StrToCurrDef(sBonus, -1);
 387           if cBonus = -1 then
 388           begin
 389             MainForm.LogInfo('抓取竞彩篮球详细赛果的胜负SP时出错', True);
 390             MainForm.LogInfo('抓取竞彩篮球详细赛果的胜负SP时出错,抓取的到SP为:' + sBonus, False);
 391             Exit;
 392           end;
 393         end;
 394         BBList[i].SFBonus := cBonus;
 395 
 396   /////////////////////抓取篮彩让分胜负的SP////////////////////////////////
 397         iPos1 := Pos('让分胜负', sTable);
 398         if iPos1 = 0 then
 399         begin
 400           MainForm.LogInfo('抓取竞彩篮球详细赛果时出错,找不到让分胜负匹配符号', True);
 401           MainForm.LogInfo('匹配符号:' + sTable, False);
 402           Exit;
 403         end;
 404 
 405         // 获取让分数值
 406         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 407         iPos1 := PosEx('让分', sTable, iPos1 + 1);
 408         iPos2 := PosEx('<', sTable, iPos1 + 1);
 409         Handicap := StrToCurrDef(copy(sTable,iPos1+9,iPos2-iPos1-9),0);
 410         BBList[i].Handicap := Handicap ;
 411 
 412         //   让分胜负的SP
 413         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 414         iPos1 := PosEx('>', sTable, iPos1 + 1);
 415         iPos2 := PosEx('</td>', sTable, iPos1 + 1);
 416         sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
 417         if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
 418         else begin
 419           cBonus := StrToCurrDef(sBonus, -1);
 420           if cBonus = -1 then
 421           begin
 422             MainForm.LogInfo('抓取竞彩篮球详细赛果的让分胜负SP时出错', True);
 423             MainForm.LogInfo('抓取竞彩篮球详细赛果的让分胜负SP时出错,抓取的到SP为:' + sBonus, False);
 424             Exit;
 425           end;
 426         end;
 427         BBList[i].RFSFBonus := cBonus;
 428   /////////////////////抓取篮彩胜分差的SP////////////////////////////////
 429   // 胜分差中的sp值在打票中已经获取,再次不需要再次获取。
 430         {
 431         iPos1 := Pos('胜分差', sTable);
 432         if iPos1 = 0 then
 433         begin
 434           MainForm.LogInfo('抓取竞彩篮球详细赛果时出错,找不到胜分差匹配符号', True);
 435           MainForm.LogInfo('匹配符号:' + sTable, False);
 436           Exit;
 437         end;
 438         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 439         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 440         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 441         iPos1 := PosEx('>', sTable, iPos1 + 1);
 442         iPos2 := PosEx('</td>', sTable, iPos1 + 1);
 443         sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
 444         if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
 445         else begin
 446           cBonus := StrToCurrDef(sBonus, -1);
 447           if cBonus = -1 then
 448           begin
 449             MainForm.LogInfo('抓取竞彩篮球详细赛果的胜分差SP时出错', True);
 450             MainForm.LogInfo('抓取竞彩篮球详细赛果的胜分差SP时出错,抓取的到SP为:' + sBonus, False);
 451             Exit;
 452           end;
 453         end;
 454         BBList[i].SFCBonus := cBonus;
 455         }
 456   /////////////////////抓取篮彩大小分的SP////////////////////////////////
 457         iPos1 := Pos('大小分', sTable);
 458         if iPos1 = 0 then
 459         begin
 460           MainForm.LogInfo('抓取竞彩篮球详细赛果时出错,找不到大小分匹配符号', True);
 461           MainForm.LogInfo('匹配符号:' + sTable, False);
 462           Exit;
 463         end;
 464 
 465         // 获取 大小分数值
 466         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 467         iPos1 := PosEx('>', sTable, iPos1 + 1);
 468         iPos1 := PosEx('>', sTable, iPos1 + 1);
 469         iPos2 := PosEx('<', sTable, iPos1 + 1);
 470 
 471         PrestScore := StrToCurrDef(copy(sTable,iPos1+3,iPos2-iPos1-3),0);
 472         BBList[i].PrestScore := PrestScore ;
 473 
 474 
 475         iPos1 := PosEx('<td', sTable, iPos1 + 1);
 476         iPos1 := PosEx('>', sTable, iPos1 + 1);
 477         iPos2 := PosEx('</td>', sTable, iPos1 + 1);
 478         sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
 479         if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
 480         else begin
 481           cBonus := StrToCurrDef(sBonus, -1);
 482           if cBonus = -1 then
 483           begin
 484             MainForm.LogInfo('抓取竞彩篮球详细赛果的大小分SP时出错', True);
 485             MainForm.LogInfo('抓取竞彩篮球详细赛果的大小分SP时出错,抓取的到SP为:' + sBonus, False);
 486             Exit;
 487           end;
 488         end;
 489         BBList[i].DXFBonus := cBonus;
 490         Result := True;
 491       end;
 492       MainForm.LogInfo('竞彩篮球详细赛果获取完毕', True);
 493       Result := True;
 494     except on E : Exception do
 495       begin
 496         MainForm.LogInfo('抓取竞彩篮球详细赛果时出错,原因:' + E.Message, True);
 497       end;
 498     end;
 499   finally
 500     idServer.Free;
 501   end;
 502 end;
 503 
 504 function TJCResultThd.ParseBBTable(aTableStr: string): Boolean;
 505 var
 506   i, iTR, iPos1, iPos2, iMatchIndex: Integer;
 507   sRow, sMatchindex,sScore, sStatus, sURL, sID: string;
 508 begin
 509   Result := False;
 510   MainForm.LogInfo('开始解析竞彩篮球赛果', True);
 511   try
 512     iTR := 0;
 513     iMatchIndex := 0;
 514     while PosEx('<tr', aTableStr, iTR + 1) > 0 do
 515     begin
 516       iTR := PosEx('<tr', aTableStr, iTR + 1);
 517       iPos1 := iTR;
 518       iPos2 := PosEx('</tr>', aTableStr, iPos1 + 1);
 519       sRow := Copy(aTableStr, iPos1, iPos2 - iPos1 + 5);
 520       if Pos('已完成', sRow) = 0 then Continue;             //只抓取已完成的比赛
 521       iPos1 := Pos('<td', sRow);
 522       iPos1 := PosEx('<td', sRow, iPos1 + 1);
 523       iPos1 := PosEx('>', sRow, iPos1 + 1);
 524       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
 525       sMatchindex := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
 526       SetLength(BBList, Length(BBList) + 1);
 527 //      BBList[iMatchIndex].MatchIndex := ChangeCompIndex(sMatchindex);
 528       for i := 0 to 6 do
 529       begin
 530         iPos1 := PosEx('<td', sRow, iPos1 + 1);
 531       end;
 532       iPos1 := PosEx('>', sRow, iPos1 + 1);
 533       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
 534       sScore := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
 535       if Pos('href=', sScore) > 0 then
 536       begin
 537         for i := 0 to 7 do
 538         begin
 539           iPos1 := PosEx('<td', sRow, iPos1 + 1);
 540         end;
 541         iPos1 := PosEx('>', sRow, iPos1 + 1);
 542         iPos2 := PosEx('</td>', sRow, iPos1 + 1);
 543         sScore := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
 544       end;
 545       if Pos(':', sScore) = 0 then
 546       begin
 547         MainForm.LogInfo('解析篮彩赛果获取比分时发生错误', True);
 548         MainForm.LogInfo('解析篮彩赛果获取比分时发生错误,抓取到的比分为:' + sScore, False);
 549       end;
 550 
 551       BBList[iMatchIndex].Score := sScore;
 552       iPos1 := PosEx('<td', sRow, iPos1 + 1);
 553       iPos1 := PosEx('>', sRow, iPos1 + 1);
 554       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
 555       sStatus := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
 556       BBList[iMatchIndex].Status := sStatus;
 557 
 558       if sStatus = '已完成' then
 559       begin
 560         // rulinzhang 2013-09-07 add
 561         //iPos1 := PosEx('href="', sRow, iPos1 + 1);
 562         iPos1 := PosEx('href=', sRow, iPos1 + 1);
 563         //iPos2 := PosEx('"', sRow, iPos1 + 7);
 564         iPos2 := PosEx('http://info.sporttery.cn/basketball/info/bk_match_mnl.php?m=', sRow, 0);
 565         sURL := Copy(sRow, ipos2, 100);
 566         iPos2 := PosEx('m=', sURL, 0);
 567         sID := Copy(sURL, iPos2 + 2, 5);
 568         //iPos1 := Pos('=', sURL);
 569         //sID := Copy(sURL, iPos1 + 1, Length(sURL) - iPos1);
 570         BBList[iMatchIndex].ID := sID;
 571       end;
 572 
 573       Inc(iMatchIndex);
 574     end;
 575     MainForm.LogInfo('竞彩篮球赛果解析完毕', True);
 576     Result := True;
 577   except on E : Exception do
 578     begin
 579       MainForm.LogInfo('解析篮彩赛果表格时发生错误,原因:' + E.Message, True);
 580       MainForm.LogInfo(aTableStr, False);
 581     end;
 582   end;
 583 end;
 584 
 585 function TJCResultThd.GetFBResult: Boolean;
 586 var
 587   idServer: TIdHTTP;
 588   i, iPos1, iPos2, iMatchCount: Integer;
 589   sResponse, sTable, sTemp: string;
 590   aPageURL: array of string;
 591   sl_MatchNo : TStringList;
 592   sUrl :string;
 593 begin
 594   Result := False;
 595   idServer := TIdHTTP.Create(nil);
 596   idServer.ConnectTimeout:=15000;  //2015-02-05 liping.chen 增加连接和读取超时属性值
 597   idServer.ReadTimeout:=15000;
 598 
 599   sl_MatchNo :=  TStringList.Create;
 600   sl_MatchNo.Delimiter :='&'; // '=';
 601   try
 602     try
 603       sUrl := MainForm.FBResultAddress;
 604       // 如果出现超过两页时的处理     默认为page = 1 单页为50条
 605       //sUrl := 'http://info.sporttery.cn/football/match_result.php?page=2&search_league=&start_date=2014-01-17&end_date=2014-01-19';
 606       //sUrl := 'http://info.sporttery.cn/football/match_result.php?page=2';
 607       //
 608       try         //2015-02-05 liping.chen
 609         MainForm.LogInfo('正在获取竞足赛果第一页', True);
 610         sResponse := idServer.Get(sUrl);
 611       except on E : Exception do
 612         begin
 613           MainForm.LogInfo('idServer.Get获取竞足赛果第一页失败'+ E.Message, True);
 614           Exit;
 615         end;
 616       end;
 617       if MainForm.IsSaveFile then
 618       begin
 619         if MainForm.SaveFile(sResponse,'FileZQSGDate') then
 620         begin
 621           MainForm.LogInfo('保存竞足赛果第一页成功', True);
 622         end;
 623       end;
 624       //
 625       // 2013-12-19 rulinzhang add
 626       iPos1 := Pos('<form', sResponse);
 627       if iPos1 = 0 then
 628         iPos1 := Pos('<FORM', sResponse);
 629       sResponse := Copy(sResponse,iPos1 + 10,Length(sResponse) - iPos1 - 11);
 630       {iPos1 := Pos('<form', sResponse);
 631       if iPos1 = 0 then
 632         iPos1 := Pos('<FORM', sResponse);
 633       sResponse := Copy(sResponse,iPos1,Length(sResponse) - iPos1);  }
 634 
 635       //
 636      { iPos2 := Pos('</form>', sResponse);
 637       if iPos2 = 0 then
 638         iPos2 := Pos('</FORM', sResponse);
 639       sResponse := Copy(sResponse,1,iPos2 + 100);  }
 640       //
 641       iPos1 := Pos(GETCOUNTSTART, sResponse);
 642       iPos2 := Pos(GETCOUNTEND, sResponse);
 643       if (iPos1 = 0) or (iPos2 = 0) then
 644       begin
 645         MainForm.LogInfo('获取足彩赛果时出错,找不到标识字符串', True);
 646         MainForm.LogInfo(sResponse, False);
 647        // Exit;
 648       end;
 649       iMatchCount := StrToIntDef(Copy(sResponse, iPos1 + 12, iPos2 - iPos1 - 12), -1);
 650       if iMatchCount = -1 then
 651       begin
 652         MainForm.LogInfo('获取足彩赛果时出错,找不到场次数量', True);
 653         MainForm.LogInfo(sResponse, False);
 654         Exit;
 655       end
 656       else if iMatchCount = 0 then
 657       begin
 658         MainForm.LogInfo('足彩无最新赛果', True);
 659         Result := True;
 660        // Exit;
 661       end;
 662   ////////////////////////抓取分页后各页的URL////////////////////////
 663       SetLength(aPageURL, 0);
 664       //iPos1 := PosEx('首页', sResponse, iPos1 + 1);
 665       //iPos2 := PosEx('尾页', sResponse, iPos1 + 1);
 666       {sTemp := Copy(sResponse, iPos2, Length(Trim(sResponse)) - iPos2);
 667       ipos1 := PosEx('href=', stemp,1);
 668       stemp := copy(stemp,ipos1 - 10,Length(Trim(stemp)) - iPos1 + 10);
 669       iPos1 := 0; }
 670 
 671       ipos1:=Pos('pagebox_num''><a',sResponse);
 672       iPos2:=PosEx('pagebox_next''><a',sResponse,iPos1+5);
 673       stemp := copy(sResponse,ipos1,iPos2-ipos1);
 674 
 675       while PosEx('href="', sTemp, 1) > 0 do
 676       begin
 677         iPos1 := PosEx('href="', sTemp, 1);
 678         iPos2 := PosEx('"', sTemp, iPos1 + 7);
 679         if Length(aPageURL) = 0 then
 680         begin
 681           SetLength(aPageURL, 1);
 682           sl_MatchNo.Clear;
 683           sl_MatchNo.DelimitedText := Copy(sTemp, iPos1 + 6, iPos2 - iPos1 - 6);
 684           aPageURL[0] := sl_MatchNo.Strings[0];
 685         end
 686         else begin
 687           if aPageURL[Length(aPageURL) - 1] <> Copy(sTemp, iPos1 + 6, iPos2 - iPos1 - 6) then
 688           begin
 689             SetLength(aPageURL, Length(aPageURL) + 1);
 690             sl_MatchNo.Clear;
 691             sl_MatchNo.DelimitedText := Copy(sTemp, iPos1 + 6, iPos2 - iPos1 - 6);
 692             aPageURL[Length(aPageURL) - 1] := sl_MatchNo.Strings[0];
 693           end;
 694         end;
 695         //
 696         {ipos1 := PosEx('<tr', stemp,1);
 697         if iPos1 = 0 then
 698           ipos1 := PosEx('<TR', stemp,1);
 699         stemp := copy(stemp,ipos1 + 5,Length(Trim(stemp)) - iPos1 - 5); }
 700 
 701         stemp := copy(stemp,ipos1 + 6,Length(Trim(stemp)) - iPos1 - 6);
 702       end;
 703   //////////////////////////获取table里面的信息//////////////////////
 704       iPos1 := Pos('开奖结果及浮动奖金额', sResponse);
 705       iPos1 := PosEx('<tr', sResponse, iPos1 + 1);
 706       iPos2 := RightPos(' VS ', sResponse);
 707       iPos2 := PosEx('</tr>', sResponse, iPos2 + 1);
 708       sTable := Copy(sResponse, iPos1, iPos2 - iPos1 + 5);
 709       MainForm.LogInfo('开始解析竞彩足球赛果', True);
 710       if not ParseFBTable(sTable) then Exit;    //取第一页
 711 
 712       ///////////////////////////获取后几页的信息//////////////
 713       if Length(aPageURL)>0 then   //2014-12-15 liping.chen 目前设定只取到第二页 以免重复取存非当前数据。
 714       begin
 715         for i := 0 to 0 do  //to Length(aPageURL) - 1 do   //aPageURL[0]就是第2页 aPageURL[1]第3页
 716         begin
 717           try        //2015-02-05 liping.chen
 718             MainForm.LogInfo('正在获取竞足赛果第二页', True);
 719             sResponse := idServer.Get(MainForm.FBDlResultAddress  + aPageURL[i]);
 720           except on E : Exception do
 721             begin
 722               MainForm.LogInfo('idServer.Get获取竞足赛果第二页失败'+ E.Message, True);
 723               Exit;
 724             end;
 725           end;
 726           if MainForm.IsSaveFile then
 727           begin
 728             if MainForm.SaveFile(sResponse,'FileZQSGDate') then
 729             begin
 730               MainForm.LogInfo('保存竞足赛果第二页成功', True);
 731             end;
 732           end;
 733           iPos1 := Pos('开奖结果及浮动奖金额', sResponse);
 734           iPos1 := PosEx('<tr', sResponse, iPos1 + 1);
 735           iPos2 := RightPos(' VS ', sResponse);
 736           iPos2 := PosEx('</tr>', sResponse, iPos2 + 1);
 737           sTable := Copy(sResponse, iPos1, iPos2 - iPos1 + 5);
 738           if not ParseFBTable(sTable) then Exit;
 739         end;
 740       end;
 741       MainForm.LogInfo('竞彩足球赛果解析完毕', True);
 742 
 743       //if not GetFBDetail then Exit;    //2014/10/21体彩中心取消单场浮动投注,不需要抓取
 744       //MainForm.LogInfo('竞彩足球赛果明细解析完毕', True);
 745       Result := True;
 746     except on E : Exception do
 747       begin
 748         MainForm.LogInfo('获取足彩赛果时出错,原因:' + E.Message, True);
 749        // Exit;
 750       end;
 751     end;
 752   finally
 753     idServer.Free;
 754     sl_MatchNo.Free;
 755   end;          
 756 end;
 757 
 758 function TJCResultThd.SaveData: Boolean;
 759 var
 760   i, iListCount, iReturnCode: Integer;
 761   sSQLString : string;
 762   BBCount,FBCount,iNoChangeNum,iRepeat: Integer;
 763   sLotMacthId : string;
 764   sMatchRet,sTmp : string;
 765 begin
 766   Result := False;
 767   try
 768     BBCount := 0 ;
 769     FBCount := 0 ;
 770     iNoChangeNum:=0;
 771      if hsl_Result.Count > 1000 then
 772        hsl_Result.Clear;
 773     //============================篮彩赛果============================
 774     iListCount := Length(BBList);
 775     MainForm.LogInfo('准备写入竞篮赛果 共'+inttostr(iListCount)+'', True);
 776     for i := 0 to iListCount - 1 do
 777     begin
 778       if BBList[i].Score ='' then
 779       begin
 780         Continue ;
 781       end;
 782       // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
 783       sLotMacthId := 'LQ' + '-' + BBList[i].ID;
 784       sMatchRet := trim(BBList[i].ID)
 785                     + '^' + trim(BBList[i].Score)
 786                     + '^' + FloatToStr(BBList[i].SFBonus)
 787                     + '^' + FloatToStr(BBList[i].RFSFBonus)
 788                     + '^' + FloatToStr(BBList[i].SFCBonus)
 789                     + '^' + FloatToStr(BBList[i].DXFBonus);
 790       // 判断hashed是否存在
 791       sTmp := trim(hsl_Result.Values[trim(sLotMacthId)]);
 792       if sTmp = '' then
 793         hsl_Result.Add(trim(sLotMacthId) + '=' + sMatchRet)
 794       else
 795       begin
 796         if sTmp = Trim(sMatchRet) then
 797         begin
 798           //MainForm.LogInfo('【竞篮赛果】无变更:' + sMatchRet, True);
 799           inc(iNoChangeNum);
 800           Continue;
 801         end
 802         else
 803           hsl_Result.Values[trim(sLotMacthId)] := Trim(sMatchRet);
 804       end;
 805       // --------------------------------------------------------------
 806       sSQLString := 'CALL P_UPDATE_JCLQ_RESULT('
 807           + QuotedStr(BBList[i].ID)
 808          // + QuotedStr(BBList[i].MatchIndex)
 809           + ',' + QuotedStr(BBList[i].Score)
 810           + ',' + FloatToStr(BBList[i].SFBonus)
 811           + ',' + FloatToStr(BBList[i].RFSFBonus)
 812           + ',' + FloatToStr(BBList[i].SFCBonus)
 813           + ',' + FloatToStr(BBList[i].DXFBonus)
 814           + ',@a); select @a;';
 815       iRepeat:=0;   //2015-02-05 liping.chen
 816       while True do
 817       begin
 818         try
 819           mqMain.Close;
 820           mqMain.SQL.Text := sSQLString;
 821           mqMain.Execute;
 822           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
 823           Break;
 824         except on E : Exception do
 825           begin
 826             inc(iRepeat);
 827             {try        // 自动激活连接数据库
 828               mcMain.Disconnect;
 829               Sleep(50);
 830               mcMain.Connect;
 831             except
 832             end; }
 833             MainForm.LogInfo('竞篮赛果'+sLotMacthId+'场次写入失败!第'+IntToStr(iRepeat)+''+ E.Message, True);
 834             // 若捕获,说明该场次没有存储成功,清空哈希对应的值
 835             mqMain.Close;
 836             if iRepeat=2 then
 837             begin
 838               hsl_Result.Values[trim(sLotMacthId)] :='';
 839               Break;
 840             end;
 841           end;
 842         end;
 843       end;
 844       if iRepeat=2 then
 845       begin
 846         Continue;
 847       end;
 848 
 849       if iReturnCode = 1 then              //数据验证失败
 850       begin
 851         MainForm.LogInfo('写入竞彩篮球赛果失败,原因:数据验证失败', True);
 852         hsl_Result.Values[trim(sLotMacthId)] :='';
 853         Continue;
 854       end
 855       else if iReturnCode = 100 then
 856       begin
 857         MainForm.LogInfo('写入竞彩篮球赛果失败,原因:未知错误', True);
 858         hsl_Result.Values[trim(sLotMacthId)] :='';
 859         Continue;
 860       end
 861       else if iReturnCode = 101 then
 862       begin
 863         MainForm.LogInfo('写入竞彩篮球赛果失败,原因:在对阵中未找到场次' + BBList[i].ID, True);
 864         hsl_Result.Values[trim(sLotMacthId)] :='';
 865         Continue;
 866       end;
 867       BBCount :=  BBCount + 1 ;
 868 
 869       /////////////////更新 LOTTERY_MATCH 让分 预设总分////////////////
 870       {mqMain.Close;   //2015-02-06 liping.chen已经不执行GetBBDetail 所以屏蔽。
 871       sSQLString := 'CALL P_UPDATE_LOTTERY_MATCH_HANDICAP('
 872           + QuotedStr(BBList[i].ID)
 873           + ',' + FloatToStr(BBList[i].Handicap)
 874           + ',' + FloatToStr(BBList[i].PrestScore)
 875           + ');';
 876       mqMain.SQL.Text := sSQLString;
 877       mqMain.Execute;  }
 878     end;
 879     //MainForm.LogInfo('抓取赛果更新对阵让分和预设总分成功!', True);
 880     MainForm.LogInfo('已写入竞篮赛果'+IntToStr(BBCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
 881 
 882     //============================足彩赛果============================
 883     iListCount := Length(FBList);
 884     iNoChangeNum:=0;
 885     MainForm.LogInfo('准备写入竞足赛果 共'+inttostr(iListCount)+'', True);
 886     for i := 0 to iListCount - 1 do
 887     begin
 888       if FBList[i].Score = '' then
 889       begin
 890         Continue ;
 891       end;
 892       // 判断本次获取的数据,是否与上次一致,如果一致不进行保存
 893       sLotMacthId := 'ZQ' + '-' + FBList[i].ID;
 894       sMatchRet := trim(FBList[i].ID)
 895                   + '^' + trim(FBList[i].HalfScore)
 896                   + '^' + trim(FBList[i].Score)
 897                   + '^' + FloatToStr(FBList[i].SPFBonus)
 898                   + '^' + FloatToStr(FBList[i].RQSPFBonus)
 899                   + '^' + FloatToStr(FBList[i].BFBonus)
 900                   + '^' + FloatToStr(FBList[i].ZJQSBonus)
 901                   + '^' + FloatToStr(FBList[i].BQCSPFBonus);
 902       // 判断hashed是否存在
 903       sTmp := trim(hsl_Result.Values[trim(sLotMacthId)]);
 904       if sTmp = '' then
 905         hsl_Result.Add(trim(sLotMacthId) + '=' + sMatchRet)
 906       else
 907       begin
 908         if sTmp = Trim(sMatchRet) then
 909         begin
 910           //MainForm.LogInfo('【竞足赛果】无变更:' + sMatchRet, True);
 911           Inc(iNoChangeNum);
 912           Continue;
 913         end
 914         else
 915           hsl_Result.Values[trim(sLotMacthId)] := Trim(sMatchRet);
 916       end;
 917       // --------------------------------------------------------------
 918       sSQLString := 'CALL P_UPDATE_JCZQ_RESULT('
 919           + QuotedStr(FBList[i].ID)
 920          // + QuotedStr(FBList[i].MatchIndex)
 921           + ',' + QuotedStr(FBList[i].HalfScore)
 922           + ',' + QuotedStr(FBList[i].Score)
 923           + ',' + FloatToStr(FBList[i].SPFBonus)
 924           + ',' + FloatToStr(FBList[i].RQSPFBonus)
 925           + ',' + FloatToStr(FBList[i].BFBonus)
 926           + ',' + FloatToStr(FBList[i].ZJQSBonus)
 927           + ',' + FloatToStr(FBList[i].BQCSPFBonus)
 928           + ',@a); select @a;';
 929       iRepeat:=0;   //2015-02-05 liping.chen
 930       while True do
 931       begin
 932         try
 933           mqMain.Close;
 934           mqMain.SQL.Text := sSQLString;
 935           mqMain.Execute;
 936           iReturnCode := mqMain.Fields.Fields[0].AsInteger;
 937           Break;
 938         except on E : Exception do
 939           begin
 940             inc(iRepeat);
 941             {try        // 自动激活连接数据库
 942               mcMain.Disconnect;
 943               Sleep(50);
 944               mcMain.Connect;
 945             except
 946             end; }
 947 
 948             MainForm.LogInfo('竞足赛果'+sLotMacthId+'场次写入失败!第'+IntToStr(iRepeat)+''+ E.Message, True);
 949             // 若捕获,说明该场次没有存储成功,清空哈希对应的值
 950 
 951             mqMain.Close;
 952             if iRepeat=2 then
 953             begin
 954               hsl_Result.Values[trim(sLotMacthId)] :='';
 955               Break;
 956             end;
 957           end;
 958         end;
 959       end;
 960       if iRepeat=2 then
 961       begin
 962         Continue;
 963       end;
 964       if iReturnCode = 1 then              //数据验证失败
 965       begin
 966         MainForm.LogInfo('写入竞彩足球赛果失败,原因:数据验证失败', True);
 967         hsl_Result.Values[trim(sLotMacthId)] :='';
 968         Continue;
 969       end
 970       else if iReturnCode = 100 then
 971       begin
 972         MainForm.LogInfo('写入竞彩足球赛果失败,原因:未知错误', True);
 973         hsl_Result.Values[trim(sLotMacthId)] :='';
 974         Continue;
 975       end
 976       else if iReturnCode = 101 then
 977       begin
 978         MainForm.LogInfo('写入竞彩足球赛果失败,原因:在对阵中未找到场次' + FBList[i].ID, True);
 979         hsl_Result.Values[trim(sLotMacthId)] :='';
 980         Continue;
 981       end;
 982       FBCount :=  FBCount +1 ;
 983     end;
 984     MainForm.LogInfo('已写入竞足赛果'+IntToStr(FBCount)+'场;无变更'+ IntToStr(iNoChangeNum)+''+#13#10, True);
 985     Result := True;
 986   except on E : Exception do
 987     begin
 988       MainForm.LogInfo('写入竞彩赛果失败,原因:' + E.Message, True);
 989       Exit;
 990     end;
 991   end;
 992 end;
 993 
 994 procedure TJCResultThd.SetPause(const aIsPause: Boolean);
 995 begin
 996   Pause := aIsPause;
 997 end;
 998 
 999 function TJCResultThd.ParseFBTable(aTableStr: string): Boolean;
1000 var
1001   i, iTR, iPos1, iPos2, iArrayIndex: Integer;
1002   sRow, sMatchindex, sScore, sHalfScore, sStatus, sURL, sID: string;
1003 begin
1004   Result := False;
1005   try
1006     iTR := 0;
1007     iArrayIndex := 0;
1008     while PosEx('<tr', aTableStr, iTR + 1) > 0 do
1009     begin
1010       iTR := PosEx('<tr', aTableStr, iTR+1);
1011       iPos1 :=iTR;  // PosEx('<tr', aTableStr, iTR+1 ); //2015-02-05 liping.chen 第一条数据最后取,有弊端=》改善
1012       iPos2 := PosEx('</tr>', aTableStr, iPos1 + 1);
1013       sRow := Copy(aTableStr, iPos1, iPos2 - iPos1 + 5);
1014       // sRow := Copy(aTableStr, iTR, iPos2 - iPos1 + 5);
1015       if Pos('已完成', sRow) = 0 then Continue;
1016       iPos1 := Pos('<td', sRow);
1017       iPos1 := PosEx('<td', sRow, iPos1 + 1);
1018       iPos1 := PosEx('>', sRow, iPos1 + 1);
1019       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
1020       sMatchindex := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
1021       SetLength(FBList, Length(FBList) + 1);
1022       iArrayIndex := Length(FBList) - 1;
1023       //FBList[iArrayIndex].MatchIndex := ChangeCompIndex(sMatchindex);
1024       for i := 0 to 2 do
1025       begin
1026         iPos1 := PosEx('<td', sRow, iPos1 + 1);
1027       end;
1028       iPos1 := PosEx('>', sRow, iPos1 + 1);
1029       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
1030       sHalfScore := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
1031       FBList[iArrayIndex].HalfScore := sHalfScore;
1032       iPos1 := PosEx('<td', sRow, iPos1 + 1);
1033       iPos1 := PosEx('>', sRow, iPos1 + 1);
1034       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
1035       sScore := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
1036       FBList[iArrayIndex].Score := sScore;
1037       iPos1 := PosEx('<td', sRow, iPos1 + 1);
1038       iPos1 := PosEx('>', sRow, iPos1 + 1);
1039       iPos2 := PosEx('</td>', sRow, iPos1 + 1);
1040       sStatus := Copy(sRow, iPos1 + 1, iPos2 - iPos1 - 1);
1041       FBList[iArrayIndex].Status := sStatus;
1042       if sStatus = '已完成' then
1043       begin
1044         iPos1 := PosEx('href="', sRow, iPos1 + 1);
1045         iPos2 := PosEx('"', sRow, iPos1 + 7);
1046         sURL := Copy(sRow, iPos1 + 6, iPos2 - iPos1 - 6);
1047         iPos1 := Pos('=', sURL);
1048         sID := Copy(sURL, iPos1 + 1, Length(sURL) - iPos1);
1049 
1050         iPos1:=Pos('&s=fb',sID );        //2015-02-05 liping.chen 场次刚完成时,ID后会带有&s=fb 表示还没有详细信息
1051         if iPos1>0 then                  //要处理
1052         begin
1053           sID:=Copy(sID,1,Length(sID)-iPos1+1)
1054         end;
1055         FBList[iArrayIndex].ID := sID;
1056       end;
1057     end;
1058     Result := True;
1059   except on E : Exception do
1060     begin
1061       MainForm.LogInfo('解析足彩赛果表格时发生错误,原因:' + E.Message, True);
1062       MainForm.LogInfo(aTableStr, False);
1063     end;
1064   end;
1065 end;
1066 
1067 function TJCResultThd.GetFBDetail: Boolean;
1068 var
1069   idServer: TIdHTTP;
1070   i, iMatchIndex, iPos1, iPos2,j : Integer;
1071   sWholeURL, sResponse, sTable, sBonus,SPFResult : string;
1072   cBonus: Currency;
1073   sNote,sTmp : string;
1074 begin
1075   Result := False;
1076   j := 0 ;
1077   SPFResult := '' ;
1078   sNote := '';
1079   while J <=  3 do
1080   begin
1081       MainForm.LogInfo('开始获取竞彩足球详细赛果', True);
1082       idServer := TIdHTTP.Create(nil);
1083       try
1084         idServer.ReadTimeout := 20000 ;
1085         idServer.ConnectTimeout := 20000 ;
1086         try
1087           iMatchIndex := Length(FBList);
1088           for i := 0 to iMatchIndex - 1 do
1089           begin
1090             sNote := '';
1091             //
1092             if FBList[i].Status <> '已完成' then Continue;            //未完成的比赛不抓取
1093             sWholeURL := MainForm.FBDlResultAddress + FBDETAILURL + FBList[i].ID;
1094             try
1095               sResponse := idServer.Get(sWholeURL);
1096             except on e: Exception do
1097               begin
1098                 MainForm.LogInfo('抓取竞彩足球详细赛果时错误,场次为'+ QuotedStr(FBList[i].ID) +' 错误详情' + e.Message, True);
1099                 Continue;
1100               end;
1101             end;
1102             // 2013-12-19 rulinzhang add
1103             iPos1 := Pos('<form', sResponse);
1104             if iPos1 = 0 then
1105               iPos1 := Pos('<FORM', sResponse);
1106             sResponse := Copy(sResponse,iPos1 + 10,Length(sResponse) - iPos1 - 11);
1107             iPos1 := Pos('<form', sResponse);
1108             if iPos1 = 0 then
1109               iPos1 := Pos('<FORM', sResponse);
1110             sResponse := Copy(sResponse,iPos1,Length(sResponse) - iPos1);
1111             //
1112 
1113             iPos2 := Pos('</form>', sResponse);
1114             if iPos2 = 0 then
1115               iPos2 := Pos('</FORM', sResponse);
1116             sResponse := Copy(sResponse,1,Length(sResponse) - iPos2 - 10);
1117             //
1118             iPos1 := Pos('开奖结果及单注浮动奖金', sResponse);
1119             iPos2 := Length(sResponse);
1120             sResponse :=  Copy(sResponse, iPos1 ,iPos2);
1121             if iPos1 = 0 then
1122             begin
1123               MainForm.LogInfo('抓取竞彩足球详细赛果时出错,找不到匹配符号', True);
1124               MainForm.LogInfo('匹配符号:' + sResponse, False);
1125               Exit;
1126             end;
1127             //
1128             iPos1 := Pos('<table', sResponse);
1129             iPos2 := PosEx('</table>', sResponse, iPos1 + 1);
1130             sTable := Copy(sResponse, iPos1, iPos2 - iPos1 + 8);
1131       /////////////////////抓取足彩让球胜平负的SP////////////////////////////////
1132             sNote := '让球胜平负';
1133             iPos1 := Pos('让球胜平负', sTable);
1134             sTable := Copy(sResponse,ipos1,length(sTable));
1135             iPos1 := Pos('让球胜平负', sTable);
1136             iPos2 := PosEx('</td>', sTable, iPos1 + 1);
1137             sTable := Copy(sTable,iPos2 + 5,length(sTable));
1138             if iPos1 = 0 then
1139             begin
1140               MainForm.LogInfo('抓取竞彩足球详细赛果时出错,找不到胜平负匹配符号', True);
1141               MainForm.LogInfo('匹配符号:' + sTable, False);
1142               Exit;
1143             end;
1144             iPos1 := PosEx('<td', sTable, 1);
1145             iPos2 := PosEx('<', sTable, iPos1 + 1);
1146             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));   // (+1)
1147             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1148             iPos2 := PosEx('<', sTable, iPos1 + 1);
1149             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));  //
1150             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1151             iPos1 := PosEx('>', sTable, iPos1 + 1);
1152             iPos1 := PosEx('>', sTable, iPos1 + 1);
1153             iPos2 := PosEx('<', sTable, iPos1 + 1);
1154             sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));    // 4.68
1155             sNote := sNote + '^' + sBonus;
1156           // 取胜平负结果
1157            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1158            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1159            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1160            iPos1 := PosEx('>', sTable, iPos1 + 1);
1161            iPos1 := PosEx('>', sTable, iPos1 + 1);
1162            iPos2 := PosEx('<', sTable, iPos1 + 1);
1163            SPFResult :=  Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
1164            sNote := sNote + '^' + SPFResult;
1165             if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
1166             else begin
1167               cBonus := StrToCurrDef(sBonus, -1);
1168               if cBonus = -1 then
1169               begin
1170                 MainForm.LogInfo('抓取竞彩足球详细赛果的让球胜平负SP时出错', True);
1171                 MainForm.LogInfo('抓取竞彩足球详细赛果的让球胜平负SP时出错,抓取的到SP为:' + sBonus, False);
1172                 //Exit;
1173               end;
1174             end;
1175             FBList[i].RQSPFBonus := cBonus;
1176             sNote := sNote + '#';
1177 
1178             // 2013-06-05 rulinzhang add
1179             /////////////////////抓取足彩胜平负的SP////////////////////////////////
1180             sNote := sNote + '胜平负';
1181             sTable := Copy(sTable,ipos1,length(sTable));
1182             iPos1 := Pos('胜平负', sTable);
1183             iPos2 := PosEx('</td>', sTable, iPos1 + 1);
1184             sTable := Copy(sTable,iPos2 + 5,length(sTable));
1185             if iPos1 = 0 then
1186             begin
1187               MainForm.LogInfo('抓取竞彩足球详细赛果时出错,找不到胜平负匹配符号', True);
1188               MainForm.LogInfo('匹配符号:' + sTable, False);
1189               Exit;
1190             end;
1191             iPos1 := PosEx('<td', sTable, 1);
1192             iPos2 := PosEx('<', sTable, iPos1 + 1);
1193             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));   // (+1)
1194             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1195             iPos2 := PosEx('<', sTable, iPos1 + 1);
1196             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));  //
1197             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1198             iPos1 := PosEx('>', sTable, iPos1 + 1);
1199             iPos2 := PosEx('<', sTable, iPos1 + 1);
1200             sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));    // 4.68
1201             sNote := sNote + '^' + sBonus;
1202           // 取胜平负结果
1203            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1204            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1205            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1206            iPos1 := PosEx('>', sTable, iPos1 + 1);
1207            iPos1 := PosEx('>', sTable, iPos1 + 1);
1208            iPos2 := PosEx('<', sTable, iPos1 + 1);
1209            SPFResult :=  Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
1210            sNote := sNote + '^' + SPFResult;
1211            //
1212             if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
1213             else begin
1214               cBonus := StrToCurrDef(sBonus, -1);
1215               if cBonus = -1 then
1216               begin
1217                 MainForm.LogInfo('抓取竞彩足球详细赛果的胜平负SP时出错', True);
1218                 MainForm.LogInfo('抓取竞彩足球详细赛果的胜平负SP时出错,抓取的到SP为:' + sBonus, False);
1219                 //Exit;
1220               end;
1221             end;
1222             FBList[i].SPFBonus := cBonus;
1223             sNote := sNote + '#';
1224 
1225 
1226 
1227       /////////////////////抓取足彩比分的SP////////////////////////////////
1228      {       iPos1 := Pos('比分', sTable);
1229             if iPos1 = 0 then
1230             begin
1231               MainForm.LogInfo('抓取竞彩足球详细赛果时出错,找不到比分匹配符号', True);
1232               MainForm.LogInfo('匹配符号:' + sTable, False);
1233               Exit;
1234             end;
1235             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1236             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1237             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1238             iPos1 := PosEx('>', sTable, iPos1 + 1);
1239             iPos2 := PosEx('</td>', sTable, iPos1 + 1);
1240             sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
1241             if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
1242             else begin
1243               cBonus := StrToCurrDef(sBonus, -1);
1244               if cBonus = -1 then
1245               begin
1246                 MainForm.LogInfo('抓取竞彩足球详细赛果的比分SP时出错', True);
1247                 MainForm.LogInfo('抓取竞彩足球详细赛果的比分SP时出错,抓取的到SP为:' + sBonus, False);
1248                 Exit;
1249               end;
1250             end;
1251             FBList[i].BFBonus := cBonus;
1252      }
1253       /////////////////////抓取足彩总进球数的SP////////////////////////////////
1254             sNote := sNote + '总进球数';
1255             sTable := Copy(sTable,ipos1,length(sTable));
1256             iPos1 := Pos('总进球数', sTable);
1257             iPos2 := PosEx('</td>', sTable, iPos1 + 1);
1258             sTable := Copy(sTable,iPos2 + 5,length(sTable));
1259             if iPos1 = 0 then
1260             begin
1261               MainForm.LogInfo('抓取竞彩足球详细赛果时出错,找不到总进球数匹配符号', True);
1262               MainForm.LogInfo('匹配符号:' + sTable, False);
1263               Exit;
1264             end;
1265             iPos1 := PosEx('<td', sTable, 1);
1266             iPos2 := PosEx('<', sTable, iPos1 + 1);
1267             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));   // (+1)
1268             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1269             iPos2 := PosEx('<', sTable, iPos1 + 1);
1270             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));  //
1271             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1272             iPos1 := PosEx('>', sTable, iPos1 + 1);
1273             iPos2 := PosEx('<', sTable, iPos1 + 1);
1274             sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));    // 4.68
1275             sNote := sNote + '^' + sBonus;
1276           // 取胜平负结果
1277            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1278            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1279            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1280            iPos1 := PosEx('>', sTable, iPos1 + 1);
1281            iPos1 := PosEx('>', sTable, iPos1 + 1);
1282            iPos2 := PosEx('<', sTable, iPos1 + 1);
1283            SPFResult :=  Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
1284            sNote := sNote + '^' + SPFResult;
1285             if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
1286             else begin
1287               cBonus := StrToCurrDef(sBonus, -1);
1288               if cBonus = -1 then
1289               begin
1290                 MainForm.LogInfo('抓取竞彩足球详细赛果的总进球数SP时出错', True);
1291                 MainForm.LogInfo('抓取竞彩足球详细赛果的总进球数SP时出错,抓取的到SP为:' + sBonus, False);
1292                 Exit;
1293               end;
1294             end;
1295             FBList[i].ZJQSBonus := cBonus;
1296             sNote := sNote + '#';
1297       /////////////////////抓取足彩半全场胜平负的SP////////////////////////////////
1298             sNote := sNote + '半全场胜平负';
1299             sTable := Copy(sTable,ipos1,length(sTable));
1300             iPos1 := Pos('半全场胜平负', sTable);
1301             iPos2 := PosEx('</td>', sTable, iPos1 + 1);
1302             sTable := Copy(sTable,iPos2 + 5,length(sTable));
1303             if iPos1 = 0 then
1304             begin
1305               MainForm.LogInfo('抓取竞彩足球详细赛果时出错,找不到半全场胜平负匹配符号', True);
1306               MainForm.LogInfo('匹配符号:' + sTable, False);
1307               Exit;
1308             end;
1309             iPos1 := PosEx('<td', sTable, 1);
1310             iPos2 := PosEx('<', sTable, iPos1 + 1);
1311             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));   // (+1)
1312             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1313             iPos2 := PosEx('<', sTable, iPos1 + 1);
1314             sNote := sNote + '^' +  Trim(Copy(sTable, iPos1 + 4, iPos2 - iPos1 - 4));  //
1315             iPos1 := PosEx('<td', sTable, iPos1 + 1);
1316             iPos1 := PosEx('>', sTable, iPos1 + 1);
1317             iPos2 := PosEx('<', sTable, iPos1 + 1);
1318             sBonus := Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));    // 4.68
1319             sNote := sNote + '^' + sBonus;
1320           // 取胜平负结果
1321            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1322            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1323            iPos1 := PosEx('<td', sTable, iPos1 + 1);
1324            iPos1 := PosEx('>', sTable, iPos1 + 1);
1325            iPos1 := PosEx('>', sTable, iPos1 + 1);
1326            iPos2 := PosEx('<', sTable, iPos1 + 1);
1327            SPFResult :=  Trim(Copy(sTable, iPos1 + 1, iPos2 - iPos1 - 1));
1328            sNote := sNote + '^' + SPFResult;
1329             if (sBonus = '') or (sBonus = '无胜出投注') then cBonus := 0
1330             else begin
1331               cBonus := StrToCurrDef(sBonus, -1);
1332               if cBonus = -1 then
1333               begin
1334                 MainForm.LogInfo('抓取竞彩足球详细赛果的半全场胜平负SP时出错', True);
1335                 MainForm.LogInfo('抓取竞彩足球详细赛果的半全场胜平负SP时出错,抓取的到SP为:' + sBonus, False);
1336                 Exit;
1337               end;
1338             end;
1339             FBList[i].BQCSPFBonus := cBonus;
1340             FBList[i].reMark := sNote;
1341 
1342           end;
1343           MainForm.LogInfo('竞彩足球详细赛果获取完毕', True);
1344 
1345         except on E : Exception do
1346           begin
1347             MainForm.LogInfo('抓取竞彩足球详细赛果时出错,原因:' + E.Message, True);
1348           end;
1349         end;
1350       finally
1351         idServer.Free;
1352       end;
1353       if SPFResult ='' then
1354       begin
1355         j:= j + 1 ;
1356         MainForm.LogInfo('重新抓取竞彩足球赛果 序列号为 :' +QuotedStr(FBList[j].ID), True);
1357         result := true;
1358         break;
1359       end else
1360       begin
1361         j := 4 ;
1362         MainForm.LogInfo('获取竞彩足球详细赛果信息成功!' , True);
1363         Result := True ;
1364       end;
1365   end;
1366 end;
1367 
1368 end.
竞彩赛果

 

   1 {*******************************************************************************
   2   Copyright (C), 2011-2015, aicaipiao
   3   File name: 所在单元
   4   Author: 许国强
   5   Version: 版本
   6   Date: 2013.03.18
   7   History:
   8    6. Date:2014-09-17
   9         Author: rulinzhang   lipingchen
  10         Modification: 北单胜负赛程与赛果抓取
  11    5. Date:2013-06-09
  12         Author: 许国强
  13         Modification: 1.代码侁化 把没有的代码去除
  14                       2.增加显示清理文件路径目录
  15    4. Date:2013-05-17
  16         Author: 张儒林
  17         Modification: 代码侁化
  18    3. Date:2013.05.02
  19         Author: 许国强
  20         Modification:  增加一个清理过期临时文件线程,ThdClearOverdueFile
  21    2. Date:2013.04.28
  22         Author: 许国强
  23         Modification:  增加一个监控线程,ThdMonitor
  24    1. Date:2013.03.18
  25         Author: 许国强
  26         Modification:  处理北单获取赛果失败
  27 注:最近更新的内容放在最前面
  28 *******************************************************************************}
  29 
  30 unit FrmMain;
  31 
  32 interface
  33 
  34 uses
  35   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  36   Dialogs, RzTray, StdCtrls, Buttons, Spin, ComCtrls, PubDefine, SyncObjs,
  37   IniFiles, ShellAPI, xmldom, XMLIntf, oxmldom, XMLDoc, OleCtrls, SHDocVw,
  38   msxmldom, Menus, ExtCtrls,ThdBDResult,DateUtils, IdBaseComponent,
  39   IdComponent, IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer, md5, IdContext,
  40   IdSocketHandle, IdHTTP, StrUtils;
  41 
  42 type
  43   TMainForm = class(TForm)
  44     PageControl1: TPageControl;
  45     TabSheet1: TTabSheet;
  46     Label9: TLabel;
  47     Label2: TLabel;
  48     Label10: TLabel;
  49     Label13: TLabel;
  50     Label14: TLabel;
  51     speJCMatchGetInterval: TSpinEdit;
  52     edtDBConStr: TEdit;
  53     speJCResultGetInterval: TSpinEdit;
  54     TabSheet2: TTabSheet;
  55     Label1: TLabel;
  56     Label3: TLabel;
  57     Label4: TLabel;
  58     Label5: TLabel;
  59     edtBBMatchListAddress: TEdit;
  60     edtFBMatchListAddress: TEdit;
  61     edtBBGivenScoreAddress: TEdit;
  62     edtBBPresetScoreAddress: TEdit;
  63     TabSheet3: TTabSheet;
  64     Label11: TLabel;
  65     Label12: TLabel;
  66     edtBBResultAddress: TEdit;
  67     edtFBResultAddress: TEdit;
  68     bbtnSaveConfig: TBitBtn;
  69     GroupBox7: TGroupBox;
  70     cbCatchJCMatch: TCheckBox;
  71     cbCatchJCResult: TCheckBox;
  72     cbCatchGeneral: TCheckBox;
  73     GroupBox4: TGroupBox;
  74     memServerLog: TMemo;
  75     GroupBox1: TGroupBox;
  76     bbtnStart: TBitBtn;
  77     bbtnStop: TBitBtn;
  78     bbtnOpenLogFolder: TBitBtn;
  79     rztiMain: TRzTrayIcon;
  80     bbtnOpenLog: TBitBtn;
  81     Label6: TLabel;
  82     speGeneralGetInterval: TSpinEdit;
  83     Label7: TLabel;
  84     TabSheet4: TTabSheet;
  85     TabSheet5: TTabSheet;
  86     Label8: TLabel;
  87     edtDLTAddress: TEdit;
  88     edtQXCAddress: TEdit;
  89     edtPL3Address: TEdit;
  90     Label16: TLabel;
  91     Label17: TLabel;
  92     Label15: TLabel;
  93     Label18: TLabel;
  94     Label19: TLabel;
  95     edtLCBQCSFAddress: TEdit;
  96     edtSCJQAddress: TEdit;
  97     edtSFCAddress: TEdit;
  98     Label20: TLabel;
  99     edtBBDetailResultAddress: TEdit;
 100     Label21: TLabel;
 101     edtFBDetailResultAddress: TEdit;
 102     pmMain: TPopupMenu;
 103     N1: TMenuItem;
 104     N2: TMenuItem;
 105     N3: TMenuItem;
 106     Label22: TLabel;
 107     edtFBGoalLineAddress: TEdit;
 108     Label23: TLabel;
 109     edtFBStopMatchResultAddress: TEdit;
 110     btnMainToSecondary: TBitBtn;
 111     btnSecondaryToMain: TBitBtn;
 112     TabSheet6: TTabSheet;
 113     EdtBDSPF: TEdit;
 114     Label25: TLabel;
 115     Label24: TLabel;
 116     edtBDZJQS: TEdit;
 117     Label26: TLabel;
 118     EdtBDBQCSPF: TEdit;
 119     Label27: TLabel;
 120     edtBDSXPDSS: TEdit;
 121     EdtDBDCBF: TEdit;
 122     Label28: TLabel;
 123     Label29: TLabel;
 124     EdtBDMatch: TEdit;
 125     Label30: TLabel;
 126     speBDMatchGetInterval: TSpinEdit;
 127     Label31: TLabel;
 128     Label32: TLabel;
 129     speBDResultGetInterval: TSpinEdit;
 130     Label33: TLabel;
 131     WebBrowser1: TWebBrowser;
 132     cbSaveFile: TCheckBox;
 133     Button1: TButton;
 134     Button2: TButton;
 135     Button3: TButton;
 136     TabSheet7: TTabSheet;
 137     lbl1: TLabel;
 138     lbl2: TLabel;
 139     lbl3: TLabel;
 140     lbl4: TLabel;
 141     lbl5: TLabel;
 142     lbl6: TLabel;
 143     edtBDBQCSPFTempDirectory: TEdit;
 144     edtBDSXPDSSTempDirectory: TEdit;
 145     edtBDSPFTempDirectory: TEdit;
 146     edtBDDCBFTempDirectory: TEdit;
 147     edtBDZJQSTempDirectory: TEdit;
 148     edtBDDZTempDirectory: TEdit;
 149     lbl7: TLabel;
 150     edtLQYSZFTempDirectory: TEdit;
 151     lbl8: TLabel;
 152     lbl9: TLabel;
 153     lbl10: TLabel;
 154     edtLQRFTempDirectory: TEdit;
 155     edtZQDZTempDirectory: TEdit;
 156     edtLQDZTempDirectory: TEdit;
 157     lbl11: TLabel;
 158     edtLogDirectory: TEdit;
 159     idhtpsrvr1: TIdHTTPServer;
 160     lbl12: TLabel;
 161     lbl13: TLabel;
 162     EdtBDSFMatch: TEdit;
 163     EdtBDSF: TEdit;
 164     procedure FormCreate(Sender: TObject);
 165     procedure bbtnOpenLoClick(Sender: TObject);
 166     procedure bbtnOpenLogFolderClick(Sender: TObject);
 167     procedure bbtnSaveConfigClick(Sender: TObject);
 168     procedure bbtnStartClick(Sender: TObject);
 169     procedure bbtnStopClick(Sender: TObject);
 170     procedure cbCatchGeneralClick(Sender: TObject);
 171     procedure cbCatchJCMatchClick(Sender: TObject);
 172     procedure cbCatchJCResultClick(Sender: TObject);
 173     procedure FormClose(Sender: TObject; var Action: TCloseAction);
 174     procedure N1Click(Sender: TObject);
 175     procedure N3Click(Sender: TObject);
 176     procedure btnMainToSecondaryClick(Sender: TObject);
 177     procedure btnSecondaryToMainClick(Sender: TObject);
 178     procedure cbSaveFileClick(Sender: TObject);
 179     procedure WebBrowser1NewWindow2(Sender: TObject; var ppDisp: IDispatch;
 180       var Cancel: WordBool);
 181     procedure Button1Click(Sender: TObject);
 182     procedure Button2Click(Sender: TObject);
 183     procedure FormDestroy(Sender: TObject);
 184     procedure idhtpsrvr1CommandGet(AContext: TIdContext;
 185       ARequestInfo: TIdHTTPRequestInfo;
 186       AResponseInfo: TIdHTTPResponseInfo);
 187     procedure Button3Click(Sender: TObject);
 188     procedure FormShow(Sender: TObject);
 189   private
 190     pub_IsChangeServerFlag : Integer ;
 191     pub_IsSaveFileFlag : Integer ;
 192     Pub_SysBakDBConStr : string ;
 193     pub_SysDBConStr : string;
 194 
 195     ctsLog: TCriticalSection;
 196     FServerStatus: Integer;
 197     FDBConStr: string;
 198     FGeneralGetInv: Integer;
 199     FJCMatchGetInv: Integer;
 200     FJCResultGetInv: Integer;
 201     FBDMatchGetInv  : Integer ;
 202     FBDResultGetInv : Integer ;
 203     FBDSFMatchGetInv  : Integer;
 204     FBDSFResultGetInv : Integer;
 205 
 206     FBBResultAddress: string;
 207     FBBPresetScoreAddress: string;
 208     FFBResultAddress: string;
 209     FFBMatchAddress: string;
 210     FBBGivenScoreAddress: string;
 211     FBBMatchAddress: string;
 212     FFBDlResultAddress: string;
 213     FFBSMResultAddress : string;   // 足球停赛记录
 214     FFBGoalLineAddress : string;
 215     FBBDlResultAddress: string;
 216     FDLTAddress: string;
 217     FLCBQCSFAddress: string;
 218     FQXCAddress: string;
 219     FSFCAddress: string;
 220     FPLAddress: string;
 221     FSCJQAddress: string;
 222     FIsCatchJCResult: Boolean;
 223     FIsCatchJCMatch: Boolean;
 224     FIsCatchGeneral: Boolean;
 225     FIsSaveFile : Boolean;
 226     FBDMatchAddress : String ;
 227     FBDResultSPFAddress : String;
 228     FBDResultZJQSAddress : String ;
 229     FBDResultBQCSPFAddress : String;
 230     FBDResultSXPDSSAddress : String;
 231     FBDResultDCBFAddress : String ;
 232     // 北单胜负
 233     FBDSFMatchAddress :string;
 234     FBDSFResultAddress :String;
 235     //
 236     BDBQCSPFTempDir : String;
 237     BDDCBFTempDir : string;
 238     BDDZTempDir : string;
 239     BDSPFTempDir : string;
 240     BDSXPDSSTempDir : string;
 241     BDZJQSTempDir : string;
 242     LQDZTempDir : string;
 243     LQRFTempDir : string;
 244     LQYSZFTempDir : string;
 245     ZQDZTempDir : string;
 246     LogDir : string;
 247     // 2013-05-29 rulinzhang 控制线程是否启动
 248     iGeneralStart :Integer;
 249     iJCMatchStart :Integer;
 250     iJCResultStart :Integer;
 251     iBDMatchStart :Integer;
 252     iDBResultStart :Integer;
 253     iClearFileStart :Integer;
 254     iMonitorStart :Integer;
 255 
 256     iBDSFMatchStart :Integer;
 257     iDBSFResultStart :Integer;
 258     // 2013-11-26 guoqiang.xu 监听端口和地址
 259     sIP : string;
 260     sPort : Integer;
 261     sReqCode, sReqUserName, sReqKey, sReqSign, sReqExeName : string;
 262     //path : TStringList;
 263     procedure Init;                                            //初始化
 264     function ReadConfig: Boolean;                              //读取配置文件
 265     procedure WriteLog(aInfo: string);                         //记录日志
 266     procedure OpenLog(FileName: string);                       //打开日志
 267     procedure OpenLogDirectory(DirName: string);               //打开日志文件夹
 268     function SaveConfig(): Boolean;                            //保存配置文件
 269     function SystemClose: TCloseAction;                        //关闭事件
 270     function ReadClearConfig: Boolean;                         //读取清理文件配置 2013-04-28
 271     procedure FreeResource;                                    //关闭系统时是否资源
 272     procedure SetPause;                                        //向所有线程发送停止信息
 273 
 274     procedure SetServerStatus(const Value: Integer);
 275     procedure SetDBConStr(const Value: string);
 276     procedure SetGeneralGetInv(const Value: Integer);
 277     procedure SetJCMatchGetInv(const Value: Integer);
 278     procedure SetJCResultGetInv(const Value: Integer);
 279     procedure SetBDMatchGetInv(const Value: Integer);
 280     procedure setBDResultGetInv(const Value: Integer);
 281     procedure SetBBMatchAddress(const Value: string);
 282     procedure SetBBResultAddress(const Value: string);
 283     procedure SetBBGivenScoreAddress(const Value: string);
 284     procedure SetFBMatchAddress(const Value: string);
 285     procedure SetFBResultAddress(const Value: string);
 286     procedure SetBBPresetScoreAddress(const Value: string);
 287     procedure SetFBGoalLineAddress (const Value: string);
 288     procedure SetBBDlResultAddress(const Value: string);
 289     procedure SetFBDlResultAddress(const Value: string);
 290     procedure SetFBSMResultAddress(const Value: string);
 291     procedure SetDLTAddress(const Value: string);
 292     procedure SetLCBQCSFAddress(const Value: string);
 293     procedure SetPLAddress(const Value: string);
 294     procedure SetQXCAddress(const Value: string);
 295     procedure SetSCJQAddress(const Value: string);
 296     procedure SetSFCAddress(const Value: string);
 297     procedure SetIsCatchGeneral(const Value: Boolean);
 298     procedure SetIsCatchJCMatch(const Value: Boolean);
 299     procedure SetIsCatchJCResult(const Value: Boolean);
 300     procedure SetIsSaveFile(const Value: Boolean);
 301     // 北单
 302     procedure setBDMatchAddress(const Value: string);
 303     procedure setBDResultSPFAddress(const Value: string);
 304     procedure setBDResultZJQSAddress(const Value: string);
 305     procedure setBDResultBQCSPFAddress(const Value: string);
 306     procedure setBDResultSXPDSSAddress(const Value: string);
 307     procedure setBDResultDCBFAddress(const Value: string);
 308     procedure setBDSFMatchAddress(const Value: string);
 309     procedure setBDSFResultAddress(const Value: string);
 310     // 2013-06-09 guoqiang.xu 增加清理文件路径显示过程
 311     procedure ShowClearFileDir;
 312     // 2013-11-26 guoqiang.xu 监听请求
 313     procedure SetServerHostAndPort;
 314     function GetReply(ARequest: string): Integer;
 315     { Private declarations }
 316   public
 317     { Public declarations }
 318     IsJCMatchCatching: Boolean;
 319     IsJCResultCatching: Boolean;
 320     IsGeneralCatching: Boolean;
 321     IsBDMatchCatching : boolean;
 322     IsBDResultCatching : Boolean;
 323     //
 324     IsBDSFMatchCatching : boolean;
 325     IsBDSFResultCatching : Boolean;
 326     //
 327     IDateLimit : string;
 328     slDirList : TStringList;
 329     sClearTimeStrat : string;
 330     sClearTimeEnd : string;
 331 
 332     Pub_GetMatch: TCriticalSection;       // 获取赛程临界
 333 
 334     property ServerStatu: Integer read FServerStatus write SetServerStatus;               //服务器当前状态 0:读取配置失败  1:停止  2:运行中
 335     property DBConStr: string read FDBConStr write SetDBConStr;
 336     property GeneralGetInv: Integer read FGeneralGetInv write SetGeneralGetInv;
 337     property JCMatchGetInv: Integer read FJCMatchGetInv write SetJCMatchGetInv;
 338     property JCResultGetInv: Integer read FJCResultGetInv write SetJCResultGetInv;
 339     property BDMatchGetInv : integer read FBDMatchGetInv write setBDMatchGetInv;       // 北单对阵抓取时间
 340     property BDResultGetInv : integer read FBDResultGetInv write setBDResultGetInv;       // 北单赛程抓取时间
 341 
 342     property BBMatchAddress: string read FBBMatchAddress write SetBBMatchAddress;           //竞彩篮球比赛场次获取地址
 343     property FBMatchAddress: string read FFBMatchAddress write SetFBMatchAddress;           //竞彩足球比赛场次获取地址
 344     property BBGivenScoreAddress: string read FBBGivenScoreAddress write SetBBGivenScoreAddress;           //竞彩篮球让分情况获取地址
 345     property BBPresetScoreAddress: string read FBBPresetScoreAddress write SetBBPresetScoreAddress;           //竞彩篮球预设总分情况获取地址
 346     property FBGoalLineAddress : string read FFBGoalLineAddress write SetFBGoalLineAddress;  //竞彩足球让分情况获取地址
 347     property BBResultAddress: string read FBBResultAddress write SetBBResultAddress;        //竞彩篮球赛果获取地址
 348     property FBResultAddress: string read FFBResultAddress write SetFBResultAddress;        //竞彩足球赛果获取地址
 349     property BBDlResultAddress: string read FBBDlResultAddress write SetBBDlResultAddress;    //竞彩篮球详细赛果获取地址
 350     property FBDlResultAddress: string read FFBDlResultAddress write SetFBDlResultAddress;    //竞彩足球详细赛果获取地址
 351     property FBSMResultAddress: string read FFBSMResultAddress write SetFBSMResultAddress;    //竞彩足球停赛结果获取地址
 352     property DLTAddress: string read FDLTAddress write SetDLTAddress;                   //大乐透开奖结果果获取地址
 353     property QXCAddress: string read FQXCAddress write SetQXCAddress;                   //七星彩开奖结果果获取地址
 354     property PLAddress: string read FPLAddress write SetPLAddress;                      //排三排五开奖结果果获取地址
 355     property SFCAddress: string read FSFCAddress write SetSFCAddress;                   //胜负彩任九开奖结果果获取地址
 356     property SCJQAddress: string read FSCJQAddress write SetSCJQAddress;                //四场进球开奖结果果获取地址
 357     property LCBQCSFAddress: string read FLCBQCSFAddress write SetLCBQCSFAddress;       //六场半全场胜负开奖结果果获取地址
 358     property IsCatchGeneral: Boolean read FIsCatchGeneral write SetIsCatchGeneral;      //是否抓取普通体彩开奖结果
 359     property IsCatchJCMatch: Boolean read FIsCatchJCMatch write SetIsCatchJCMatch;      //是否抓取竞彩对阵
 360     property IsCatchJCResult: Boolean read FIsCatchJCResult write SetIsCatchJCResult;   //是否抓取竞彩赛果
 361     property IsSaveFile : Boolean read  FIsSaveFile write  setIsSaveFile;    // 是否保存抓取数据文件
 362     property BDMatchAddress : string read  FBDMatchAddress write  setBDMatchAddress;    // 北单场次地址
 363 
 364     property BDResultSPFAddress : string read  FBDResultSPFAddress write  setBDResultSPFAddress;  // 北单胜平负结果地址
 365     property BDResultZJQSAddress : string read  FBDResultZJQSAddress write  setBDResultZJQSAddress;    // 北单胜总进球数地址
 366     property BDResultBQCSPFAddress : string read  FBDResultBQCSPFAddress write  setBDResultBQCSPFAddress;  // 半全场胜平负地址
 367     property BDResultSXPDSSAddress : string read  FBDResultSXPDSSAddress write  setBDResultSXPDSSAddress;   //  上下盘单双数
 368     property BDResultDCBFAddress : string read  FBDResultDCBFAddress write  setBDResultDCBFAddress;   //  单场比分
 369 
 370     property BDSFMatchAddress : string read  FBDSFMatchAddress write  setBDSFMatchAddress;    // 北单胜负场次地址
 371     property BDSFResultAddress : string read  FBDSFResultAddress write  setBDSFResultAddress;  // 北单胜负结果地址
 372 
 373     procedure LogInfo(aInfo: string; IsShow: Boolean);                                  //显示日志
 374     function  SaveFile(Content : string ;PathFileName : string ) : Boolean;
 375 
 376 
 377   end;
 378 
 379 
 380 
 381 var
 382   MainForm: TMainForm;
 383 
 384 
 385 implementation
 386 
 387 uses ThdJCMatch, ThdJCResult, ThdGeneral, ThdBDMatch,
 388 UntFrmOther, ThdClearOverdueFile, ThdMonitor,UntFrmHandJC,ThdBDSFMatch,ThdBDSFResult;
 389 
 390 {$R *.dfm}
 391 
 392 var
 393   JCMatchThd: TJCMatchThd;
 394   JCResultThd: TJCResultThd;
 395   GeneralThd: TGeneralThd;
 396   BDMatchThd : TBDMatchThd;
 397   BDResultThd : TBDResultThd;
 398   BDSFMatchThd : TBDSFMatchThd;
 399   BDSFResultThd : TBDSFResultThd;
 400   ClearOverdueFileThd : TClearOverdueFileThd;
 401   MonitorThd : TMonitorThd;
 402   //addLogThread :  TAddLogThread
 403   Hand_JCMatchThd: TJCMatchThd;
 404   Hand_JCResultThd: TJCResultThd;
 405   Hand_BDMatchThd : TBDMatchThd;
 406   Hand_BDResultThd : TBDResultThd;
 407 
 408   Hand_BDSFMatchThd : TBDSFMatchThd;
 409   Hand_BDSFResultThd : TBDSFResultThd;
 410 
 411 { TMainForm }
 412 
 413 procedure  DoNavigator(var Aurl : string);
 414 begin
 415   MainForm.WebBrowser1.Navigate(Aurl);
 416 end;
 417 
 418 procedure  DoParse(var Content: string);
 419 var OldTime : TDateTime;
 420 begin
 421   if MainForm.WebBrowser1.ReadyState = READYSTATE_COMPLETE then
 422   begin
 423     Content := MainForm.WebBrowser1.OleObject.Document.all.tags('HTML').Item(0).outerHTML;
 424      //MainForm.SaveFile(Content,'BDTest');
 425   end
 426   else
 427   begin
 428     //2013.03.18 guoqiang.xu update 北单获取赛果异常
 429     OldTime := Now;
 430     while True do
 431     begin
 432        Sleep(10);
 433        if SecondsBetween(OldTime, Now) > 1 then Break;
 434        Application.ProcessMessages;
 435     end;
 436   end;
 437 end;
 438 
 439 procedure TMainForm.Init;
 440 var
 441   slConnection: TStringList;
 442 begin
 443   slConnection := TStringList.Create;
 444   try
 445     Pub_EXEPath := ExtractFileDir(Application.ExeName);
 446     WebBrowser1.Silent := True;
 447     if (not ReadConfig) or (not ReadClearConfig) then
 448     begin
 449       SetServerStatus(0);
 450       LogInfo('初始化配置失败!', True);
 451       Exit;
 452     end;
 453     // 2013-06-09 guoqiang.xu add 显示清理文件目录
 454     ShowClearFileDir;
 455     //
 456     slConnection.Delimiter := '&';
 457     slConnection.DelimitedText := DBConStr;
 458     ConnectionConfig.Server := slConnection.Values['Server'];
 459     ConnectionConfig.Username := slConnection.Values['Username'];
 460     ConnectionConfig.Password := slConnection.Values['Password'];
 461     ConnectionConfig.Port := StrToInt(slConnection.Values['Port']);
 462     ConnectionConfig.Database := slConnection.Values['Database'];
 463     SetIsCatchGeneral(True);
 464     SetIsCatchJCMatch(True);
 465     SetIsCatchJCResult(True);
 466    // SetIsSaveFile(pub_IsSaveFileFlag);
 467     SetServerStatus(1);
 468     // 传统线程
 469     if iGeneralStart = 1 then
 470       GeneralThd := TGeneralThd.Create;
 471     // 竞彩线程
 472     if iJCMatchStart = 1 then
 473       JCMatchThd := TJCMatchThd.Create(0,FJCMatchGetInv);
 474     if iJCResultStart = 1 then
 475       JCResultThd := TJCResultThd.Create(0,FJCResultGetInv);
 476     // 北单线程
 477     if iBDMatchStart = 1 then
 478       BDMatchThd := TBDMatchThd.Create(0,FBDMatchGetInv);
 479     if iDBResultStart = 1 then
 480       BDResultThd := TBDResultThd.create(DoNavigator,DoParse,0,FBDResultGetInv);
 481 
 482     if iBDSFMatchStart = 1 then
 483        BDSFMatchThd := TBDSFMatchThd.Create(0,FBDSFMatchGetInv);
 484     if iDBSFResultStart = 1 then
 485        BDSFResultThd := TBDSFResultThd.create(0,FBDSFResultGetInv);
 486      //--------------------------------------------
 487     // TAddLogThread.Create;
 488     //2013-5-2
 489     if iClearFileStart = 1 then
 490     begin
 491       slDirList.Clear;
 492       slDirList.Delimiter := '|';
 493       slDirList.DelimitedText := BDBQCSPFTempDir +'|'+ BDDCBFTempDir +'|'+ BDDZTempDir +'|'+ BDSPFTempDir +'|'+ BDSXPDSSTempDir +'|'+ BDZJQSTempDir+'|'
 494                                  + LQDZTempDir + '|' + LQRFTempDir + '|' + LQYSZFTempDir + '|' + ZQDZTempDir + '|' + LogDir;
 495       ClearOverdueFileThd := TClearOverdueFileThd.create;
 496       ClearOverdueFileThd.resume;
 497     end;
 498     // 线程监控
 499     if iMonitorStart = 1 then
 500     begin
 501       MonitorThd := TMonitorThd.create;
 502       MonitorThd.resume;
 503     end;
 504     //2013-11-28 guoqiang.xu 开启http监听
 505     try
 506       SetServerHostAndPort;
 507       idhtpsrvr1.Active := True;
 508       if idhtpsrvr1.Active then
 509         LogInfo('监听服务器启动成功!', true)
 510       else
 511         LogInfo('监听服务器启动失败!', true);
 512     except on E : Exception do
 513       begin
 514         LogInfo('监听服务器启动失败!'+ E.Message, true);
 515       end;
 516     end;
 517     //
 518     LogInfo('初始化成功', True);
 519   finally
 520     if slConnection <> nil then slConnection.Free;
 521   end;
 522 end;
 523 
 524 procedure TMainForm.SetServerHostAndPort;
 525 var
 526   Binding : TIdSocketHandle;
 527 begin
 528   idhtpsrvr1.Bindings.Clear;
 529   //1.绑定IP地址和端口
 530   idhtpsrvr1.DefaultPort := 80;   //若有固定绑定端口参数,一定要写这个
 531   Binding := idhtpsrvr1.Bindings.Add;
 532   Binding.IP := sIP;
 533   Binding.Port := sPort;
 534 end;
 535 
 536 function TMainForm.ReadConfig: Boolean;
 537 var
 538   MyIniFile: TIniFile;
 539 begin
 540   Result := false;
 541   MyIniFile := TIniFile.Create(Pub_EXEPath + '\CatchServer.ini');
 542   try
 543     try
 544       // 竞彩
 545       SetJCMatchGetInv(MyIniFile.ReadInteger('Config', 'JCMatchGetInterval', 60));
 546       SetJCResultGetInv(MyIniFile.ReadInteger('Config', 'JCResultGetInterval', 60));
 547       // 传统
 548       SetGeneralGetInv(MyIniFile.ReadInteger('Config', 'GeneralGetInterval', 60));
 549       // 北单
 550       setBDResultGetInv(MyIniFile.ReadInteger('Config', 'BDResultGetInterval', 60));
 551       SetBDMatchGetInv(MyIniFile.ReadInteger('Config', 'BDMatchGetInterval', 60));
 552       // 2014-09-17 北单胜负
 553       FBDSFMatchGetInv := MyIniFile.ReadInteger('Config', 'BDSFMatchGetInterval', 600);
 554       FBDSFResultGetInv := MyIniFile.ReadInteger('Config', 'BDSFResultGetInterval', 600);
 555       // 数据库连接
 556       pub_SysDBConStr := MyIniFile.ReadString('Config', 'DBConnectionString', '');
 557       Pub_SysBakDBConStr := Trim(MyIniFile.ReadString('Config', 'BakDBConnectionString', ''));
 558       pub_IsChangeServerFlag := MyIniFile.ReadInteger('Config', 'IsChangeServerFlag', 0);
 559       if  pub_IsChangeServerFlag=0 then
 560         SetDBConStr(pub_SysDBConStr)
 561       else
 562         SetDBConStr(Pub_SysBakDBConStr);
 563       // 保存状态
 564       pub_IsSaveFileFlag   :=  MyIniFile.ReadInteger('Config', 'IsSaveFileFlag', 0);
 565       if pub_IsSaveFileFlag = 0 then
 566         SetIsSaveFile(False)
 567       else
 568         SetIsSaveFile(True);
 569       //
 570       SetBBMatchAddress(MyIniFile.ReadString('Config', 'BBMatchAddress', ''));
 571       SetFBMatchAddress(MyIniFile.ReadString('Config', 'FBMatchAddress', ''));
 572       SetBBGivenScoreAddress(MyIniFile.ReadString('Config', 'BBGivenScoreAddress', ''));
 573       SetBBPresetScoreAddress(MyIniFile.ReadString('Config', 'BBPresetScoreAddress', ''));
 574       SetBBResultAddress(MyIniFile.ReadString('Config', 'BBResultAddress', ''));
 575       SetFBResultAddress(MyIniFile.ReadString('Config', 'FBResultAddress', ''));
 576       SetFBGoalLineAddress(MyIniFile.ReadString('Config', 'FBGoalLineAddress', ''));
 577       SetBBDlResultAddress(MyIniFile.ReadString('Config', 'BBDetailResultAddress', ''));
 578       SetFBDlResultAddress(MyIniFile.ReadString('Config', 'FBDetailResultAddress', ''));
 579       SetFBSMResultAddress(MyIniFile.ReadString('Config', 'FBStopMatchResultAddress', ''));
 580       SetDLTAddress(MyIniFile.ReadString('Config', 'DLTAddress', ''));
 581       SetQXCAddress(MyIniFile.ReadString('Config', 'QXCAddress', ''));
 582       SetPLAddress(MyIniFile.ReadString('Config', 'PLAddress', ''));
 583       SetSFCAddress(MyIniFile.ReadString('Config', 'SFCAddress', ''));
 584       SetSCJQAddress(MyIniFile.ReadString('Config', 'SCJQAddress', ''));
 585       SetLCBQCSFAddress(MyIniFile.ReadString('Config', 'LCBQCSFAddress', ''));
 586       setBDMatchAddress(MyIniFile.ReadString('Config', 'BDMatchAddress', ''));
 587       setBDResultSPFAddress(MyIniFile.ReadString('Config', 'BDResultSPFAddress', ''));
 588       setBDResultZJQSAddress(MyIniFile.ReadString('Config', 'BDResultZJQSAddress', ''));
 589       setBDResultBQCSPFAddress(MyIniFile.ReadString('Config', 'BDResultBQCSPFAddress', ''));
 590       setBDResultDCBFAddress(MyIniFile.ReadString('Config', 'BDResultDCBFAddress', ''));
 591       setBDResultSXPDSSAddress(MyIniFile.ReadString('Config', 'BDResultSXPDSSAddress', ''));
 592       setBDSFMatchAddress(MyIniFile.ReadString('Config', 'BDSFMatchAddress', ''));
 593       setBDSFResultAddress(MyIniFile.ReadString('Config', 'BDSFResultAddress', ''));
 594       //2013-05-29 rulinzhang 读取启动线程配置文件
 595       iGeneralStart := MyIniFile.ReadInteger('setup', 'GeneralStart', 0);
 596       iJCMatchStart := MyIniFile.ReadInteger('setup', 'JCMatchStart', 0);
 597       iJCResultStart := MyIniFile.ReadInteger('setup', 'JCResultStart', 0);
 598       iBDMatchStart := MyIniFile.ReadInteger('setup', 'BDMatchStart', 0);
 599       iDBResultStart := MyIniFile.ReadInteger('setup', 'DBResultStart', 0);
 600       iClearFileStart := MyIniFile.ReadInteger('setup', 'ClearFileStart', 0);
 601       iMonitorStart := MyIniFile.ReadInteger('setup', 'MonitorStart', 0);
 602       // 2014-07-27 rulinzhang add
 603       iBDSFMatchStart := MyIniFile.ReadInteger('setup', 'BDSFMatchStart', 0);
 604       iDBSFResultStart := MyIniFile.ReadInteger('setup', 'DBSFResultStart', 0);
 605       //2013-11-26 guoqiang.xu 配置http监听地址和端口
 606       sIP := MyIniFile.ReadString('handCatch', 'IP', '127.0.0.1');
 607       sPort := MyIniFile.ReadInteger('handCatch', 'Port', 80);
 608       //
 609       Result := true;
 610     except on E : Exception do
 611       begin
 612         WriteLog(E.Message);
 613         Exit;
 614       end;
 615     end;
 616   finally
 617     MyIniFile.Free;
 618   end;
 619 end;
 620 
 621 // 2013-04-28 guoqiang.xu
 622 function TMainForm.ReadClearConfig: Boolean;
 623 var
 624   MyIniFile: TIniFile;
 625 begin
 626   Result := True;
 627   MyIniFile := TIniFile.Create(Pub_EXEPath + '\ClearCatchServer.ini');
 628   try
 629     try
 630       BDBQCSPFTempDir := (MyIniFile.ReadString('ClearConfig', 'BDBQCSPFTempDir', ''));
 631       BDDCBFTempDir := (MyIniFile.ReadString('ClearConfig', 'BDDCBFTempDir', ''));
 632       BDDZTempDir := (MyIniFile.ReadString('ClearConfig', 'BDDZTempDir', ''));
 633       BDSPFTempDir := (MyIniFile.ReadString('ClearConfig', 'BDSPFTempDir', ''));
 634       BDSXPDSSTempDir := (MyIniFile.ReadString('ClearConfig', 'BDSXPDSSTempDir', ''));
 635       BDZJQSTempDir := (MyIniFile.ReadString('ClearConfig', 'BDZJQSTempDir', ''));
 636       LQDZTempDir := (MyIniFile.ReadString('ClearConfig', 'LQDZTempDir', ''));
 637       LQRFTempDir := (MyIniFile.ReadString('ClearConfig', 'LQRFTempDir', ''));
 638       LQYSZFTempDir := (MyIniFile.ReadString('ClearConfig', 'LQYSZFTempDir', ''));
 639       ZQDZTempDir := (MyIniFile.ReadString('ClearConfig', 'ZQDZTempDir', ''));
 640       LogDir :=(MyIniFile.ReadString('ClearConfig', 'LogDir', ''));
 641       IDateLimit := (MyIniFile.ReadString('ClearConfig', 'IDateLimit', ''));
 642       sClearTimeStrat := (MyIniFile.ReadString('ClearConfig', 'sClearTimeStrat', ''));
 643       sClearTimeEnd := (MyIniFile.ReadString('ClearConfig', 'sClearTimeEnd', ''));
 644     except on E : Exception do
 645       begin
 646         WriteLog(E.Message);
 647         Result := False;
 648       end;
 649     end;
 650   finally
 651     MyIniFile.Free;
 652   end;   
 653 end;
 654 
 655 procedure TMainForm.SetServerStatus(const Value: Integer);
 656 begin
 657   FServerStatus := Value;
 658   case Value of
 659     0 :                    //0:读取配置失败
 660       begin
 661         bbtnSaveConfig.Enabled := True;
 662         bbtnStart.Enabled := False;
 663         bbtnStop.Enabled := False;
 664         cbCatchGeneral.Enabled := False;
 665         cbCatchJCMatch.Enabled := False;
 666         cbCatchJCResult.Enabled := False;
 667         cbSaveFile.Enabled := False; 
 668       end;
 669     1 :                    //1:停止
 670       begin
 671         bbtnSaveConfig.Enabled := True;
 672         bbtnStart.Enabled := True;
 673         bbtnStop.Enabled := False;
 674         cbCatchGeneral.Enabled := True;
 675         cbCatchJCMatch.Enabled := True;
 676         cbCatchJCResult.Enabled := True;
 677         cbSaveFile.Enabled := True; 
 678       end;
 679     2 :                    //2:运行中
 680       begin
 681         bbtnSaveConfig.Enabled := False;
 682         bbtnStart.Enabled := False;
 683         bbtnStop.Enabled := False;
 684         cbCatchGeneral.Enabled := False;
 685         cbCatchJCMatch.Enabled := False;
 686         cbCatchJCResult.Enabled := False;
 687         cbSaveFile.Enabled := False; 
 688       end;
 689     3 :                    //3:等待中
 690       begin
 691         bbtnSaveConfig.Enabled := False;
 692         bbtnStart.Enabled := False;
 693         bbtnStop.Enabled := True;
 694         cbCatchGeneral.Enabled := False;
 695         cbCatchJCMatch.Enabled := False;
 696         cbCatchJCResult.Enabled := False;
 697         cbSaveFile.Enabled := False;
 698         if iGeneralStart = 1 then
 699           GeneralThd.SetPause(False);
 700         if iJCMatchStart = 1 then
 701           JCMatchThd.SetPause(False);
 702         if iJCResultStart = 1 then
 703           JCResultThd.SetPause(False);
 704         if iBDMatchStart = 1 then
 705           BDMatchThd.SetPause(False);
 706         if iDBResultStart = 1 then
 707           BDResultThd.SetPause(False);
 708         // 2014-07-24 rulinzhang add
 709         if iBDSFMatchStart = 1 then
 710             BDSFMatchThd.SetPause(False);
 711         if iDBSFResultStart = 1 then
 712            BDSFResultThd.SetPause(False);
 713       end;
 714   end;
 715 end;
 716 
 717 procedure TMainForm.SetBBMatchAddress(const Value: string);
 718 begin
 719   FBBMatchAddress := Value;
 720   edtBBMatchListAddress.Text := Value;
 721 end;
 722 
 723 procedure TMainForm.SetBBResultAddress(const Value: string);
 724 begin
 725   FBBResultAddress := Value;
 726   edtBBResultAddress.Text := Value;
 727 end;
 728 
 729 procedure TMainForm.SetBBGivenScoreAddress(const Value: string);
 730 begin
 731   FBBGivenScoreAddress := Value;
 732   edtBBGivenScoreAddress.Text := Value;
 733 end;
 734 
 735 procedure TMainForm.SetDBConStr(const Value: string);
 736 begin
 737   FDBConStr := Value;
 738   edtDBConStr.Text := Value;
 739 end;
 740 
 741 procedure TMainForm.SetDLTAddress(const Value: string);
 742 begin
 743   FDLTAddress := Value;
 744   edtDLTAddress.Text := Value;
 745 end;
 746 
 747 procedure TMainForm.SetFBMatchAddress(const Value: string);
 748 begin
 749   FFBMatchAddress := Value;
 750   edtFBMatchListAddress.Text := Value;
 751 end;
 752 
 753 procedure TMainForm.SetFBResultAddress(const Value: string);
 754 begin
 755   FFBResultAddress := Value;
 756   edtFBResultAddress.Text := Value;
 757 end;
 758 
 759 procedure TMainForm.SetBBPresetScoreAddress(const Value: string);
 760 begin
 761   FBBPresetScoreAddress := Value;
 762   edtBBPresetScoreAddress.Text := Value;
 763 end;
 764 
 765 procedure TmainForm.SetFBGoalLineAddress(const value : string);
 766 begin
 767   FFBGoalLineAddress := value ;
 768   edtFBGoalLineAddress.text :=  value;
 769 end;
 770 
 771 procedure TMainForm.SetGeneralGetInv(const Value: Integer);
 772 begin
 773   FGeneralGetInv := Value;
 774   speGeneralGetInterval.Value := Value;
 775 end;
 776 
 777 procedure TMainForm.SetJCMatchGetInv(const Value: Integer);
 778 begin
 779   FJCMatchGetInv := Value;
 780   speJCMatchGetInterval.Value := Value;
 781 end;
 782 
 783 procedure TMainForm.SetJCResultGetInv(const Value: Integer);
 784 begin
 785   FJCResultGetInv := Value;
 786   speJCResultGetInterval.Value := Value;
 787 end;
 788 
 789 procedure TMainForm.SetLCBQCSFAddress(const Value: string);
 790 begin
 791   FLCBQCSFAddress := Value;
 792   edtLCBQCSFAddress.Text := Value;
 793 end;
 794 
 795 procedure TMainForm.SetPLAddress(const Value: string);
 796 begin
 797   FPLAddress := Value;
 798   edtPL3Address.Text := Value;
 799 end;
 800 
 801 procedure TMainForm.SetQXCAddress(const Value: string);
 802 begin
 803   FQXCAddress := Value;
 804   edtQXCAddress.Text := Value;
 805 end;
 806 
 807 procedure TMainForm.SetSCJQAddress(const Value: string);
 808 begin
 809   FSCJQAddress := Value;
 810   edtSCJQAddress.Text := Value;
 811 end;
 812 
 813 procedure TMainForm.SetSFCAddress(const Value: string);
 814 begin
 815   FSFCAddress := Value;
 816   edtSFCAddress.Text := Value;
 817 end;
 818 
 819 procedure TMainForm.LogInfo(aInfo: string; IsShow: Boolean);
 820 begin
 821   ctsLog.Enter;
 822   try
 823     if memServerLog.Lines.Count > 100 then memServerLog.Clear;
 824     aInfo := FormatDateTime('yyyy-mm-dd HH:mm:ss', Now) + '-----' + aInfo;
 825     memServerLog.Lines.Append(aInfo);
 826     WriteLog(aInfo);
 827   finally
 828     ctsLog.Leave;
 829   end;
 830 end;
 831 
 832 procedure TMainForm.WriteLog(aInfo: string);
 833 var
 834   sFileName: string;
 835   tfRecordFile: Textfile;
 836 begin
 837   try
 838     if not DirectoryExists(Pub_EXEPath + '\日志') then CreateDir(Pub_EXEPath + '\日志');
 839     sFileName:= Pub_EXEPath + '\日志\' + FormatDateTime('yyyy-mm-dd', Date) + '.txt';
 840     AssignFile(tfRecordFile, sFileName);
 841     if not FileExists(sFileName) then Rewrite(tfRecordFile)
 842     else begin
 843       Reset(tfRecordFile);
 844       Append(tfRecordFile);
 845     end;
 846     Writeln(tfRecordFile, aInfo);
 847   finally
 848     CloseFile(tfRecordFile);
 849   end;
 850 end;
 851 
 852 procedure TMainForm.FormCreate(Sender: TObject);
 853 begin
 854   Pub_GetMatch := TCriticalSection.Create;       // 获取赛程临界
 855   ctsLog := TCriticalSection.Create;
 856   slDirList := TStringList.Create;
 857 end;
 858 
 859 procedure TMainForm.bbtnOpenLoClick(Sender: TObject);
 860 var
 861   sLogName: string;
 862 begin
 863   sLogName := Pub_EXEPath + '\日志\' + FormatDateTime('yyyy-mm-dd',date())+'.txt';
 864   if not FileExists(sLogName) then
 865   begin
 866     MessageBox(0, '今日无错误日志!', '提示', MB_OK + MB_ICONINFORMATION);
 867     Exit;
 868   end;
 869   try
 870     OpenLog(sLogName);
 871   except on E : Exception do
 872     begin
 873       LogInfo('打开日志文件出错,原因:' + E.Message, True);
 874       MessageBox(0, '打开日志文件出错,请重试!', '错误', MB_OK + MB_ICONERROR);
 875     end;
 876   end;
 877 end;
 878 
 879 procedure TMainForm.bbtnOpenLogFolderClick(Sender: TObject);
 880 var
 881   sDirName: string;
 882 begin
 883   sDirName := Pub_EXEPath + '\日志';
 884   if not DirectoryExists(sDirName) then CreateDir(sDirName);
 885   try
 886     OpenLogDirectory(sDirName);
 887   except on E : Exception do
 888     begin
 889       LogInfo('打开日志目录出错,原因:' + E.Message, True);
 890       MessageBox(0, '打开日志目录出错,请重试!', '错误', MB_OK + MB_ICONERROR);
 891     end;
 892   end;
 893 end;
 894 
 895 procedure TMainForm.OpenLogDirectory(DirName: string);
 896 begin
 897   ShellExecute(Handle,'Open',PChar(DirName), nil, nil, 1);
 898 end;
 899 
 900 procedure TMainForm.OpenLog(FileName: string);
 901 begin
 902   ShellExecute(Handle, 'Open', PChar('NotePad'), PChar(FileName), nil, SW_SHOW);
 903 end;
 904 
 905 procedure TMainForm.bbtnSaveConfigClick(Sender: TObject);
 906 begin
 907   if SaveConfig then
 908   begin
 909     LogInfo('保存配置成功,即将重新初始化', True);
 910 
 911     //2015-02-05 liping.chen 调用Init会重新创建线程,原有的线程还在运行,造成内存泄露。将现有终止
 912     //不过此按钮的SaveConfig 是将配置保存到Config.ini ,
 913     begin
 914       if Assigned(GeneralThd)   then GeneralThd.Terminate;
 915       if Assigned(JCMatchThd)   then JCMatchThd.Terminate;
 916       if Assigned(JCResultThd)  then JCResultThd.Terminate;
 917       if Assigned(BDMatchThd)   then BDMatchThd.Terminate;
 918       if Assigned(BDResultThd)  then BDResultThd.Terminate;
 919       if Assigned(BDSFMatchThd) then BDSFMatchThd.Terminate;
 920       if Assigned(BDSFResultThd)then BDSFResultThd.Terminate;
 921     end;
 922 
 923     Init;
 924   end
 925   else MessageBox(0, '保存配置失败,请检查!', '错误', MB_OK + MB_ICONERROR);
 926 end;
 927 
 928 function TMainForm.SaveConfig: Boolean;
 929 var
 930   infTemp,IniFileTemp: TIniFile;
 931 begin
 932   Result := True;
 933   infTemp := TIniFile.Create(Pub_EXEPath + '\Config.ini');
 934   IniFileTemp := TIniFile.Create(Pub_EXEPath + '\ClearConfig.ini');
 935   try
 936     try
 937       infTemp.WriteInteger('Config', 'JCMatchGetInterval', speJCMatchGetInterval.Value);
 938       infTemp.WriteInteger('Config', 'JCResultGetInterval', speJCResultGetInterval.Value);
 939       infTemp.WriteInteger('Config', 'GeneralGetInterval', speGeneralGetInterval.Value);
 940       infTemp.WriteInteger('config','BDMatchGetInterval',speBDMatchGetInterval.Value);
 941       infTemp.WriteInteger('config','BDResultGetInterval',speBDResultGetInterval.Value);
 942       infTemp.WriteString('Config', 'DBConnectionString', edtDBConStr.Text);
 943       infTemp.WriteString('Config', 'BBMatchAddress', edtBBMatchListAddress.Text);
 944       infTemp.WriteString('Config', 'FBMatchAddress', edtFBMatchListAddress.Text);
 945       infTemp.WriteString('Config', 'BBGivenScoreAddress', edtBBGivenScoreAddress.Text);
 946       infTemp.WriteString('Config', 'BBPresetScoreAddress', edtBBPresetScoreAddress.Text);
 947       infTemp.WriteString('Config', 'BBResultAddress', edtBBResultAddress.Text);
 948       infTemp.WriteString('Config', 'FBResultAddress', edtFBResultAddress.Text);
 949       infTemp.WriteString('Config', 'FBGoalLineAddress', edtFBGoalLineAddress.Text);
 950       infTemp.WriteString('Config', 'BBDetailResultAddress', edtBBDetailResultAddress.Text);
 951       infTemp.WriteString('Config', 'FBDetailResultAddress', edtFBDetailResultAddress.Text);
 952       infTemp.WriteString('Config', 'FBStopMatchResultAddress', edtFBStopMatchResultAddress.Text);
 953       infTemp.WriteString('Config', 'DLTAddress', edtDLTAddress.Text);
 954       infTemp.WriteString('Config', 'QXCAddress', edtQXCAddress.Text);
 955       infTemp.WriteString('Config', 'PLAddress', edtPL3Address.Text);
 956       infTemp.WriteString('Config', 'SFCAddress', edtSFCAddress.Text);
 957       infTemp.WriteString('Config', 'SCJQAddress', edtSCJQAddress.Text);
 958       infTemp.WriteString('Config', 'LCBQCSFAddress', edtLCBQCSFAddress.Text);
 959       infTemp.WriteString('Config', 'BDMatchAddress', EdtBDMatch.Text);
 960       infTemp.WriteString('Config', 'BDResultSPFAddress', EdtBDSPF.Text);
 961       infTemp.WriteString('Config', 'BDResultBQCSPFAddress', EdtBDBQCSPF.Text);
 962       infTemp.WriteString('Config', 'BDResultSXPDSSAddress', edtBDSXPDSS.Text);
 963       infTemp.WriteString('Config', 'BDResultDCBFAddress', EdtDBDCBF.Text);
 964       infTemp.WriteString('Config', 'BDResultZJQSAddress', edtBDZJQS.Text);
 965       infTemp.WriteString('Config', 'BDMatchSFAddress', EdtBDSFMatch.Text); // 2014-07-24 rulinzhang add
 966       infTemp.WriteString('Config', 'BDSFResultAddress', EdtBDSF.Text);    // 2014-07-24 rulinzhang add
 967       if cbSaveFile.Checked then
 968         infTemp.WriteInteger('Config','IsSaveFileFlag',1)
 969       else
 970         infTemp.WriteInteger('Config','IsSaveFileFlag',0)
 971     except on E : Exception do
 972       begin
 973         LogInfo('保存日志文件失败,原因:' + E.Message, True);
 974         Result := False;
 975       end;
 976     end;
 977   finally
 978     infTemp.Free;
 979     IniFileTemp.Free;
 980   end;
 981 end;
 982 
 983 procedure TMainForm.SetIsCatchGeneral(const Value: Boolean);
 984 begin
 985   FIsCatchGeneral := Value;
 986   cbCatchGeneral.Checked := Value;
 987 end;
 988 
 989 procedure TMainForm.SetIsCatchJCMatch(const Value: Boolean);
 990 begin
 991   FIsCatchJCMatch := Value;
 992   cbCatchJCMatch.Checked := Value;
 993 end;
 994 
 995 procedure TMainForm.SetIsCatchJCResult(const Value: Boolean);
 996 begin
 997   FIsCatchJCResult := Value;
 998   cbCatchJCResult.Checked := Value;
 999 end;
1000 
1001 
1002 
1003 procedure TMainForm.bbtnStartClick(Sender: TObject);
1004 begin
1005   SetServerStatus(3);
1006 end;
1007 
1008 procedure TMainForm.bbtnStopClick(Sender: TObject);
1009 begin
1010   case ServerStatu of
1011     1 : ;          //停止
1012     2 : ;          //运行
1013     3 :            //等待
1014       begin
1015         if Application.Messagebox('是否停止获取?', '注意', MB_OKCANCEL) = 1 then
1016         begin
1017           LogInfo('正在停止中', True);
1018           SetPause;      // 停止所有线程
1019           while IsGeneralCatching or IsJCMatchCatching or IsJCResultCatching or IsBDMatchCatching or
1020            IsBDResultCatching or IsBDSFMatchCatching or IsBDSFResultCatching do
1021           begin
1022             Application.ProcessMessages;
1023           end;
1024           LogInfo('已停止所有操作', True);
1025           SetServerStatus(1);
1026         end;
1027       end;
1028   end;
1029 end;
1030 
1031 procedure TMainForm.cbCatchGeneralClick(Sender: TObject);
1032 begin
1033   SetIsCatchGeneral(cbCatchGeneral.Checked);
1034 end;
1035 
1036 procedure TMainForm.cbCatchJCMatchClick(Sender: TObject);
1037 begin
1038   SetIsCatchJCMatch(cbCatchJCMatch.Checked);
1039 end;
1040 
1041 procedure TMainForm.cbCatchJCResultClick(Sender: TObject);
1042 begin
1043   SetIsCatchJCResult(cbCatchJCResult.Checked);
1044 end;
1045 
1046 procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
1047 begin
1048   Action := SystemClose;        
1049 end;
1050 
1051 function TMainForm.SystemClose: TCloseAction;
1052 begin
1053   if ServerStatu > 1 then
1054   begin
1055     MessageBox(0, '服务器正在运行中,不允许退出!', '警告', MB_OK + MB_ICONWARNING);
1056     Result := caNone;         
1057     Exit;
1058   end;
1059   if Messagebox(handle, '是否退出爱彩票抓取服务器', '退出', MB_OKCANCEL) = 1 then
1060   begin
1061     FreeResource;
1062     Result := caFree;
1063     Application.Terminate;
1064   end
1065   else Result := caNone;
1066 end;
1067 
1068 procedure TMainForm.FreeResource;
1069 begin
1070   if Assigned(slDirList) then slDirList.Free;
1071   if Assigned(ctsLog) then ctsLog.Free;
1072    //2013.6.3 Guoqiang.xu 
1073   if Assigned(GeneralThd) then GeneralThd.Terminate;
1074   //
1075   if Assigned(JCMatchThd) then JCMatchThd.Terminate;
1076   if Assigned(JCResultThd) then JCResultThd.Terminate;
1077   //
1078   if Assigned(BDMatchThd) then BDMatchThd.Terminate;
1079   if Assigned(BDResultThd) then BDResultThd.Terminate;
1080   //
1081   if Assigned(MonitorThd) then MonitorThd.Free;
1082   // 2014-01-12 rulinzhang add
1083   if Assigned(Hand_JCMatchThd) then Hand_JCMatchThd.Terminate;
1084   if Assigned(Hand_JCResultThd) then Hand_JCResultThd.Terminate;
1085   if Assigned(Hand_BDMatchThd) then Hand_BDMatchThd.Terminate;
1086   if Assigned(Hand_BDResultThd) then Hand_BDResultThd.Terminate;
1087   // 2014-07-24 rulinzhang add
1088   if Assigned(BDSFMatchThd) then BDSFMatchThd.Terminate;
1089   if Assigned(BDSFResultThd) then BDSFResultThd.Terminate;
1090 end;
1091 
1092 procedure TMainForm.SetBBDlResultAddress(const Value: string);
1093 begin
1094   FBBDlResultAddress := Value;
1095   edtBBDetailResultAddress.Text := Value;
1096 end;
1097 
1098 procedure TMainForm.SetFBDlResultAddress(const Value: string);
1099 begin
1100   FFBDlResultAddress := Value;
1101   edtFBDetailResultAddress.Text := Value;
1102 end;
1103 
1104 procedure TMainForm.N1Click(Sender: TObject);
1105 begin
1106   rztiMain.RestoreApp;
1107 end;
1108 
1109 procedure TMainForm.N3Click(Sender: TObject);
1110 begin
1111   SystemClose;
1112 end;
1113 
1114 procedure TMainForm.SetPause;
1115 begin
1116   if iGeneralStart = 1 then
1117      GeneralThd.SetPause(True);
1118   if iJCMatchStart = 1 then
1119     JCMatchThd.SetPause(True);
1120   if iJCResultStart = 1 then
1121     JCResultThd.SetPause(True);
1122   if iBDMatchStart = 1 then
1123     BDMatchThd.SetPause(True);
1124   if iDBResultStart = 1 then
1125     BDResultThd.SetPause(True);
1126   // 2014-07-24  rulinzhang add
1127   if iBDSFMatchStart = 1 then
1128     BDSFMatchThd.SetPause(True);
1129   if iDBSFResultStart = 1 then
1130     BDSFResultThd.SetPause(True);
1131 end;
1132 
1133 procedure TMainForm.SetFBSMResultAddress(const Value: string);
1134 begin
1135   FFBSMResultAddress := Value;
1136   edtFBStopMatchResultAddress.Text := Value;
1137 end;
1138 
1139 procedure TMainForm.btnMainToSecondaryClick(Sender: TObject);
1140 var
1141   MyIniFile: TIniFile;
1142   slConnection: TStringList;
1143 begin
1144   MyIniFile := TIniFile.Create(Pub_EXEPath + '\Config.ini');
1145   slConnection := TStringList.Create;
1146   try
1147     try
1148       slConnection.Delimiter := '&';
1149       slConnection.DelimitedText := Pub_SysBakDBConStr;
1150 
1151        IF Application.MessageBox(Pchar('您是否确定将主库切换至从库?')
1152         ,'询问信息',MB_YESNO+MB_ICONQUESTION)= 6 then
1153        begin
1154           bbtnStop.Click;
1155           SetDBConStr(Pub_SysBakDBConStr);
1156           slConnection.Delimiter := '&';
1157           slConnection.DelimitedText := DBConStr;
1158           ConnectionConfig.Server := slConnection.Values['Server'];
1159           ConnectionConfig.Username := slConnection.Values['Username'];
1160           ConnectionConfig.Password := slConnection.Values['Password'];
1161           ConnectionConfig.Port := StrToInt(slConnection.Values['Port']);
1162           ConnectionConfig.Database := slConnection.Values['Database'];
1163           Application.MessageBox(Pchar('将主库配置切换至从库配置成功,请从新启动程序!'),'提示',MB_OK) ;
1164           pub_IsChangeServerFlag := 1 ;
1165           MyIniFile.WriteInteger('Config','IsChangeServerFlag',pub_IsChangeServerFlag);
1166        end;
1167     except on E: Exception do
1168       begin
1169         Application.MessageBox(Pchar('将主库配置切换至从库配置失败,请检查服务器地址!'),'提示',MB_OK);
1170         Exit;
1171       end;
1172     end;
1173   finally
1174      MyIniFile.free;
1175      slConnection.Free;
1176      Application.Terminate;
1177   end;
1178 end;
1179 
1180 procedure TMainForm.btnSecondaryToMainClick(Sender: TObject);
1181 var
1182   MyIniFile: TIniFile;
1183   slConnection: TStringList;
1184 begin
1185   MyIniFile := TIniFile.Create(Pub_EXEPath + '\Config.ini');
1186   slConnection := TStringList.Create;
1187   try
1188     Try
1189       slConnection.Delimiter := '&';
1190       slConnection.DelimitedText := Pub_SysBakDBConStr;
1191       IF Application.MessageBox(Pchar('您是否确定将从库切换至主库?')
1192         ,'询问信息',MB_YESNO+MB_ICONQUESTION)= 6 then
1193       begin
1194         SetDBConStr(pub_SysDBConStr);
1195         slConnection.Delimiter := '&';
1196         slConnection.DelimitedText := DBConStr;
1197         ConnectionConfig.Server := slConnection.Values['Server'];
1198         ConnectionConfig.Username := slConnection.Values['Username'];
1199         ConnectionConfig.Password := slConnection.Values['Password'];
1200         ConnectionConfig.Port := StrToInt(slConnection.Values['Port']);
1201         ConnectionConfig.Database := slConnection.Values['Database'];
1202         bbtnStop.Click;
1203 
1204         Application.MessageBox(Pchar('将从库配置切换至主库配置成功,请从新启动程序!'),'提示',MB_OK) ;
1205         pub_IsChangeServerFlag := 0 ;
1206         MyIniFile.WriteInteger('Config','IsChangeServerFlag',pub_IsChangeServerFlag);
1207       end;
1208     except on E: Exception do
1209       begin
1210         Application.MessageBox(Pchar('将从库配置切换至主库配置失败,请检查服务器地址!'),'提示',MB_OK);
1211         Exit;
1212       end;
1213     end;
1214   finally
1215     MyIniFile.free;
1216     slConnection.Free;
1217     Application.Terminate;
1218   end;
1219 end;
1220 
1221 procedure TMainForm.setBDMatchAddress(const Value: string);
1222 begin
1223   FBDMatchAddress := Value;
1224   EdtBDMatch.Text := Value;
1225 end;
1226 
1227 procedure TMainForm.setBDSFMatchAddress(const Value: string);
1228 begin
1229   FBDSFMatchAddress := Value;
1230   EdtBDSFMatch.Text := Value;
1231 end;
1232 procedure TMainForm.setBDSFResultAddress(const Value: string);
1233 begin
1234   FBDSFResultAddress := value ;
1235   EdtBDSF.Text := Value;
1236 end;
1237 
1238 procedure TMainForm.setBDResultBQCSPFAddress(const Value: string);
1239 begin
1240   FBDResultBQCSPFAddress := Value;
1241   EdtBDBQCSPF.Text := Value;
1242 end;
1243 
1244 procedure TMainForm.setBDResultDCBFAddress(const Value: string);
1245 begin
1246   FBDResultDCBFAddress := Value;
1247   EdtDBDCBF.Text := Value;
1248 end;
1249 
1250 procedure TMainForm.setBDResultSXPDSSAddress(const Value: string);
1251 begin
1252   FBDResultSXPDSSAddress := Value;
1253   edtBDSXPDSS.Text := Value;
1254 end;
1255 
1256 procedure TMainForm.setBDResultZJQSAddress(const Value: string);
1257 begin
1258   FBDResultZJQSAddress := Value;
1259   edtBDZJQS.Text := value;
1260 end;
1261 
1262 procedure TMainForm.setBDResultSPFAddress(const Value: string);
1263 begin
1264   FBDResultSPFAddress := value ;
1265   EdtBDSPF.Text := Value;
1266 end;
1267 
1268 procedure TMainForm.SetBDMatchGetInv(const Value: Integer);
1269 begin
1270   FBDMatchGetInv := Value ;
1271   speBDMatchGetInterval.Value := Value;
1272 end;
1273 
1274 
1275 procedure TMainForm.setBDResultGetInv(const Value: Integer);
1276 begin
1277   FBDResultGetInv := Value ;
1278   speBDResultGetInterval.Value := Value ;
1279 end;
1280 
1281 procedure TMainForm.SetIsSaveFile(const Value: Boolean);
1282 begin
1283   FIsSaveFile := Value;
1284   cbSaveFile.Checked := Value;
1285 end;
1286 
1287 procedure TMainForm.cbSaveFileClick(Sender: TObject);
1288 begin
1289 // SetIsCatchJCResult(cbCatchJCResult.Checked);
1290   SetIsSaveFile(cbSaveFile.Checked);
1291 
1292 end;
1293 
1294 procedure TMainForm.WebBrowser1NewWindow2(Sender: TObject;
1295   var ppDisp: IDispatch; var Cancel: WordBool);
1296 begin
1297   Cancel := True;
1298 end;
1299 
1300 function  TMainForm.SaveFile(Content : string ;PathFileName : string ) : Boolean;
1301 var
1302   sFileName: string;
1303   tfRecordFile: Textfile;
1304 begin
1305   result := False;
1306   /// +'\页面信息\'
1307   try
1308     try
1309       if not DirectoryExists(Pub_EXEPath + PathFileName) then CreateDir(Pub_EXEPath +'\' +  PathFileName);
1310       sFileName:= Pub_EXEPath +'\'+  PathFileName +'\' + FormatDateTime('yy-mm-dd-hh-mm-ss', Now()) + '.txt';
1311       AssignFile(tfRecordFile, sFileName);
1312       if not FileExists(sFileName) then
1313         Rewrite(tfRecordFile)
1314       else begin
1315         Reset(tfRecordFile);
1316         Append(tfRecordFile);
1317       end;
1318       Writeln(tfRecordFile, Content);
1319       Result := True;
1320     except
1321 
1322     end;
1323   finally
1324     CloseFile(tfRecordFile);
1325   end;
1326 end;
1327 
1328 procedure TMainForm.Button1Click(Sender: TObject);
1329 begin
1330   FrmOther.show;
1331 end;
1332 
1333 procedure TMainForm.Button2Click(Sender: TObject);
1334 var
1335   s :string;
1336   url :string;
1337 begin
1338   url := 'http://www.bjlot.com/ssm/report200.shtml';
1339   MainForm.WebBrowser1.Navigate(url);
1340   if MainForm.WebBrowser1.ReadyState = READYSTATE_COMPLETE then
1341   begin
1342     s := MainForm.WebBrowser1.OleObject.Document.all.tags('HTML').Item(0).outerHTML;
1343  //   SaveToFile(Content);
1344   end;
1345   ShowMessage(s);
1346 end;
1347 
1348 procedure TMainForm.FormDestroy(Sender: TObject);
1349 begin
1350   {if Assigned(slDirList) then slDirList.Free;
1351   //
1352   if Assigned(GeneralThd) then GeneralThd.Free;
1353   //
1354   if Assigned(JCMatchThd) then JCMatchThd.Free;
1355   if Assigned(JCResultThd) then JCResultThd.Free;
1356   //
1357   if Assigned(BDMatchThd) then BDMatchThd.Free;
1358   if Assigned(BDResultThd) then BDResultThd.Free;
1359   //
1360   if Assigned(BDSFMatchThd) then BDSFMatchThd.Free;   
1361   if Assigned(BDSFResultThd) then BDSFResultThd.Free;
1362   //
1363   if Assigned(ClearOverdueFileThd) then ClearOverdueFileThd.Free;
1364   if Assigned(MonitorThd) then MonitorThd.Free;  }
1365   //2014-12-03 liping.chen屏蔽以上,因FreeResource已经释放,此时对象已经不在。  Assigned只是指针
1366   if Assigned(Pub_GetMatch) then Pub_GetMatch.Free;
1367 end;
1368 
1369 procedure TMainForm.ShowClearFileDir;
1370 begin
1371   edtBDBQCSPFTempDirectory.Text := Pub_EXEPath + '\' + BDBQCSPFTempDir;
1372   edtBDSXPDSSTempDirectory.Text := Pub_EXEPath + '\' + BDSXPDSSTempDir;
1373   edtBDSPFTempDirectory.Text := Pub_EXEPath + '\' + BDSPFTempDir;
1374   edtBDDCBFTempDirectory.Text := Pub_EXEPath + '\' + BDDCBFTempDir;
1375   edtBDZJQSTempDirectory.Text := Pub_EXEPath + '\' + BDZJQSTempDir;
1376   edtLQYSZFTempDirectory.Text := Pub_EXEPath + '\' + LQYSZFTempDir;
1377   edtLQRFTempDirectory.Text := Pub_EXEPath + '\' + LQRFTempDir;
1378   edtLQDZTempDirectory.Text := Pub_EXEPath + '\' + LQDZTempDir;
1379   edtBDDZTempDirectory.Text := Pub_EXEPath + '\' + BDDZTempDir;
1380   edtZQDZTempDirectory.Text := Pub_EXEPath + '\' + ZQDZTempDir;
1381   edtLogDirectory.Text := Pub_EXEPath + '\' + LogDir;
1382 end;
1383 
1384 //2013-11-28 guoqiang.xu add
1385 procedure TMainForm.idhtpsrvr1CommandGet(AContext: TIdContext;
1386   ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
1387 var
1388   sReqContext : string;
1389 begin
1390   try
1391     //Post方式获取请求内容
1392     if ARequestInfo.Command = 'POST' then
1393     begin
1394       //获取请求串
1395       sReqContext := ARequestInfo.FormParams;
1396       // 请求串为空,退出
1397       if Trim(sReqContext) = '' then
1398         Exit;
1399       //解析请求串
1400       //ParseRequest(sReqContext);
1401       //处理请求
1402       //GetReply(sReqContext);
1403     end
1404     else
1405     begin
1406       //获取请求串
1407       sReqContext := ARequestInfo.QueryParams;
1408       // 请求串为空,退出
1409       if Trim(sReqContext) = '' then Exit;
1410       //处理请求
1411       GetReply(sReqContext);
1412       Exit;
1413     end;
1414   except on E: Exception do
1415     begin
1416       LogInfo('【TOMis客户端手动请求获取竞彩对阵异常!】,异常原因:' + e.Message, True);
1417       Exit;
1418     end;
1419   end;
1420 end;
1421 
1422 function TMainForm.GetReply(ARequest: string): Integer;
1423 var
1424   WholeParams: TStringList;
1425   Msg_UserName, Msg_Code, Msg_Sign : string;
1426   sReqStr,sTemp : string;
1427 begin
1428   Result := 0;
1429   WholeParams := TStringList.Create;
1430   try
1431     Pub_GetMatch.Enter;
1432     try
1433       Msg_UserName := 'ReqUser';
1434       Msg_Code := 'ReqCode';
1435       Msg_Sign := 'aSign';
1436       WholeParams.Delimiter := '&';
1437       WholeParams.DelimitedText := ARequest;
1438       sReqUserName := Trim(WholeParams.Values[Msg_UserName]);
1439       sReqCode := Trim(WholeParams.Values[Msg_Code]);
1440       sReqSign := Trim(WholeParams.Values[Msg_Sign]);
1441       //
1442       sReqStr := Trim(sReqUserName) + Trim(sReqCode) + 'aicai123456!';   // 公共密钥
1443       sTemp := MD5String2(sReqStr);
1444       if sTemp = sReqSign then
1445       begin
1446         case StrToInt(sReqCode) of
1447           //竞足对阵(停赛对阵)  竞篮对阵
1448           7,4 :
1449           begin
1450             try
1451               Hand_JCMatchThd := TJCMatchThd.Create(StrToInt(sReqCode),0);
1452             finally
1453             end;
1454           end;
1455           //竞足竞篮赛果
1456           70,45 :
1457           begin
1458             begin
1459               try
1460                 Hand_JCResultThd := TJCResultThd.Create(StrToInt(sReqCode),0);
1461               finally
1462               end;
1463             end;
1464           end;
1465           //北单对阵
1466           3 :
1467           begin
1468             try
1469               Hand_BDMatchThd := TBDMatchThd.Create(3,0);
1470             finally
1471             end;
1472           end;
1473           //北单赛果   300 为获取全部
1474           30,31,32,33,34,300 :
1475           begin
1476             try
1477               Hand_BDResultThd := TBDResultThd.create(DoNavigator,DoParse,StrToInt(sReqCode),0);
1478             finally
1479             end;
1480           end;
1481           //北单胜负对阵
1482           35 :
1483           begin
1484             try
1485               Hand_BDSFMatchThd := TBDSFMatchThd.Create(35,0);
1486             finally
1487             end;
1488           end;
1489           //北单胜负赛果
1490           350 :
1491           begin
1492             try
1493               Hand_BDSFResultThd := TBDSFResultThd.Create(350,0);
1494             finally
1495             end;
1496           end;
1497           else
1498             Exit;
1499         end;
1500       end
1501       else
1502       begin
1503         LogInfo('【手动请求获取竞彩对阵或赛果,校验签名不一样,终止请求!】' + sReqSign, True);
1504         Exit;
1505       end;
1506     except on Ex: Exception do
1507       begin
1508         LogInfo('【手动请求获取竞彩对阵或赛果,请求参数异常!】,异常原因:' + Ex.Message, True);
1509         Exit;
1510       end;
1511     end;
1512   finally
1513     WholeParams.Free;
1514     Pub_GetMatch.Leave;
1515   end;
1516 end;
1517 
1518 procedure TMainForm.Button3Click(Sender: TObject);
1519 begin
1520   FrmHandJC.show;
1521 end;
1522 
1523 procedure TMainForm.FormShow(Sender: TObject);
1524 begin
1525   SetServerStatus(0);
1526   Init;
1527   if pub_IsChangeServerFlag =0 then
1528     btnSecondaryToMain.Enabled := False
1529   else
1530     btnMainToSecondary.Enabled := False ;
1531   bbtnStart.Click ;
1532 end;
1533 
1534 end.
窗体单元文件
   1 object MainForm: TMainForm
   2   Left = 442
   3   Top = 211
   4   BorderIcons = [biSystemMenu, biMinimize]
   5   BorderStyle = bsSingle
   6   Caption = 'sl'
   7   ClientHeight = 554
   8   ClientWidth = 671
   9   Color = clBtnFace
  10   Font.Charset = DEFAULT_CHARSET
  11   Font.Color = clWindowText
  12   Font.Height = -11
  13   Font.Name = 'MS Sans Serif'
  14   Font.Style = []
  15   OldCreateOrder = False
  16   Position = poDesktopCenter
  17   OnClose = FormClose
  18   OnCreate = FormCreate
  19   OnDestroy = FormDestroy
  20   OnShow = FormShow
  21   PixelsPerInch = 96
  22   TextHeight = 13
  23   object PageControl1: TPageControl
  24     Left = 0
  25     Top = 0
  26     Width = 671
  27     Height = 267
  28     ActivePage = TabSheet6
  29     Align = alTop
  30     TabHeight = 33
  31     TabOrder = 0
  32     TabWidth = 65
  33     object TabSheet1: TTabSheet
  34       Caption = '基本配置'
  35       object Label9: TLabel
  36         Left = 16
  37         Top = 40
  38         Width = 113
  39         Height = 13
  40         AutoSize = False
  41         Caption = '竞彩对阵获取间隔'
  42       end
  43       object Label2: TLabel
  44         Left = 224
  45         Top = 40
  46         Width = 16
  47         Height = 13
  48         AutoSize = False
  49         Caption = ''
  50       end
  51       object Label10: TLabel
  52         Left = 16
  53         Top = 147
  54         Width = 81
  55         Height = 13
  56         AutoSize = False
  57         Caption = '数据库连接'
  58       end
  59       object Label13: TLabel
  60         Left = 16
  61         Top = 67
  62         Width = 113
  63         Height = 13
  64         AutoSize = False
  65         Caption = '竞彩赛果获取间隔'
  66       end
  67       object Label14: TLabel
  68         Left = 224
  69         Top = 68
  70         Width = 16
  71         Height = 13
  72         AutoSize = False
  73         Caption = ''
  74       end
  75       object Label6: TLabel
  76         Left = 16
  77         Top = 13
  78         Width = 113
  79         Height = 13
  80         AutoSize = False
  81         Caption = '传统体彩获取间隔'
  82       end
  83       object Label7: TLabel
  84         Left = 224
  85         Top = 13
  86         Width = 16
  87         Height = 13
  88         AutoSize = False
  89         Caption = ''
  90       end
  91       object Label30: TLabel
  92         Left = 16
  93         Top = 94
  94         Width = 113
  95         Height = 13
  96         AutoSize = False
  97         Caption = '北单对阵获取间隔'
  98       end
  99       object Label31: TLabel
 100         Left = 224
 101         Top = 92
 102         Width = 16
 103         Height = 13
 104         AutoSize = False
 105         Caption = ''
 106       end
 107       object Label32: TLabel
 108         Left = 16
 109         Top = 120
 110         Width = 113
 111         Height = 13
 112         AutoSize = False
 113         Caption = '北单赛果获取间隔'
 114       end
 115       object Label33: TLabel
 116         Left = 224
 117         Top = 120
 118         Width = 16
 119         Height = 13
 120         AutoSize = False
 121         Caption = ''
 122       end
 123       object speJCMatchGetInterval: TSpinEdit
 124         Left = 142
 125         Top = 35
 126         Width = 67
 127         Height = 22
 128         MaxValue = 999999
 129         MinValue = 1
 130         TabOrder = 0
 131         Value = 1
 132       end
 133       object edtDBConStr: TEdit
 134         Left = 142
 135         Top = 142
 136         Width = 363
 137         Height = 21
 138         ImeName = '中文 (简体) - 搜狗拼音输入法'
 139         TabOrder = 1
 140       end
 141       object speJCResultGetInterval: TSpinEdit
 142         Left = 142
 143         Top = 62
 144         Width = 67
 145         Height = 22
 146         MaxValue = 999999
 147         MinValue = 1
 148         TabOrder = 2
 149         Value = 1
 150       end
 151       object speGeneralGetInterval: TSpinEdit
 152         Left = 142
 153         Top = 8
 154         Width = 67
 155         Height = 22
 156         MaxValue = 999999
 157         MinValue = 1
 158         TabOrder = 3
 159         Value = 1
 160       end
 161       object btnMainToSecondary: TBitBtn
 162         Left = 384
 163         Top = 13
 164         Width = 113
 165         Height = 28
 166         Caption = '主库切换至从库'
 167         TabOrder = 4
 168         OnClick = btnMainToSecondaryClick
 169       end
 170       object btnSecondaryToMain: TBitBtn
 171         Left = 384
 172         Top = 53
 173         Width = 112
 174         Height = 28
 175         Caption = '从库切换至主库'
 176         TabOrder = 5
 177         OnClick = btnSecondaryToMainClick
 178       end
 179       object speBDMatchGetInterval: TSpinEdit
 180         Left = 142
 181         Top = 89
 182         Width = 67
 183         Height = 22
 184         MaxValue = 999999
 185         MinValue = 1
 186         TabOrder = 6
 187         Value = 1
 188       end
 189       object speBDResultGetInterval: TSpinEdit
 190         Left = 142
 191         Top = 115
 192         Width = 67
 193         Height = 22
 194         MaxValue = 999999
 195         MinValue = 1
 196         TabOrder = 7
 197         Value = 1
 198       end
 199       object WebBrowser1: TWebBrowser
 200         Left = 274
 201         Top = 10
 202         Width = 96
 203         Height = 103
 204         Align = alCustom
 205         TabOrder = 8
 206         OnNewWindow2 = WebBrowser1NewWindow2
 207         ControlData = {
 208           4C000000EC090000A50A00000000000000000000000000000000000000000000
 209           000000004C000000000000000000000001000000E0D057007335CF11AE690800
 210           2B2E126208000000000000004C0000000114020000000000C000000000000046
 211           8000000000000000000000000000000000000000000000000000000000000000
 212           00000000000000000100000000000000000000000000000000000000}
 213       end
 214     end
 215     object TabSheet2: TTabSheet
 216       Caption = '竞彩对阵'
 217       ImageIndex = 1
 218       object Label1: TLabel
 219         Left = 29
 220         Top = 13
 221         Width = 92
 222         Height = 13
 223         AutoSize = False
 224         Caption = '竞彩篮球对阵'
 225       end
 226       object Label3: TLabel
 227         Left = 29
 228         Top = 51
 229         Width = 92
 230         Height = 13
 231         AutoSize = False
 232         Caption = '竞彩足球对阵'
 233       end
 234       object Label4: TLabel
 235         Left = 29
 236         Top = 91
 237         Width = 92
 238         Height = 13
 239         AutoSize = False
 240         Caption = '篮球让分情况'
 241       end
 242       object Label5: TLabel
 243         Left = 5
 244         Top = 128
 245         Width = 116
 246         Height = 13
 247         AutoSize = False
 248         Caption = '篮球预设总分情况'
 249       end
 250       object Label22: TLabel
 251         Left = 17
 252         Top = 163
 253         Width = 89
 254         Height = 13
 255         AutoSize = False
 256         Caption = '足球让分情况'
 257       end
 258       object edtBBMatchListAddress: TEdit
 259         Left = 118
 260         Top = 8
 261         Width = 392
 262         Height = 21
 263         ImeName = '中文 (简体) - 搜狗拼音输入法'
 264         ParentShowHint = False
 265         ShowHint = False
 266         TabOrder = 0
 267       end
 268       object edtFBMatchListAddress: TEdit
 269         Left = 118
 270         Top = 46
 271         Width = 392
 272         Height = 21
 273         ImeName = '中文 (简体) - 搜狗拼音输入法'
 274         TabOrder = 1
 275       end
 276       object edtBBGivenScoreAddress: TEdit
 277         Left = 118
 278         Top = 86
 279         Width = 392
 280         Height = 21
 281         ImeName = '中文 (简体) - 搜狗拼音输入法'
 282         TabOrder = 2
 283       end
 284       object edtBBPresetScoreAddress: TEdit
 285         Left = 118
 286         Top = 123
 287         Width = 392
 288         Height = 21
 289         ImeName = '中文 (简体) - 搜狗拼音输入法'
 290         TabOrder = 3
 291       end
 292       object edtFBGoalLineAddress: TEdit
 293         Left = 119
 294         Top = 159
 295         Width = 392
 296         Height = 21
 297         ImeName = '中文 (简体) - 搜狗拼音输入法'
 298         TabOrder = 4
 299       end
 300     end
 301     object TabSheet3: TTabSheet
 302       Caption = '竞彩赛果'
 303       ImageIndex = 2
 304       object Label11: TLabel
 305         Left = 8
 306         Top = 13
 307         Width = 87
 308         Height = 13
 309         AutoSize = False
 310         Caption = '竞彩篮球赛果'
 311       end
 312       object Label12: TLabel
 313         Left = 8
 314         Top = 43
 315         Width = 89
 316         Height = 13
 317         AutoSize = False
 318         Caption = '竞彩足球赛果'
 319       end
 320       object Label20: TLabel
 321         Left = 8
 322         Top = 74
 323         Width = 87
 324         Height = 13
 325         AutoSize = False
 326         Caption = '篮彩详细赛果'
 327       end
 328       object Label21: TLabel
 329         Left = 8
 330         Top = 106
 331         Width = 87
 332         Height = 13
 333         AutoSize = False
 334         Caption = '足彩详细赛果'
 335       end
 336       object Label23: TLabel
 337         Left = 8
 338         Top = 136
 339         Width = 87
 340         Height = 13
 341         AutoSize = False
 342         Caption = '足彩停赛结果'
 343       end
 344       object edtBBResultAddress: TEdit
 345         Left = 103
 346         Top = 8
 347         Width = 409
 348         Height = 21
 349         ImeName = '中文 (简体) - 搜狗拼音输入法'
 350         ParentShowHint = False
 351         ShowHint = False
 352         TabOrder = 0
 353       end
 354       object edtFBResultAddress: TEdit
 355         Left = 103
 356         Top = 38
 357         Width = 409
 358         Height = 21
 359         ImeName = '中文 (简体) - 搜狗拼音输入法'
 360         TabOrder = 1
 361       end
 362       object edtBBDetailResultAddress: TEdit
 363         Left = 103
 364         Top = 69
 365         Width = 409
 366         Height = 21
 367         ImeName = '中文 (简体) - 搜狗拼音输入法'
 368         ParentShowHint = False
 369         ShowHint = False
 370         TabOrder = 2
 371       end
 372       object edtFBDetailResultAddress: TEdit
 373         Left = 103
 374         Top = 101
 375         Width = 409
 376         Height = 21
 377         ImeName = '中文 (简体) - 搜狗拼音输入法'
 378         ParentShowHint = False
 379         ShowHint = False
 380         TabOrder = 3
 381       end
 382       object edtFBStopMatchResultAddress: TEdit
 383         Left = 103
 384         Top = 132
 385         Width = 409
 386         Height = 21
 387         ImeName = '中文 (简体) - 搜狗拼音输入法'
 388         ParentShowHint = False
 389         ShowHint = False
 390         TabOrder = 4
 391       end
 392       object Button3: TButton
 393         Left = 484
 394         Top = 160
 395         Width = 82
 396         Height = 36
 397         Caption = '手动获取'
 398         TabOrder = 5
 399         OnClick = Button3Click
 400       end
 401     end
 402     object TabSheet4: TTabSheet
 403       Caption = '数字彩'
 404       ImageIndex = 3
 405       object Label8: TLabel
 406         Left = 8
 407         Top = 18
 408         Width = 87
 409         Height = 13
 410         AutoSize = False
 411         Caption = '大乐透'
 412       end
 413       object Label16: TLabel
 414         Left = 8
 415         Top = 102
 416         Width = 89
 417         Height = 13
 418         AutoSize = False
 419         Caption = '排列三排列五'
 420       end
 421       object Label17: TLabel
 422         Left = 8
 423         Top = 61
 424         Width = 89
 425         Height = 13
 426         AutoSize = False
 427         Caption = '七星彩'
 428       end
 429       object edtDLTAddress: TEdit
 430         Left = 103
 431         Top = 13
 432         Width = 411
 433         Height = 21
 434         ImeName = '中文 (简体) - 搜狗拼音输入法'
 435         ParentShowHint = False
 436         ShowHint = False
 437         TabOrder = 0
 438       end
 439       object edtQXCAddress: TEdit
 440         Left = 103
 441         Top = 56
 442         Width = 411
 443         Height = 21
 444         ImeName = '中文 (简体) - 搜狗拼音输入法'
 445         TabOrder = 1
 446       end
 447       object edtPL3Address: TEdit
 448         Left = 103
 449         Top = 97
 450         Width = 411
 451         Height = 21
 452         ImeName = '中文 (简体) - 搜狗拼音输入法'
 453         TabOrder = 2
 454       end
 455     end
 456     object TabSheet5: TTabSheet
 457       Caption = '传统体彩'
 458       ImageIndex = 4
 459       object Label15: TLabel
 460         Left = 8
 461         Top = 20
 462         Width = 87
 463         Height = 13
 464         AutoSize = False
 465         Caption = '胜负彩,任九'
 466       end
 467       object Label18: TLabel
 468         Left = 8
 469         Top = 62
 470         Width = 89
 471         Height = 13
 472         AutoSize = False
 473         Caption = '四场进球'
 474       end
 475       object Label19: TLabel
 476         Left = 8
 477         Top = 104
 478         Width = 97
 479         Height = 13
 480         AutoSize = False
 481         Caption = '六场半全场胜负'
 482       end
 483       object edtLCBQCSFAddress: TEdit
 484         Left = 112
 485         Top = 99
 486         Width = 399
 487         Height = 21
 488         ImeName = '中文 (简体) - 搜狗拼音输入法'
 489         TabOrder = 0
 490       end
 491       object edtSCJQAddress: TEdit
 492         Left = 112
 493         Top = 57
 494         Width = 399
 495         Height = 21
 496         ImeName = '中文 (简体) - 搜狗拼音输入法'
 497         TabOrder = 1
 498       end
 499       object edtSFCAddress: TEdit
 500         Left = 112
 501         Top = 15
 502         Width = 399
 503         Height = 21
 504         ImeName = '中文 (简体) - 搜狗拼音输入法'
 505         ParentShowHint = False
 506         ShowHint = False
 507         TabOrder = 2
 508       end
 509     end
 510     object TabSheet6: TTabSheet
 511       Caption = '北京单场'
 512       ImageIndex = 5
 513       object Label25: TLabel
 514         Left = 12
 515         Top = 32
 516         Width = 87
 517         Height = 13
 518         AutoSize = False
 519         Caption = '胜平负'
 520       end
 521       object Label24: TLabel
 522         Left = 12
 523         Top = 56
 524         Width = 87
 525         Height = 13
 526         AutoSize = False
 527         Caption = '总进球数'
 528       end
 529       object Label26: TLabel
 530         Left = 12
 531         Top = 82
 532         Width = 87
 533         Height = 13
 534         AutoSize = False
 535         Caption = '半全场胜平负'
 536       end
 537       object Label27: TLabel
 538         Left = 12
 539         Top = 107
 540         Width = 87
 541         Height = 13
 542         AutoSize = False
 543         Caption = '上下盘单双数'
 544       end
 545       object Label28: TLabel
 546         Left = 12
 547         Top = 130
 548         Width = 87
 549         Height = 13
 550         AutoSize = False
 551         Caption = '单场比分'
 552       end
 553       object Label29: TLabel
 554         Left = 12
 555         Top = 8
 556         Width = 93
 557         Height = 13
 558         AutoSize = False
 559         Caption = '北单赛程'
 560       end
 561       object lbl12: TLabel
 562         Left = 12
 563         Top = 162
 564         Width = 87
 565         Height = 13
 566         AutoSize = False
 567         Caption = '北单胜负赛程'
 568       end
 569       object lbl13: TLabel
 570         Left = 12
 571         Top = 185
 572         Width = 100
 573         Height = 13
 574         AutoSize = False
 575         Caption = '北单胜负过关赛果'
 576       end
 577       object EdtBDSPF: TEdit
 578         Left = 112
 579         Top = 28
 580         Width = 399
 581         Height = 21
 582         ImeName = '中文 (简体) - 搜狗拼音输入法'
 583         ParentShowHint = False
 584         ShowHint = False
 585         TabOrder = 0
 586       end
 587       object edtBDZJQS: TEdit
 588         Left = 112
 589         Top = 52
 590         Width = 399
 591         Height = 21
 592         ImeName = '中文 (简体) - 搜狗拼音输入法'
 593         ParentShowHint = False
 594         ShowHint = False
 595         TabOrder = 1
 596       end
 597       object EdtBDBQCSPF: TEdit
 598         Left = 112
 599         Top = 78
 600         Width = 399
 601         Height = 21
 602         ImeName = '中文 (简体) - 搜狗拼音输入法'
 603         ParentShowHint = False
 604         ShowHint = False
 605         TabOrder = 2
 606       end
 607       object edtBDSXPDSS: TEdit
 608         Left = 112
 609         Top = 103
 610         Width = 399
 611         Height = 21
 612         ImeName = '中文 (简体) - 搜狗拼音输入法'
 613         ParentShowHint = False
 614         ShowHint = False
 615         TabOrder = 3
 616       end
 617       object EdtDBDCBF: TEdit
 618         Left = 112
 619         Top = 127
 620         Width = 399
 621         Height = 21
 622         ImeName = '中文 (简体) - 搜狗拼音输入法'
 623         ParentShowHint = False
 624         ShowHint = False
 625         TabOrder = 4
 626       end
 627       object EdtBDMatch: TEdit
 628         Left = 112
 629         Top = 4
 630         Width = 399
 631         Height = 21
 632         ImeName = '中文 (简体) - 搜狗拼音输入法'
 633         ParentShowHint = False
 634         ShowHint = False
 635         TabOrder = 5
 636       end
 637       object Button1: TButton
 638         Left = 520
 639         Top = 41
 640         Width = 137
 641         Height = 35
 642         Caption = '手动获取赛程'
 643         TabOrder = 6
 644         OnClick = Button1Click
 645       end
 646       object EdtBDSFMatch: TEdit
 647         Left = 112
 648         Top = 159
 649         Width = 399
 650         Height = 21
 651         ImeName = '中文 (简体) - 搜狗拼音输入法'
 652         ParentShowHint = False
 653         ShowHint = False
 654         TabOrder = 7
 655       end
 656       object EdtBDSF: TEdit
 657         Left = 112
 658         Top = 183
 659         Width = 399
 660         Height = 21
 661         ImeName = '中文 (简体) - 搜狗拼音输入法'
 662         ParentShowHint = False
 663         ShowHint = False
 664         TabOrder = 8
 665       end
 666     end
 667     object TabSheet7: TTabSheet
 668       Caption = '清理文件'
 669       ImageIndex = 6
 670       object lbl1: TLabel
 671         Left = 8
 672         Top = 14
 673         Width = 152
 674         Height = 13
 675         AutoSize = False
 676         Caption = '北单半全场胜平负目录:'
 677       end
 678       object lbl2: TLabel
 679         Left = 8
 680         Top = 100
 681         Width = 152
 682         Height = 13
 683         AutoSize = False
 684         Caption = '北单单场比分目录:'
 685       end
 686       object lbl3: TLabel
 687         Left = 8
 688         Top = 128
 689         Width = 152
 690         Height = 13
 691         AutoSize = False
 692         Caption = '北单总进球数目录:'
 693       end
 694       object lbl4: TLabel
 695         Left = 8
 696         Top = 43
 697         Width = 152
 698         Height = 13
 699         AutoSize = False
 700         Caption = '北单上下盘单双数目录:'
 701       end
 702       object lbl5: TLabel
 703         Left = 317
 704         Top = 128
 705         Width = 105
 706         Height = 13
 707         AutoSize = False
 708         Caption = '北单单注目录:'
 709       end
 710       object lbl6: TLabel
 711         Left = 8
 712         Top = 71
 713         Width = 152
 714         Height = 13
 715         AutoSize = False
 716         Caption = '北单胜平负目录:'
 717       end
 718       object lbl7: TLabel
 719         Left = 317
 720         Top = 100
 721         Width = 105
 722         Height = 13
 723         AutoSize = False
 724         Caption = '篮球单注目录:'
 725       end
 726       object lbl8: TLabel
 727         Left = 317
 728         Top = 43
 729         Width = 105
 730         Height = 13
 731         AutoSize = False
 732         Caption = '篮球让分目录:'
 733       end
 734       object lbl9: TLabel
 735         Left = 317
 736         Top = 14
 737         Width = 123
 738         Height = 13
 739         AutoSize = False
 740         Caption = '篮球赢输总分目录:'
 741       end
 742       object lbl10: TLabel
 743         Left = 317
 744         Top = 71
 745         Width = 105
 746         Height = 13
 747         AutoSize = False
 748         Caption = '足球单注目录:'
 749       end
 750       object lbl11: TLabel
 751         Left = 8
 752         Top = 157
 753         Width = 57
 754         Height = 13
 755         AutoSize = False
 756         Caption = '日   志:'
 757       end
 758       object edtBDBQCSPFTempDirectory: TEdit
 759         Left = 161
 760         Top = 8
 761         Width = 138
 762         Height = 21
 763         ImeName = '中文 - QQ五笔输入法'
 764         TabOrder = 0
 765       end
 766       object edtBDSXPDSSTempDirectory: TEdit
 767         Left = 161
 768         Top = 37
 769         Width = 138
 770         Height = 21
 771         ImeName = '中文 - QQ五笔输入法'
 772         TabOrder = 1
 773       end
 774       object edtBDSPFTempDirectory: TEdit
 775         Left = 161
 776         Top = 66
 777         Width = 138
 778         Height = 21
 779         ImeName = '中文 - QQ五笔输入法'
 780         TabOrder = 2
 781       end
 782       object edtBDDCBFTempDirectory: TEdit
 783         Left = 161
 784         Top = 95
 785         Width = 138
 786         Height = 21
 787         ImeName = '中文 - QQ五笔输入法'
 788         TabOrder = 3
 789       end
 790       object edtBDZJQSTempDirectory: TEdit
 791         Left = 161
 792         Top = 124
 793         Width = 138
 794         Height = 21
 795         ImeName = '中文 - QQ五笔输入法'
 796         TabOrder = 4
 797       end
 798       object edtBDDZTempDirectory: TEdit
 799         Left = 439
 800         Top = 124
 801         Width = 138
 802         Height = 21
 803         ImeName = '中文 - QQ五笔输入法'
 804         TabOrder = 5
 805       end
 806       object edtLQYSZFTempDirectory: TEdit
 807         Left = 439
 808         Top = 8
 809         Width = 138
 810         Height = 21
 811         ImeName = '中文 - QQ五笔输入法'
 812         TabOrder = 6
 813       end
 814       object edtLQRFTempDirectory: TEdit
 815         Left = 439
 816         Top = 37
 817         Width = 138
 818         Height = 21
 819         ImeName = '中文 - QQ五笔输入法'
 820         TabOrder = 7
 821       end
 822       object edtZQDZTempDirectory: TEdit
 823         Left = 439
 824         Top = 66
 825         Width = 138
 826         Height = 21
 827         ImeName = '中文 - QQ五笔输入法'
 828         TabOrder = 8
 829       end
 830       object edtLQDZTempDirectory: TEdit
 831         Left = 439
 832         Top = 95
 833         Width = 138
 834         Height = 21
 835         ImeName = '中文 - QQ五笔输入法'
 836         TabOrder = 9
 837       end
 838       object edtLogDirectory: TEdit
 839         Left = 72
 840         Top = 154
 841         Width = 225
 842         Height = 21
 843         ImeName = '中文 - QQ五笔输入法'
 844         TabOrder = 10
 845       end
 846     end
 847   end
 848   object bbtnSaveConfig: TBitBtn
 849     Left = 501
 850     Top = 3
 851     Width = 91
 852     Height = 32
 853     Caption = '保存配置'
 854     TabOrder = 1
 855     OnClick = bbtnSaveConfigClick
 856     Glyph.Data = {
 857       F6060000424DF606000000000000360000002800000018000000180000000100
 858       180000000000C0060000120B0000120B00000000000000000000FDFBFAD4B6A0
 859       AC7045A26131A26130A26131A26131A26131A26131A26131A26131A26131A261
 860       31A26131A26131A26131A26131A26131A26131A26130A26131AC7045D4B6A0FD
 861       FBFAD5B6A09C5623B0784EC59C7DC69C7EC89C7CCA9B7BCA9C7BCA9C7BCA9C7B
 862       CA9C7BCA9C7BCA9C7BCA9C7BCA9C7BCA9C7BCA9C7BCA9B7BC89C7CC69C7EC59C
 863       7DB0784E9C5623D5B6A0AB6F43B07850F7F2EEFFFFFFFFFFFFFFFFFFFCFFFFFB
 864       FFFFFBFFFFFBFFFFFBFFFFFBFFFFFBFFFFFBFFFFFBFFFFFBFFFFFBFFFFFCFFFF
 865       FFFFFFFFFFFFFFFFFFF7F2EEB07850AB6F43A26030C69D7FFFFFFFFFFFFFD1F0
 866       FE73D1FA57C7F958C8F958C8F958C8F958C8F958C8F958C8F958C8F958C8F958
 867       C8F958C8F957C7F973D1FAD1F0FEFFFFFFFFFFFFC69D7FA26030A26131C69C7E
 868       FFFFFFD1F0FE34BAF518B1F41AB1F31BB1F31BB1F31BB1F31BB1F31BB1F31BB1
 869       F31BB1F31BB1F31BB1F31BB1F31AB1F318B1F434BAF5D1F0FEFFFFFFC59C7EA2
 870       6131A26131C99B7BFFFFFF72D0F918B0F325B5F425B5F425B5F425B5F425B5F4
 871       25B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F418B0F371D0
 872       FAFFFFFFC89B7BA26131A26131CA9B7BFCFFFF57C7F91AB1F325B5F425B5F425
 873       B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F4
 874       25B5F41AB1F357C7F9FCFFFFCA9B7BA26131A26131CA9C7BFBFFFF58C8F91BB1
 875       F325B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425
 876       B5F425B5F425B5F425B5F41BB1F358C8F9FBFFFFCA9C7BA26131A26131CA9C7B
 877       FBFFFF58C8F91BB1F325B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5
 878       F425B5F425B5F425B5F425B5F425B5F425B5F41BB1F358C8F9FBFFFFCA9C7BA2
 879       6131A26131CA9B7BFCFFFF57C7F91AB1F325B5F425B5F425B5F425B5F425B5F4
 880       25B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F41AB1F357C7
 881       F9FCFFFFCA9B7BA26131A26131C99B7BFFFFFF6FD0F918B1F325B5F425B5F425
 882       B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F425B5F4
 883       25B5F418B1F36FD0FAFFFFFFC99B7BA26131A26131C69C7DFFFFFFCDEFFE31BA
 884       F518B1F31BB1F31BB2F31BB2F31BB2F31BB2F31BB2F31BB2F31BB2F31BB2F31B
 885       B2F31BB2F31BB1F318B1F331BAF5CDEFFEFFFFFFC69C7DA26131A26131C59C7E
 886       FFFFFFFFFFFFCCEDFC6ECEF953C6F953C7F954C7F954C7F954C7F954C7F954C7
 887       F954C7F954C7F954C7F953C7F953C6F96ECEF9CCEDFCFFFFFFFFFFFFC59C7EA2
 888       6131A26131C59C7EFFFFFFFFFFFFFFFFFFFFFFFFF9FFFFF6FEFFF7FEFFF7FEFF
 889       F7FEFFF7FEFFF7FEFFF7FEFFF7FEFFF7FEFFF6FEFFF9FFFFFFFFFFFFFFFFFFFF
 890       FFFFFFFFC59C7EA26131A26131C59C7EFFFFFFFFFFFFF4EBE5D4B298C99976C9
 891       9774CA9876CB9A78CB9A78CB9A78CB9A78CB9A78CB9A78CB9A78CA9978CB9B79
 892       D5B29AF4EBE5FFFFFFFFFFFFC59C7EA26131A26131C59C7EFFFFFFF2E8E1AF76
 893       4C9C5622A56738A76A3DA15F2F9C56249E5A289E5A289E5A289E5A289E5A289E
 894       5A289E5A289D59279C5724B0784FF2E8E1FFFFFFC59C7EA26131A26131C59C7F
 895       FFFFFFC79F819D5825D7BBA6F8F2EFFAF6F3EDDFD6B5815A9F5B2AA26030A260
 896       30A26030A26030A26030A26030A26030A260309B5521C8A084FFFFFFC59C7FA2
 897       6131A26131C69E81FEFEFEB47F59B07950FDFAF9FFFFFFFFFFFFFFFFFFD6BAA4
 898       9F5B2AA25F2FA26030A26030A26030A26030A26030A26030A260309D5825B987
 899       62FFFEFEC69E81A26131A26131C79E81FEFDFDB47E57B27D56FDFBF9FFFFFFFF
 900       FFFFFFFFFFDABFACA05D2CA25F2FA26030A26030A26030A26030A26030A26030
 901       A260309E5826B88661FEFDFDC79E81A26131A26131C79F82FEFDFDB47F58B27C
 902       54FCFAF8FFFFFFFFFFFFFFFFFFD9BDABA05D2CA25F2FA26030A26030A26030A2
 903       6030A26030A26030A260309E5826B88662FEFDFDC79F82A26131A26030C79F82
 904       FFFFFFB47F58B37D56FDFCFBFFFFFFFFFFFFFFFFFFD9BFABA05D2CA25F2FA260
 905       30A26030A26030A26030A26030A26030A260309E5826B88662FFFFFFC79F82A2
 906       6030AB6F43B17B53F8F3F0B88662A56638EDE0D7FFFFFFFFFFFFFDFDFCC4997B
 907       9F5A29A26030A26030A26030A26030A26030A26030A26030A260309D5825BB8A
 908       67F8F3F0B17A53AB6F43D5B6A09D5725B17A51AB6E429E5A28AD7248C49A7BC6
 909       9E81B88662A15F2FA15E2EA25F2FA25F2FA25F2FA25F2FA25F2FA25F2FA25F2F
 910       A25F2FA05D2CAA6E42B179519D5725D5B6A0FDFBFAD4B6A0AB6F45A66638A768
 911       3BA56536A36132A26030A46334A66739A7683AA7673AA7673AA7673AA7673AA7
 912       673AA7673AA7673AA7673AA7683AA66638AB7045D4B6A0FDFBFA}
 913   end
 914   object GroupBox7: TGroupBox
 915     Left = 0
 916     Top = 267
 917     Width = 671
 918     Height = 49
 919     Align = alTop
 920     Caption = '需要抓取'
 921     Font.Charset = DEFAULT_CHARSET
 922     Font.Color = clBlack
 923     Font.Height = -12
 924     Font.Name = 'MS Sans Serif'
 925     Font.Style = []
 926     ParentFont = False
 927     TabOrder = 2
 928     object cbCatchJCMatch: TCheckBox
 929       Left = 153
 930       Top = 21
 931       Width = 97
 932       Height = 17
 933       Caption = '竞彩对阵'
 934       Font.Charset = DEFAULT_CHARSET
 935       Font.Color = clBlack
 936       Font.Height = -12
 937       Font.Name = 'MS Sans Serif'
 938       Font.Style = [fsBold]
 939       ParentFont = False
 940       TabOrder = 0
 941       OnClick = cbCatchJCMatchClick
 942     end
 943     object cbCatchJCResult: TCheckBox
 944       Left = 272
 945       Top = 21
 946       Width = 81
 947       Height = 17
 948       Caption = '竞彩赛果'
 949       Font.Charset = DEFAULT_CHARSET
 950       Font.Color = clBlack
 951       Font.Height = -12
 952       Font.Name = 'MS Sans Serif'
 953       Font.Style = [fsBold]
 954       ParentFont = False
 955       TabOrder = 1
 956       OnClick = cbCatchJCResultClick
 957     end
 958     object cbCatchGeneral: TCheckBox
 959       Left = 32
 960       Top = 21
 961       Width = 113
 962       Height = 17
 963       Caption = '传统体彩结果'
 964       Font.Charset = DEFAULT_CHARSET
 965       Font.Color = clBlack
 966       Font.Height = -12
 967       Font.Name = 'MS Sans Serif'
 968       Font.Style = [fsBold]
 969       ParentFont = False
 970       TabOrder = 2
 971       OnClick = cbCatchGeneralClick
 972     end
 973     object cbSaveFile: TCheckBox
 974       Left = 376
 975       Top = 21
 976       Width = 113
 977       Height = 17
 978       Caption = '是否保存文件'
 979       Font.Charset = DEFAULT_CHARSET
 980       Font.Color = clBlack
 981       Font.Height = -12
 982       Font.Name = 'MS Sans Serif'
 983       Font.Style = [fsBold]
 984       ParentFont = False
 985       TabOrder = 3
 986       OnClick = cbSaveFileClick
 987     end
 988   end
 989   object GroupBox4: TGroupBox
 990     Left = 0
 991     Top = 316
 992     Width = 671
 993     Height = 180
 994     Align = alClient
 995     Caption = '服务器状态'
 996     TabOrder = 3
 997     object memServerLog: TMemo
 998       Left = 2
 999       Top = 15
1000       Width = 667
1001       Height = 163
1002       Align = alClient
1003       BorderStyle = bsNone
1004       Color = clBtnFace
1005       Ctl3D = False
1006       ImeName = '中文 (简体) - 搜狗拼音输入法'
1007       ParentCtl3D = False
1008       ReadOnly = True
1009       ScrollBars = ssVertical
1010       TabOrder = 0
1011     end
1012   end
1013   object GroupBox1: TGroupBox
1014     Left = 0
1015     Top = 496
1016     Width = 671
1017     Height = 58
1018     Align = alBottom
1019     Font.Charset = DEFAULT_CHARSET
1020     Font.Color = clBlack
1021     Font.Height = -12
1022     Font.Name = 'MS Sans Serif'
1023     Font.Style = []
1024     ParentFont = False
1025     TabOrder = 4
1026     object bbtnStart: TBitBtn
1027       Left = 7
1028       Top = 10
1029       Width = 94
1030       Height = 43
1031       Caption = '开始'
1032       TabOrder = 0
1033       OnClick = bbtnStartClick
1034       Glyph.Data = {
1035         360C0000424D360C000000000000360000002800000020000000200000000100
1036         180000000000000C0000120B0000120B00000000000000000000FFFFFFFFFFFF
1037         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE6EEE2B1CAA581A8
1038         6D6192484D843047802A47802A4D843061924881A86DB1CAA5E6EEE2FFFFFFFF
1039         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1040         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3E1CC7FA76A447E273B781C3B78
1041         1C3B781C3B781C3B781C3B781C3B781C3B781C3B781C3B781C447E277FA76AD3
1042         E1CCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1043         FFFFFFFFFFFFFFFFFFFFFFFFF0F5EE8AAF783D791E3B781C3B781C54893986AB
1044         72B0C8A3CCDCC4D5E2CFD5E2CFCCDCC4B0C8A386AB725489393B781C3B781C3D
1045         791E8AAF78F1F5EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1046         FFFFFFFFFFFFFFFFFFD7E3D15B8E403B781C3B771B67944EBDD1B3F6F9F4FFFF
1047         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6F9F4BED2B36897503B
1048         781C3B781C5B8E40D7E3D1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1049         FFFFFFFFFFFFCDDDC549822C3B781C457E27B6CDABFFFFFFFFFFFFFFFFFFFFFF
1050         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFEFDAF
1051         C8A2467F283B781C49822CCEDDC6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1052         FFFFFFD9E5D247802A3B781C578A3CDEE9D9E3F1E0A2D79B9FD699CCE9C8FDFE
1053         FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1054         FFFFD9E5D3578C3D3B781C48812BD9E5D2FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1055         F2F6F0588C3E3B781C578A3BE9F0E6EFF7EE72C36967BC5C67BC5C67BC5C85C9
1056         7DCCE9C9FEFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1057         FFFFFFFFFFE7EFE3578C3D3B781C588C3EF2F6F0FFFFFFFFFFFFFFFFFFFFFFFF
1058         89AE773B781C467F28DBE6D5FFFFFFBAE2B567BC5C67BC5C67BC5C67BC5C67BC
1059         5C67BC5C8ACC82D2EBCEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1060         FFFFFFFFFFFFFFFFDCE7D6467F283B781C8AAF78FFFFFFFFFFFFFFFFFFD6E3D0
1061         3D791E3B781CAFC8A3FFFFFFFFFFFFA9D9A367BC5C67BC5C67BC5C67BC5C67BC
1062         5C67BC5C67BC5C67BC5C90CE88D6EDD4FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1063         FFFFFFFFFFFFFFFFFFFFFFB0C8A33B781C3D791ED6E3D0FFFFFFFFFFFF7DA669
1064         3B781C66964EFDFEFDFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1065         5C67BC5C67BC5C67BC5C67BC5C67BC5C94D08DDCEFD9FFFFFFFFFFFFFFFFFFFF
1066         FFFFFFFFFFFFFFFFFFFFFFFDFEFD65954C3B781C7DA669FFFFFFE8EFE4437D25
1067         3B781CC0D4B6FFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1068         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C68BC5D9AD393E1F2DEFFFFFFFF
1069         FFFFFFFFFFFFFFFFFFFFFFFFFFFFBFD3B53B781C437D25E8EFE4B1C9A43B781C
1070         538838F7FAF6FFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1071         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C6ABD5FA0D599E5
1072         F4E4FFFFFFFFFFFFFFFFFFFFFFFFF7FAF65388383B781CB1C9A47FA76B3B781C
1073         86AB72FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1074         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C6D
1075         BF62A6D8A0EAF6E9FFFFFFFFFFFFFFFFFF85AB723B781C7FA76B5F91463B781C
1076         B1C9A4FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1077         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67
1078         BC5C67BC5C70C066ACDAA6F2F9F1FFFFFFAFC7A33B781C5F91464D84303B781C
1079         CCDCC4FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1080         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67
1081         BC5C67BC5C67BC5C67BC5C7AC570E4F2E1D4E2CE3A771B4D84304780293B781C
1082         D6E3D0FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1083         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67
1084         BC5C67BC5C67BC5C67BC5C67BC5C96D28EDFEBDA3975194780294780293B781C
1085         D6E3D0FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1086         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67
1087         BC5C67BC5C67BC5C67BC5C67BC5C96D28EDFEBDA3975194780294D84303B781C
1088         CCDCC4FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1089         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67
1090         BC5C67BC5C67BC5C67BC5C7AC570E4F2E1D4E2CE3A771B4D84305F91463B781C
1091         B1C9A4FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1092         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67
1093         BC5C67BC5C70C066ACDAA6F2F9F1FFFFFFAFC7A33B781C5F91467FA76B3B781C
1094         86AB72FFFFFFFFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1095         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C6D
1096         BF62A6D8A0EAF6E9FFFFFFFFFFFFFFFFFF85AB723B781C7FA76BB1C9A43B781C
1097         538838F7FAF6FFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1098         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C6ABD5FA0D599E5
1099         F4E4FFFFFFFFFFFFFFFFFFFFFFFFF7FAF65388383B781CB1C9A4E8EFE4437D25
1100         3B781CC0D4B6FFFFFFFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1101         5C67BC5C67BC5C67BC5C67BC5C67BC5C67BC5C68BC5D9AD393E1F2DEFFFFFFFF
1102         FFFFFFFFFFFFFFFFFFFFFFFFFFFFC0D4B63B781C437D25E8EFE4FFFFFF7DA669
1103         3B781C66964EFDFEFDFFFFFFFFFFFFAAD9A467BC5C67BC5C67BC5C67BC5C67BC
1104         5C67BC5C67BC5C67BC5C67BC5C67BC5C94D08DDCEFD9FFFFFFFFFFFFFFFFFFFF
1105         FFFFFFFFFFFFFFFFFFFFFFFDFEFD65954D3B781C7DA669FFFFFFFFFFFFD6E3D0
1106         3D791E3B781CAFC8A3FFFFFFFFFFFFA9D9A367BC5C67BC5C67BC5C67BC5C67BC
1107         5C67BC5C67BC5C67BC5C90CE88D6EDD4FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1108         FFFFFFFFFFFFFFFFFFFFFFB0C8A33B781C3D791ED6E3D0FFFFFFFFFFFFFFFFFF
1109         89AE773B781C467F28DBE6D6FFFFFFB9E2B567BC5C67BC5C67BC5C67BC5C67BC
1110         5C67BC5C8ACC82D2EBCEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1111         FFFFFFFFFFFFFFFFDCE7D6467F283B781C89AE77FFFFFFFFFFFFFFFFFFFFFFFF
1112         F2F6F0578C3D3B781C578A3BE9F1E6F0F8EF72C36867BC5C67BC5C67BC5C85C9
1113         7DCCE9C9FEFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1114         FFFFFFFFFFE7EFE3578C3D3B781C588C3EF2F6F0FFFFFFFFFFFFFFFFFFFFFFFF
1115         FFFFFFD8E4D247802A3B781C578A3BDFEADBE4F2E1A2D89C9FD698CCE9C8FDFE
1116         FCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1117         FFFFD9E5D3578C3D3B781C47802AD9E5D2FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1118         FFFFFFFFFFFFCDDDC549822C3B781C447D26B7CEACFFFFFFFFFFFFFFFFFFFFFF
1119         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFEFDAF
1120         C8A2467F283B781C49822CCDDDC5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1121         FFFFFFFFFFFFFFFFFFD7E3D15B8E403B781C3A771B67954EBED2B4F6F9F4FFFF
1122         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6F9F4BED3B46897513B
1123         781C3B781C5B8E40D7E3D1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1124         FFFFFFFFFFFFFFFFFFFFFFFFF0F5EE8AAF783D791E3B781C3B781C54893986AB
1125         72B0C8A3CCDCC4D5E2CFD5E2CFCCDCC4B0C8A386AB725489393B781C3B781C3D
1126         791E8AAF78F0F5EEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1127         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3E1CC7EA669447E273B781C3B78
1128         1C3B781C3B781C3B781C3B781C3B781C3B781C3B781C3B781C447E277FA76AD3
1129         E1CCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1130         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE6EEE2B1CAA581A8
1131         6D6192484D843047802A47802A4D843061924881A86DB1CAA5E6EEE2FFFFFFFF
1132         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
1133     end
1134     object bbtnStop: TBitBtn
1135       Left = 106
1136       Top = 10
1137       Width = 94
1138       Height = 43
1139       Caption = '停止'
1140       TabOrder = 1
1141       OnClick = bbtnStopClick
1142       Glyph.Data = {
1143         360C0000424D360C000000000000360000002800000020000000200000000100
1144         180000000000000C0000120B0000120B00000000000000000000FFFFFFFFFFFF
1145         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE3E2F5A8A6DF726F
1146         CB4E4ABE3833B5322DB3322DB33833B54E4ABE726FCBA8A6DFE3E2F5FFFFFFFF
1147         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1148         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCECDED706CCA2E2AB2241FAE241F
1149         AE241FAE241FAE241FAE241FAE241FAE241FAE241FAE241FAE2E2AB2706CCACE
1150         CDEDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1151         FFFFFFFFFFFFFFFFFFFFFFFFEFEEF97C79CF2621AF241FAE241FAE403CB87774
1152         CDA7A5DEC6C5EAD1D0EED1D0EEC6C5EAA7A5DE7774CD403CB8241FAE241FAE26
1153         21AF7C79CFF0EFF9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1154         FFFFFFFFFFFFFFFFFFD2D1EE4743BB241FAE241FAE5753C1B7B5E4F5F4FBFFFF
1155         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F4FBB6B4E45652C024
1156         1FAE241FAE4743BBD2D1EEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1157         FFFFFFFFFFFFC7C6EA332FB4241FAE302BB2A6A4DEFDFDFEFFFFFFFFFFFFFFFF
1158         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFDFEA6
1159         A4DE302BB2241FAE332FB4C8C7EBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1160         FFFFFFD4D3EF322DB3241FAE4440BAD5D4EFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1161         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1162         FFFFD5D4EF4440BA241FAE332EB3D4D3EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1163         F0F0FA4540BA241FAE4440BAE4E4F5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1164         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1165         FFFFFFFFFFE4E4F54440BA241FAE4540BAF0F0FAFFFFFFFFFFFFFFFFFFFFFFFF
1166         7C79CE241FAE302BB2D8D7F1FFFFFFFFFFFFFFFFFFF0F0FEABA9F88784F58381
1167         F58481F58481F58481F58481F58481F58481F58381F58784F5ABA9F8F0F0FEFF
1168         FFFFFFFFFFFFFFFFD7D7F0302BB2241FAE7C79CFFFFFFFFFFFFFFFFFFFD1D0EE
1169         2621AF241FAEA7A5DEFFFFFFFFFFFFFFFFFFD1D0FB433FF0241FED241FED241F
1170         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED433FF0D1
1171         D0FBFFFFFFFFFFFFFFFFFFA7A5DE241FAE2621AFD1D0EEFFFFFFFFFFFF6E6BC9
1172         241FAE5450C0FDFDFEFFFFFFFFFFFFF0EFFE3F3AEF241FED241FED241FED241F
1173         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED3F
1174         3AEFF0EFFEFFFFFFFFFFFFFDFDFE524EBF241FAE6E6BC9FFFFFFE5E5F52D28B1
1175         241FAEB9B7E5FFFFFFFFFFFFFFFFFFA9A7F8241FED241FED241FED241FED241F
1176         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1177         1FEDAAA8F8FFFFFFFFFFFFFFFFFFB8B6E5241FAE2D28B1E5E5F5A7A5DF241FAE
1178         3F3AB8F6F6FCFFFFFFFFFFFFFFFFFF8582F5241FED241FED241FED241FED241F
1179         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1180         1FED8481F5FFFFFFFFFFFFFFFFFFF6F6FC3F3AB8241FAEA7A5DF706DCA241FAE
1181         7774CDFFFFFFFFFFFFFFFFFFFFFFFF8381F5241FED241FED241FED241FED241F
1182         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1183         1FED8381F5FFFFFFFFFFFFFFFFFFFFFFFF7774CD241FAE706DCA4C48BD241FAE
1184         A7A5DFFFFFFFFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1185         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1186         1FED8481F5FFFFFFFFFFFFFFFFFFFFFFFFA7A5DF241FAE4C48BD3833B5241FAE
1187         C6C5EAFFFFFFFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1188         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1189         1FED8481F5FFFFFFFFFFFFFFFFFFFFFFFFC6C5EA241FAE3833B5312CB3241FAE
1190         D1D0EEFFFFFFFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1191         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1192         1FED8481F5FFFFFFFFFFFFFFFFFFFFFFFFD1D0EE241FAE312CB3312CB3241FAE
1193         D1D0EEFFFFFFFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1194         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1195         1FED8481F5FFFFFFFFFFFFFFFFFFFFFFFFD1D0EE241FAE312CB33833B5241FAE
1196         C6C5EAFFFFFFFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1197         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1198         1FED8481F5FFFFFFFFFFFFFFFFFFFFFFFFC6C5EA241FAE3833B54C48BD241FAE
1199         A7A5DFFFFFFFFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1200         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1201         1FED8481F5FFFFFFFFFFFFFFFFFFFFFFFFA7A5DF241FAE4C48BD706DCA241FAE
1202         7774CDFFFFFFFFFFFFFFFFFFFFFFFF8381F5241FED241FED241FED241FED241F
1203         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1204         1FED8381F5FFFFFFFFFFFFFFFFFFFFFFFF7774CD241FAE706DCAA7A5DF241FAE
1205         3F3AB8F6F6FCFFFFFFFFFFFFFFFFFF8481F5241FED241FED241FED241FED241F
1206         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1207         1FED8481F5FFFFFFFFFFFFFFFFFFF6F6FC3F3AB8241FAEA7A5DFE5E5F52D28B1
1208         241FAEB9B7E5FFFFFFFFFFFFFFFFFFAAA8F8241FED241FED241FED241FED241F
1209         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED24
1210         1FEDAAA8F8FFFFFFFFFFFFFFFFFFB9B7E5241FAE2D28B1E5E5F5FFFFFF6E6BC9
1211         241FAE5450C0FDFDFEFFFFFFFFFFFFF0EFFE3F3AEF241FED241FED241FED241F
1212         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED241FED3F
1213         3AEFF0EFFEFFFFFFFFFFFFFDFDFE534FBF241FAE6E6BC9FFFFFFFFFFFFD1D0EE
1214         2621AF241FAEA7A5DEFFFFFFFFFFFFFFFFFFD1D0FB433FF0241FED241FED241F
1215         ED241FED241FED241FED241FED241FED241FED241FED241FED241FED433FF0D1
1216         D0FBFFFFFFFFFFFFFFFFFFA7A5DE241FAE2621AFD1D0EEFFFFFFFFFFFFFFFFFF
1217         7C79CE241FAE302BB2D7D7F0FFFFFFFFFFFFFFFFFFF0F0FEABA9F88784F58381
1218         F58481F58481F58481F58481F58481F58481F58381F58784F5ABA9F8F0F0FEFF
1219         FFFFFFFFFFFFFFFFD7D7F0302BB2241FAE7C79CEFFFFFFFFFFFFFFFFFFFFFFFF
1220         F0F0FA4440BA241FAE4440BAE4E4F5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1221         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1222         FFFFFFFFFFE4E4F54440BA241FAE4540BAF0F0FAFFFFFFFFFFFFFFFFFFFFFFFF
1223         FFFFFFD3D2EF322DB3241FAE4440BAD6D5F0FFFFFFFFFFFFFFFFFFFFFFFFFFFF
1224         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1225         FFFFD5D4EF4440BA241FAE322DB3D4D3EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1226         FFFFFFFFFFFFC7C6EA332FB4241FAE302BB2A6A4DEFDFDFEFFFFFFFFFFFFFFFF
1227         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFDFEA6
1228         A4DE302BB2241FAE332FB4C7C6EAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1229         FFFFFFFFFFFFFFFFFFD2D1EE4743BB241FAE241FAE5854C1B7B5E4F5F4FBFFFF
1230         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F4FBB7B5E45753C124
1231         1FAE241FAE4743BBD2D1EEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1232         FFFFFFFFFFFFFFFFFFFFFFFFEFEEF97C79CF2621AF241FAE241FAE403CB87774
1233         CDA7A5DEC6C5EAD1D0EED1D0EEC6C5EAA7A5DE7774CD403CB8241FAE241FAE26
1234         21AF7C79CFEFEEF9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1235         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCECDED6F6BCA2E2AB2241FAE241F
1236         AE241FAE241FAE241FAE241FAE241FAE241FAE241FAE241FAE2E2AB2706CCACE
1237         CDEDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1238         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE3E2F5A8A6DF726F
1239         CB4E4ABE3833B5322DB3322DB33833B54E4ABE726FCBA8A6DFE3E2F5FFFFFFFF
1240         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
1241     end
1242     object bbtnOpenLogFolder: TBitBtn
1243       Left = 313
1244       Top = 10
1245       Width = 102
1246       Height = 43
1247       Caption = '历史日志'
1248       TabOrder = 2
1249       OnClick = bbtnOpenLogFolderClick
1250       Glyph.Data = {
1251         360C0000424D360C000000000000360000002800000020000000200000000100
1252         180000000000000C0000120B0000120B00000000000000000000FFFFFFEEF7FE
1253         88C6F94BA9F7389FF6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369E
1254         F6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369EF636
1255         9EF6369EF6369EF6369EF6389FF64BA9F788C6F9EEF7FEFFFFFFEEF7FE51ABF7
1256         2998F52998F52998F52998F52998F52998F52998F52998F52998F52998F52998
1257         F52998F52998F52998F52998F52998F52998F52998F52998F52998F52998F529
1258         98F52998F52998F52998F52998F52998F52998F551ABF7EEF7FE86C5F92998F5
1259         369EF6A2D2FBCEE8FDD3EAFDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9
1260         FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2
1261         E9FDD2E9FDD2E9FDD3EAFDCEE8FDA2D2FB369EF62998F586C5F947A7F62998F5
1262         A3D3FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1263         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1264         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA4D3FB2998F547A7F6379FF62998F5
1265         D3EAFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1266         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1267         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3EAFD2998F5389FF6369EF62998F5
1268         D3EAFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1269         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1270         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3EAFD2998F5369EF6369EF62998F5
1271         D2E9FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1272         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1273         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2E9FD2998F5369EF6369EF62998F5
1274         D2E9FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1275         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1276         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2E9FD2998F5369EF6369EF62998F5
1277         D2E9FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1278         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1279         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2E9FD2998F5369EF6369EF62998F5
1280         D2E9FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1281         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1282         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2E9FD2998F5369EF6369EF62998F5
1283         D2E9FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1284         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1285         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD1E8FD2998F5369EF6369EF62998F5
1286         D2E9FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1287         FFFFFFFFFFFFFFFFFFFFE0F5FDC7ECFCC7ECFCC7ECFCC7ECFCC7ECFCC7ECFCC7
1288         ECFCC7ECFCC7ECFCC7ECFCC7ECFCF0FAFED5EBFD2997F5369EF6369EF62998F5
1289         D4EAFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1290         FFFFFFFFFFFFFFF4FBFE3FBEF525B5F425B5F425B5F425B5F425B5F425B5F425
1291         B5F425B5F425B5F425B5F425B5F474D0F8D9EEFD2997F5369EF644A5F62998F5
1292         AFD9FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1293         FFFFFFFFFFFFFFEFF9FE31B9F525B5F425B5F425B5F425B5F425B5F425B5F425
1294         B5F425B5F425B5F425B5F425B5F458C7F7D3EBFD2997F5369EF67ABFF92998F5
1295         40A3F6BADEFCE3F2FEE7F3FEE6F3FEE6F3FEE6F3FEE6F3FEE6F3FEE6F3FEE6F3
1296         FEE6F3FEE8F4FEEEF8FE35BCF525B5F425B5F425B5F425B5F425B5F425B5F425
1297         B5F425B5F425B5F425B5F425B5F45CC8F7D3EBFD2997F5369EF6E3F2FE41A4F6
1298         2998F52998F52E9AF5319CF5309BF5309BF5309BF5309BF5309BF5309BF5319C
1299         F5329CF546A4F6E1F3FE39BDF525B5F425B5F425B5F425B5F425B5F425B5F425
1300         B5F425B5F425B5F425B5F425B5F45CC8F7D3EBFD2997F5369EF6FFFFFFE0F0FE
1301         6BBBFD32A1FF279BFD259AFC2998F62A98F52A98F52A98F52A98F52A98F52998
1302         F52998F53B9FF6E1F3FE34BCF525B5F425B5F425B5F425B5F425B5F425B5F425
1303         B5F425B5F425B5F425B5F425B5F457C7F7D5ECFD2997F5369EF6FFFFFFFFFFFF
1304         FFFFFFEBF1F5DBE8F3DEEBF6DBEEFEDBEEFEDCEEFDDCEEFDDCEEFDDDEEFDB7DC
1305         FC2998F5359CF6E7F5FE57C8F725B6F425B6F425B6F425B6F425B6F425B6F425
1306         B6F425B6F425B6F425B6F426B7F48AD7F9CAE7FD2997F540A3F6FFFFFFFFFFFF
1307         FFFFFFDCA876D19256EFD9C4FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6FB
1308         FF3AA0F62998F583C3F9E3F4FED3EEFDD3EEFDD3EEFDD3EEFDD3EEFDD3EEFDD3
1309         EEFDD3EEFDD3EEFDD3EEFDD4EFFDE0F2FE5BAFF72998F565B5F8FFFFFFFFFFFF
1310         FFFFFFCF9A66C48242E8CEB5FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1311         FF9BD1FD2998F52998F543A4F65FB1F85FB1F85FB1F85FB1F85FB1F85FB1F85F
1312         B1F85FB1F85FB1F85FB1F85BAFF7379EF62998F52C99F5CCE6FDFFFFFFFFFFFF
1313         FFFFFFD09C6AC48242EAD3BCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1314         FFFFFFFF93CDFF369EF62998F52998F52998F52998F52998F52998F52998F529
1315         98F52998F52998F52798F82698F82499FB42A5F9BADEFCFFFFFFFFFFFFFFFFFF
1316         FFFFFFCF9A66C48242D09B67D7AA7FD7AA7ED7AA7ED7AA7ED7AA7ED7A97DE6C1
1317         9DFDFCFBFFFFFFE5F3FFBEE0FCAED8FBAED8FBAED8FBAED8FBAED8FBAED8FBAE
1318         D8FBAED8FBABD8FEB3D9F9BDDEF8D2E6F6F3F9FEFFFFFFFFFFFFFFFFFFFFFFFF
1319         FFFFFFDCB48EC48242C48242C48242C48242C48242C48242C48242C48242C482
1320         43E2B68CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1321         FFFFFFFFFFFFFFFFF2E9E0D6B595DFBFA0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1322         FFFFFFFCF9F5D4A577C48242C48242C48242C48242C48242C48242C48242C482
1323         42CC925AFEFCFAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1324         FFFFFFFFFFFFFFFFEACDB1C7823FD09861FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1325         FFFFFFFFFFFFFCFAF7D4A577C48242C48242C48242C48242C48242C48242C482
1326         42CB9057FCF9F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1327         FFFFFFFFFFFFFFFFE9CFB7C48242D09C6AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1328         FFFFFFFFFFFFFFFFFFFCFAF7D4A577C48242C48242C48242C48242C48242C482
1329         42CB9158FCFAF7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1330         FFFFFFFFFFFFFFFFE9CFB7C48242D09C6AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1331         FFFFFFFFFFFFFFFFFFFFFFFFFCFAF7D4A577C48242C48242C48242C48242C482
1332         42CB9158FCFAF7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1333         FFFFFFFFFFFFFFFFE9D0B8C48242D09C69FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1334         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCFAF7D4A577C48242C48242C48242C482
1335         42CB9158FCFAF7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1336         FFFFFFFFFFFFFFFFE9CFB7C48242D19D6BFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1337         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCFAF7D4A577C48242C48242C482
1338         42CB9159FFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1339         FFFFFFFFFFFFFFFFDBB38BC48242D6A77AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1340         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCFAF7D4A577C48242C482
1341         42CA8E54F0E0D0F3E5D7F3E5D7F3E5D7F3E5D7F3E5D7F3E5D7F3E5D7F3E5D7F3
1342         E5D8F1E2D3E0BE9CC58445C48242E9CFB7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1343         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCFAF7D4A577C482
1344         42C48242C48242C48242C48242C48242C48242C48242C48242C48242C48242C4
1345         8242C48242C48242C48242D7AA7EFEFDFCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1346         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCFAF7D8AD
1347         82C88B4FC88A4EC88A4EC88A4EC88A4EC88A4EC88A4EC88A4EC88A4EC88A4EC8
1348         8A4EC98C52CF9965E3C4A6FEFCFBFFFFFFFFFFFFFFFFFFFFFFFF}
1349     end
1350     object bbtnOpenLog: TBitBtn
1351       Left = 206
1352       Top = 10
1353       Width = 102
1354       Height = 43
1355       Caption = '今日日志'
1356       TabOrder = 3
1357       OnClick = bbtnOpenLoClick
1358       Glyph.Data = {
1359         360C0000424D360C000000000000360000002800000020000000200000000100
1360         180000000000000C0000120B0000120B00000000000000000000FFFFFFFFFFFF
1361         FFFFFFFFFFFFF5FAFF8FC9FA43A5F6359EF6369EF6369EF6369EF6369EF6369E
1362         F6369EF6369EF6369EF6369EF6369EF6329CF566B5F8F0F8FEFFFFFFFFFFFFFF
1363         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1364         FFFFFFFBFDFF65B5F82998F52998F52998F52998F52998F52998F52998F52998
1365         F52998F52998F52998F52998F52998F52998F52998F55BB0F7F1F8FEFFFFFFFF
1366         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1367         FFFFFFABD7FB2998F52C9AF599CEFAD6EBFDD2E9FDD2E9FDD2E9FDD2E9FDD2E9
1368         FDD2E9FDD2E9FDD2E9FDD3EAFDCEE8FD45A5F62998F52998F55BB0F7F1F8FEFF
1369         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1370         FFFFFF6AB8F82998F580C2F9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1371         FFFFFFFFFFFFFFFFFFFFFFFFFFFCFDFF4DA9F72998F52998F52998F560B3F8F6
1372         FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1373         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1374         FFFFFFFFFFFFFFFFFFFFFFFFFFFBFDFF4CA9F72998F52998F52998F52998F565
1375         B5F8F6FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1376         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1377         FFFFFFFFFFFFFFFFFFFFFFFFFFFBFDFF4CA9F72998F52998F52998F52998F529
1378         98F565B5F8F6FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1379         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1380         FFFFFFFFFFFFFFFFFFFFFFFFFFFBFDFF4CA9F72998F52998F52998F52998F529
1381         98F52998F565B5F8F6FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1382         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1383         FFFFFFFFFFFFFFFFFFFFFFFFFFFBFDFF4BA9F72998F52998F52998F52998F529
1384         98F52998F52998F565B5F8F6FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1385         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1386         FFFFFFFFFFFFFFFFFFFFFFFFFFFCFDFF4DA9F72998F52998F52998F52998F529
1387         98F52998F52998F52998F565B5F8F6FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1388         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1389         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF87C5F92998F52998F52998F52998F529
1390         98F52998F52998F52998F52998F57FC2F9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1391         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1392         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8FCFF99CEFA6AB7F86DB9F86DB9F86D
1393         B9F86DB9F870BAF853ACF72998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1394         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1395         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1396         FFFFFFFFFFFFFFFFAED8FB2998F560B2F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1397         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1398         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1399         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1400         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1401         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1402         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1403         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1404         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1405         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1406         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1407         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1408         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1409         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1410         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1411         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1412         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1413         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1414         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1415         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1416         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1417         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1418         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1419         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1420         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1421         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1422         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1423         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1424         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1425         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1426         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1427         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1428         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1429         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1430         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1431         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1432         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1433         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1434         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1435         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1436         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1437         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1438         FFFFFFFFFFFFFFFFAED8FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1439         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1440         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1441         FFFFFFFFFFFFFFFFAED8FB2998F560B2F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1442         FFFFFF60B3F82998F5A1D2FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1443         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1444         FFFFFFFFFFFFFFFFAAD6FB2998F560B3F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1445         FFFFFF6AB8F82998F580C2F9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1446         FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1447         FFFFFFFFFFFFFFFF7FC2F92998F56AB8F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1448         FFFFFFABD7FB2998F52C9AF599CEFAD6EBFDD2E9FDD2E9FDD2E9FDD2E9FDD2E9
1449         FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2E9FDD2
1450         E9FDD6EBFD99CEFA2C9AF52998F5ABD7FBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1451         FFFFFFFBFDFF65B5F82998F52998F52998F52998F52998F52998F52998F52998
1452         F52998F52998F52998F52998F52998F52998F52998F52998F52998F52998F529
1453         98F52998F52998F52998F565B5F8FBFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1454         FFFFFFFFFFFFF5FAFF8FC9FA43A5F6359EF6369EF6369EF6369EF6369EF6369E
1455         F6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369EF6369EF636
1456         9EF6359EF643A5F68FC9FAF5FAFFFFFFFFFFFFFFFFFFFFFFFFFF}
1457     end
1458     object Button2: TButton
1459       Left = 456
1460       Top = 24
1461       Width = 75
1462       Height = 25
1463       Caption = 'Button2'
1464       Enabled = False
1465       TabOrder = 4
1466       OnClick = Button2Click
1467     end
1468   end
1469   object rztiMain: TRzTrayIcon
1470     Hint = '爱彩票抓取服务器'
1471     PopupMenu = pmMain
1472     Left = 192
1473     Top = 296
1474   end
1475   object pmMain: TPopupMenu
1476     Left = 227
1477     Top = 296
1478     object N1: TMenuItem
1479       Caption = '打开主界面'
1480       OnClick = N1Click
1481     end
1482     object N2: TMenuItem
1483       Caption = '-'
1484     end
1485     object N3: TMenuItem
1486       Caption = '退出'
1487       OnClick = N3Click
1488     end
1489   end
1490   object idhtpsrvr1: TIdHTTPServer
1491     Bindings = <>
1492     DefaultPort = 8090
1493     MaxConnections = 500
1494     TerminateWaitTime = 500
1495     OnCommandGet = idhtpsrvr1CommandGet
1496     Left = 152
1497     Top = 296
1498   end
1499 end
窗体文件
  1 {*******************************************************************************
  2   Copyright (C), 2011-2015, 
  3   File name:
  4   Author:
  5   Version: 1.0
  6   Date:
  7   Description:
  8   Others:
  9   Function List:
 10   History:
 11     1. Date: 2013-04-28
 12         Author: 
 13         Modification: 增加监控其他线程的全局变量
 14 *******************************************************************************}
 15 unit PubDefine;
 16 
 17 interface
 18 
 19 uses
 20   Controls, SysUtils, DateUtils, StrUtils;
 21 
 22 const
 23   RETRY_INV = 5000;             //抓取失败重试间隔时间,单位:毫秒
 24   URLREQUEST_TIMEOUT = 20;      //请求网页时的超时时间,单位:秒
 25 
 26 type
 27 
 28   TConnectionConfig = record
 29     Server: string;
 30     Username: string;
 31     Password: string;
 32     Port: Integer;
 33     Database: string;
 34   end;
 35 
 36   TSales = record            //开售状态
 37     LotteryType: string;     //彩种
 38     IsDGSale: Boolean;       //单关是否开售
 39     IsGGSale: Boolean;       //过关是否开售
 40   end;
 41 
 42   TMatch = record             //单场比赛
 43     ID: string;               //获取到的比赛ID
 44     MatchIndex: string;       //场次编码,格式为:110217-301
 45     MatchTime: TDateTime;     //比赛时间
 46     Sales: array of TSales;   //开售状态
 47     HomeTeam: string;         //主队名
 48     AwayTeam: string;         //客队名
 49     GivenScore: Real;         //让分让球
 50     PresetScore: Real;        //预设总分
 51   end;
 52 
 53   TBBMatchResult = record     //竞彩篮球赛果
 54     ID: string;               //比赛ID(官方ID)
 55     MatchIndex: string;       //场次编码
 56     Score: string;            //全场比分
 57     SFBonus: Currency;        //胜负SP
 58     RFSFBonus: Currency;      //让分胜负SP
 59     SFCBonus: Currency;       //胜分差SP
 60     DXFBonus: Currency;       //大小分SP
 61     Handicap : Currency ;     // 让分数值
 62     PrestScore :Currency ;    //大小分数值
 63     Status: string;           //状态
 64   end;
 65 
 66   TFBMatchResult = record     //竞彩足球赛果
 67     ID: string;               //比赛ID(官方ID)
 68     MatchIndex: string;       //场次编码
 69     Score: string;            //全场比分
 70     HalfScore: string;        //半场比分
 71     SPFBonus: Currency;       //胜平负SP
 72     RQSPFBonus: Currency;       //让球胜平负SP  2013-06-05 rulinzhang
 73     BFBonus: Currency;        //比分SP
 74     ZJQSBonus: Currency;      //总进球数SP
 75     BQCSPFBonus: Currency;    //半全场胜平负SP
 76     Status: string;           //状态
 77     reMark : string;         // 2013-06-05 rulinzhang 
 78   end;
 79 
 80   TBDMatch = record           // 北京单场对阵
 81     TERM: string;             // 彩期
 82     Status : Integer;         // 状态
 83     StartDate : TDateTime;    // 开赛时间
 84     RaceName: string;         //  赛事
 85     HomeTeam: string;         // 主队
 86     VisitingTeam : string;    // 客队
 87     MatchNo: Integer;         // 场次序号
 88     Handicap :  Currency ;   // 让分
 89   end;
 90 
 91   TBDResult = record              // 北京单场赛果
 92     TERM : string;                // 彩期
 93     SCORE : string;               //  比分
 94     MatchResult : String;       // 赛果
 95     SP : Double;               //  sp 值
 96     SingleBonus : Currency ;    // 单注奖金(元)
 97     MatchNo: Integer;            // 场次序号
 98 
 99   end;
100   TBDSFMatch = record           // 北京单场胜负对阵
101     TERM: string;             // 彩期
102     Status : Integer;         // 状态
103     StartDate : TDateTime;    // 开赛时间
104     RaceName: string;         //  赛事
105     HomeTeam: string;         // 主队
106     VisitingTeam : string;    // 客队
107     MatchNo: Integer;         // 场次序号
108     Handicap : Currency ;   // 让分
109   end;
110 
111   TDLTResult = record                    //大乐透开奖结果
112     Term: string;                        //彩期
113     DrawaTime: TDateTime;                //官方开奖时间
114     BingoNumer: array [0..6] of string;  //开奖号码
115     Prize: array [0..15] of Currency;    //奖金
116   end;
117 
118   TQXCResult = record                    //七星彩开奖结果
119     Term: string;                        //彩期
120     DrawaTime: TDateTime;                //官方开奖时间
121     BingoNumer: array [0..6] of string;  //开奖号码
122     Prize: array [0..5] of Currency;     //奖金
123   end;
124 
125   TPLResult = record                     //排列三排列五开奖结果
126     Term: string;                        //彩期
127     DrawaTime: TDateTime;                //官方开奖时间
128     BingoNumer: array [0..4] of string;  //开奖号码
129     Prize: array [0..3] of Currency;     //奖金
130   end;
131 
132   TSFCResult = record                    //胜负彩任九开奖结果
133     IsDrawed: Boolean;                   //是否已开奖
134     Term: string;                        //彩期
135     DrawaTime: TDateTime;                //官方开奖时间
136     BingoNumer: array [0..13] of string; //开奖号码
137     Prize: array [0..2] of Currency;     //奖金
138   end;
139 
140   TSCJQResult = record                   //四场进球开奖结果
141     IsDrawed: Boolean;                   //是否已开奖
142     Term: string;                        //彩期
143     DrawaTime: TDateTime;                //官方开奖时间
144     BingoNumer: array [0..7] of string;  //开奖号码
145     Prize: Currency;                     //奖金
146   end;
147 
148   TLCBQCSFResult = record                //六场半全场胜负开奖结果
149     IsDrawed: Boolean;                   //是否已开奖
150     Term: string;                        //彩期
151     DrawaTime: TDateTime;                //官方开奖时间
152     BingoNumer: array [0..11] of string; //开奖号码
153     Prize: Currency;                     //奖金
154   end;
155 
156   function ChangeCompIndex(aCompIndex: string): string;         //转换赛事编号,从周四301转换成110210-301
157   function RightPos(Substr, S: string): Integer;                //从右向左查找子字符串
158   function TranDrawDate(const aDrawDate: string): TDateTime;    //转化开奖号码,格式:从2011年05月11日 20:30转化到TDateTime
159   function TranDrawDateEx(const aDrawDate: string): TDateTime;  //转化开奖号码,格式:从2011年05月11日转化到TDateTime
160   procedure MyFillChar(out aArray; aCount: Integer);
161   {
162     封装系统的FillChar函数
163     因为系统的FillChar操纵内存后不会改变字符串的引用计数
164     这样会引起内存泄露
165   }
166    
167 var
168   Pub_EXEPath: string;
169   ConnectionConfig: TConnectionConfig;
170   //2013-04-28 guoqiang.xu 监控线程全局变量
171   JcMtchRunTime,JcResultRunTime,GeneralRunTime,BDMatchRunTime,BDResultRunTime:TDateTime;
172   BDSFMatchRunTime,BDSFResultRunTime :TDateTime; 
173 implementation
174 
175 uses FrmMain;
176 
177 procedure MyFillChar(out aArray; aCount: Integer);
178 begin
179   FillChar(aArray, aCount, #0);
180 end;
181 
182 function TranDrawDateEx(const aDrawDate: string): TDateTime;
183 var
184   FS:TFormatSettings;
185   sTemp: string;
186 begin
187   FS.ShortDateFormat := 'yyyy-mm-dd';
188   FS.LongTimeFormat := 'hh:mm:ss';
189   FS.DateSeparator := '-';
190   FS.TimeSeparator := ':';
191   sTemp := aDrawDate;
192   sTemp := StringReplace(sTemp, '', '-', [rfReplaceAll, rfIgnoreCase]);
193   sTemp := StringReplace(sTemp, '', '-', [rfReplaceAll, rfIgnoreCase]);
194   sTemp := StringReplace(sTemp, '', ' ', [rfReplaceAll, rfIgnoreCase]);
195   sTemp := sTemp + '00:00:00';
196   Result := StrToDateTimeDef(sTemp, MinDateTime, FS);
197 end;
198 
199 function TranDrawDate(const aDrawDate: string): TDateTime;
200 var
201   FS:TFormatSettings;
202   sTemp: string;
203 begin
204   sTemp := aDrawDate;
205   FS.ShortDateFormat := 'yyyy-mm-dd';
206   FS.LongTimeFormat := 'hh:mm:ss';
207   FS.DateSeparator := '-';
208   FS.TimeSeparator := ':';
209   sTemp := StringReplace(sTemp, '', '-', [rfReplaceAll, rfIgnoreCase]);
210   sTemp := StringReplace(sTemp, '', '-', [rfReplaceAll, rfIgnoreCase]);
211   sTemp := StringReplace(sTemp, '', '', [rfReplaceAll, rfIgnoreCase]);
212   sTemp := sTemp + ':00';
213   Result := StrToDateTimeDef(sTemp, MinDateTime, FS);
214 end;
215 
216 function ChangeCompIndex(aCompIndex: string): string;
217 var
218   sCompDateStr, sIndexStr: string;
219   iCompDayOfWeek, iNowDayOfWeek: Integer;
220   dtCompDate: TDate;
221 begin
222   sCompDateStr := Copy(aCompIndex, 1, 4);
223   sIndexStr := Copy(aCompIndex, 5, 3);
224   iNowDayOfWeek := DayOfWeek(Date());
225   if sCompDateStr = '周一' then iCompDayOfWeek := 2
226   else
227     if sCompDateStr = '周二' then iCompDayOfWeek := 3
228     else
229       if sCompDateStr = '周三' then iCompDayOfWeek := 4
230       else
231         if sCompDateStr = '周四' then iCompDayOfWeek := 5
232         else
233           if sCompDateStr = '周五' then iCompDayOfWeek := 6
234           else
235             if sCompDateStr = '周六' then iCompDayOfWeek := 7
236             else
237               if sCompDateStr = '周日' then iCompDayOfWeek := 1;
238   //
239   dtCompDate := IncDay(Date(), iCompDayOfWeek - iNowDayOfWeek);
240   Result := FormatDateTime('YYMMDD', dtCompDate) + '-' + sIndexStr;
241 end;
242 
243 function RightPos(Substr, S: string): Integer;
244 begin
245   Result := Pos(ReverseString(Substr), ReverseString(S));
246   if Result > 0 then
247     Result := Length(S) - Result + 1 - Length(Substr) + 1;
248 end;
249 
250 end.
PubDefine公共单元
   1 unit ThdGeneral;
   2 
   3 interface
   4 
   5 uses
   6   Classes, ShDocVw, MyAccess, SysUtils, PubDefine, DateUtils, IdHTTP,
   7   StrUtils;
   8 
   9 type
  10   TGeneralThd = class(TThread)
  11   private
  12     { Private declarations }
  13     Pause: Boolean;
  14     mcMain: TMyConnection;
  15     mqMain: TMyQuery;
  16     DLTResult: TDLTResult;
  17     QXCResult: TQXCResult;
  18     PLResult: TPLResult;
  19     SFCResult: TSFCResult;
  20     SCJQResult: TSCJQResult;
  21     LCBQCSFResult: TLCBQCSFResult;
  22 
  23     function CatchResult: Boolean;
  24     procedure Clear;
  25     function GetDLTResult: Boolean;
  26     function GetQXCResult: Boolean;
  27     function GetPLResult: Boolean;
  28     function GetSFCResult: Boolean;
  29     function GetSCJQResult: Boolean;
  30     function GetLCBQCSFResult: Boolean;
  31     function SaveData: Boolean;
  32   protected
  33     procedure Execute; override;
  34   public
  35     constructor Create;
  36     destructor Destroy; override;
  37     procedure SetPause(const aIsPause: Boolean);
  38   end;
  39 
  40 implementation
  41 
  42 uses FrmMain;
  43 
  44 { Important: Methods and properties of objects in visual components can only be
  45   used in a method called using Synchronize, for example,
  46 
  47       Synchronize(UpdateCaption);
  48 
  49   and UpdateCaption could look like,
  50 
  51     procedure TGeneralThd.UpdateCaption;
  52     begin
  53       Form1.Caption := 'Updated in a thread';
  54     end; }
  55 
  56 { TGeneralThd }
  57 
  58 function TGeneralThd.CatchResult: Boolean;
  59 begin
  60   Result := False;
  61   MainForm.LogInfo('开始抓取数字彩开奖结果和竞彩赛果', True);
  62   Clear;
  63   if not GetDLTResult then
  64   begin
  65     MainForm.LogInfo('获取大乐透开奖结果出错,等待重试!', True);
  66     Exit;
  67   end;
  68   if not GetQXCResult then
  69   begin
  70     MainForm.LogInfo('获取七星彩开奖结果出错,等待重试!', True);
  71     Exit;
  72   end;
  73   if not GetPLResult then
  74   begin
  75     MainForm.LogInfo('获取排列三排列五开奖结果出错,等待重试!', True);
  76     Exit;
  77   end;
  78   if not GetSFCResult then
  79   begin
  80     MainForm.LogInfo('获取胜负彩开奖结果出错,等待重试!', True);
  81     Exit;
  82   end;
  83   if not GetSCJQResult then
  84   begin
  85     MainForm.LogInfo('获取四场进球开奖结果出错,等待重试!', True);
  86     Exit;
  87   end;
  88   if not GetLCBQCSFResult then
  89   begin
  90     MainForm.LogInfo('获取六场半全场胜负开奖结果出错,等待重试!', True);
  91     Exit;
  92   end;
  93   Result := SaveData;
  94   MainForm.LogInfo('传统体彩开奖结果抓取成功,等待下一次抓取', True);
  95 end;
  96 
  97 procedure TGeneralThd.Clear;
  98 begin
  99   DLTResult.Term := '';
 100   DLTResult.DrawaTime := MinDateTime;
 101   MyFillChar(DLTResult.BingoNumer, SizeOf(DLTResult.BingoNumer));
 102   FillChar(DLTResult.Prize, SizeOf(DLTResult.Prize), Ord(0));
 103 
 104   QXCResult.Term := '';
 105   QXCResult.DrawaTime := MinDateTime;
 106   MyFillChar(QXCResult.BingoNumer, SizeOf(QXCResult.BingoNumer));
 107   FillChar(QXCResult.Prize, SizeOf(QXCResult.Prize), Ord(0));
 108 
 109   PLResult.Term := '';
 110   PLResult.DrawaTime := MinDateTime;
 111   MyFillChar(PLResult.BingoNumer, SizeOf(PLResult.BingoNumer));
 112   FillChar(PLResult.Prize, SizeOf(PLResult.Prize), Ord(0));
 113 
 114   SFCResult.IsDrawed := False;
 115   SFCResult.Term := '';
 116   SFCResult.DrawaTime := MinDateTime;
 117   MyFillChar(SFCResult.BingoNumer, SizeOf(SFCResult.BingoNumer));
 118   FillChar(SFCResult.Prize, SizeOf(SFCResult.Prize), Ord(0));
 119 
 120   SCJQResult.IsDrawed := False;
 121   SCJQResult.Term := '';
 122   SCJQResult.DrawaTime := MinDateTime;
 123   MyFillChar(SCJQResult.BingoNumer, SizeOf(SCJQResult.BingoNumer));
 124   SCJQResult.Prize := 0;
 125 
 126   LCBQCSFResult.IsDrawed := False;
 127   LCBQCSFResult.Term := '';
 128   LCBQCSFResult.DrawaTime := MinDateTime;
 129   MyFillChar(LCBQCSFResult.BingoNumer, SizeOf(LCBQCSFResult.BingoNumer));
 130   LCBQCSFResult.Prize := 0;
 131 end;
 132 
 133 constructor TGeneralThd.Create;
 134 begin
 135   inherited Create(True); 
 136   FreeOnTerminate := True;
 137   mcMain := TMyConnection.Create(nil);
 138   mcMain.Server := ConnectionConfig.Server;
 139   mcMain.Username := ConnectionConfig.Username;
 140   mcMain.Password := ConnectionConfig.Password;
 141   mcMain.Port := ConnectionConfig.Port;
 142   mcMain.Database := ConnectionConfig.Database;
 143   mcMain.LoginPrompt := False;
 144   try
 145     mcMain.Connect;
 146   except on ex:Exception do
 147     begin
 148       MainForm.LogInfo('初始化数据库连接超时:' + ex.Message, True);
 149       Exit;
 150     end;
 151   end;
 152   mqMain := TMyQuery.Create(nil);
 153   mqMain.Connection := mcMain;
 154   SetPause(True);
 155   Self.Resume;
 156 end;
 157 
 158 destructor TGeneralThd.Destroy;
 159 begin
 160   if Assigned(mcMain) then mcMain.Free;
 161   if Assigned(mqMain) then mqMain.Free;
 162   inherited;
 163 end;
 164 
 165 procedure TGeneralThd.Execute;
 166 var
 167   bPauseStatus: Boolean;
 168   dtTemp: TDateTime;
 169 begin
 170   { Place thread code here }
 171   bPauseStatus := Pause;
 172   while True do
 173   begin
 174     GeneralRunTime := Now;                     //2013-04-28 监控变量
 175     if not Pause then                          //如果没有收到暂停信息
 176     begin
 177       if MainForm.IsCatchGeneral then         //如果需要抓取
 178       begin
 179         if bPauseStatus <> Pause then
 180         begin
 181           MainForm.LogInfo('抓取线程***传统体彩开奖结果***已启动', True);
 182           bPauseStatus := Pause;
 183         end;
 184         MainForm.IsGeneralCatching := True;
 185         if CatchResult then                    //如果抓取成功
 186         begin
 187           dtTemp := Now;
 188           while not Pause do
 189           begin
 190             Sleep(500);
 191             if SecondsBetween(Now, dtTemp) > MainForm.GeneralGetInv then Break;
 192           end;
 193         end
 194         else begin
 195           MainForm.LogInfo('抓取传统体彩开奖结果失败,等待重试', True);
 196           Sleep(RETRY_INV);
 197         end;
 198       end
 199       else begin
 200         if bPauseStatus <> Pause then
 201         begin
 202           MainForm.LogInfo('抓取线程***传统体彩开奖结果***已启动,但设置为不抓取', True);
 203           bPauseStatus := Pause;
 204         end;
 205         Sleep(200);
 206       end;
 207     end
 208     else begin                                 //如果暂停抓取
 209       if bPauseStatus <> Pause then
 210       begin
 211         MainForm.LogInfo('抓取线程***传统体彩开奖结果***已暂停', True);
 212         bPauseStatus := Pause;
 213       end;
 214       MainForm.IsGeneralCatching := False;
 215       Sleep(500);
 216     end;
 217   end;
 218 end;
 219 
 220 function TGeneralThd.GetDLTResult: Boolean;
 221 var
 222   idServer: TIdHTTP;
 223   sResponse, sTerm, sDrawDate, sBingoNum, sPrize: AnsiString;
 224   iPos1, iPos2: Integer;
 225   dtDrawDate: TDateTime;
 226   cPrize: Currency;
 227 begin
 228   Result := False;
 229   idServer := TIdHTTP.Create(nil);
 230   try
 231     try
 232       MainForm.LogInfo('正在获取大乐透开奖结果', True);
 233       sResponse := Utf8ToAnsi(idServer.Get(MainForm.DLTAddress));       //一定要转换编码
 234       iPos1 := Pos('超级大乐透', sResponse);
 235       if iPos1 = 0 then
 236       begin
 237         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:找不到彩种字符串', True);
 238         Exit;
 239       end;
 240   ///////////////////////////////获取彩期//////////////////////////////////////
 241       iPos1 := PosEx('id="DropDownListEvents"', sResponse, iPos1 + 1);
 242       iPos2 := PosEx('selected="selected"', sResponse, iPos1 + 1);
 243       if (iPos1 = 0) or (iPos2 = 0) then
 244       begin
 245         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:找不到彩期', True);
 246         Exit;
 247       end;
 248       iPos1 := PosEx('>', sResponse, iPos2 + 1);
 249       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 250       sTerm := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 251       if StrToIntDef(sTerm, 0) = 0 then
 252       begin
 253         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:彩期抓取错误', True);
 254         Exit;
 255       end;
 256       DLTResult.Term := sTerm;
 257   ///////////////////////////////获取开奖日期//////////////////////////////////////
 258       iPos1 := PosEx('id="LabelEventDrawDate"', sResponse, iPos1 + 1);
 259       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 260       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 261       sDrawDate := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 262       dtDrawDate := TranDrawDate(sDrawDate);
 263       if dtDrawDate = MinDateTime then
 264       begin
 265         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:开奖时间抓取错误', True);
 266         Exit;
 267       end;
 268       DLTResult.DrawaTime := dtDrawDate;
 269   ///////////////////////////////获取红球1//////////////////////////////////////
 270       iPos1 := PosEx('id="LabelDrawContent_R_1"', sResponse, iPos1 + 1);
 271 
 272       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 273       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 274      // sResponse := copy(sResponse,iPos1 + 1,Length(sResponse)-iPos1-2);
 275       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 276       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 277 
 278 
 279     //  iPos1 := PosEx('<span id="LabelDrawContent_R_1" style="color:White;">', sResponse, iPos1 + 1);
 280      // iPos2 := PosEx('<', sResponse, iPos1 + 1);
 281     //  sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 282 
 283       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 284       begin
 285         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:红球1抓取错误', True);
 286         Exit;
 287       end;
 288       DLTResult.BingoNumer[0] := sBingoNum;
 289   ///////////////////////////////获取红球2//////////////////////////////////////
 290       iPos1 := PosEx('id="LabelDrawContent_R_2"', sResponse, iPos1 + 1);
 291       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 292       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 293       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 294       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 295       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 296       begin
 297         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:红球2抓取错误', True);
 298         Exit;
 299       end;
 300       DLTResult.BingoNumer[1] := sBingoNum;
 301   ///////////////////////////////获取红球3//////////////////////////////////////
 302       iPos1 := PosEx('id="LabelDrawContent_R_3"', sResponse, iPos1 + 1);
 303       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 304       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 305       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 306       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 307       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 308       begin
 309         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:红球3抓取错误', True);
 310         Exit;
 311       end;
 312       DLTResult.BingoNumer[2] := sBingoNum;
 313   ///////////////////////////////获取红球4//////////////////////////////////////
 314       iPos1 := PosEx('id="LabelDrawContent_R_4"', sResponse, iPos1 + 1);
 315       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 316       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 317       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 318       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 319       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 320       begin
 321         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:红球4抓取错误', True);
 322         Exit;
 323       end;
 324       DLTResult.BingoNumer[3] := sBingoNum;
 325   ///////////////////////////////获取红球5//////////////////////////////////////
 326       iPos1 := PosEx('id="LabelDrawContent_R_5"', sResponse, iPos1 + 1);
 327       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 328       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 329       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 330       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 331       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 332       begin
 333         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:红球5抓取错误', True);
 334         Exit;
 335       end;
 336       DLTResult.BingoNumer[4] := sBingoNum;
 337   ///////////////////////////////获取蓝球1//////////////////////////////////////
 338       iPos1 := PosEx('id="LabelDrawContent_B_1"', sResponse, iPos1 + 1);
 339       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 340       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 341       //sResponse := copy(sResponse,iPos1 + 1,Length(sResponse)-iPos1-2);
 342       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 343       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 344       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 345       begin
 346         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:蓝球1抓取错误', True);
 347         Exit;
 348       end;
 349       DLTResult.BingoNumer[5] := sBingoNum;
 350   ///////////////////////////////获取蓝球2//////////////////////////////////////
 351       iPos1 := PosEx('id="LabelDrawContent_B_2"', sResponse, iPos1 + 1);
 352       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 353       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 354       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 355       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 356       if (Length(sBingoNum) <> 2) or (StrToIntDef(sBingoNum, -1) = -1) then
 357       begin
 358         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:蓝球2抓取错误', True);
 359         Exit;
 360       end;
 361       DLTResult.BingoNumer[6] := sBingoNum;
 362   ///////////////////////////////获取一等奖//////////////////////////////////////
 363       iPos1 := PosEx('id="Label_L1_B"', sResponse, iPos1 + 1);
 364       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 365       iPos1 := PosEx('>', sResponse, iPos1 + 1);      //一二等奖和追加的一二等奖是红色的
 366       iPos2 := PosEx('<', sResponse, iPos1);
 367       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 368       cPrize := StrToCurrDef(sPrize, -1);
 369       if (cPrize = -1) then
 370       begin
 371         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:一等奖抓取错误', True);
 372         Exit;
 373       end;
 374       DLTResult.Prize[0] := cPrize;
 375   ///////////////////////////////获取二等奖//////////////////////////////////////
 376       iPos1 := PosEx('id="Label_L2_B"', sResponse, iPos1 + 1);
 377       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 378       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 379       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 380       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 381       cPrize := StrToCurrDef(sPrize, -1);
 382       if (cPrize = -1) then
 383       begin
 384         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:二等奖抓取错误', True);
 385         Exit;
 386       end;
 387       DLTResult.Prize[1] := cPrize;
 388   ///////////////////////////////获取三等奖//////////////////////////////////////
 389       iPos1 := PosEx('id="Label_L3_B"', sResponse, iPos1 + 1);
 390       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 391       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 392       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 393       cPrize := StrToCurrDef(sPrize, -1);
 394       if (cPrize = -1) then
 395       begin
 396         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:三等奖抓取错误', True);
 397         Exit;
 398       end;
 399       DLTResult.Prize[2] := cPrize;
 400   ///////////////////////////////获取四等奖//////////////////////////////////////
 401       iPos1 := PosEx('id="Label_L4_B"', sResponse, iPos1 + 1);
 402       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 403       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 404       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 405       cPrize := StrToCurrDef(sPrize, -1);
 406       if (cPrize = -1) then
 407       begin
 408         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:四等奖抓取错误', True);
 409         Exit;
 410       end;
 411       DLTResult.Prize[3] := cPrize;
 412   ///////////////////////////////获取五等奖//////////////////////////////////////
 413       iPos1 := PosEx('id="Label_L5_B"', sResponse, iPos1 + 1);
 414       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 415       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 416       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 417       cPrize := StrToCurrDef(sPrize, -1);
 418       if (cPrize = -1) then
 419       begin
 420         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:五等奖抓取错误', True);
 421         Exit;
 422       end;
 423       DLTResult.Prize[4] := cPrize;
 424   ///////////////////////////////获取六等奖//////////////////////////////////////
 425       iPos1 := PosEx('id="Label_L6_B"', sResponse, iPos1 + 1);
 426       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 427       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 428       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 429       cPrize := StrToCurrDef(sPrize, -1);
 430       if (cPrize = -1) then
 431       begin
 432         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:六等奖抓取错误', True);
 433         Exit;
 434       end;
 435       DLTResult.Prize[5] := cPrize;
 436   ///////////////////////////////获取七等奖//////////////////////////////////////
 437       iPos1 := PosEx('id="Label_L7_B"', sResponse, iPos1 + 1);
 438       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 439       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 440       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 441       cPrize := StrToCurrDef(sPrize, -1);
 442       if (cPrize = -1) then
 443       begin
 444         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:七等奖抓取错误', True);
 445         Exit;
 446       end;
 447       DLTResult.Prize[6] := cPrize;
 448   ///////////////////////////////获取八等奖//////////////////////////////////////
 449       iPos1 := PosEx('id="Label_L8_B"', sResponse, iPos1 + 1);
 450       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 451       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 452       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 453       cPrize := StrToCurrDef(sPrize, -1);
 454       if (cPrize = -1) then
 455       begin
 456         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:八等奖抓取错误', True);
 457         Exit;
 458       end;
 459       DLTResult.Prize[7] := cPrize;
 460   ///////////////////////////////获取一等奖追加//////////////////////////////////////
 461       iPos1 := PosEx('id="Label_Z1_B"', sResponse, iPos1 + 1);
 462       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 463       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 464       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 465       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 466       cPrize := StrToCurrDef(sPrize, -1);
 467       if (cPrize = -1) then
 468       begin
 469         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:一等奖追加抓取错误', True);
 470         Exit;
 471       end;
 472       DLTResult.Prize[8] := cPrize;
 473   ///////////////////////////////获取二等奖追加//////////////////////////////////////
 474       iPos1 := PosEx('id="Label_Z2_B"', sResponse, iPos1 + 1);
 475       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 476       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 477       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 478       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 479       cPrize := StrToCurrDef(sPrize, -1);
 480       if (cPrize = -1) then
 481       begin
 482         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:二等奖追加抓取错误', True);
 483         Exit;
 484       end;
 485       DLTResult.Prize[9] := cPrize;
 486   ///////////////////////////////获取三等奖追加//////////////////////////////////////
 487       iPos1 := PosEx('id="Label_Z3_B"', sResponse, iPos1 + 1);
 488       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 489       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 490       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 491       cPrize := StrToCurrDef(sPrize, -1);
 492       if (cPrize = -1) then
 493       begin
 494         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:三等奖追加抓取错误', True);
 495         Exit;
 496       end;
 497       DLTResult.Prize[10] := cPrize;
 498   ///////////////////////////////获取四等奖追加//////////////////////////////////////
 499       iPos1 := PosEx('id="Label_Z4_B"', sResponse, iPos1 + 1);
 500       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 501       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 502       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 503       cPrize := StrToCurrDef(sPrize, -1);
 504       if (cPrize = -1) then
 505       begin
 506         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:四等奖追加抓取错误', True);
 507         Exit;
 508       end;
 509       DLTResult.Prize[11] := cPrize;
 510   ///////////////////////////////获取五等奖追加//////////////////////////////////////
 511       iPos1 := PosEx('id="Label_Z5_B"', sResponse, iPos1 + 1);
 512       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 513       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 514       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 515       cPrize := StrToCurrDef(sPrize, -1);
 516       if (cPrize = -1) then
 517       begin
 518         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:五等奖追加抓取错误', True);
 519         Exit;
 520       end;
 521       DLTResult.Prize[12] := cPrize;
 522   ///////////////////////////////获取六等奖追加//////////////////////////////////////
 523       iPos1 := PosEx('id="Label_Z6_B"', sResponse, iPos1 + 1);
 524       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 525       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 526       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 527       cPrize := StrToCurrDef(sPrize, -1);
 528       if (cPrize = -1) then
 529       begin
 530         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:六等奖追加抓取错误', True);
 531         Exit;
 532       end;
 533       DLTResult.Prize[13] := cPrize;
 534   ///////////////////////////////获取七等奖追加//////////////////////////////////////
 535       iPos1 := PosEx('id="Label_Z7_B"', sResponse, iPos1 + 1);
 536       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 537       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 538       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 539       cPrize := StrToCurrDef(sPrize, -1);
 540       if (cPrize = -1) then
 541       begin
 542         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:七等奖追加抓取错误', True);
 543         Exit;
 544       end;
 545       DLTResult.Prize[14] := cPrize;
 546   ///////////////////////////////获取12选2奖//////////////////////////////////////
 547       iPos1 := PosEx('id="Label_12x2_B"', sResponse, iPos1 + 1);
 548       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 549       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 550       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 551       cPrize := StrToCurrDef(sPrize, -1);
 552       if (cPrize = -1) then
 553       begin
 554         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:12选2奖抓取错误', True);
 555         Exit;
 556       end;
 557       DLTResult.Prize[15] := cPrize;
 558       MainForm.LogInfo('大乐透' + sTerm + '期开奖结果获取成功', True);
 559       Result := True;
 560     except on E : Exception do
 561       begin
 562         MainForm.LogInfo('获取大乐透开奖结果时出错,原因:' + E.Message, True);
 563         Exit;
 564       end;
 565     end;
 566   finally
 567     if idServer <> nil then idServer.Free;
 568   end;          
 569 end;
 570 
 571 function TGeneralThd.GetLCBQCSFResult: Boolean;
 572 var
 573   idServer: TIdHTTP;
 574   sResponse, sTerm, sDrawDate, sPrize, sTemp: string;     //sMatchResult
 575   i, iPos1, iPos2, iPos3: Integer;
 576   dtDrawDate: TDateTime;
 577   cPrize: Currency;
 578 begin
 579   Result := False;
 580   idServer := TIdHTTP.Create(nil);
 581   try
 582     try
 583       MainForm.LogInfo('正在获取六场半全场胜负开奖结果', True);
 584       sResponse := Utf8ToAnsi(idServer.Get(MainForm.LCBQCSFAddress));       //一定要转换编码
 585   ///////////////////////////////获取彩期//////////////////////////////////////
 586       iPos1 := Pos('id="DropDownListEvents"', sResponse);
 587       if iPos1 = 0 then
 588       begin
 589         MainForm.LogInfo('获取六场半全场胜负开奖结果时出错,原因:找不到彩期', True);
 590         Exit;
 591       end;
 592       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 593       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 594       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 595       sTerm := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 596       if StrToIntDef(sTerm, 0) = 0 then
 597       begin
 598         MainForm.LogInfo('获取六场半全场胜负开奖结果时出错,原因:彩期抓取错误', True);
 599         Exit;
 600       end;
 601       LCBQCSFResult.Term := sTerm;
 602   ///////////////////////////////获取开奖日期//////////////////////////////////////
 603       iPos1 := PosEx('id="LabelDrawDate"', sResponse, iPos1 + 1);
 604       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 605       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 606       sDrawDate := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 607       dtDrawDate := TranDrawDateEx(sDrawDate);
 608       if dtDrawDate = MinDateTime then
 609       begin
 610         MainForm.LogInfo('获取六场半全场胜负开奖结果时出错,原因:开奖时间抓取错误', True);
 611         Exit;
 612       end;
 613       LCBQCSFResult.DrawaTime := dtDrawDate;
 614   ///////////////////////////////获取第i个赛果//////////////////////////////////////
 615       iPos1 := PosEx('<TABLE', sResponse, iPos1 + 1);
 616       iPos1 := PosEx('<TABLE', sResponse, iPos1 + 1);
 617       iPos1 := PosEx('<TR', sResponse, iPos1 + 1);
 618       iPos1 := PosEx('<TR', sResponse, iPos1 + 1);
 619       for i := 0 to 11 do
 620       begin
 621         iPos1 := PosEx('<B>', sResponse, iPos1 + 1);
 622         sTemp := Copy(sResponse, iPos1 + 3, 1);
 623         if sTemp = '-' then        //官方未开奖
 624         begin
 625           Result := True;
 626           LCBQCSFResult.IsDrawed := False;
 627           MainForm.LogInfo('六场半全场胜负' + sTerm + '期官方未开奖,不抓取', True);
 628           Exit;
 629         end
 630         else if StrToIntDef(sTemp, -1) = -1 then
 631         begin
 632           MainForm.LogInfo('获取六场半全场胜负开奖结果时出错,原因:第' + IntToStr(i + 1) + '个赛果抓取错误', True);
 633           Exit;
 634         end;
 635         LCBQCSFResult.BingoNumer[i] := sTemp;
 636       end;
 637   ///////////////////////////////获取奖金明细//////////////////////////////////////
 638       iPos1 := PosEx('id="LabelDrawDetails"', sResponse, iPos1 + 1);
 639       iPos1 := PosEx('', sResponse, iPos1 + 1);
 640       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 641       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 642       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 643       sPrize := StringReplace(sPrize, ',', '', [rfReplaceAll, rfIgnoreCase]);
 644       cPrize := StrToCurrDef(sPrize, -1);
 645       if cPrize = -1 then
 646       begin
 647         MainForm.LogInfo('获取六场半全场胜负开奖结果时出错,原因:一等奖奖金抓取错误', True);
 648         Exit;
 649       end;
 650       LCBQCSFResult.Prize := cPrize;
 651       MainForm.LogInfo('六场半全场胜负' + sTerm + '期开奖结果获取成功', True);
 652       LCBQCSFResult.IsDrawed := True;
 653       Result := True;
 654     except on E : Exception do
 655       begin
 656         MainForm.LogInfo('获取六场半全场胜负开奖结果时出错,原因:' + E.Message, True);
 657         Exit;
 658       end;
 659     end;
 660   finally
 661     if idServer <> nil then idServer.Free;
 662   end;          
 663 end;
 664 
 665 function TGeneralThd.GetPLResult: Boolean;
 666 var
 667   idServer: TIdHTTP;
 668   sResponse, sDrawDate, sBingoNum, sPrize, sTemp,sTerm: string;
 669   iPos1, iPos2, iPos3: Integer;
 670   dtDrawDate: TDateTime;
 671   cPrize: Currency;
 672 begin
 673   Result := False;
 674   idServer := TIdHTTP.Create(nil);
 675   try
 676     try
 677       MainForm.LogInfo('正在获取排列三排列五开奖结果', True);
 678       sResponse := Utf8ToAnsi(idServer.Get(MainForm.PLAddress));       //一定要转换编码
 679       iPos1 := Pos('排列3、5', sResponse);
 680       if iPos1 = 0 then
 681       begin
 682         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:找不到彩种字符串', True);
 683         Exit;
 684       end;
 685   ///////////////////////////////获取彩期//////////////////////////////////////
 686       iPos1 := PosEx('id="DropDownListEvents"', sResponse, iPos1 + 1);
 687       iPos2 := PosEx('selected="selected"', sResponse, iPos1 + 1);
 688       if (iPos1 = 0) or (iPos2 = 0) then
 689       begin
 690         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:找不到彩期', True);
 691         Exit;
 692       end;
 693       iPos1 := PosEx('>', sResponse, iPos2 + 1);
 694       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 695       sTerm := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 696       if StrToIntDef(sTerm, 0) = 0 then
 697       begin
 698         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:彩期抓取错误', True);
 699         Exit;
 700       end;
 701       PLResult.Term := sTerm;
 702   ///////////////////////////////获取开奖日期//////////////////////////////////////
 703       iPos1 := PosEx('id="LabelEventDrawDate"', sResponse, iPos1 + 1);
 704       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 705       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 706       sDrawDate := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 707       dtDrawDate := TranDrawDate(sDrawDate);
 708       if dtDrawDate = MinDateTime then
 709       begin
 710         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:开奖时间抓取错误', True);
 711         Exit;
 712       end;
 713       PLResult.DrawaTime := dtDrawDate;
 714   ///////////////////////////////获取号码1//////////////////////////////////////
 715       iPos1 := PosEx('id="LabelDrawContent_PLW_1"', sResponse, iPos1 + 1);
 716       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 717       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 718       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 719       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 720       begin
 721         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:号码1抓取错误', True);
 722         Exit;
 723       end;
 724       PLResult.BingoNumer[0] := sBingoNum;
 725   ///////////////////////////////获取号码2//////////////////////////////////////
 726       iPos1 := PosEx('id="LabelDrawContent_PLW_2"', sResponse, iPos1 + 1);
 727       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 728       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 729       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 730       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 731       begin
 732         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:号码2抓取错误', True);
 733         Exit;
 734       end;
 735       PLResult.BingoNumer[1] := sBingoNum;
 736   ///////////////////////////////获取号码3//////////////////////////////////////
 737       iPos1 := PosEx('id="LabelDrawContent_PLW_3"', sResponse, iPos1 + 1);
 738       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 739       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 740       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 741       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 742       begin
 743         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:号码3抓取错误', True);
 744         Exit;
 745       end;
 746       PLResult.BingoNumer[2] := sBingoNum;
 747   ///////////////////////////////获取号码4//////////////////////////////////////
 748       iPos1 := PosEx('id="LabelDrawContent_PLW_4"', sResponse, iPos1 + 1);
 749       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 750       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 751       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 752       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 753       begin
 754         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:号码4抓取错误', True);
 755         Exit;
 756       end;
 757       PLResult.BingoNumer[3] := sBingoNum;
 758   ///////////////////////////////获取号码5//////////////////////////////////////
 759       iPos1 := PosEx('id="LabelDrawContent_PLW_5"', sResponse, iPos1 + 1);
 760       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 761       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 762       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 763       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 764       begin
 765         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:号码5抓取错误', True);
 766         Exit;
 767       end;
 768       PLResult.BingoNumer[4] := sBingoNum;
 769   ///////////////////////////////获取奖金明细//////////////////////////////////////
 770       iPos1 := PosEx('id="LabelDrawDetails"', sResponse, iPos1 + 1);
 771       iPos1 := PosEx('排列3:', sResponse, iPos1 + 1);
 772       iPos3 := PosEx('排列5:', sResponse, iPos1 + 1);
 773       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 774       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 775       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 776       cPrize := StrToCurrDef(sPrize, -1);
 777       if cPrize = -1 then
 778       begin
 779         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:直选奖金抓取错误', True);
 780         Exit;
 781       end;
 782       PLResult.Prize[1] := cPrize;
 783       iPos1 := PosEx('', sResponse, iPos1 + 1);
 784       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 785       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 786       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 787       cPrize := StrToCurrDef(sPrize, -1);
 788       if cPrize = -1 then
 789       begin
 790         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:组选三奖金抓取错误', True);
 791         Exit;
 792       end;
 793       PLResult.Prize[2] := cPrize;
 794       iPos1 := PosEx('', sResponse, iPos1 + 1);
 795       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 796       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 797       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 798       cPrize := StrToCurrDef(sPrize, -1);
 799       if cPrize = -1 then
 800       begin
 801         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:组选六奖金抓取错误', True);
 802         Exit;
 803       end;
 804       PLResult.Prize[3] := cPrize;
 805       iPos1 := PosEx('', sResponse, iPos1 + 1);
 806       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 807       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 808       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 809       cPrize := StrToCurrDef(sPrize, -1);
 810       if cPrize = -1 then
 811       begin
 812         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:排列五奖金抓取错误', True);
 813         Exit;
 814       end;
 815       PLResult.Prize[0] := cPrize;
 816       MainForm.LogInfo('排列三排列五' + sTerm + '期开奖结果获取成功', True);
 817       Result := True;
 818     except on E : Exception do
 819       begin
 820         MainForm.LogInfo('获取排列三排列五开奖结果时出错,原因:' + E.Message, True);
 821         Exit;
 822       end;
 823     end;
 824   finally
 825     if idServer <> nil then idServer.Free;
 826   end;          
 827 end;
 828 
 829 function TGeneralThd.GetQXCResult: Boolean;
 830 var
 831   idServer: TIdHTTP;
 832   sResponse, sTerm, sDrawDate, sBingoNum, sPrize: string;
 833   iPos1, iPos2: Integer;
 834   dtDrawDate: TDateTime;
 835   cPrize: Currency;
 836 begin
 837   Result := False;
 838   idServer := TIdHTTP.Create(nil);
 839   try
 840     try
 841       MainForm.LogInfo('正在获取七星彩开奖结果', True);
 842       sResponse := Utf8ToAnsi(idServer.Get(MainForm.QXCAddress));       //一定要转换编码
 843       iPos1 := Pos('七星彩', sResponse);
 844       if iPos1 = 0 then
 845       begin
 846         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:找不到彩种字符串', True);
 847         Exit;
 848       end;
 849   ///////////////////////////////获取彩期//////////////////////////////////////
 850       iPos1 := PosEx('id="DropDownListEvents"', sResponse, iPos1 + 1);
 851       iPos2 := PosEx('selected="selected"', sResponse, iPos1 + 1);
 852       if (iPos1 = 0) or (iPos2 = 0) then
 853       begin
 854         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:找不到彩期', True);
 855         Exit;
 856       end;
 857       iPos1 := PosEx('>', sResponse, iPos2 + 1);
 858       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 859       sTerm := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 860       if StrToIntDef(sTerm, 0) = 0 then
 861       begin
 862         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:彩期抓取错误', True);
 863         Exit;
 864       end;
 865       QXCResult.Term := sTerm;
 866   ///////////////////////////////获取开奖日期//////////////////////////////////////
 867       iPos1 := PosEx('id="LabelEventDrawDate"', sResponse, iPos1 + 1);
 868       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 869       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 870       sDrawDate := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 871       dtDrawDate := TranDrawDate(sDrawDate);
 872       if dtDrawDate = MinDateTime then
 873       begin
 874         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:开奖时间抓取错误', True);
 875         Exit;
 876       end;
 877       QXCResult.DrawaTime := dtDrawDate;
 878   ///////////////////////////////获取号码1//////////////////////////////////////
 879       iPos1 := PosEx('id="LabelDrawContent_R_1"', sResponse, iPos1 + 1);
 880       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 881       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 882       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 883       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 884       begin
 885         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码1抓取错误', True);
 886         Exit;
 887       end;
 888       QXCResult.BingoNumer[0] := sBingoNum;
 889   ///////////////////////////////获取号码2//////////////////////////////////////
 890       iPos1 := PosEx('id="LabelDrawContent_R_2"', sResponse, iPos1 + 1);
 891       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 892       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 893       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 894       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 895       begin
 896         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码2抓取错误', True);
 897         Exit;
 898       end;
 899       QXCResult.BingoNumer[1] := sBingoNum;
 900   ///////////////////////////////获取号码3//////////////////////////////////////
 901       iPos1 := PosEx('id="LabelDrawContent_R_3"', sResponse, iPos1 + 1);
 902       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 903       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 904       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 905       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 906       begin
 907         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码3抓取错误', True);
 908         Exit;
 909       end;
 910       QXCResult.BingoNumer[2] := sBingoNum;
 911   ///////////////////////////////获取号码4//////////////////////////////////////
 912       iPos1 := PosEx('id="LabelDrawContent_R_4"', sResponse, iPos1 + 1);
 913       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 914       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 915       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 916       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 917       begin
 918         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码4抓取错误', True);
 919         Exit;
 920       end;
 921       QXCResult.BingoNumer[3] := sBingoNum;
 922   ///////////////////////////////获取号码5//////////////////////////////////////
 923       iPos1 := PosEx('id="LabelDrawContent_R_5"', sResponse, iPos1 + 1);
 924       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 925       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 926       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 927       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 928       begin
 929         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码5抓取错误', True);
 930         Exit;
 931       end;
 932       QXCResult.BingoNumer[4] := sBingoNum;
 933   ///////////////////////////////获取号码6//////////////////////////////////////
 934       iPos1 := PosEx('id="LabelDrawContent_R_6"', sResponse, iPos1 + 1);
 935       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 936       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 937       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 938       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 939       begin
 940         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码6抓取错误', True);
 941         Exit;
 942       end;
 943       QXCResult.BingoNumer[5] := sBingoNum;
 944   ///////////////////////////////获取号码7//////////////////////////////////////
 945       iPos1 := PosEx('id="LabelDrawContent_R_7"', sResponse, iPos1 + 1);
 946       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 947       iPos2 := PosEx('<', sResponse, iPos1 + 1);
 948       sBingoNum := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 949       if (Length(sBingoNum) <> 1) or (StrToIntDef(sBingoNum, -1) = -1) then
 950       begin
 951         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:号码7抓取错误', True);
 952         Exit;
 953       end;
 954       QXCResult.BingoNumer[6] := sBingoNum;
 955   ///////////////////////////////获取一等奖//////////////////////////////////////
 956       iPos1 := PosEx('id="Label_L1_B"', sResponse, iPos1 + 1);
 957       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 958       iPos1 := PosEx('>', sResponse, iPos1 + 1);      //一二等奖和追加的一二等奖是红色的
 959       iPos2 := PosEx('<', sResponse, iPos1);
 960       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 961       cPrize := StrToCurrDef(sPrize, -1);
 962       if (cPrize = -1) then
 963       begin
 964         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:一等奖抓取错误', True);
 965         Exit;
 966       end;
 967       QXCResult.Prize[0] := cPrize;
 968   ///////////////////////////////获取二等奖//////////////////////////////////////
 969       iPos1 := PosEx('id="Label_L2_B"', sResponse, iPos1 + 1);
 970       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 971       iPos1 := PosEx('>', sResponse, iPos1 + 1);      //一二等奖和追加的一二等奖是红色的
 972       iPos2 := PosEx('<', sResponse, iPos1);
 973       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 974       cPrize := StrToCurrDef(sPrize, -1);
 975       if (cPrize = -1) then
 976       begin
 977         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:二等奖抓取错误', True);
 978         Exit;
 979       end;
 980       QXCResult.Prize[1] := cPrize;
 981   ///////////////////////////////获取三等奖//////////////////////////////////////
 982       iPos1 := PosEx('id="Label_L3_B"', sResponse, iPos1 + 1);
 983       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 984       iPos2 := PosEx('<', sResponse, iPos1);
 985       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 986       cPrize := StrToCurrDef(sPrize, -1);
 987       if (cPrize = -1) then
 988       begin
 989         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:三等奖抓取错误', True);
 990         Exit;
 991       end;
 992       QXCResult.Prize[2] := cPrize;
 993   ///////////////////////////////获取四等奖//////////////////////////////////////
 994       iPos1 := PosEx('id="Label_L4_B"', sResponse, iPos1 + 1);
 995       iPos1 := PosEx('>', sResponse, iPos1 + 1);
 996       iPos2 := PosEx('<', sResponse, iPos1);
 997       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
 998       cPrize := StrToCurrDef(sPrize, -1);
 999       if (cPrize = -1) then
1000       begin
1001         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:四等奖抓取错误', True);
1002         Exit;
1003       end;
1004       QXCResult.Prize[3] := cPrize;
1005   ///////////////////////////////获取五等奖//////////////////////////////////////
1006       iPos1 := PosEx('id="Label_L5_B"', sResponse, iPos1 + 1);
1007       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1008       iPos2 := PosEx('<', sResponse, iPos1);
1009       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1010       cPrize := StrToCurrDef(sPrize, -1);
1011       if (cPrize = -1) then
1012       begin
1013         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:五等奖抓取错误', True);
1014         Exit;
1015       end;
1016       QXCResult.Prize[4] := cPrize;
1017   ///////////////////////////////获取六等奖//////////////////////////////////////
1018       iPos1 := PosEx('id="Label_L6_B"', sResponse, iPos1 + 1);
1019       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1020       iPos2 := PosEx('<', sResponse, iPos1);
1021       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1022       cPrize := StrToCurrDef(sPrize, -1);
1023       if (cPrize = -1) then
1024       begin
1025         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:六等奖抓取错误', True);
1026         Exit;
1027       end;
1028       QXCResult.Prize[5] := cPrize;
1029       MainForm.LogInfo('七星彩' + sTerm + '期开奖结果获取成功', True);
1030       Result := True;
1031     except on E : Exception do
1032       begin
1033         MainForm.LogInfo('获取七星彩开奖结果时出错,原因:' + E.Message, True);
1034         Exit;
1035       end;
1036     end;
1037   finally
1038     if idServer <> nil then idServer.Free;
1039   end;          
1040 end;
1041 
1042 function TGeneralThd.GetSCJQResult: Boolean;
1043 var
1044   idServer: TIdHTTP;
1045   sResponse, sTerm, sDrawDate,sPrize, sTemp: string;
1046   i, iPos1, iPos2: Integer;
1047   dtDrawDate: TDateTime;
1048   cPrize: Currency;
1049 begin
1050   Result := False;
1051   idServer := TIdHTTP.Create(nil);
1052   try
1053     try
1054       MainForm.LogInfo('正在获取四场进球开奖结果', True);
1055       sResponse := Utf8ToAnsi(idServer.Get(MainForm.SCJQAddress));       //一定要转换编码
1056   ///////////////////////////////获取彩期//////////////////////////////////////
1057       iPos1 := Pos('id="DropDownListEvents"', sResponse);
1058       if iPos1 = 0 then
1059       begin
1060         MainForm.LogInfo('获取四场进球开奖结果时出错,原因:找不到彩期', True);
1061         Exit;
1062       end;
1063       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1064       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1065       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1066       sTerm := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1067       if StrToIntDef(sTerm, 0) = 0 then
1068       begin
1069         MainForm.LogInfo('获取四场进球开奖结果时出错,原因:彩期抓取错误', True);
1070         Exit;
1071       end;
1072       SCJQResult.Term := sTerm;
1073   ///////////////////////////////获取开奖日期//////////////////////////////////////
1074       iPos1 := PosEx('id="LabelDrawDate"', sResponse, iPos1 + 1);
1075       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1076       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1077       sDrawDate := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1078       dtDrawDate := TranDrawDateEx(sDrawDate);
1079       if dtDrawDate = MinDateTime then
1080       begin
1081         MainForm.LogInfo('获取四场进球开奖结果时出错,原因:开奖时间抓取错误', True);
1082         Exit;
1083       end;
1084       SCJQResult.DrawaTime := dtDrawDate;
1085   ///////////////////////////////获取第i场赛果//////////////////////////////////////
1086       iPos1 := PosEx('<TABLE', sResponse, iPos1 + 1);
1087       iPos1 := PosEx('<TABLE', sResponse, iPos1 + 1);
1088       iPos1 := PosEx('<TR', sResponse, iPos1 + 1);
1089       iPos1 := PosEx('<TR', sResponse, iPos1 + 1);
1090       for i := 0 to 7 do
1091       begin
1092         iPos1 := PosEx('<B>', sResponse, iPos1 + 1);
1093         sTemp := Copy(sResponse, iPos1 + 3, 1);
1094         if sTemp = '-' then        //官方未开奖
1095         begin
1096           Result := True;
1097           SCJQResult.IsDrawed := False;
1098           MainForm.LogInfo('四场进球' + sTerm + '期官方未开奖,不抓取', True);
1099           Exit;
1100         end
1101         else if StrToIntDef(sTemp, -1) = -1 then
1102         begin
1103           MainForm.LogInfo('获取四场进球开奖结果时出错,原因:第' + IntToStr(i + 1) + '场赛果抓取错误', True);
1104           Exit;
1105         end;
1106         SCJQResult.BingoNumer[i] := sTemp;
1107       end;
1108   ///////////////////////////////获取奖金明细//////////////////////////////////////
1109       iPos1 := PosEx('id="LabelDrawDetails"', sResponse, iPos1 + 1);
1110       iPos1 := PosEx('', sResponse, iPos1 + 1);
1111       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1112       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1113       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1114       sPrize := StringReplace(sPrize, ',', '', [rfReplaceAll, rfIgnoreCase]);
1115       cPrize := StrToCurrDef(sPrize, -1);
1116       if cPrize = -1 then
1117       begin
1118         MainForm.LogInfo('获取四场进球开奖结果时出错,原因:一等奖奖金抓取错误', True);
1119         Exit;
1120       end;
1121       SCJQResult.Prize := cPrize;
1122       MainForm.LogInfo('四场进球开奖结果获取成功', True);
1123       SCJQResult.IsDrawed := True;
1124       Result := True;
1125     except on E : Exception do
1126       begin
1127         MainForm.LogInfo('获取四场进球' + sTerm + '期开奖结果时出错,原因:' + E.Message, True);
1128         Exit;
1129       end;
1130     end;
1131   finally
1132     if idServer <> nil then idServer.Free;
1133   end;          
1134 end;
1135 
1136 function TGeneralThd.GetSFCResult: Boolean;
1137 var
1138   idServer: TIdHTTP;
1139   sResponse, sTerm, sDrawDate, sMatchResult, sPrize, sTemp: string;
1140   i, iPos1, iPos2, iPos3: Integer;
1141   dtDrawDate: TDateTime;
1142   cPrize: Currency;
1143 begin
1144   Result := False;
1145   idServer := TIdHTTP.Create(nil);
1146   try
1147     try
1148       MainForm.LogInfo('正在获取胜负彩开奖结果', True);
1149       sResponse := Utf8ToAnsi(idServer.Get(MainForm.SFCAddress));       //一定要转换编码
1150       iPos1 := Pos('任选九', sResponse);
1151       if iPos1 = 0 then
1152       begin
1153         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:找不到彩种字符串', True);
1154         Exit;
1155       end;
1156   ///////////////////////////////获取彩期//////////////////////////////////////
1157       iPos1 := Pos('id="DropDownListEvents"', sResponse);
1158       if iPos1 = 0 then
1159       begin
1160         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:找不到彩期', True);
1161         Exit;
1162       end;
1163       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1164       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1165       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1166       sTerm := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1167       if StrToIntDef(sTerm, 0) = 0 then
1168       begin
1169         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:彩期抓取错误', True);
1170         Exit;
1171       end;
1172       SFCResult.Term := sTerm;
1173   ///////////////////////////////获取开奖日期//////////////////////////////////////
1174       iPos1 := PosEx('id="LabelDrawDate"', sResponse, iPos1 + 1);
1175       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1176       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1177       sDrawDate := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1178       dtDrawDate := TranDrawDateEx(sDrawDate);
1179       if dtDrawDate = MinDateTime then
1180       begin
1181         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:开奖时间抓取错误', True);
1182         Exit;
1183       end;
1184       SFCResult.DrawaTime := dtDrawDate;
1185   ///////////////////////////////获取第i场赛果//////////////////////////////////////
1186       iPos1 := PosEx('<TABLE', sResponse, iPos1 + 1);
1187       iPos1 := PosEx('<TABLE', sResponse, iPos1 + 1);
1188       iPos1 := PosEx('<TR', sResponse, iPos1 + 1);
1189       iPos1 := PosEx('<TR', sResponse, iPos1 + 1);
1190       for i := 0 to 13 do
1191       begin
1192         iPos1 := PosEx('<B>', sResponse, iPos1 + 1);
1193         sTemp := Copy(sResponse, iPos1 + 3, 1);
1194         if sTemp = '-' then        //官方未开奖
1195         begin
1196           Result := True;
1197           SFCResult.IsDrawed := False;
1198           MainForm.LogInfo('胜负彩' + sTerm + '期官方未开奖,不抓取', True);
1199           Exit;
1200         end
1201         else if not (StrToIntDef(sTemp, -1) in [0, 1, 3]) then
1202         begin
1203           MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:第' + IntToStr(i + 1) + '场赛果抓取错误', True);
1204           Exit;
1205         end;
1206         SFCResult.BingoNumer[i] := sTemp;
1207       end;
1208   ///////////////////////////////获取奖金明细//////////////////////////////////////
1209       iPos1 := PosEx('id="LabelDrawDetails"', sResponse, iPos1 + 1);
1210       iPos1 := PosEx('', sResponse, iPos1 + 1);
1211       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1212       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1213       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1214       sPrize := StringReplace(sPrize, ',', '', [rfReplaceAll, rfIgnoreCase]);
1215       cPrize := StrToCurrDef(sPrize, -1);
1216       if cPrize = -1 then
1217       begin
1218         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:一等奖奖金抓取错误', True);
1219         Exit;
1220       end;
1221       SFCResult.Prize[0] := cPrize;
1222       iPos1 := PosEx('', sResponse, iPos1 + 1);
1223       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1224       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1225       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1226       sPrize := StringReplace(sPrize, ',', '', [rfReplaceAll, rfIgnoreCase]);
1227       cPrize := StrToCurrDef(sPrize, -1);
1228       if cPrize = -1 then
1229       begin
1230         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:二等奖奖金抓取错误', True);
1231         Exit;
1232       end;
1233       SFCResult.Prize[1] := cPrize;
1234       iPos1 := PosEx('', sResponse, iPos1 + 1);
1235       iPos1 := PosEx('>', sResponse, iPos1 + 1);
1236       iPos2 := PosEx('<', sResponse, iPos1 + 1);
1237       sPrize := Copy(sResponse, iPos1 + 1, iPos2 - iPos1 - 1);
1238       sPrize := StringReplace(sPrize, ',', '', [rfReplaceAll, rfIgnoreCase]);
1239       cPrize := StrToCurrDef(sPrize, -1);
1240       if cPrize = -1 then
1241       begin
1242         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:任九奖金抓取错误', True);
1243         Exit;
1244       end;
1245       SFCResult.Prize[2] := cPrize;
1246       MainForm.LogInfo('胜负彩' + sTerm + '期开奖结果获取成功', True);
1247       SFCResult.IsDrawed := True;
1248       Result := True;
1249     except on E : Exception do
1250       begin
1251         MainForm.LogInfo('获取胜负彩开奖结果时出错,原因:' + E.Message, True);
1252         Exit;
1253       end;
1254     end;
1255   finally
1256     if idServer <> nil then idServer.Free;
1257   end;
1258 end;
1259 
1260 function TGeneralThd.SaveData: Boolean;
1261 var
1262   iReturnCode: Integer;
1263   sSQLString: string;
1264 begin
1265   Result := False;
1266   MainForm.LogInfo('准备写入传统体彩开奖结果', True);
1267 ///////////////////////////////////////大乐透////////////////////////////////////////////////
1268   try
1269     mqMain.Close;
1270     sSQLString := 'CALL P_UPDATE_DLT_RESULT('
1271       + QuotedStr(DLTResult.Term)
1272       + ',' + QuotedStr(DateTimeToStr(DLTResult.DrawaTime))
1273       + ',' + QuotedStr(DLTResult.BingoNumer[0])
1274       + ',' + QuotedStr(DLTResult.BingoNumer[1])
1275       + ',' + QuotedStr(DLTResult.BingoNumer[2])
1276       + ',' + QuotedStr(DLTResult.BingoNumer[3])
1277       + ',' + QuotedStr(DLTResult.BingoNumer[4])
1278       + ',' + QuotedStr(DLTResult.BingoNumer[5])
1279       + ',' + QuotedStr(DLTResult.BingoNumer[6])
1280       + ',' + CurrToStr(DLTResult.Prize[0])
1281       + ',' + CurrToStr(DLTResult.Prize[1])
1282       + ',' + CurrToStr(DLTResult.Prize[2])
1283       + ',' + CurrToStr(DLTResult.Prize[3])
1284       + ',' + CurrToStr(DLTResult.Prize[4])
1285       + ',' + CurrToStr(DLTResult.Prize[5])
1286       + ',' + CurrToStr(DLTResult.Prize[6])
1287       + ',' + CurrToStr(DLTResult.Prize[7])
1288       + ',' + CurrToStr(DLTResult.Prize[8])
1289       + ',' + CurrToStr(DLTResult.Prize[9])
1290       + ',' + CurrToStr(DLTResult.Prize[10])
1291       + ',' + CurrToStr(DLTResult.Prize[11])
1292       + ',' + CurrToStr(DLTResult.Prize[12])
1293       + ',' + CurrToStr(DLTResult.Prize[13])
1294       + ',' + CurrToStr(DLTResult.Prize[14])
1295       + ',' + CurrToStr(DLTResult.Prize[15]);
1296     sSQLString := sSQLString +',@a); select @a;';
1297     mqMain.Close;
1298     mqMain.SQL.Text := sSQLString;
1299     mqMain.Execute;
1300     iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1301     mqMain.Close;
1302     if iReturnCode = 1 then              //数据验证失败
1303     begin
1304       MainForm.LogInfo('写入大乐透结果失败,原因:数据验证失败', True);
1305       Exit;
1306     end
1307     else if iReturnCode = 100 then
1308     begin
1309       MainForm.LogInfo('写入大乐透开奖结果失败,原因:未知错误', True);
1310       Exit;
1311     end;
1312   except on E : Exception do
1313     begin
1314       MainForm.LogInfo('写入大乐透开奖结果失败,原因:' + E.Message, True);
1315       Exit;
1316     end;
1317   end;
1318   MainForm.LogInfo('已写入大乐透第' + DLTResult.Term + '期开奖结果', True);
1319 ///////////////////////////////////////七星彩////////////////////////////////////////////////
1320   try
1321     mqMain.Close;
1322     sSQLString := 'CALL P_UPDATE_QXC_RESULT('
1323       + QuotedStr(QXCResult.Term)
1324       + ',' + QuotedStr(DateTimeToStr(QXCResult.DrawaTime))
1325       + ',' + QuotedStr(QXCResult.BingoNumer[0])
1326       + ',' + QuotedStr(QXCResult.BingoNumer[1])
1327       + ',' + QuotedStr(QXCResult.BingoNumer[2])
1328       + ',' + QuotedStr(QXCResult.BingoNumer[3])
1329       + ',' + QuotedStr(QXCResult.BingoNumer[4])
1330       + ',' + QuotedStr(QXCResult.BingoNumer[5])
1331       + ',' + QuotedStr(QXCResult.BingoNumer[6])
1332       + ',' + CurrToStr(QXCResult.Prize[0])
1333       + ',' + CurrToStr(QXCResult.Prize[1])
1334       + ',' + CurrToStr(QXCResult.Prize[2])
1335       + ',' + CurrToStr(QXCResult.Prize[3])
1336       + ',' + CurrToStr(QXCResult.Prize[4])
1337       + ',' + CurrToStr(QXCResult.Prize[5]);
1338     sSQLString := sSQLString +',@a); select @a;';
1339     mqMain.Close;
1340     mqMain.SQL.Text := sSQLString;
1341     mqMain.Execute;
1342     iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1343     mqMain.Close;
1344     if iReturnCode = 1 then              //数据验证失败
1345     begin
1346       MainForm.LogInfo('写入七星彩开奖结果失败,原因:数据验证失败', True);
1347       Exit;
1348     end
1349     else if iReturnCode = 100 then
1350     begin
1351       MainForm.LogInfo('写入七星彩开奖结果失败,原因:未知错误', True);
1352       Exit;
1353     end;
1354   except on E : Exception do
1355     begin
1356       MainForm.LogInfo('写入七星彩开奖结果失败,原因:' + E.Message, True);
1357       Exit;
1358     end;
1359   end;
1360   MainForm.LogInfo('已写入七星彩第' + QXCResult.Term + '期开奖结果', True);
1361 ///////////////////////////////////////排列三排列五////////////////////////////////////////////////
1362   try
1363     mqMain.Close;
1364     sSQLString := 'CALL P_UPDATE_PSPW_RESULT('
1365       + QuotedStr(PLResult.Term)
1366       + ',' + QuotedStr(DateTimeToStr(PLResult.DrawaTime))
1367       + ',' + QuotedStr(PLResult.BingoNumer[0])
1368       + ',' + QuotedStr(PLResult.BingoNumer[1])
1369       + ',' + QuotedStr(PLResult.BingoNumer[2])
1370       + ',' + QuotedStr(PLResult.BingoNumer[3])
1371       + ',' + QuotedStr(PLResult.BingoNumer[4])
1372       + ',' + CurrToStr(PLResult.Prize[0])
1373       + ',' + CurrToStr(PLResult.Prize[1])
1374       + ',' + CurrToStr(PLResult.Prize[2])       
1375       + ',' + CurrToStr(PLResult.Prize[3]);
1376     sSQLString := sSQLString +',@a); select @a;';
1377     mqMain.Close;
1378     mqMain.SQL.Text := sSQLString;
1379     mqMain.Execute;
1380     iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1381     mqMain.Close;
1382     if iReturnCode = 1 then              //数据验证失败
1383     begin
1384       MainForm.LogInfo('写入排列三排列五开奖结果失败,原因:数据验证失败', True);
1385       Exit;
1386     end
1387     else if iReturnCode = 100 then
1388     begin
1389       MainForm.LogInfo('写入排列三排列五开奖结果失败,原因:未知错误', True);
1390       Exit;
1391     end;
1392   except on E : Exception do
1393     begin
1394       MainForm.LogInfo('写入排列三排列五开奖结果失败,原因:' + E.Message, True);
1395       Exit;
1396     end;
1397   end;
1398   MainForm.LogInfo('已写入排列三排列五第' + PLResult.Term + '期开奖结果', True);
1399 ///////////////////////////////////////胜负彩////////////////////////////////////////////////
1400   if SFCResult.IsDrawed then
1401   begin
1402     try
1403       mqMain.Close;
1404       sSQLString := 'CALL P_UPDATE_SFC_RESULT('
1405         + QuotedStr(SFCResult.Term)
1406         + ',' + QuotedStr(DateTimeToStr(SFCResult.DrawaTime))
1407         + ',' + QuotedStr(SFCResult.BingoNumer[0])
1408         + ',' + QuotedStr(SFCResult.BingoNumer[1])
1409         + ',' + QuotedStr(SFCResult.BingoNumer[2])
1410         + ',' + QuotedStr(SFCResult.BingoNumer[3])
1411         + ',' + QuotedStr(SFCResult.BingoNumer[4])
1412         + ',' + QuotedStr(SFCResult.BingoNumer[5])
1413         + ',' + QuotedStr(SFCResult.BingoNumer[6])
1414         + ',' + QuotedStr(SFCResult.BingoNumer[7])
1415         + ',' + QuotedStr(SFCResult.BingoNumer[8])
1416         + ',' + QuotedStr(SFCResult.BingoNumer[9])
1417         + ',' + QuotedStr(SFCResult.BingoNumer[10])
1418         + ',' + QuotedStr(SFCResult.BingoNumer[11])
1419         + ',' + QuotedStr(SFCResult.BingoNumer[12])
1420         + ',' + QuotedStr(SFCResult.BingoNumer[13])
1421         + ',' + CurrToStr(SFCResult.Prize[0])         
1422         + ',' + CurrToStr(SFCResult.Prize[1])
1423         + ',' + CurrToStr(SFCResult.Prize[2]);
1424       sSQLString := sSQLString +',@a); select @a;';
1425       mqMain.Close;
1426       mqMain.SQL.Text := sSQLString;
1427       mqMain.Execute;
1428       iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1429       mqMain.Close;
1430       if iReturnCode = 1 then              //数据验证失败
1431       begin
1432         MainForm.LogInfo('写入胜负彩开奖结果失败,原因:数据验证失败', True);
1433         Exit;
1434       end
1435       else if iReturnCode = 100 then
1436       begin
1437         MainForm.LogInfo('写入胜负彩开奖结果失败,原因:未知错误', True);
1438         Exit;
1439       end;
1440     except on E : Exception do
1441       begin
1442         MainForm.LogInfo('写入胜负彩开奖结果失败,原因:' + E.Message, True);
1443         Exit;
1444       end;
1445     end;
1446     MainForm.LogInfo('已写入胜负彩第' + SFCResult.Term + '期开奖结果', True);
1447   end;
1448 ///////////////////////////////////////四场进球////////////////////////////////////////////////
1449   if SCJQResult.IsDrawed then
1450   begin
1451     try
1452       mqMain.Close;
1453       sSQLString := 'CALL P_UPDATE_SCJQ_RESULT('
1454         + QuotedStr(SCJQResult.Term)
1455         + ',' + QuotedStr(DateTimeToStr(SCJQResult.DrawaTime))
1456         + ',' + QuotedStr(SCJQResult.BingoNumer[0])
1457         + ',' + QuotedStr(SCJQResult.BingoNumer[1])
1458         + ',' + QuotedStr(SCJQResult.BingoNumer[2])
1459         + ',' + QuotedStr(SCJQResult.BingoNumer[3])
1460         + ',' + QuotedStr(SCJQResult.BingoNumer[4])
1461         + ',' + QuotedStr(SCJQResult.BingoNumer[5])
1462         + ',' + QuotedStr(SCJQResult.BingoNumer[6])
1463         + ',' + QuotedStr(SCJQResult.BingoNumer[7])
1464         + ',' + CurrToStr(SCJQResult.Prize);
1465       sSQLString := sSQLString +',@a); select @a;';
1466       mqMain.Close;
1467       mqMain.SQL.Text := sSQLString;
1468       mqMain.Execute;
1469       iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1470       mqMain.Close;
1471       if iReturnCode = 1 then              //数据验证失败
1472       begin
1473         MainForm.LogInfo('写入四场进球开奖结果失败,原因:数据验证失败', True);
1474         Exit;
1475       end
1476       else if iReturnCode = 100 then
1477       begin
1478         MainForm.LogInfo('写入四场进球开奖结果失败,原因:未知错误', True);
1479         Exit;
1480       end;
1481     except on E : Exception do
1482       begin
1483         MainForm.LogInfo('写入四场进球开奖结果失败,原因:' + E.Message, True);
1484         Exit;
1485       end;
1486     end;
1487     MainForm.LogInfo('已写入四场进球第' + SCJQResult.Term + '期开奖结果', True);
1488   end;
1489 ///////////////////////////////////////六场半全场胜负////////////////////////////////////////////////
1490   if LCBQCSFResult.IsDrawed then
1491   begin
1492     try
1493       mqMain.Close;
1494       sSQLString := 'CALL P_UPDATE_LCBQCSF_RESULT('
1495         + QuotedStr(LCBQCSFResult.Term)
1496         + ',' + QuotedStr(DateTimeToStr(LCBQCSFResult.DrawaTime))
1497         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[0])
1498         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[1])
1499         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[2])
1500         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[3])
1501         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[4])
1502         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[5])
1503         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[6])
1504         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[7])
1505         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[8])
1506         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[9])
1507         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[10])
1508         + ',' + QuotedStr(LCBQCSFResult.BingoNumer[11])
1509         + ',' + CurrToStr(LCBQCSFResult.Prize);
1510       sSQLString := sSQLString +',@a); select @a;';
1511       mqMain.Close;
1512       mqMain.SQL.Text := sSQLString;
1513       mqMain.Execute;
1514       iReturnCode := mqMain.Fields.Fields[0].AsInteger;
1515       mqMain.Close;
1516       if iReturnCode = 1 then              //数据验证失败
1517       begin
1518         MainForm.LogInfo('写入六场半全场胜负开奖结果失败,原因:数据验证失败', True);
1519         Exit;
1520       end
1521       else if iReturnCode = 100 then
1522       begin
1523         MainForm.LogInfo('写入六场半全场胜负开奖结果失败,原因:未知错误', True);
1524         Exit;
1525       end;
1526     except on E : Exception do
1527       begin
1528         MainForm.LogInfo('写入六场半全场胜负开奖结果失败,原因:' + E.Message, True);
1529         Exit;
1530       end;
1531     end;
1532     MainForm.LogInfo('已写入六场半全场胜负第' + LCBQCSFResult.Term + '期开奖结果', True);
1533   end;
1534   MainForm.LogInfo('写入传统体彩开奖结果成功', True);
1535   Result := True;
1536 end;
1537 
1538 procedure TGeneralThd.SetPause(const aIsPause: Boolean);
1539 begin
1540   Pause := aIsPause;
1541 end;
1542 
1543 end.
传统

 

posted @ 2015-04-13 14:28  海蓝7  阅读(168)  评论(0编辑  收藏  举报