組態王作為經典的國產組態軟件,對于一些小的系統特別適用。但是組態王的歷史報警記錄需要配置數據庫。否則關機后,下次打開就沒有了。
首先我們建立一個測試變量。
建立報警界面:
建立兩個時鐘變量,分別是開始日期和結束日期。
開始日期設置:
VOID closeup2()
float Ayear;
float Amonth;
float Aday;
string temp52;
Ayear=ADate52.Year;
Amonth=ADate52.Month;
Aday=ADate52.Day;
temp52=StrFromInt( Ayear, 10 );
if(Amonth<10)
temp52=temp52+"/0"+StrFromInt( Amonth, 10 );
else
temp52=temp52+"/"+StrFromInt( Amonth, 10 );
if(Aday<10)
temp52=temp52+"/0"+StrFromInt( Aday, 10 );
else
temp52=temp52+"/"+StrFromInt( Aday, 10 );
\\local\選擇日期52=temp52;
結束日期設置:
VOID closeUP355()
float Ayear;
float Amonth;
float Aday;
string temp55;
Ayear=ADate55.Year;
Amonth=ADate55.Month;
Aday=ADate55.Day;
temp55=StrFromInt( Ayear, 10 );
if(Amonth<10)
temp55=temp55+"/0"+StrFromInt( Amonth, 10 );
else
temp55=temp55+"/"+StrFromInt( Amonth, 10 );
if(Aday<10)
temp55=temp55+"/0"+StrFromInt( Aday, 10 );
else
temp55=temp55+"/"+StrFromInt( Aday, 10 );
\\local\選擇日期55=temp55;
【查詢記錄】設置:
string whe1;
string str = \\local\選擇日期52;
string str1 = ConvertLocalTimeToUTC(str);
str = \\local\選擇日期55;
string str2 = ConvertLocalTimeToUTC(str) ;
whe1 = "AlarmTime >=#"+str1+"# And AlarmTime <=#"+str2+"#";
Trace('test = %2s', whe1);
Ctrl14.Where = whe1;
Ctrl14.FetchData();
Ctrl14.FetchEnd();
【報警打印】設置:
Ctrl14.PrintPreview();
找到【KvAdoDBGrid Class】
以上是畫面的設計:
下面需要配置歷史記錄。
1)變量設置報警記錄
2)報警配置
3)配置ODBC
注意一定要是以下路徑的ODBCAD32
這個數據庫是自己生成的。
測試效果: