323 lines
8.7 KiB
ObjectPascal
323 lines
8.7 KiB
ObjectPascal
unit fOBS;
|
|
|
|
interface
|
|
|
|
uses
|
|
System.SysUtils, System.Types, System.UITypes, System.Classes,
|
|
System.Variants,
|
|
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
|
|
System.Rtti, FMX.Grid.Style, FMX.Grid, FMX.ScrollBox, FMX.Edit, FMX.Colors,
|
|
FMX.ListBox, FMX.EditBox, FMX.SpinBox, FMX.Controls.Presentation, uRecords;
|
|
|
|
type
|
|
TfrOBS = class(TFrame)
|
|
sgWebChats: TStringGrid;
|
|
btnCreateOBSChat: TButton;
|
|
btnDeleteeChat: TButton;
|
|
Label1: TLabel;
|
|
IntegerColumn1: TIntegerColumn;
|
|
StringColumn1: TStringColumn;
|
|
StringColumn2: TStringColumn;
|
|
btnCreateOBSNotify: TButton;
|
|
btnCreateOBSKandinsky: TButton;
|
|
procedure btnDeleteeChatClick(Sender: TObject);
|
|
procedure btnCreateOBSKandinskyClick(Sender: TObject);
|
|
procedure btnCreateOBSChatClick(Sender: TObject);
|
|
procedure btnCreateOBSNotifyClick(Sender: TObject);
|
|
procedure sgWebChatsCellDblClick(const Column: TColumn; const Row: Integer);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
listChats: TArray<TOBSChat>;
|
|
listNotify: TArray<TOBSNotify>;
|
|
listKandinsky: TArray<TOBSKandinsky>;
|
|
|
|
procedure UpdateGridFromArray;
|
|
procedure AddChat(newRecord: TOBSChat);
|
|
procedure EdtChat(newRecord: TOBSChat; oldPort: Integer);
|
|
procedure DelChat(aPort: Integer);
|
|
|
|
procedure AddNotify(newRecord: TOBSNotify);
|
|
procedure EdtNotify(newRecord: TOBSNotify; oldPort: Integer);
|
|
procedure DelNotify(aPort: Integer);
|
|
|
|
procedure AddKandinsky(newRecord: TOBSKandinsky);
|
|
procedure DelKandinsky(aPort: Integer);
|
|
|
|
end;
|
|
|
|
implementation
|
|
|
|
{$R *.fmx}
|
|
|
|
uses uGeneral, uCreateChat, uCreateNotify;
|
|
|
|
{ TfrOBS }
|
|
|
|
procedure TfrOBS.AddChat(newRecord: TOBSChat);
|
|
begin
|
|
SetLength(listChats, Length(listChats) + 1);
|
|
listChats[High(listChats)] := newRecord;
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSChat>('listChats', listChats);
|
|
end;
|
|
|
|
procedure TfrOBS.AddKandinsky(newRecord: TOBSKandinsky);
|
|
begin
|
|
SetLength(listKandinsky, Length(listKandinsky) + 1);
|
|
listKandinsky[High(listKandinsky)] := newRecord;
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSKandinsky>('listKandinsky', listKandinsky);
|
|
end;
|
|
|
|
procedure TfrOBS.AddNotify(newRecord: TOBSNotify);
|
|
begin
|
|
SetLength(listNotify, Length(listNotify) + 1);
|
|
listNotify[High(listNotify)] := newRecord;
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSNotify>('listNotify', listNotify);
|
|
end;
|
|
|
|
procedure TfrOBS.btnCreateOBSChatClick(Sender: TObject);
|
|
var
|
|
dport, i: Integer;
|
|
begin
|
|
dport := 8080;
|
|
for i := 0 to sgWebChats.RowCount - 1 do
|
|
begin
|
|
if strtoint(sgWebChats.Cells[0, i]) >= dport then
|
|
dport := strtoint(sgWebChats.Cells[0, i]) + 1;
|
|
end;
|
|
fCreateChat.sbWebServerPort.Value := dport;
|
|
fCreateChat.isEdit := false;
|
|
fCreateChat.Show;
|
|
end;
|
|
|
|
procedure TfrOBS.btnCreateOBSKandinskyClick(Sender: TObject);
|
|
var
|
|
dport: Integer;
|
|
i: Integer;
|
|
rk: TOBSKandinsky;
|
|
begin
|
|
dport := 8080;
|
|
for i := 0 to sgWebChats.RowCount - 1 do
|
|
begin
|
|
if strtoint(sgWebChats.Cells[0, i]) >= dport then
|
|
dport := strtoint(sgWebChats.Cells[0, i]) + 1;
|
|
end;
|
|
rk.port := dport;
|
|
AddKandinsky(rk);
|
|
|
|
end;
|
|
|
|
procedure TfrOBS.btnCreateOBSNotifyClick(Sender: TObject);
|
|
var
|
|
dport, i: Integer;
|
|
begin
|
|
dport := 8080;
|
|
for i := 0 to sgWebChats.RowCount - 1 do
|
|
begin
|
|
if strtoint(sgWebChats.Cells[0, i]) >= dport then
|
|
dport := strtoint(sgWebChats.Cells[0, i]) + 1;
|
|
end;
|
|
fCreateNotify.sbWebServerPort.Value := dport;
|
|
fCreateNotify.isEdit := false;
|
|
fCreateNotify.Show;
|
|
end;
|
|
|
|
procedure TfrOBS.btnDeleteeChatClick(Sender: TObject);
|
|
begin
|
|
if sgWebChats.Cells[1, sgWebChats.Row] = '×àò' then
|
|
begin
|
|
DelChat(strtoint(sgWebChats.Cells[0, sgWebChats.Row]));
|
|
end;
|
|
if sgWebChats.Cells[1, sgWebChats.Row] = 'Kandinsky' then
|
|
begin
|
|
DelKandinsky(strtoint(sgWebChats.Cells[0, sgWebChats.Row]));
|
|
end;
|
|
if sgWebChats.Cells[1, sgWebChats.Row] = 'Îïîâåùåíèå' then
|
|
begin
|
|
DelNotify(strtoint(sgWebChats.Cells[0, sgWebChats.Row]));
|
|
end;
|
|
end;
|
|
|
|
procedure TfrOBS.DelChat(aPort: Integer);
|
|
var
|
|
i, j: Integer;
|
|
begin
|
|
// Èùåì â îáðàòíîì ïîðÿäêå äëÿ áåçîïàñíîãî óäàëåíèÿ
|
|
for i := High(listChats) downto 0 do
|
|
begin
|
|
if listChats[i].port = aPort then
|
|
begin
|
|
// Ñäâèãàåì ýëåìåíòû ìàññèâà
|
|
for j := i to High(listChats) - 1 do
|
|
listChats[j] := listChats[j + 1];
|
|
// Óìåíüøàåì ðàçìåð ìàññèâà
|
|
SetLength(listChats, Length(listChats) - 1);
|
|
// Âûõîäèì ïîñëå ïåðâîãî íàéäåííîãî ñîâïàäåíèÿ (ïðåäïîëàãàåì óíèêàëüíîñòü ïîðòîâ)
|
|
Break;
|
|
end;
|
|
end;
|
|
|
|
db.SaveRecordArray<TOBSChat>('listChats', listChats);
|
|
UpdateGridFromArray;
|
|
end;
|
|
|
|
procedure TfrOBS.DelKandinsky(aPort: Integer);
|
|
var
|
|
i, j: Integer;
|
|
begin
|
|
// Èùåì â îáðàòíîì ïîðÿäêå äëÿ áåçîïàñíîãî óäàëåíèÿ
|
|
for i := High(listKandinsky) downto 0 do
|
|
begin
|
|
if listKandinsky[i].port = aPort then
|
|
begin
|
|
// Ñäâèãàåì ýëåìåíòû ìàññèâà
|
|
for j := i to High(listKandinsky) do
|
|
listKandinsky[j] := listKandinsky[j + 1];
|
|
// Óìåíüøàåì ðàçìåð ìàññèâà
|
|
SetLength(listKandinsky, Length(listKandinsky) - 1);
|
|
// Âûõîäèì ïîñëå ïåðâîãî íàéäåííîãî ñîâïàäåíèÿ (ïðåäïîëàãàåì óíèêàëüíîñòü ïîðòîâ)
|
|
Break;
|
|
end;
|
|
end;
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSKandinsky>('listKandinsky', listKandinsky);
|
|
end;
|
|
|
|
procedure TfrOBS.DelNotify(aPort: Integer);
|
|
var
|
|
i, j: Integer;
|
|
begin
|
|
// Èùåì â îáðàòíîì ïîðÿäêå äëÿ áåçîïàñíîãî óäàëåíèÿ
|
|
for i := High(listNotify) downto 0 do
|
|
begin
|
|
if listNotify[i].port = aPort then
|
|
begin
|
|
// Ñäâèãàåì ýëåìåíòû ìàññèâà
|
|
for j := i to High(listNotify) do
|
|
listNotify[j] := listNotify[j + 1];
|
|
// Óìåíüøàåì ðàçìåð ìàññèâà
|
|
SetLength(listNotify, Length(listNotify) - 1);
|
|
// Âûõîäèì ïîñëå ïåðâîãî íàéäåííîãî ñîâïàäåíèÿ (ïðåäïîëàãàåì óíèêàëüíîñòü ïîðòîâ)
|
|
Break;
|
|
end;
|
|
end;
|
|
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSNotify>('listNotify', listNotify);
|
|
end;
|
|
|
|
procedure TfrOBS.EdtChat(newRecord: TOBSChat; oldPort: Integer);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to High(listChats) do
|
|
if listChats[i].port = oldPort then
|
|
begin
|
|
listChats[i] := newRecord;
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSChat>('listChats', listChats);
|
|
Break;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrOBS.EdtNotify(newRecord: TOBSNotify; oldPort: Integer);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to High(listNotify) do
|
|
if listNotify[i].port = oldPort then
|
|
begin
|
|
listNotify[i] := newRecord;
|
|
UpdateGridFromArray;
|
|
db.SaveRecordArray<TOBSNotify>('listNotify', listNotify);
|
|
Break;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrOBS.sgWebChatsCellDblClick(const Column: TColumn;
|
|
const Row: Integer);
|
|
var
|
|
myChatRec: TOBSChat;
|
|
myNotifyRec: TOBSNotify;
|
|
i: Integer;
|
|
begin
|
|
if sgWebChats.Cells[1, Row] = 'Îïîâåùåíèå' then
|
|
begin
|
|
for i := 0 to High(listNotify) do
|
|
if listNotify[i].port = (strtoint(sgWebChats.Cells[0, Row])) then
|
|
begin
|
|
myNotifyRec := listNotify[i];
|
|
Break;
|
|
end;
|
|
|
|
fCreateNotify.isEdit := true;
|
|
fCreateNotify.setRecord(myNotifyRec);
|
|
fCreateNotify.Show;
|
|
end;
|
|
if sgWebChats.Cells[1, Row] = '×àò' then
|
|
begin
|
|
for i := 0 to High(listChats) do
|
|
if listChats[i].port = (strtoint(sgWebChats.Cells[0, Row])) then
|
|
begin
|
|
myChatRec := listChats[i];
|
|
Break;
|
|
end;
|
|
fCreateChat.isEdit := true;
|
|
fCreateChat.setRecord(myChatRec);
|
|
fCreateChat.Show;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrOBS.UpdateGridFromArray;
|
|
var
|
|
i, rowIndex: Integer;
|
|
begin
|
|
sgWebChats.BeginUpdate;
|
|
try
|
|
sgWebChats.RowCount := 0; // Ñáðàñûâàåì ñòðîêè
|
|
|
|
rowIndex := 0; // Îòäåëüíûé ñ÷åò÷èê äëÿ ñòðîê ñåòêè
|
|
|
|
// listChats
|
|
for i := 0 to High(listChats) do
|
|
begin
|
|
sgWebChats.RowCount := rowIndex + 1;
|
|
sgWebChats.Cells[0, rowIndex] := inttostr(listChats[i].port);
|
|
sgWebChats.Cells[1, rowIndex] := '×àò';
|
|
sgWebChats.Cells[2, rowIndex] := 'http://127.0.0.1:' +
|
|
inttostr(listChats[i].port);
|
|
Inc(rowIndex); // Óâåëè÷èâàåì ñ÷åò÷èê ñòðîê
|
|
end;
|
|
|
|
// listNotify
|
|
for i := 0 to High(listNotify) do
|
|
begin
|
|
sgWebChats.RowCount := rowIndex + 1;
|
|
sgWebChats.Cells[0, rowIndex] := inttostr(listNotify[i].port);
|
|
sgWebChats.Cells[1, rowIndex] := 'Îïîâåùåíèå';
|
|
sgWebChats.Cells[2, rowIndex] := 'http://127.0.0.1:' +
|
|
inttostr(listNotify[i].port);
|
|
Inc(rowIndex); // Óâåëè÷èâàåì ñ÷åò÷èê ñòðîê
|
|
end;
|
|
|
|
// listKandinsky
|
|
for i := 0 to High(listKandinsky) do
|
|
begin
|
|
sgWebChats.RowCount := rowIndex + 1;
|
|
sgWebChats.Cells[0, rowIndex] := inttostr(listKandinsky[i].port);
|
|
sgWebChats.Cells[1, rowIndex] := 'Kandinsky';
|
|
sgWebChats.Cells[2, rowIndex] := 'http://127.0.0.1:' +
|
|
inttostr(listKandinsky[i].port);
|
|
Inc(rowIndex); // Óâåëè÷èâàåì ñ÷åò÷èê ñòðîê
|
|
end;
|
|
finally
|
|
sgWebChats.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
end.
|