單元結構sql
Unit 後邊跟的是單元的名稱數據庫
至關於名稱空間數據結構
Interface 至關於引入的基礎的單元庫,也就是名稱空間庫dom
Type 下邊是定義的類或者數據結構。ide
舉例說明:函數
線程第一種使用方法:post
====================================================================測試
TReadThread=class(TThread)//解析數據表中接受到的數據ui
privatespa
{Privatedeclarations}
procedureUpdateRead;
protected
procedureExecute;override;
public
constructor Create(CreateSuspended:Boolean);
end;
======================================================================
TReadThread=class(TThread)//解析數據表中接受到的數據
private
{Privatedeclarations}
procedureUpdateRead;///這個是操做界面的
protected
procedureExecute;override;///這個是後臺執行的
public
constructor Create(CreateSuspended:Boolean);///這個是建立線程類句柄的
end;
======================================================================
上邊是類結構體
Var 實現的是聲明整個單元的變量和過程函數
Implementation
後邊是具體的
過程函數
uses 是過程和函數用的單元。
上邊全部的聲明的過程和函數的具體的內容
並具體全部類的函數或者過程
其中有關聲明的過程和實際的過程體的標識問題。是全局的仍是怎樣的?
建立線程類實例方法:
constructor TReadThread.Create(CreateSuspended:Boolean);
begin
ThredRun:=1;//標註線程建立
ReadKX:=0;//空閒次數
FreeOnTerminate:=true;//退出時釋放
inherited Create(CreateSuspended);//可暫停的方式
end;
==============================================================================
建立執行後臺執行的代碼:
==============================================================================
procedure TReadThread.Execute;
var
i:Integer;
begin
{Placethreadcodehere}
whileReadKX<3 do//空閒次數不超過3次,連續讀數據庫超過3次無記錄中止
begin
if Terminatedthenbreak;//收到中止命令了退出
Synchronize(UpdateRead);//循環執行操做
sleep(200);
end;
if(ReadKX>=3) and (ThredRun=1) then
begin
// ReadThr.Suspend;//空閒掛起等待
ReadThr.Terminate;//結束
ThredRun:=0;
end;
end;
===============================================================================
下邊是具體的操做的:經過使用synchronize()解決這個問題
===============================================================================
procedureTReadThread.UpdateRead;
var
OneData,v_sql,v_str:string;
adoq,adom,adon,ADOT:TADOQuery;
s_jzq,s_jzqname,s_xqnum,s_xqname,s_zhcode,s_zhfj,s_zhb,s_date,s_jzqxh,s_lhnum:string;
s_isic:string;
v_temp1,v_temp2,v_temp3,v_temp4:string;
i_mllx,v_gswd,v_hswd:Integer;//命令類型供回水
v_nd,v_ksrq,v_jsrq:string;//設採暖期年度,時間
v_bgz,v_bgzxx:string;//故障值
v_temr,v_dtemp:string;
begin
// 讀取數據庫若是不爲空執行解析操做
ADOQ := TADOQuery.Create(Nil);
ADOQ.Connection := DM.con;
ADOm := TADOQuery.Create(Nil);
ADOm.Connection := DM.con;
ADOn := TADOQuery.Create(Nil);
ADOn.Connection := DM.con;
ADOT := TADOQuery.Create(Nil);
ADOT.Connection := DM.con;
v_sql:='select top 100 * from DM_Read where IsJx=0 order by id ';
Execsql(ADOQ,v_sql,true);
if adoq.RecordCount>0 then
begin
ReadKX:=0;
adoq.First;
while not adoq.Eof do
begin
//循環解析查詢到的數據
s_jzq:=adoq.Fieldbyname('jzqnum').AsString;
v_SQL:='select * from View_CollectInfo where FactoryCode=''01'' andCollectCode='''+s_jzq+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_xqnum:= adom.Fieldbyname('CommunityCode').AsString;
s_xqname:=adom.Fieldbyname('CommunityName').AsString;
s_jzqname:=adom.Fieldbyname('CollectName').AsString;
s_jzqxh:= adom.Fieldbyname('Model').AsString;
s_isic:=adom.Fieldbyname('isic').AsString;
end;
s_date:= adoq.Fieldbyname('GetTime').AsString;
i_mllx:=adoq.Fieldbyname('mllx').AsInteger;
OneData:=adoq.Fieldbyname('Readtxt').AsString;
//爲防止錯誤數據,先修改記錄,後解析
v_sql:='updateDM_Read set isjx=1 where id='''+adoq.Fieldbyname('id').AsString+'''';
Execsql(ADOn,v_sql,false);
case i_mllx of
1: begin
//-----1----集中器表號設置發送開始 -----------------------
//回覆:DCDC+集中器編號(4B) +和校驗(1B)+ED
F_Main.mmo_m1.Lines.Add(s_date+' 集中器開始初始化');
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
2: begin
//---*--2---開始發送表號--------------------------------------
//回覆:DDDD+集中器編號(4B)+簡碼(2B)+ 表號(4B)+面積(3B)+房間號(4B)+和校驗(1B)+ED
//2012版+IC卡編號(4B)+單戶表通斷比比值係數(1B)+系統保留字(4B)+
s_zhb:= copy(OneData,17,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
//命令解析部分
v_sql:=' select * from DT_CollectInfo whereCollectCode='''+s_jzq+
''' and RoomSimCode='''+copy(onedata,13,4)+''' and MeterCode='''+
s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('RoomSimCode').Value:=copy(onedata,13,4);
fieldbyname('HeatingArea').Value:=StrToInt(copy(onedata,25,6))/100;
fieldbyname('RoomCode').Value:=copy(onedata,31,8);
if (s_jzqxh='2011') and (s_isic='1') then//2011年IC卡得ICnum
fieldbyname('ICCode').Value:=copy(onedata,39,8);
if s_jzqxh>='2012' then//2012年添加改動初始化表
begin
fieldbyname('ICCode').Value:=copy(onedata,39,8);
fieldbyname('jlxs').Value:=strtoint(copy(onedata,47,2))/10;
fieldbyname('bl').Value:=copy(onedata,49,8);
end;
post;
end;
except
adoq.Next;
Continue;
end;
end;
end;
end;
3: begin
//-----3-------集中器表號設置發送完成 -----------------------
//回覆:DCDB+集中器編號(4B)+表總數(2B)+和校驗(1B)+ED
F_Main.mmo_m1.Lines.Add(s_date+' 集中器初始化完成');
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
4:begin
//---*---4------初初始化單表完成--------------------------------
//回覆:DDAA +集中器編號(4B)+簡碼(2B)+ 表號(4B)+面積(3B)+房間號(4B)+和校驗(1B)+ED
//2012版+IC卡編號(4B)+單戶表通斷比比值係數(1B)+系統保留字(4B)+
s_zhb:= copy(OneData,17,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回初始化單表命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
v_sql:=' select * from DT_CollectInfo whereCollectCode='''+s_jzq+
''' and RoomSimCode='''+copy(onedata,13,4)+''' and MeterCode='''+
s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('RoomSimCode').Value:=copy(onedata,13,4);
fieldbyname('HeatingArea').Value:=StrToInt(copy(onedata,25,6))/100;
fieldbyname('RoomCode').Value:=copy(onedata,31,8);
if (s_jzqxh='2011') and (s_isic='1') then//2011年IC卡得ICnum
fieldbyname('ICCode').Value:=copy(onedata,39,8);
if s_jzqxh>='2012' then//2012年添加改動初始化表
begin
fieldbyname('ICCode').Value:=copy(onedata,39,8);
fieldbyname('jlxs').Value:=strtoint(copy(onedata,47,2))/10;
fieldbyname('bl').Value:=copy(onedata,49,8);
end;
post;
end;
except
adoq.Next;
Continue;
end;
end;
end;
end;
5:begin
//=======5==========寫集中器各表熱量命令=====================
//回覆:AABA+集中器編號(4B)+表號(4B)+熱量(4B)+和校驗(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
//命令解析部分
v_sql:=' select * from DT_IniHeat where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('Cardroom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('MeterHeat').Value:=StrToInt(copy(onedata,21,8))/100;
post;
end;
except
adoq.Next;
Continue;
end;
end;
end;
end;
6:begin
//---------6--------寫集中器各表熱量完成 -----------------------
//回覆: AABB+集中器編號(4B)+和校驗(1B)+ED
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回集中器寫熱完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
end;
7:begin
//=======7==========寫集中器單表熱量命令=====================
//回覆: AABC +集中器編號(4B)+簡碼(2B)+ 表號(4B)+單表熱量(4B) +和校驗
s_zhb:= copy(OneData,17,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回單表寫熱量命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
v_sql:=' select * from DT_IniHeat where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('Cardroom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('MeterHeat').Value:=StrToInt(copy(onedata,21,8))/100;
post;
end;
except
adoq.Next;
Continue;
end;
end;
end;
end;
8: begin
//-------8-----上位機控制溫控器是否顯示熱量---------------------
//回覆: CCBB +集中器號(4B)+溫控器熱狀態(1B: 00:不顯示;02:顯示)+校驗位+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置溫控器顯熱命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+'集中器:'+s_jzqname);
//命令解析部分
v_sql:=' select top 1 * from T_dzbd where CollectCode='''+
s_jzq+''' order by id ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CollectCode').Value:=s_jzq;
if Copy(onedata,13,2)='00' then
fieldbyname('Collectcs').Value:='0'
else fieldbyname('Collectcs').Value:='1';
post;
end;
except
end;
end;
9:begin
//-----9-----返回集中器羣表設溫各表回覆------------------------------
//回覆:DAAB +集中器號(4B)+表號(4B)+校驗位+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
//命令解析部分
v_sql:=' select * from DT_jzqsw where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('Cardroom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('RoomSimCode').Value:=adom.Fieldbyname('RoomSimCode').AsString;
post;
end;
except
adoq.Next;
Continue;
end;
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器羣表設溫錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
10: begin
//----10-----------發送集中器設溫完成回覆 ------------------------------
//回覆: DAAC +集中器編號(4B) +校驗和+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回集中器設溫完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
11:begin
//-----11-----返回集中器單表設溫各表回覆------------------------------
//回覆:DAAA +集中器號(4B)+表號(4B)+校驗位+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回集中器單表設溫命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
v_sql:=' select * from DT_jzqsw where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('Cardroom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('RoomSimCode').Value:=adom.Fieldbyname('RoomSimCode').AsString;
post;
end;
except
adoq.Next;
Continue;
end;
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器單表設溫錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
12: begin
//----12------------------發送集中器校時完成------------------------------
//回覆:BDBC+集中器號碼(4B)+[年月日時分秒(6B)]+校驗和(1B)+ED
//F_Main.mmo_m1.Lines.Add(s_date+' 返回設置集中器校時完成命令') ;
//F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
13: begin
//----13-----------------發送集中器各表校時完成------------------------------
//回覆:BDBD+集中器號碼(4B)+表號(4B)+校驗和(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置集中器單表校時完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
//命令解析部分
v_sql:=' select * from DT_ConTimTh where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('Cardroom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('RoomSimCode').Value:=adom.Fieldbyname('RoomSimCode').AsString;
post;
end;
except
adoq.Next;
Continue;
end;
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器單表校時錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
14:begin
//----14-----------發送集中器校時,總表回覆 ------------------------------
//回覆:AAAD+集中器號碼(4B)+表號(4B)+校驗和(1B)+ED
end;
15:begin
//----15------------發送集中器校時,完成回覆 ------------------------------
//回覆:BDBB+集中器編號(4B) +校驗和+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置集中器校時完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
16:begin
//----16------------發送集中器清零,集中器回覆 -----------------
//回覆:AAAB+集中器號碼(4B)+校驗和(1B)+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置集中器清零完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
//命令解析部分
v_sql:=' select top 1 * from DT_dzbd where CollectCode='''+
s_jzq+''' order by id ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('Collectcs').Value:='1';
post;
end;
except
end;
end;
17:begin
//----17------------發送集中器清零,總表回覆 --------------------------
//回覆:AAAC+集中器號碼(4B)+總表+校驗和(1B)+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置集中器總表清零完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
18:begin
//----18------------發送設置採暖期時間集中器回覆-----------------------
//回覆:DBCB+集中器號(4B)+開始月日(2B)+結束月日(2B)+校驗位+ED
// 2012增長開始月日(2B)+結束月日(2B)
F_Main.mmo_m1.Lines.Add(s_date+' 返回集中器設採暖期命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
19:begin
//----19-------------發送集中器各表設置採暖季時間回覆--------------
//回覆:DBCA +集中器號(4B)+表號(4B)+起始月日(2B)+結束月日(2B) +校驗和(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' and CollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
//命令解析部分
v_sql:=' select * from DT_HeatPerSet where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
v_sql:='select top 1 * from DE_HeatPerSet order by Year desc ';
execsql(adot,v_sql,true);
if adot.recordcount>0 then
begin
v_nd:= adot.Fieldbyname('Year').AsString;
v_ksrq:=adot.Fieldbyname('StartDate').AsString;
v_jsrq:=adot.Fieldbyname('EndDate').AsString;
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CardRoom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('RoomSimCode').Value:=adom.Fieldbyname('fjjm').AsString;
fieldbyname('SetTime').Value:=s_date;
fieldbyname('Year').Value:=v_nd;
fieldbyname('StartDate').Value:=v_ksrq;
fieldbyname('EndDate').Value:=v_jsrq;
post;
end;
end;
except
adoq.Next;
Continue;
end;
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器羣表設採暖期錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
20:begin
//----20-------------發送單表設置採暖季時間完成----------------------
//回覆:DBBA+集中器號(4B)+表號(4B)+起始月日(2B)+結束月日(2B) +校驗和(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回單表設採暖期命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
v_sql:=' select * from T_xqcnq where jzqnum='''+
s_jzq+''' and zhbnum='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
v_sql:='select top 1 * from DE_HeatPerSet order by Year desc ';
execsql(adot,v_sql,true);
if adot.recordcount>0 then
begin
v_nd:= adot.Fieldbyname('Year').AsString;
v_ksrq:=adot.Fieldbyname('StartDate').AsString;
v_jsrq:=adot.Fieldbyname('EndDate').AsString;
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CardRoom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('RoomSimCode').Value:=adom.Fieldbyname('fjjm').AsString;
fieldbyname('SetTime').Value:=s_date;
fieldbyname('Year').Value:=v_nd;
fieldbyname('StartDate').Value:=v_ksrq;
fieldbyname('EndDate').Value:=v_jsrq;
post;
end;
end;
except
adoq.Next;
Continue;
end;
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器單表設採暖期錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
21:begin
//----21-------------發送設置採暖期時間完畢比對--------------------
//回覆:DBAA+集中器號(4B)+校驗位+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置集中器設採暖期完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
22: begin
//----22------------發送下傳單表通斷時間完成-------------------------
//回覆:BABA +集中器編號(4B)+表號(4B)+接通時間(3字節BCD,高字節在前)+斷開時間(3字節BCD,高字節在前)+
//鎖閉時間(3字節BCD,高字節在前)+ 校驗和+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回下傳單表通斷時間命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
v_sql:=' select * from DT_IniRatio where CollectCode='''+
s_jzq+''' and MeterCode='''+s_zhb+''' ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('Cardroom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('RoomSimCode').Value:=adom.fieldbyname('RoomSimCode').AsString;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('TurnonTime').Value:=strtoint(Copy(OneData,21,6))/100;
fieldbyname('OffTime').Value:=strtoint(Copy(OneData,27,6))/100;
fieldbyname('LockTime').Value:=strtoint(Copy(OneData,33,6))/100;
post;
end;
except
adoq.Next;
Continue;
end;
end;
end;
end;
23: begin
//----*--23-----------處理單表即時數據信息----------------------------
//回覆:AAAA+小區集中器號(4b)+戶表號(4B)+熱量(4B)+年度比值3(3B)+供水溫度(1B)+
//回水溫度(1B)+。。。。。。。 +校驗位+ED(結束符)
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回單表即時數據命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//數據解析過程
v_sql:=' select * from DM_HouseData where1=2 ' ;
{ v_sql:=' select * from DM_HouseData whereCollectCode='''+
s_jzq+''' and CardRoom='''+s_zhcode+
''' and substring(GetTime,1,10)='''+copy(s_date,1,10)+'''' ;
}
execsql(adon,v_sql,true);
try
with adon do
begin
// if adon.RecordCount>0 then Edit
//else
insert;
fieldbyname('CardRoom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('GetTime').Value:=s_date;
fieldbyname('CaloHeat').Value:=strtoint(copy(onedata,21,8))/100;
fieldbyname('Ratio').Value:=strtoint(copy(onedata,29,6))/100000;
fieldbyname('WarterT').Value:=strtoint(copy(onedata,35,2));
fieldbyname('RWarterT').Value:=strtoint(copy(onedata,37,2));
fieldbyname('TPoor').Value:=abs(strtoint(copy(onedata,37,2))-strtoint(copy(onedata,35,2)));
if copy(onedata,39,2)='55' then
begin
fieldbyname('CaloLock').Value:=1;
fieldbyname('VStatus').Value:=1;
end
else
begin
fieldbyname('CaloLock').Value:=0;
fieldbyname('VStatus').Value:=0;
end;
if s_jzqxh>='2011' then////是2011年版的,纔有這個解析
begin
fieldbyname('TurnTime').Value:=strtoint(copy(onedata,39,6))/100;
fieldbyname('OffTime').Value:=strtoint(copy(onedata,45,6))/100;
v_bgz:= IntToBin(strtoint(copy(onedata,51,4)),7) ;
v_bgzxx:='';
fieldbyname('FaultNo').Value:=v_bgz ;
if Copy(v_bgz,8,1)='1' then fieldbyname('gz1').Value:='溫控器失聯 ' else fieldbyname('gz1').Value:='';
if Copy(v_bgz,7,1)='1' then fieldbyname('gz2').Value:='鎖閉回溫接近總表回溫 ' else fieldbyname('gz2').Value:='';
if Copy(v_bgz,6,1)='1' then fieldbyname('gz3').Value:='鎖閉供溫接近總表供溫 ' else fieldbyname('gz3').Value:='';
if Copy(v_bgz,5,1)='1' then fieldbyname('gz4').Value:='鎖閉室溫高 ' else fieldbyname('gz4').Value:='';
if Copy(v_bgz,4,1)='1' then fieldbyname('gz5').Value:='開啓且接通供溫低 ' else fieldbyname('gz5').Value:='';
if Copy(v_bgz,3,1)='1' then fieldbyname('gz6').Value:='開啓且接通回溫低 ' else fieldbyname('gz6').Value:='';
if Copy(v_bgz,2,1)='1' then fieldbyname('gz7').Value:='開啓且接通供回水溫差小 ' else fieldbyname('gz7').Value:='';
if Copy(v_bgz,1,1)='1' then fieldbyname('gz8').Value:='開啓且接通室溫低 ' else fieldbyname('gz8').Value:='';
fieldbyname('SetT').Value:=strtoint(copy(onedata,55,4))/100;
fieldbyname('RoomT').Value:=strtoint(copy(onedata,59,4))/100;
fieldbyname('CaloLock').Value:=strtoint(copy(onedata,63,2));
fieldbyname('VStatus').Value:=strtoint(copy(onedata,65,2));
fieldbyname('BatStatus').Value:=strtoint(copy(onedata,67,2));
fieldbyname('LockTime').Value:=strtoint(copy(onedata,69,6))/100;
fieldbyname('CumuATSet').Value:=strtoint(copy(onedata,75,4))/100;
fieldbyname('CumuAInT').Value:=strtoint(copy(onedata,79,4))/100;
fieldbyname('CycleAInT').Value:=strtoint(copy(onedata,83,4))/100;
fieldbyname('CycleAWT').Value:=strtoint(copy(onedata,87,2));
fieldbyname('CycleARwT').Value:=strtoint(copy(onedata,89,2));
fieldbyname('CalosSte').Value:=strtoint(copy(onedata,91,2));
fieldbyname('ForcedRoomT').Value:=strtoint(copy(onedata,93,3))/10;
v_temr:=inttobin(strtoint(copy(onedata,96,1)),4);
v_temr:= Copy(v_temr, Length(v_temr)-1,2);
fieldbyname('IS_EffecForce').Value:=strtoint(Copy(v_temr,2,1));
fieldbyname('isxr').Value:=strtoint(Copy(v_temr,1,1));
//if length(onedata)>100 then
//fieldbyname('zqswsj').Value:=strtoint(copy(onedata,97,10))/10;//2011 非IC卡得
v_dtemp:=copy(onedata,105,2) ;//2011 IC卡得
if v_dtemp='01' then
begin
fieldbyname('issk').Value:= 1 ;
// Changezhbzt(v_str1,v_str2,v_str3);
end
else fieldbyname('issk').Value:=0;
if length(onedata)>112 then
fieldbyname('zqswsj').Value:=strtoint(copy(onedata,107,10))/10;
if s_jzqxh>='2012' then
begin
fieldbyname('ndczr').Value:=strtoint(copy(onedata,117,8))/100;
v_dtemp:=copy(onedata,125,2) ;
v_temp1:= copy(onedata,127,6)+'.'+copy(onedata,133,2) ;
if v_dtemp='01' then//
fieldbyname('ndsyr').Value:='-'+v_temp1
else fieldbyname('ndsyr').Value:=v_temp1;
fieldbyname('fmtdcs').Value:=strtoint(copy(onedata,135,6));
fieldbyname('tdbzxs').Value:=strtoint(copy(onedata,141,2))/10;
fieldbyname('xtblz').Value:= copy(onedata,143,8) ;
end;
end;
post;
end;
except
adoq.Next;
Continue;
end;
if ((strtoint(copy(onedata,37,2))=0) and (strtoint(copy(onedata,35,2))=0)) then
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器單表通信斷開'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
end;
24:begin
//------ 24----------取集中器總表數據完成--------------------------
//回覆:CBCB+小區集中器編號(4B)+累積熱量(5B)+累積流量(4B)+進水溫度(2B)+
//回水溫度(2B)+瞬時流量(3B)+總表熱量狀態(1B)+校驗和+ED
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回總表要數命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
//數據解析過程
v_sql:=' select * from DM_BigMeterData where 1=2 ';
{ v_sql:=' select * from DM_BigMeterData whereCollectCode='''+
s_jzq+ ''' and substring(GetTime,1,10)='''+copy(s_date,1,10)+'''' ;
}
execsql(adon,v_sql,true);
try
with adon do
begin
// if adon.RecordCount>0 then Edit
// else
insert;
fieldbyname('CommunityCode').Value:=s_xqnum;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('GetTime').Value:=s_date;
fieldbyname('BigMeterCode').Value:='00000000';
fieldbyname('CumuHeat').Value:=StrToInt(Copy(onedata,13,10));
fieldbyname('CumuF').Value:=StrToInt(Copy(onedata,23,8));
fieldbyname('WarterT').Value:=StrToInt(Copy(onedata,31,4));
fieldbyname('RWarterT').Value:=StrToInt(Copy(onedata,35,4));
fieldbyname('InstanF').Value:=StrToInt(Copy(onedata,39,6))/1000;
if s_jzqxh>='2011' then////是2011年版的,纔有這個解析
fieldbyname('DataState').Value:=StrToInt(Copy(onedata,45,2));
post;
end;
except
adoq.Next;
Continue;
end;
end;
end;
25:begin
//----25--取集中器總表數據完成-------2塊表處理-------------------
//回覆:CBCD+小區集中器編號(4B)+累積熱量(5B)+累積流量(4B)+進水溫度(2B)+回水溫度(2B)+
end;
26:begin
//---*--26--- ----處理集中器羣表即時數據信息------------------------
// 回覆:ACAC+集中器編號(4B)+住戶表編號(4B)+熱量(4B)+比值2(3B)+供水溫度(1B)+回水溫度(1B)+和校驗(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
//數據解析過程
v_sql:=' select * from DM_HouseData where1=2 ' ;
{v_sql:=' select * from DM_HouseData whereCollectCode='''+
s_jzq+''' and CardRoom='''+s_zhcode+
''' and substring(GetTime,1,10)='''+copy(s_date,1,10)+'''' ;
}
execsql(adon,v_sql,true);
try
with adon do
begin
// if adon.RecordCount>0 then Edit
//else
insert;
fieldbyname('CardRoom').Value:=s_zhcode;
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('MeterCode').Value:=s_zhb;
fieldbyname('GetTime').Value:=s_date;
fieldbyname('CaloHeat').Value:=strtoint(copy(onedata,21,8))/100;
fieldbyname('Ratio').Value:=strtoint(copy(onedata,29,6))/100000;
fieldbyname('WarterT').Value:=strtoint(copy(onedata,35,2));
fieldbyname('RWarterT').Value:=strtoint(copy(onedata,37,2));
fieldbyname('TPoor').Value:=abs(strtoint(copy(onedata,37,2))-strtoint(copy(onedata,35,2)));
if copy(onedata,39,2)='55' then
begin
fieldbyname('CaloLock').Value:=1;
fieldbyname('VStatus').Value:=1;
end
else
begin
fieldbyname('CaloLock').Value:=0;
fieldbyname('VStatus').Value:=0;
end;
if s_jzqxh>='2011' then////是2011年版的,纔有這個解析
begin
fieldbyname('TurnTime').Value:=strtoint(copy(onedata,39,6))/100;
fieldbyname('OffTime').Value:=strtoint(copy(onedata,45,6))/100;
v_bgz:= IntToBin(strtoint(copy(onedata,51,4)),7) ;
v_bgzxx:='';
fieldbyname('FaultNo').Value:=v_bgz ;
if Copy(v_bgz,8,1)='1' then fieldbyname('gz1').Value:='溫控器失聯 ' else fieldbyname('gz1').Value:='';
if Copy(v_bgz,7,1)='1' then fieldbyname('gz2').Value:='鎖閉回溫接近總表回溫 ' else fieldbyname('gz2').Value:='';
if Copy(v_bgz,6,1)='1' then fieldbyname('gz3').Value:='鎖閉供溫接近總表供溫 ' else fieldbyname('gz3').Value:='';
if Copy(v_bgz,5,1)='1' then fieldbyname('gz4').Value:='鎖閉室溫高 ' else fieldbyname('gz4').Value:='';
if Copy(v_bgz,4,1)='1' then fieldbyname('gz5').Value:='開啓且接通供溫低 ' else fieldbyname('gz5').Value:='';
if Copy(v_bgz,3,1)='1' then fieldbyname('gz6').Value:='開啓且接通回溫低 ' else fieldbyname('gz6').Value:='';
if Copy(v_bgz,2,1)='1' then fieldbyname('gz7').Value:='開啓且接通供回水溫差小 ' else fieldbyname('gz7').Value:='';
if Copy(v_bgz,1,1)='1' then fieldbyname('gz8').Value:='開啓且接通室溫低 ' else fieldbyname('gz8').Value:='';
fieldbyname('SetT').Value:=strtoint(copy(onedata,55,4))/100;
fieldbyname('RoomT').Value:=strtoint(copy(onedata,59,4))/100;
fieldbyname('CaloLock').Value:=strtoint(copy(onedata,63,2));
fieldbyname('VStatus').Value:=strtoint(copy(onedata,65,2));
fieldbyname('BatStatus').Value:=strtoint(copy(onedata,67,2));
fieldbyname('LockTime').Value:=strtoint(copy(onedata,69,6))/100;
fieldbyname('CumuATSet').Value:=strtoint(copy(onedata,75,4))/100;
fieldbyname('CumuAInT').Value:=strtoint(copy(onedata,79,4))/100;
fieldbyname('CycleAInT').Value:=strtoint(copy(onedata,83,4))/100;
fieldbyname('CycleAWT').Value:=strtoint(copy(onedata,87,2));
fieldbyname('CycleARwT').Value:=strtoint(copy(onedata,89,2));
fieldbyname('CalosSte').Value:=strtoint(copy(onedata,91,2));
fieldbyname('ForcedRoomT').Value:=strtoint(copy(onedata,93,3))/10;
v_temr:=inttobin(strtoint(copy(onedata,96,1)),4);
v_temr:= Copy(v_temr, Length(v_temr)-1,2);
fieldbyname('IS_EffecForce').Value:=strtoint(Copy(v_temr,2,1));
fieldbyname('isxr').Value:=strtoint(Copy(v_temr,1,1));
//if length(onedata)>100 then
//fieldbyname('zqswsj').Value:=strtoint(copy(onedata,97,10))/10;//2011 非IC卡得
v_dtemp:=copy(onedata,105,2) ;//2011 IC卡得
if v_dtemp='01' then
begin
fieldbyname('issk').Value:= 1 ;
// Changezhbzt(v_str1,v_str2,v_str3);
end
else fieldbyname('issk').Value:=0;
if length(onedata)>112 then
fieldbyname('zqswsj').Value:=strtoint(copy(onedata,107,10))/10;
if s_jzqxh>='2012' then
begin
fieldbyname('ndczr').Value:=strtoint(copy(onedata,117,8))/100;
v_dtemp:=copy(onedata,125,2) ;
v_temp1:= copy(onedata,127,6)+'.'+copy(onedata,133,2) ;
if v_dtemp='01' then//
fieldbyname('ndsyr').Value:='-'+v_temp1
else fieldbyname('ndsyr').Value:=v_temp1;
fieldbyname('fmtdcs').Value:=strtoint(copy(onedata,135,6));
fieldbyname('tdbzxs').Value:=strtoint(copy(onedata,141,2))/10;
fieldbyname('xtblz').Value:= copy(onedata,143,8) ;
end;
end;
post;
end;
except
adoq.Next;
Continue;
end;
if ((strtoint(copy(onedata,37,2))=0) and (strtoint(copy(onedata,35,2))=0)) then
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器羣表通信斷開'+''')';
execsql(adon,v_sql,false);
end;
end
else
begin
v_sql:='insert into t_hbxx (jzqnum,zhbnum,zhcode,jlsj,jlyy) values ( '''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器羣表即時數據錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
27:begin
//-----27------------發送羣表要數完畢完成 -------------------------------
//回覆:ACDB+ 集中器編號(4B)+和校驗(1B)+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回羣表要數完成命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
28:begin
//-----28-----------取分攤係數完成 -------------------------------
//回覆:ACDD+ 集中器編號(4B)+分攤係數(1B)+和校驗(1B)+ED
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回取分攤係數命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname+' 分攤係數:'+ copy(onedata,13,1)+'.'+copy(onedata,14,1));
//命令解析部分
v_sql:=' select top 1 * from DT_dzbd where CollectCode='''+
s_jzq+''' order by id ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('Collectcs').Value:=copy(onedata,13,1)+'.'+copy(onedata,14,1);
post;
end;
except
end;
end;
end;
29:begin
//-----29------------設置分攤係數完成 -------------------------------
//回覆:ACBD+ 集中器編號(4B)+分攤係數(1B)+和校驗(1B)+ED
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置分攤係數命令。') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname+' 分攤係數:'+ copy(onedata,13,1)+'.'+copy(onedata,14,1));
//命令解析部分
v_sql:=' select top 1 * from DT_dzbd where CollectCode='''+
s_jzq+''' order by id ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('Collectcs').Value:=copy(onedata,13,1)+'.'+copy(onedata,14,1);
post;
end;
except
end;
end;
end;
30:begin
//-----30------------發送對單表的強制關斷完成 -------------------------------
//回覆:CCCC+小區編號+集中器編號(2B)+住戶表編號(4B)+和校驗(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回單表鎖閉命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
//修改表信息中的關閉信息
v_sql:=' update DE_HouseInfo set ISLock=1 whereCollectCode='''+
s_jzq+''' and MeterCode=''' +s_zhb+''' and CardRoom='''+s_zhcode+''' ';
execsql(ADOn,v_sql,false);
v_sql:='insert into DT_ConACMTh (CollectCode,MeterCode,Cardroom,RoomSimCode,FactoryCode) values ( '''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
ADOm.fieldbyname('fjjm').AsString+''',''01'')';
execsql(ADOn,v_sql,false);
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器單表鎖閉錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
31:begin
//-----31------------發送對單表的解除強制關斷完成 -----------------
//回覆:CCBD+小區編號+集中器編號(2B)+住戶表編號(4B)+和校驗(1B)+ED
s_zhb:= copy(OneData,13,8) ;
v_SQL:='select * from View_HouseInfo whereFactoryCode=''01'' andCollectCode+MeterCode='''+s_jzq+s_zhb+'''';
Execsql(adom,v_sql,true);
if adom.RecordCount>0 then
begin
s_zhcode:=adom.Fieldbyname('CardRoom').AsString;
s_zhfj:=adom.Fieldbyname('BuildCode').AsString+'-'+adom.Fieldbyname('UnitCode').AsString+'-'+adom.Fieldbyname('FloorCode').AsString+adom.Fieldbyname('RoomCode').AsString;
if CheckHtoM(onedata) then
begin
F_Main.mmo_m1.Lines.Add(s_date+' 返回單表開啓命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 房間號:'+s_zhfj);
//命令解析部分
//修改表信息中的關閉信息
v_sql:=' update DE_HouseInfo set ISLock=0 whereCollectCode='''+
s_jzq+''' and MeterCode=''' +s_zhb+''' and CardRoom='''+s_zhcode+''' ';
execsql(ADOn,v_sql,false);
v_sql:='insert into DT_ConACMTh (CollectCode,MeterCode,Cardroom,RoomSimCode,FactoryCode) values ( '''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
ADOm.fieldbyname('fjjm').AsString+''',''01'')';
execsql(ADOn,v_sql,false);
end
else
begin
v_sql:='insert into DT_BadMeterInfo (FactoryCode,CollectCode,MeterCode,CardRoom,BadTime,BadRea) values ( ''01'','''+
s_jzq+''','''+s_zhb+''','''+s_zhcode+''','''+
s_date+''','''+'集中器單表開啓錯誤'+''')';
execsql(adon,v_sql,false);
end;
end;
end;
32:begin
//----32------------------發送開羣表完畢比對------------------------------
//回覆:FE+CCCB+集中器編號(4B) +校驗和+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回開羣表完畢命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
33:begin
//----33------------------發送關羣表完畢比對------------------------------
//回覆:FE+CCBA+集中器編號(4B) +校驗和+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回關羣表完畢命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+' 集中器:'+s_jzqname);
end;
34:begin
//----34---------調取測試集中器表號-----------------
//回覆:FE+ DDAB +集中器編號(4B)+簡碼(2B)+ 表號(4B)+和校驗(1B)+ED
end;
35:begin
//----35--------調取集中器表號完成 -----------------------
//回覆:DDAC +集中器號(4B)+ 表個數(2B)+校驗位+ED
end;
36:begin
//------36--------廣播校時命令完成 -----------------------
//回覆:AAAD +集中器號(4B)+ ...+校驗位+ED
end;
37:begin
end;
38:begin
end;
39:begin
end;
40:begin
end;
41:begin
//------41--------溫控器顯示剩餘熱量數據結束完成 -----------------------
//FECCBC +集中器號(4B)+ 年充值熱/剩餘熱的狀態(1B: 00:不顯示;04:顯示)+校驗位+ED
F_Main.mmo_m1.Lines.Add(s_date+' 返回設置溫控器顯剩餘熱量命令') ;
F_Main.mmo_m1.Lines.Add('小區:'+s_xqname+'集中器:'+s_jzqname);
//命令解析部分
v_sql:=' select top 1 * from DT_dzbd where CollectCode='''+
s_jzq+''' order by id ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CollectCode').Value:=s_jzq;
if copy(onedata,13,2)='00' then
fieldbyname('jzqcs').Value:='0'
elsefieldbyname('Collectcs').Value:='1';
post;
end;
except
end;
end;
42:begin
//------42--------集中器設置採暖方式結束完成 -----------------------
//回覆:FE+ CBAD +小區集中器號(4b)+採暖方式(1B BCD碼:00:散熱器方式;01:地暖方式;)+校驗和+ed
F_Main.mmo_m1.Lines.Add(s_date+' 返回集中器設置採暖方式命令') ;
ifcopy(onedata,13,2)='01' then
v_dtemp:= '小區:'+s_xqname+'集中器:'+s_jzqname+' 採暖方式:'+copy(onedata,13,2)+' 地板採暖'
else v_dtemp:= '小區:'+s_xqname+'集中器:'+s_jzqname+' 採暖方式:'+copy(onedata,13,2)+' 散熱器採暖';
F_Main.mmo_m1.Lines.Add(v_dtemp);
//命令解析部分
v_sql:=' select top 1 * from DT_dzbd where CollectCode='''+
s_jzq+''' order by id ';
execsql(adon,v_sql,true);
try
with adon do
begin
if adon.RecordCount>0 then Edit
else insert;
fieldbyname('FactoryCode').Value:='01';
fieldbyname('CollectCode').Value:=s_jzq;
fieldbyname('Collectcs').Value:=copy(onedata,13,2);
post;
end;
except
end;
end;
end;
adoq.Next;
end;
end
else
begin
ReadKX:=ReadKX+1;
end;
ADOQ.Free;
ADOm.Free;
ADOn.Free;
ADOT.free;
end;
procedure TReadThread.Execute;
var
i:Integer;
begin
{Placethreadcodehere}
whileReadKX<3 do//空閒次數不超過3次,連續讀數據庫超過3次無記錄中止
begin
if Terminatedthenbreak;//收到中止命令了退出
Synchronize(UpdateRead);//循環執行操做
sleep(200);
end;
if(ReadKX>=3) and (ThredRun=1) then
begin
// ReadThr.Suspend;//空閒掛起等待
ReadThr.Terminate;//結束
ThredRun:=0;
end;
end;
================================
線程第二種使用方法:
Timer使用方法
聲明線程句柄
hThread: THandle; {線程句柄}
{線程入口函數}
function MyThreadFun(p: Pointer): Integer; stdcall;
begin
while True do {假如線程不掛起, 這個循環將一直循環下去}
begin
num := Random(100);
end;
Result := 0;
end;
================
建立線程
+========
procedure TThreadSortForm.btn2Click(Sender: TObject);
var
ID: DWORD;
begin
//線程句柄返回的是這個
hThread := CreateThread(nil, 0, @MyThreadFun, nil, CREATE_SUSPENDED, ID);
end;
=====================
激活線程
===================
procedure TThreadSortForm.btn3Click(Sender: TObject);
begin
///操做建立了的線程激活線程
ResumeThread(hThread);
end;
=======================
掛起線程
=====================
procedure TThreadSortForm.btn4Click(Sender: TObject);
begin
///掛起線程
SuspendThread(hThread);
end;