-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrmHostAccountInfo.cpp
105 lines (95 loc) · 3.45 KB
/
FrmHostAccountInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FrmHostAccountInfo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormHostAccountInfo *FormHostAccountInfo;
//---------------------------------------------------------------------------
__fastcall TFormHostAccountInfo::TFormHostAccountInfo(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::FormCreate(TObject *Sender)
{
StringGrid->RowCount = (StringGrid->Height / StringGrid->DefaultRowHeight) + 5;
StringGrid->Cells[0][0] = "UserID";
StringGrid->Cells[1][0] = "Password";
StringGrid->Cells[2][0] = "Full Name";
StringGrid->ColWidths[0] = (StringGrid->GridWidth * 0.25);
StringGrid->ColWidths[1] = (StringGrid->GridWidth * 0.25);
StringGrid->ColWidths[2] = (StringGrid->GridWidth * 0.50);
SortedID = new TStringList();
Pass = new TStringList();
Pass->Sorted = false;
FName = new TStringList();
FName->Sorted = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::FormDestroy(TObject *Sender)
{
delete SortedID;
delete Pass;
delete FName;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::BtnCancelClick(TObject *Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::BtnOkClick(TObject *Sender)
{
SortGridInfo();
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::StringGridSetEditText(
TObject *Sender, int ACol, int ARow, const AnsiString Value)
{
int c = CountUsers();
LabelUsrCnt->Caption = IntToStr(c);
StringGrid->RowCount = (StringGrid->Height / StringGrid->DefaultRowHeight) + 5 + c;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::SortGridInfo()
{
SortedID->Clear();
Pass->Clear();
FName->Clear();
for (int i = 1; i <= StringGrid->RowCount; i++)
if (StringGrid->Cells[0][i] != "") {
int j = Pass->Add(StringGrid->Cells[1][i]);
FName->Add(StringGrid->Cells[2][i]);
SortedID->AddObject(StringGrid->Cells[0][i], (TObject *)j);
}
for (int i = 1; i <= StringGrid->RowCount; i++) {
StringGrid->Cells[0][i] = "";
StringGrid->Cells[1][i] = "";
StringGrid->Cells[2][i] = "";
}
SortedID->Sort();
for (int i = 0; i < SortedID->Count; i++) {
StringGrid->Cells[0][i + 1] = SortedID->Strings[i];
StringGrid->Cells[1][i + 1] = Pass->Strings[(int)SortedID->Objects[i]];
StringGrid->Cells[2][i + 1] = FName->Strings[(int)SortedID->Objects[i]];
}
}
//---------------------------------------------------------------------------
int __fastcall TFormHostAccountInfo::CountUsers()
{
int uc = 0;
for (int i = 1; i <= StringGrid->RowCount; i++)
if (StringGrid->Cells[0][i] != "")
uc++;
return uc;
}
//---------------------------------------------------------------------------
void __fastcall TFormHostAccountInfo::FormShow(TObject *Sender)
{
SortGridInfo();
LabelUsrCnt->Caption = IntToStr(CountUsers());
}
//---------------------------------------------------------------------------