-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAGElaunchBRoleEntitlementsUpload.aspx.cs
executable file
·556 lines (422 loc) · 18.8 KB
/
PAGElaunchBRoleEntitlementsUpload.aspx.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using RBSR_AUFW.DB.IBusRoleOwner;
using RBSR_AUFW.DB.IBusRole;
using RBSR_AUFW.DB.IEntitlement;
using RBSR_AUFW.DB.IEntAssignment;
namespace _6MAR_WebApplication
{
public partial class WebForm121 : AFWACpage
{
protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
PANELcond_AbortUpload.Visible = false;
PANELcond_AllowUpload.Visible = false;
System.Data.Odbc.OdbcConnection conn = HELPERS.NewOdbcConn();
session.ObtainWorkspaceContext();
if ((session.idWorkspace >= 0) && session.isWorkspaceOwner)
{
PANELcond_AllowUpload.Visible = true;
PANELcond_AbortUpload.Visible = false;
}
else
{
PANELcond_AbortUpload.Visible = true;
PANELcond_AllowUpload.Visible = false;
}
// This next line exposes a bug in WEB.UI:
// If we do this, the selected index is LOCKED to 0.
// If user changes the selection and then submits,
// the selindex is still 0 from within the C# code.
// This has to be conditionalized: not in a postback?
if ( ! IsPostBack) {
COMBOXchooseUnregEntAction.SelectedIndex = 0;
}
}
protected void
ONCLICK_BulkUploadNewBusRoles(object sender, EventArgs e)
{
IBusRoleOwner ENGINEbrown = new IBusRoleOwner(HELPERS.NewOdbcConn());
IBusRole ENGINEbr = new IBusRole(HELPERS.NewOdbcConn());
if (this.FileUpload_AddRoles.HasFile)
{
string pathTempFolder = System.IO.Path.GetTempPath();
string pathTempFile = System.IO.Path.GetTempFileName();
FileUpload_AddRoles.SaveAs(pathTempFile);
DataTable dt = HELPERS.LoadCsv(pathTempFolder,
System.IO.Path.GetFileName(pathTempFile));
if (dt != null)
{
if (dt.Columns.Count < 2)
{
throw new Exception("The uploaded CSV file must have at least the name and description columns. (It can optionally also have the two approver/owner columns.)");
}
Queue RETmsgs = new Queue();
IEnumerator<System.Data.DataRow> x =
(IEnumerator<System.Data.DataRow>)dt.Rows.GetEnumerator();
int recordseq = 0;
int okCount = 0;
while (x.MoveNext())
{
recordseq++;
string rolename = x.Current[0].ToString().Trim();
string description = x.Current[1].ToString().Trim();
string roletype = x.Current[2].ToString().Trim();
string primaryApprover = x.Current[3].ToString().Trim().ToUpper();
string primaryOwner = x.Current[4].ToString().Trim().ToUpper();
int IDrole = -1;
try
{
IDrole = HELPERS.FindBusRoleByName(rolename);
}
catch (Exception)
{
/* The exception is what we WANT! If this does not throw an exception, this row must be ignored! */
}
bool doRoleCreation = true;
if (IDrole >= 0) {
// This role name is already in use somewhere in the system (not nec this subpr).
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": Role already exists, so the only action will be updating of owner/approver info. Role name: " + rolename);
doRoleCreation = false;
}
int newID = (doRoleCreation ? -1 : IDrole);
if (doRoleCreation)
{
switch (roletype)
{
case "A":
break;
case "F":
break;
case "E":
break;
default:
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": line ignored due to unknown role-type code: " + roletype);
continue;
}
try
{
newID = ENGINEbr.NewBusRole(rolename, description, session.idSubprocess);
ENGINEbr.SetBusRole(newID, roletype);
okCount++;
}
catch (Exception ee)
{
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": " + ee.Message);
}
}
if (newID >= 0)
{
// New code added Thanksgiving 2012: supporting approver/owner
if (primaryOwner.Length > 2)
{
string __eid = primaryOwner;
string __rank = "OWNprim";
string __rankPretty = "Primary Owner";
try
{
HELPERS.FindUser(HELPERS.NewOdbcConn(), __eid, __eid, false);
returnListBusRoleOwnerByBusRole[] theList = ENGINEbrown.ListBusRoleOwnerByBusRole(null, newID);
if (theList.Length < 1)
ENGINEbrown.NewBusRoleOwner(__eid, "", __rank, newID);
else
{
foreach (returnListBusRoleOwnerByBusRole roleowner in theList)
{
if (roleowner.Rank == __rank)
ENGINEbrown.DeleteBusRoleOwner(roleowner.ID);
}
}
}
catch (Exception ee)
{
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": ignoring setting of " + __rankPretty + " due to unknown employee ID: " + __eid);
}
}
if (primaryApprover.Length > 2)
{
string __eid = primaryApprover;
string __rank = "appr";
string __rankPretty = "Primary Approver";
try
{
HELPERS.FindUser(HELPERS.NewOdbcConn(), __eid, __eid, false);
returnListBusRoleOwnerByBusRole[] theList = ENGINEbrown.ListBusRoleOwnerByBusRole(null, newID);
if (theList.Length < 1)
ENGINEbrown.NewBusRoleOwner(__eid, "", __rank, newID);
else
{
foreach (returnListBusRoleOwnerByBusRole roleowner in theList)
{
if (roleowner.Rank == __rank)
ENGINEbrown.DeleteBusRoleOwner(roleowner.ID);
}
}
}
catch (Exception ee)
{
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": ignoring setting of " + __rankPretty + " due to unknown employee ID: " + __eid);
}
}
}
}
// -----------------------------------------------
RETmsgs.Enqueue("------------------");
RETmsgs.Enqueue("Number of NEW business roles created successfully: " + okCount.ToString());
if (RETmsgs.Count > 0)
{
string strMsgs = "";
foreach (object objMsg in RETmsgs.ToArray())
{
strMsgs += "\n" + objMsg.ToString();
}
TXTimportEngineMessages.Text = strMsgs;
DIVimportFeeback.Visible = true;
PANELcond_AbortUpload.Visible = false;
PANELcond_AllowUpload.Visible = false;
}
}
}
}
protected void
ONCLICK_BulkUploadPersonnel(object sender, EventArgs e)
{
Dictionary<string, bool> DOESEXISTbyEid = new Dictionary<string,bool>();
Dictionary<string, int> DICTbusrole = new Dictionary<string,int>();
IBusRoleOwner ENGINEbrown = new IBusRoleOwner(HELPERS.NewOdbcConn());
IBusRole ENGINEbr = new IBusRole(HELPERS.NewOdbcConn());
if (this.FileUpload_PersonnelMappings.HasFile)
{
string pathTempFolder = System.IO.Path.GetTempPath();
string pathTempFile = System.IO.Path.GetTempFileName();
FileUpload_PersonnelMappings.SaveAs(pathTempFile);
DataTable dt = HELPERS.LoadCsv(pathTempFolder,
System.IO.Path.GetFileName(pathTempFile));
if (dt != null)
{
if (dt.Columns.Count < 3)
{
throw new Exception("The uploaded CSV file does not have at least 3 columns.");
}
Queue RETmsgs = new Queue();
IEnumerator<System.Data.DataRow> x =
(IEnumerator<System.Data.DataRow>)dt.Rows.GetEnumerator();
int recordseq = 0;
int okCount = 0;
while (x.MoveNext())
{
recordseq++;
string rolename = x.Current[0].ToString().Trim();
string rank = x.Current[1].ToString().Trim();
string eid = x.Current[2].ToString().Trim().ToUpper();
switch (rank)
{
case "Primary Owner":
rank = "OWNprim";
break;
case "Delegate Owner":
rank = "OWNdele";
break;
case "Primary Approver":
rank = "appr";
break;
case "Delegate Approver":
rank = "delegate";
break;
default:
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": line ignored due to unknown rank name: " + rank);
continue;
}
if (recordseq == 1)
{
// Upon seeing at least one row in the CSV, erase the entire personnel mapping table!
HELPERS.DestroyAllBusroleToPersonnelMappings();
}
if (DOESEXISTbyEid.ContainsKey(eid) == false)
{
HELPERS.FindUser(HELPERS.NewOdbcConn(), eid, eid, true);
DOESEXISTbyEid.Add(eid, true);
}
int IDrole = -1;
if (DICTbusrole.ContainsKey(rolename))
IDrole = DICTbusrole[rolename];
else
{
try
{
IDrole = HELPERS.FindBusRoleByName(rolename);
DICTbusrole.Add(rolename, IDrole);
}
catch (Exception)
{
}
}
if (IDrole < 0)
{
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": line ignored due to unknown role: " + rolename);
continue;
}
try
{
ENGINEbrown.NewBusRoleOwner(eid, "", rank, IDrole);
okCount++;
}
catch (Exception ee)
{
RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": " + ee.Message);
}
}
RETmsgs.Enqueue("------------------");
RETmsgs.Enqueue("Number of records processed successfully: " + okCount.ToString());
if (RETmsgs.Count > 0)
{
string strMsgs = "";
foreach (object objMsg in RETmsgs.ToArray())
{
strMsgs += "\n" + objMsg.ToString();
}
TXTimportEngineMessages.Text = strMsgs;
DIVimportFeeback.Visible = true;
PANELcond_AbortUpload.Visible = false;
PANELcond_AllowUpload.Visible = false;
}
}
}
}
protected void ONCLICK_BulkRemove(object sender, EventArgs e)
{
if (this.FileUpload_BulkRemove.HasFile)
{
string pathTempFolder = System.IO.Path.GetTempPath();
string pathTempFile = System.IO.Path.GetTempFileName();
FileUpload_BulkRemove.SaveAs(pathTempFile);
DataTable dt = HELPERS.LoadCsv(pathTempFolder,
System.IO.Path.GetFileName(pathTempFile));
if (dt != null)
{
if (dt.Columns.Count != 2)
{
throw new Exception("The uploaded CSV file has more than two columns.");
}
Queue RETmsgs = new Queue();
IEnumerator<System.Data.DataRow> x =
(IEnumerator<System.Data.DataRow>)dt.Rows.GetEnumerator();
int recordseq = 0;
int okCount = 0;
IBusRole ENGINEbusrole = new IBusRole(HELPERS.NewOdbcConn());
IEntitlement ENGINE = new IEntitlement(HELPERS.NewOdbcConn());
IEntAssignment IEA = new IEntAssignment(HELPERS.NewOdbcConn());
while (x.MoveNext())
{
recordseq++;
string rolename = x.Current[0].ToString();
string privstring = x.Current[1].ToString();
try
{
HELPERS.RemoveEntitlementFromRole(rolename, privstring, ENGINEbusrole, ENGINE, IEA);
okCount++;
}
catch (Exception ee)
{
RETmsgs.Enqueue ("REC#" + recordseq.ToString() + ": " + ee.Message);
}
}
RETmsgs.Enqueue("------------------");
RETmsgs.Enqueue("Number of records processed without message: " + okCount.ToString());
if (RETmsgs.Count > 0)
{
string strMsgs = "";
foreach (object objMsg in RETmsgs.ToArray())
{
strMsgs += "\n" + objMsg.ToString();
}
TXTimportEngineMessages.Text = strMsgs;
DIVimportFeeback.Visible = true;
PANELcond_AbortUpload.Visible = false;
PANELcond_AllowUpload.Visible = false;
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
REACTlaunchUpload(sender, e);
}
protected void REACTlaunchUpload(object sender, EventArgs e)
{
// For safety, do yet another verification that this user owns the
// workspace.
session.ObtainWorkspaceContext();
if (!((session.idWorkspace >= 0) && session.isWorkspaceOwner))
{
throw new Exception("There is no active workspace, owned by you, for this subprocess.");
}
if (this.FileUpload2.HasFile)
{
string pathTempFolder = System.IO.Path.GetTempPath();
string pathTempFile = System.IO.Path.GetTempFileName();
/*
if (this.COMBOXchooseBrole.SelectedIndex < 0)
{
throw new Exception("Select a role from the dropdown list!");
}
*/
/*
* TURNS OUT THAT idBusRole was never being used after being set.
*
int idBusRole = -1;
if (this.COMBOXchooseBrole.SelectedItem != null)
{
idBusRole = int.Parse(this.COMBOXchooseBrole.SelectedItem.Value);
}
*/
FileUpload2.SaveAs(pathTempFile);
DataTable dt = HELPERS.LoadCsv(pathTempFolder,
System.IO.Path.GetFileName(pathTempFile));
if (dt != null)
{
if (dt.Columns.Count > 1)
{
System.Data.Odbc.OdbcConnection conn =
new System.Data.Odbc.OdbcConnection(
ConfigurationManager.AppSettings["DBconnstr"]);
conn.Open();
Queue RETmsgs = new Queue();
HELPERS.ImportBusRoleAssignmentsFromDataTable
(dt, session.idUser, session.idWorkspace,
this.COMBOXchooseUnregEntAction.SelectedValue,
this.COMBOXchooseBrole.SelectedValue, RETmsgs,
session.idSubprocess);
if (RETmsgs.Count > 0)
{
string strMsgs = "";
foreach (object objMsg in RETmsgs.ToArray())
{
strMsgs += "\n" + objMsg.ToString();
}
TXTimportEngineMessages.Text = strMsgs;
DIVimportFeeback.Visible = true;
PANELcond_AbortUpload.Visible = false;
PANELcond_AllowUpload.Visible = false;
}
else
{
Response.Redirect("ListBRoles.aspx");
}
}
}
}
}
}
}