-
Notifications
You must be signed in to change notification settings - Fork 1
/
WispUserEditor.pas
284 lines (245 loc) · 7.2 KB
/
WispUserEditor.pas
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
unit WispUserEditor;
interface
uses
Dialogs,
Forms,
StdCtrls,
ExtCtrls,
Graphics,
Controls,
Classes,
SysUtils,
ZDataset,
cxTextEdit,
cxButtons,
WispEditBox,
WispDatePicker,
WispLookUpComboBox,
WispEntity,
WispEntityGrid,
WispArrayTools,
WispEntityManager,
WispQueryTools,
WispDbConnection,
WispTimeTools,
WispAccesManager,
WispCheckBox,
WispVisualComponent,
WispTimePicker,
WispStrTools,
WispMathTools,
cxPC,
Messages,
Windows,
WispUser,
WispUserGrid,
WispStyleManager,
WispConstantManager,
WispImageTools,
WispButton;
Const
EdtWidth = 320;
type
TUserEditor = Class(TObject)
private
// User Editor
CurrentID: String;
EditMode: Boolean;
BoxUserEditor: TScrollBox;
DbColumns: Array of string;
BtnOk: TWispButton;
Tab: TcxTabSheet;
EdtUserName: TWispEditBox;
EdtPassWord: TWispEditBox;
EdtPassConf: TWispEditBox;
EdtFirstName: TWispEditBox;
EdtFamilyName: TWispEditBox;
EdtUserPhone: TWispEditBox;
EdtUserMail: TWispEditBox;
LookUpProfile: TWispLookUpComboBox;
Procedure NewUserToDb;
Procedure UpdateUserToDb;
procedure BtnOk_OnClick(Sender: TObject);
procedure TabOnShow(Sender: TObject);
protected
public
Constructor Create(ParamOwner: TComponent; ParamParent: TWinControl;
ParamUserId: string = '0');
end;
implementation
uses WispMainMenuManager;
// =============================================================================
Constructor TUserEditor.Create(ParamOwner: TComponent; ParamParent: TWinControl;
ParamUserId: string = '0');
var
H, YOffset: integer;
TmpUser: TWispUser;
begin
// The editor is owned and drawn on a tab
Tab := TcxTabSheet(ParamOwner); // So basicly tab is ParamOwner
Tab.OnShow := Self.TabOnShow;
YOffset := 16;
if ParamUserId = '0' then
begin
EditMode := FALSE;
end;
// ...
if ParamUserId <> '0' then
begin
EditMode := TRUE;
TmpUser := TWispUser.Create;
TmpUser.LoadFromDbById(ParamUserId);
end;
// Create the entity editor form
BoxUserEditor := TScrollBox.Create(ParamOwner);
with BoxUserEditor do
begin
Width := 320;
Height := H;
BorderStyle := bsNone;
Parent := ParamParent;
Color := clGray;
Align := alClient;
Global_Singleton_MainMenuManager.CurrentFocusedScrollBox :=
Self.BoxUserEditor;
end;
// BG
DrawBgImage(BoxUserEditor);
// Username
EdtUserName := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1, 0,
YOffset, 'Username');
EdtUserName.CenterHorizontally;
YOffset := YOffset + 80;
// Password 1
EdtPassWord := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1, 0,
YOffset, 'Password');
EdtPassWord.EdtBox.Properties.EchoMode := eemPassword;
EdtPassWord.CenterHorizontally;
YOffset := YOffset + 80;
// Password 2
EdtPassConf := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1, 0,
YOffset, 'Password Confirmation');
EdtPassConf.EdtBox.Properties.EchoMode := eemPassword;
EdtPassConf.CenterHorizontally;
YOffset := YOffset + 80;
// First Name
EdtFirstName := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1, 0,
YOffset, 'First Name');
EdtFirstName.CenterHorizontally;
YOffset := YOffset + 80;
// Family Name
EdtFamilyName := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1,
0, YOffset, 'Family Name');
EdtFamilyName.CenterHorizontally;
YOffset := YOffset + 80;
// Phone Number
EdtUserPhone := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1, 0,
YOffset, 'Phone Number');
EdtUserPhone.CenterHorizontally;
YOffset := YOffset + 80;
// E-Mail
EdtUserMail := TWispEditBox.Create(ParamOwner, BoxUserEditor, EdtWidth, 1, 0,
YOffset, 'E-Mail');
EdtUserMail.CenterHorizontally;
YOffset := YOffset + 80;
// Profile
LookUpProfile := TWispLookUpComboBox.Create(ParamOwner, BoxUserEditor,
EdtWidth, 0, YOffset, 'Profile');
LookUpProfile.CenterHorizontally;
LookUpProfile.LoadFromTable('wisp_profiles', 'WISP_NAME', 'Name', 'WISP_ID');
YOffset := YOffset + 80;
// Add Ok and Cancel buttons
BtnOk := TWispButton.Create(BoxUserEditor);
with BtnOk do
begin
Parent := BoxUserEditor;
Width := 64;
Height := 24;
Caption := 'OK';
Top := YOffset + 50;
Left := Round((Parent.Width - Width) / 2);
Default := TRUE;
OnClick := BtnOk_OnClick;
end;
if ParamUserId <> '0' then
begin
EdtUserName.EdtBox.Text := TmpUser.UserName;
EdtFirstName.EdtBox.Text := TmpUser.FirstName;
EdtFamilyName.EdtBox.Text := TmpUser.FamilyName;
EdtUserPhone.EdtBox.Text := TmpUser.PhoneNumber;
EdtUserMail.EdtBox.Text := TmpUser.Email;
end;
// ...
BoxUserEditor.Show;
end;
// =============================================================================
procedure TUserEditor.BtnOk_OnClick(Sender: TObject);
begin
if EditMode = FALSE then
NewUserToDb;
end;
// =============================================================================
Procedure TUserEditor.NewUserToDb;
const
WM_KILLTAB = WM_USER + 1;
Var
TmpUserGrid: TUserGrid;
TmpUser: TWispUser;
begin
if EdtUserName.GetText = '' then
begin
ShowMessage('Please enter a username');
EXIT;
end;
if Global_Singleton_AccesManager.CheckIfUserNameExists(EdtUserName.GetText)
then
begin
ShowMessage('This username is already used');
EXIT;
end;
if EdtPassWord.GetText = '' then
begin
ShowMessage('Please enter a password');
EXIT;
end;
if not(EdtPassWord.GetText = EdtPassConf.GetText) then
begin
ShowMessage('Passwords does not match');
EXIT;
end;
if LookUpProfile.LookUpComboBox.ItemIndex = -1 then
begin
ShowMessage('Please select a profile');
EXIT;
end;
Global_Singleton_AccesManager.AddNewUser(EdtUserName.GetText,
EdtPassWord.GetText);
TmpUser := TWispUser.Create;
TmpUser.UserName := EdtUserName.GetText;
TmpUser.FirstName := EdtFirstName.GetText;
TmpUser.FamilyName := EdtFamilyName.GetText;
TmpUser.PhoneNumber := EdtUserPhone.GetText;
TmpUser.Email := EdtUserMail.GetText;
Global_Singleton_AccesManager.SaveUserByUserName(TmpUser);
TmpUser.LoadFromDbByUserName(EdtUserName.GetText);
TmpUser.UpdateProfileId
(LookUpProfile.GetKey(LookUpProfile.LookUpComboBox.ItemIndex));
TmpUserGrid := TUserGrid(Global_Singleton_MainMenuManager.PageControlMain.
GetParentObject('USER_EDIT', 'USER', '0'));
// TmpUserGrid.RefreshGrid;
Global_Singleton_MainMenuManager.PageControlMain.UnRegisterTab('USER_EDIT',
'USER', '0');
PostMessage(Global_Singleton_MainMenuManager.PageControlMain.Handle,
WM_KILLTAB, 0, Tab.PageIndex);
end;
// =============================================================================
Procedure TUserEditor.UpdateUserToDb;
begin
end;
// =============================================================================
procedure TUserEditor.TabOnShow(Sender: TObject);
begin
Global_Singleton_MainMenuManager.CurrentFocusedScrollBox :=
Self.BoxUserEditor;
end;
end.