доделал автоматические действия
This commit is contained in:
+236
-31
@@ -4,7 +4,7 @@ interface
|
||||
|
||||
uses
|
||||
System.SysUtils, System.Types, System.UITypes, System.Classes,
|
||||
System.Variants,
|
||||
System.Variants, uRegExpr,
|
||||
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
|
||||
System.Rtti, FMX.Grid.Style, FMX.Grid, FMX.ScrollBox, FMX.Edit, StrUtils,
|
||||
FMX.Controls.Presentation, uMyTimer, uRecords, System.Generics.Collections;
|
||||
@@ -54,6 +54,18 @@ type
|
||||
procedure btnRmMessageClick(Sender: TObject);
|
||||
procedure btnNotifyTestClick(Sender: TObject);
|
||||
procedure sgTimersEditingDone(Sender: TObject; const ACol, ARow: Integer);
|
||||
procedure btnBanWordsCheckClick(Sender: TObject);
|
||||
procedure btnBanWordsAddClick(Sender: TObject);
|
||||
procedure btnBanWordsEdtClick(Sender: TObject);
|
||||
procedure btnBanWordsDelClick(Sender: TObject);
|
||||
procedure btnCounterAddClick(Sender: TObject);
|
||||
procedure btnCounterEditClick(Sender: TObject);
|
||||
procedure btnCounterDeleteClick(Sender: TObject);
|
||||
procedure btnCounterPClick(Sender: TObject);
|
||||
procedure btnCounterMClick(Sender: TObject);
|
||||
procedure sgTimersCellClick(const Column: TColumn; const Row: Integer);
|
||||
procedure sgBanWordsCellClick(const Column: TColumn; const Row: Integer);
|
||||
procedure sgCounterCellClick(const Column: TColumn; const Row: Integer);
|
||||
private
|
||||
{ Private declarations }
|
||||
procedure OnMyTimerExec(Sender: TObject; const txt: string; o: Boolean);
|
||||
@@ -62,6 +74,8 @@ type
|
||||
{ Public declarations }
|
||||
FTimerList: TObjectList<TMyTimerThread>;
|
||||
listTimer: TArray<TListTimer>;
|
||||
listBanWords: TArray<TBanWord>;
|
||||
listCounters: TArray<TCounter>;
|
||||
procedure UpdateGridFromArray;
|
||||
procedure initTimers;
|
||||
end;
|
||||
@@ -100,12 +114,165 @@ begin
|
||||
edtInterval.text := '10';
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnBanWordsAddClick(Sender: TObject);
|
||||
var
|
||||
NewRec: TBanWord;
|
||||
begin
|
||||
if (edtBanWords.text = '') then
|
||||
exit;
|
||||
|
||||
NewRec.regexp := edtBanWords.text;
|
||||
|
||||
SetLength(listBanWords, Length(listBanWords) + 1);
|
||||
listBanWords[High(listBanWords)] := NewRec;
|
||||
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TBanWord>('listBanWords', listBanWords);
|
||||
|
||||
edtBanWords.text := '';
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnBanWordsCheckClick(Sender: TObject);
|
||||
var
|
||||
rx: TRegExpr;
|
||||
begin
|
||||
rx := TRegExpr.Create;
|
||||
rx.InputString := edtBanWordsCheck.text;
|
||||
rx.Expression := edtBanWords.text;
|
||||
if rx.Exec then
|
||||
lBanWordsCheck.text := 'åñòü áàíâîðä'
|
||||
else
|
||||
lBanWordsCheck.text := 'íåò áàíâîðäà';
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnBanWordsDelClick(Sender: TObject);
|
||||
var
|
||||
SelectedRow: Integer;
|
||||
I: Integer;
|
||||
begin
|
||||
SelectedRow := sgBanWords.Row;
|
||||
// Ïðîâåðÿåì âàëèäíîñòü âûáðàííîé ñòðîêè
|
||||
if (SelectedRow < 0) or (SelectedRow >= sgBanWords.RowCount) then
|
||||
exit;
|
||||
|
||||
// Ñäâèãàåì ýëåìåíòû ìàññèâà
|
||||
for I := SelectedRow to High(listBanWords) - 1 do
|
||||
listBanWords[I] := listBanWords[I + 1];
|
||||
SetLength(listBanWords, Length(listBanWords) - 1);
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TBanWord>('listBanWords', listBanWords);
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnBanWordsEdtClick(Sender: TObject);
|
||||
var
|
||||
SelectedRow: Integer;
|
||||
NewText, oldText: string;
|
||||
I: Integer;
|
||||
myRec: TBanWord;
|
||||
begin
|
||||
SelectedRow := sgBanWords.Row;
|
||||
if (edtBanWords.text = '') or (SelectedRow <= 0) or
|
||||
(SelectedRow >= sgBanWords.RowCount) then
|
||||
exit;
|
||||
NewText := edtBanWords.text;
|
||||
oldText := sgBanWords.Cells[0, SelectedRow];
|
||||
for I := 0 to High(listBanWords) do
|
||||
if listBanWords[I].regexp = oldText then
|
||||
begin
|
||||
listBanWords[I].regexp := NewText;
|
||||
break;
|
||||
end;
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TBanWord>('listBanWords', listBanWords);
|
||||
edtBanWords.text := '';
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnCounterAddClick(Sender: TObject);
|
||||
var
|
||||
NewRec: TCounter;
|
||||
begin
|
||||
if (edtCounterName.text = '') or (edtCounterTrigger.text = '') then
|
||||
exit;
|
||||
if (edtCounterCount.text = '') then
|
||||
edtCounterCount.text := '0';
|
||||
|
||||
NewRec.counterName := edtCounterName.text;
|
||||
NewRec.trigger := edtCounterTrigger.text;
|
||||
NewRec.count := strtoint(edtCounterCount.text);
|
||||
NewRec.auto := 0;
|
||||
|
||||
SetLength(listCounters, Length(listCounters) + 1);
|
||||
listCounters[High(listCounters)] := NewRec;
|
||||
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TCounter>('listCounters', listCounters);
|
||||
|
||||
edtCounterName.text := '';
|
||||
edtCounterTrigger.text := '';
|
||||
edtCounterCount.text := '0';
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnCounterDeleteClick(Sender: TObject);
|
||||
var
|
||||
SelectedRow: Integer;
|
||||
I: Integer;
|
||||
begin
|
||||
SelectedRow := sgCounter.Row;
|
||||
// Ïðîâåðÿåì âàëèäíîñòü âûáðàííîé ñòðîêè
|
||||
if (SelectedRow < 0) or (SelectedRow >= sgCounter.RowCount) then
|
||||
exit;
|
||||
|
||||
for I := SelectedRow to High(listCounters) - 1 do
|
||||
listCounters[I] := listCounters[I + 1];
|
||||
SetLength(listCounters, Length(listCounters) - 1);
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TCounter>('listCounters', listCounters);
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnCounterEditClick(Sender: TObject);
|
||||
var
|
||||
SelectedRow: Integer;
|
||||
oldName: string;
|
||||
I: Integer;
|
||||
begin
|
||||
SelectedRow := sgCounter.Row;
|
||||
if (edtCounterName.text = '') or (edtCounterTrigger.text = '') then
|
||||
exit;
|
||||
if (edtCounterCount.text = '') then
|
||||
edtCounterCount.text := '0';
|
||||
oldName := sgCounter.Cells[0, SelectedRow];
|
||||
for I := 0 to high(listCounters) do
|
||||
if listCounters[I].counterName = oldName then
|
||||
begin
|
||||
listCounters[I].counterName := edtCounterName.text;
|
||||
listCounters[I].trigger := edtCounterTrigger.text;
|
||||
listCounters[I].count := strtoint(edtCounterCount.text);
|
||||
end;
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TCounter>('listCounters', listCounters);
|
||||
edtCounterName.text := '';
|
||||
edtCounterTrigger.text := '';
|
||||
edtCounterCount.text := '0';
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnCounterMClick(Sender: TObject);
|
||||
begin
|
||||
edtCounterCount.text := inttostr(strtoint(edtCounterCount.text) - 1);
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnCounterPClick(Sender: TObject);
|
||||
begin
|
||||
edtCounterCount.text := inttostr(strtoint(edtCounterCount.text) + 1);
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.btnEditMessageClick(Sender: TObject);
|
||||
var
|
||||
SelectedRow: Integer;
|
||||
NewText: string;
|
||||
NewInterval: Integer;
|
||||
RowIndex: Integer;
|
||||
|
||||
begin
|
||||
SelectedRow := sgTimers.Row;
|
||||
if (edtMessage.text = '') or (edtInterval.text = '') or (SelectedRow <= 0) or
|
||||
@@ -114,17 +281,11 @@ begin
|
||||
NewText := edtMessage.text;
|
||||
NewInterval := StrToIntDef(edtInterval.text, 0);
|
||||
|
||||
RowIndex := sgTimers.Row;
|
||||
if (RowIndex < 0) or (RowIndex > High(listTimer)) then
|
||||
exit;
|
||||
if NewInterval <= 0 then
|
||||
exit;
|
||||
|
||||
// Îáíîâëÿåì íàñòðîéêè òàéìåðà
|
||||
FTimerList[SelectedRow].Update(sgTimers.Cells[2, SelectedRow].ToInteger,
|
||||
sgTimers.Cells[1, SelectedRow], (sgTimers.Cells[3, SelectedRow] = 'True'));
|
||||
listTimer[RowIndex].interval := NewInterval;
|
||||
listTimer[RowIndex].mess := NewText;
|
||||
listTimer[SelectedRow].interval := NewInterval;
|
||||
listTimer[SelectedRow].mess := NewText;
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TListTimer>('listTimer', listTimer);
|
||||
|
||||
@@ -148,14 +309,14 @@ end;
|
||||
procedure TfrAutoActions.btnRmMessageClick(Sender: TObject);
|
||||
var
|
||||
SelectedRow: Integer;
|
||||
i, RowIndex: Integer;
|
||||
I: Integer;
|
||||
begin
|
||||
SelectedRow := sgTimers.Row;
|
||||
// Ïðîâåðÿåì âàëèäíîñòü âûáðàííîé ñòðîêè
|
||||
if (SelectedRow < 0) or (SelectedRow >= sgTimers.RowCount) then
|
||||
exit;
|
||||
// Ïðîâåðÿåì íàëè÷èå òàéìåðà â ñïèñêå
|
||||
if (SelectedRow < FTimerList.Count) then
|
||||
if (SelectedRow < FTimerList.count) then
|
||||
begin
|
||||
// Îñòàíàâëèâàåì è óíè÷òîæàåì òàéìåð
|
||||
if Assigned(FTimerList[SelectedRow]) then
|
||||
@@ -165,15 +326,9 @@ begin
|
||||
FTimerList.Delete(SelectedRow); // Óäàëÿåì èç ñïèñêà ñ àâòîóíè÷òîæåíèåì
|
||||
end;
|
||||
end;
|
||||
// Óäàëÿåì ñòðîêó èç ñåòêè
|
||||
|
||||
RowIndex := sgTimers.Row;
|
||||
if (RowIndex < 0) or (RowIndex > High(listTimer)) then
|
||||
exit;
|
||||
|
||||
// Ñäâèãàåì ýëåìåíòû ìàññèâà
|
||||
for i := RowIndex to High(listTimer) do
|
||||
listTimer[i] := listTimer[i + 1];
|
||||
for I := SelectedRow to High(listTimer) - 1 do
|
||||
listTimer[I] := listTimer[I + 1];
|
||||
SetLength(listTimer, Length(listTimer) - 1);
|
||||
UpdateGridFromArray;
|
||||
DB.SaveRecordArray<TListTimer>('listTimer', listTimer);
|
||||
@@ -181,13 +336,13 @@ end;
|
||||
|
||||
procedure TfrAutoActions.initTimers;
|
||||
var
|
||||
i: Integer;
|
||||
I: Integer;
|
||||
TimerThread: TMyTimerThread;
|
||||
begin
|
||||
for i := 0 to High(listTimer) do
|
||||
for I := 0 to High(listTimer) do
|
||||
begin
|
||||
TimerThread := TMyTimerThread.Create(listTimer[i].interval,
|
||||
listTimer[i].mess, listTimer[i].o = 1);
|
||||
TimerThread := TMyTimerThread.Create(listTimer[I].interval,
|
||||
listTimer[I].mess, listTimer[I].o = 1);
|
||||
TimerThread.OnTimerExec := OnMyTimerExec;
|
||||
FTimerList.Add(TimerThread);
|
||||
end;
|
||||
@@ -202,6 +357,29 @@ begin
|
||||
ttw_IRS.sendMessage(txt); }
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.sgBanWordsCellClick(const Column: TColumn;
|
||||
const Row: Integer);
|
||||
begin
|
||||
edtBanWords.text := sgBanWords.Cells[0, Row];
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.sgCounterCellClick(const Column: TColumn;
|
||||
const Row: Integer);
|
||||
begin
|
||||
edtCounterName.text := sgCounter.Cells[0, Row];
|
||||
edtCounterTrigger.text := sgCounter.Cells[1, Row];
|
||||
edtCounterCount.text := sgCounter.Cells[2, Row];
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.sgTimersCellClick(const Column: TColumn;
|
||||
const Row: Integer);
|
||||
begin
|
||||
edtMessage.text := sgTimers.Cells[1, Row];
|
||||
edtInterval.text := sgTimers.Cells[2, Row];
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrAutoActions.sgTimersEditingDone(Sender: TObject;
|
||||
const ACol, ARow: Integer);
|
||||
var
|
||||
@@ -230,23 +408,50 @@ end;
|
||||
|
||||
procedure TfrAutoActions.UpdateGridFromArray;
|
||||
var
|
||||
i: Integer;
|
||||
I: Integer;
|
||||
begin
|
||||
sgTimers.BeginUpdate;
|
||||
try
|
||||
sgTimers.RowCount := 0; // Ñáðàñûâàåì ñòðîêè (îñòàâëÿåì òîëüêî çàãîëîâêè)
|
||||
|
||||
for i := 0 to High(listTimer) do
|
||||
for I := 0 to High(listTimer) do
|
||||
begin
|
||||
sgTimers.RowCount := i + 1;
|
||||
sgTimers.Cells[0, i] := ifthen(listTimer[i].Enable = 1, 'True', 'False');
|
||||
sgTimers.Cells[1, i] := listTimer[i].mess;
|
||||
sgTimers.Cells[2, i] := IntToStr(listTimer[i].interval);
|
||||
sgTimers.Cells[3, i] := ifthen(listTimer[i].o = 1, 'True', 'False');
|
||||
sgTimers.RowCount := I + 1;
|
||||
sgTimers.Cells[0, I] := ifthen(listTimer[I].Enable = 1, 'True', 'False');
|
||||
sgTimers.Cells[1, I] := listTimer[I].mess;
|
||||
sgTimers.Cells[2, I] := inttostr(listTimer[I].interval);
|
||||
sgTimers.Cells[3, I] := ifthen(listTimer[I].o = 1, 'True', 'False');
|
||||
end;
|
||||
finally
|
||||
sgTimers.EndUpdate;
|
||||
end;
|
||||
sgBanWords.BeginUpdate;
|
||||
try
|
||||
sgBanWords.RowCount := 0; // Ñáðàñûâàåì ñòðîêè (îñòàâëÿåì òîëüêî çàãîëîâêè)
|
||||
|
||||
for I := 0 to High(listBanWords) do
|
||||
begin
|
||||
sgBanWords.RowCount := I + 1;
|
||||
sgBanWords.Cells[0, I] := listBanWords[I].regexp;
|
||||
end;
|
||||
finally
|
||||
sgBanWords.EndUpdate;
|
||||
end;
|
||||
sgCounter.BeginUpdate;
|
||||
try
|
||||
sgCounter.RowCount := 0; // Ñáðàñûâàåì ñòðîêè (îñòàâëÿåì òîëüêî çàãîëîâêè)
|
||||
|
||||
for I := 0 to High(listCounters) do
|
||||
begin
|
||||
sgCounter.RowCount := I + 1;
|
||||
sgCounter.Cells[0, I] := listCounters[I].counterName;
|
||||
sgCounter.Cells[1, I] := listCounters[I].trigger;
|
||||
sgCounter.Cells[2, I] := inttostr(listCounters[I].count);
|
||||
sgCounter.Cells[3, I] := ifthen(listCounters[I].auto = 1, '1', '0');
|
||||
end;
|
||||
finally
|
||||
sgCounter.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user