-
Notifications
You must be signed in to change notification settings - Fork 4
/
frmUsersManage.cs
279 lines (258 loc) · 10.7 KB
/
frmUsersManage.cs
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
using System;
using UpgradeHelpers.DB.ADO;
using UpgradeHelpers.Helpers;
using Mobilize.WebMap.Common.Attributes;
using Mobilize.Web.Extensions;
namespace SKS
{
[Observable]
internal partial class frmUsersManage
: Mobilize.Web.Form
{
public frmUsersManage()
: base()
{
if ( m_vb6FormDefInstance is null )
{
if ( m_InitializingDefInstance )
{
m_vb6FormDefInstance = this;
}
else
{
try
{
//For the start-up form, the first instance created is the default instance.
if ( !(System.Reflection.Assembly.GetExecutingAssembly().EntryPoint is null) && System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType == this.GetType() )
{
m_vb6FormDefInstance = this;
}
}
catch
{
}
}
}
//This call is required by the Windows Form Designer.
InitializeComponent();
ReLoadForm(false);
}
private void frmUsersManage_Activated(System.Object eventSender, System.EventArgs eventArgs)
{
if ( Stub._UpgradeHelpers.Gui.Utils.ActivateHelper.myActiveForm != eventSender )
{
Stub._UpgradeHelpers.Gui.Utils.ActivateHelper.myActiveForm = (Mobilize.Web.Form)eventSender;
}
}
[Intercepted]
string CurrentEditedUser { get; set; } = "";
private void cmdClear_Click(Object eventSender, EventArgs eventArgs)
{
txtUsername.Text = "";
txtUsername.Focus();
ClearFields();
}
private void cmdDelete_Click(Object eventSender, EventArgs eventArgs)
{
if ( modFunctions.NoRecords(lstAccounts, "Please add/select a user") )
{
return ;
}
if ( Mobilize.Web.MessageBox.Show("Are you sure you want to delete the user '" + lstAccounts.FocusedItem.Text + "'?", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.YesNo, Mobilize.Web.MessageBoxIcon.Exclamation) == Mobilize.Web.DialogResult.Yes )
{
modConnection.ExecuteSql("Select * from Users");
if ( modConnection.rs.RecordCount == 1 )
{
Mobilize.Web.MessageBox.Show("You cannot delete the last user", "Delete error", Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Error);
return ;
}
modConnection.ExecuteSql("Delete From Users Where Username = '" + lstAccounts.FocusedItem.Text + "'");
LoadUsers();
}
}
private void cmdEdit_Click(Object eventSender, EventArgs eventArgs)
{
if ( modFunctions.NoRecords(lstAccounts, "Please add/select a user") )
{
return ;
}
modConnection.ExecuteSql("Select * from Users where Username = '" + lstAccounts.FocusedItem.Text + "'");
txtUsername.Text = Convert.ToString(modConnection.rs["UserName"]);
if ( modConnection.rs.EOF )
{
Mobilize.Web.MessageBox.Show("This user does not exist", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Information);
txtUsername.Focus();
}
else
{
txtUsername.Text = Convert.ToString(modConnection.rs["UserName"]);
CurrentEditedUser = txtUsername.Text;
txtPassword.Text = Convert.ToString(modConnection.rs["Password"]);
txtFullname.Text = Convert.ToString(modConnection.rs["Fullname"]);
cboLevel.Text = Convert.ToString(modConnection.rs["Level"]);
cmdSave.Text = "&Update";
}
}
private void cmdSave_Click(Object eventSender, EventArgs eventArgs)
{
string SecId = "";
if ( modFunctions.TextBoxEmpty(txtUsername) )
{
return ;
}
if ( modFunctions.TextBoxEmpty(txtPassword) )
{
return ;
}
if ( modFunctions.TextBoxEmpty(txtFullname) )
{
return ;
}
if ( modFunctions.ComboEmpty(cboLevel) )
{
return ;
}
modConnection.ExecuteSql("Select * from Users where Username = '" + txtUsername.Text + "'");
if ( cmdSave.Text != "&Update" )
{
if ( !modConnection.rs.EOF )
{
Mobilize.Web.MessageBox.Show("Add failed: Username already exists", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Error);
return ;
}
if ( cboLevel.Text != "Administrator" )
{
modConnection.ExecuteSql2("Select * from Users where level = 'Administrator'");
if ( modConnection.rs2.EOF )
{
Mobilize.Web.MessageBox.Show("Update failed: No any Administrator found on accounts. You are not allowed to change the level of this account", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Error);
return ;
}
}
if ( !modMain.CurrentUserAdmin && cboLevel.Text == "Administrator" )
{
Mobilize.Web.MessageBox.Show("You cannot add another level without being 'Administrator'", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Information);
cboLevel.Focus();
return ;
}
modConnection.rs.AddNew();
modMain.msg = "Added new user " + txtUsername.Text;
}
else if ( CurrentEditedUser != txtUsername.Text )
{
modConnection.ExecuteSql2("Select * from Users where username = '" + txtUsername.Text + "'");
if ( !modConnection.rs2.EOF )
{
Mobilize.Web.MessageBox.Show("Username '" + txtUsername.Text + "' already exists.", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Information);
txtUsername.Focus();
modFunctions.SelectAll(txtUsername);
return ;
}
modMain.msg = "Record for the user " + txtUsername.Text + " has been successfully updated";
}
else
{
modMain.msg = "Record for the user " + txtUsername.Text + " has been successfully updated";
}
modConnection.rs["UserName"] = txtUsername.Text;
modConnection.rs["Password"] = txtPassword.Text;
modConnection.rs["Level"] = cboLevel.Text;
modConnection.rs["Fullname"] = txtFullname.Text;
modConnection.rs.Update();
modMain.LogStatus(modMain.msg);
ClearFields();
LoadUsers();
if ( modMain.CurrentUserAdmin )
{
this.Close();
}
}
public void LoadUsers()
{
modConnection.ExecuteSql("Select * from Users");
lstAccounts.Items.Clear();
Mobilize.Web.ListViewItem x = null;
while ( !modConnection.rs.EOF )
{
x = lstAccounts.Items.Add(Convert.ToString(modConnection.rs["UserName"]));
Mobilize.Web.ListView.GetListViewSubItem(x, 1).Text = Convert.ToString(modConnection.rs["Fullname"]);
Mobilize.Web.ListView.GetListViewSubItem(x, 2).Text = Convert.ToString(modConnection.rs["Level"]);
modConnection.rs.MoveNext();
}
}
public void LoadUsersAvoidingWith()
{
modConnection.ExecuteSql("Select * from Users");
lstAccounts.Items.Clear();
Mobilize.Web.ListViewItem x = null;
while ( !modConnection.rs.EOF )
{
x = lstAccounts.Items.Add(Convert.ToString(modConnection.rs["UserName"]));
Mobilize.Web.ListView.GetListViewSubItem(x, 1).Text = Convert.ToString(modConnection.rs["Fullname"]);
Mobilize.Web.ListView.GetListViewSubItem(x, 2).Text = Convert.ToString(modConnection.rs["Level"]);
modConnection.rs.MoveNext();
}
}
public void ClearFields()
{
txtUsername.Text = "";
txtPassword.Text = "";
txtFullname.Text = "";
cboLevel.SelectedIndex = -1;
cmdSave.Text = "&Save";
}
private void cmdClose_Click(Object eventSender, EventArgs eventArgs)
{
this.Close();
}
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
private void Form_Load()
{
modConnection.ExecuteSql("Select * from Levels");
while ( !modConnection.rs.EOF )
{
cboLevel.AddItem(Convert.ToString(modConnection.rs["Level"]));
modConnection.rs.MoveNext();
}
if ( modMain.CurrentUserAdmin )
{
cboLevel.Text = "Administrator";
}
else
{
cboLevel.SelectedIndex = -1;
}
LoadUsers();
}
private void Form_Closed(Object eventSender, EventArgs eventArgs)
{
if ( modMain.CurrentUserAdmin )
{
modConnection.ExecuteSql("Select * from Users");
if ( modConnection.rs.EOF )
{
Mobilize.Web.MessageBox.Show("System has failed to initialized. Please contact your administrator" + Environment.NewLine + Environment.NewLine + "Status: analysing accounts configuration" + Environment.NewLine + "Error: No users found", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()), Mobilize.Web.MessageBoxButtons.OK, Mobilize.Web.MessageBoxIcon.Error);
Environment.Exit(0);
}
//frmxSplash.tmrLoad.Enabled = True
}
modMain.LogStatus("");
}
private void lstAccounts_DoubleClick(Object eventSender, EventArgs eventArgs)
{
cmdEdit_Click(cmdEdit, new EventArgs());
}
private void txtFullname_Enter(Object eventSender, EventArgs eventArgs)
{
modFunctions.SelectAll(txtFullname);
}
private void txtPassword_Enter(Object eventSender, EventArgs eventArgs)
{
modFunctions.SelectAll(txtPassword);
}
private void txtUsername_Enter(Object eventSender, EventArgs eventArgs)
{
modFunctions.SelectAll(txtUsername);
}
}
}