(***************************
** Function: ShowAlarms **
****************************
** Show the active alarms **
** with a database grid **
***************************)
function TForm_ActiveFault.ShowAlarms():Integer;
var
i : Integer;
ID_Str :
String;
Status : Integer;
begin
Status := 0;
try
(* TODO: Testversion: The deleteprogress produces an error *)
DataModule1.ADOQueryFaultAct.Close;
(* TODO : Testversion: deletes the active faults of the current client from the ADO table *)
Datamodule1.ADOQueryFaultDel.Close;
Datamodule1.ADOQueryFaultDel.SQL.Clear;
Datamodule1.ADOQueryFaultDel.SQL.Text := '
DELETE * FROM Fault_Active WHERE Client_ID = ' + IntToStr (Curr_Client_ID);
Datamodule1.ADOQueryFaultDel.ExecSQL;
Datamodule1.ADOQueryFaultDel.Close;
Datamodule1.ADOTableFaultAct.Active := True;
Datamodule1.ADOTableFaultAct.First;
ID_Str := IntToStr(Curr_Client_ID);
(* Read the active faults from the server into the stringgrid *)
Read_CSV_File (ACTIVEALARMS_Path + '
active' + ID_Str, #9, StringGrid_Hide);
(* Write the content of the stringgrid into the ADO Table *)
for i := 1
to Pred(StringGrid_Hide.RowCount)
do
begin
StringGrid_Hide.Cells[1,i-1] := DateTimeToStr(Now);
if StringGrid_Hide.Cells[3,i-1] = '
'
then StringGrid_Hide.Cells[3,i-1] := '
0';
Datamodule1.ADOTableFaultAct.Append;
Datamodule1.ADOTableFaultAct.FieldByName ('
Client_ID') .AsString := ID_Str;
Datamodule1.ADOTableFaultAct.FieldByName ('
Name') .AsString := StringGrid_Hide.Cells[0,i-1];
// Faultname
Datamodule1.ADOTableFaultAct.FieldByName ('
StartTime') .AsString := StringGrid_Hide.Cells[1,i-1];
// StartTime
Datamodule1.ADOTableFaultAct.FieldByName ('
Code') .AsString := StringGrid_Hide.Cells[2,i-1];
// Code
Datamodule1.ADOTableFaultAct.FieldByName ('
Subcode') .AsString := StringGrid_Hide.Cells[3,i-1];
// Subcode
Datamodule1.ADOTableFaultAct.FieldByName ('
Priority') .AsString := StringGrid_Hide.Cells[4,i-1];
// Priority
Datamodule1.ADOTableFaultAct.Next;
end;
DataModule1.ADOTableFaultAct.Close;
// DataModule1.ADOTableFaultAct.EnableControls;
DataModule1.ADOQueryFaultAct.SQL.Clear;
(* Read the active alarms of the current client from the Fault_Active table and *)
(* connect them with the information from the 'Fault_Definition' table *)
DataModule1.ADOQueryFaultAct.SQL.Text :=
'
SELECT Fault_Active.Code As Code, ' +
'
Fault_Active.SubCode As Subcode, ' +
'
Fault_Definition.Priority As Priority, ' +
'
Fault_Active.StartTime As StartTime, ' +
'
Fault_Definition.DisplayName As FaultText, ' +
'
Fault_Definition.description As Description, ' +
'
Fault_Definition.manualRef As Reference ' +
'
FROM Fault_Definition, Fault_Active ' +
'
WHERE Fault_Definition.Name = Fault_Active.Name ' +
'
AND Fault_Definition.Client_ID = Fault_Active.Client_ID ' +
'
AND Fault_Definition.Client_ID = ' + IntToStr (Curr_Client_ID) +
'
ORDER BY Fault_Active.StartTime ASC';
DataModule1.ADOQueryFaultAct.ExecSQL;
DataModule1.ADOQueryFaultAct.Open;
(* Pass the FieldNames of the queryresult to the DBGrid *)
DBGrid_Active.Columns[0].FieldName := '
Code';
DBGrid_Active.Columns[1].FieldName := '
Subcode';
DBGrid_Active.Columns[2].FieldName := '
Priority';
DBGrid_Active.Columns[3].FieldName := '
StartTime';
DBGrid_Active.Columns[4].FieldName := '
FaultText';
DBGrid_Active.Columns[5].FieldName := '
Description';
DBGrid_Active.Columns[6].FieldName := '
Reference';
for i := 1
to Pred(StringGrid_Hide.RowCount)
do
begin
if StrToInt(StringGrid_Hide.Cells[4,i-1]) > Status
then Status := StrToInt(StringGrid_Hide.Cells[4,i-1]);
end;
except
begin
Release_ActiveFault := False;
Messagebox(
Handle, PChar('
Disturbed database connection'), PChar('
Database fault'), MB_OK
or MB_ICONWARNING);
end;
end;
Result := Status;
end;