-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAGE_Bents_bulkassign.aspx.cs
executable file
·385 lines (317 loc) · 13 KB
/
PAGE_Bents_bulkassign.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
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 RBSR_AUFW.DB.IEntitlement;
using ComponentArt.Web.UI;
using RBSR_AUFW.DB.IBusRole;
using System.Collections.Generic;
using RBSR_AUFW.DB.IEntAssignmentSet;
using RBSR_AUFW.DB.IEntAssignment;
namespace _6MAR_WebApplication
{
public partial class WebForm126 : AFWACpage
{
public int IDentitlement;
public returnGetEntitlement THEent;
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
Grid1.ItemCheckChanged +=
new ComponentArt.Web.UI.Grid.ItemCheckChangedEventHandler(this.OnItemCheckChanged);
Grid1.BeforeCallback +=
new ComponentArt.Web.UI.Grid.BeforeCallbackEventHandler(this.OnBeforeCallback);
Grid1.AfterCallback +=
new ComponentArt.Web.UI.Grid.AfterCallbackEventHandler(this.OnAfterCallback);
}
private Dictionary<int, HELPERS.infoEASet> MAPsubprToEASet;
// Key is ID of subprocess
private Dictionary<int, int> MAPbroleToSubproc = new Dictionary<int, int>();
//Key is ID of brole
private Dictionary<int, string> MAPbroleIdToName = new Dictionary<int, string>();
private Queue<int> QUEUEidsBusrolesToADD;
private Queue<int> QUEUEidsBusrolesToREMOVE;
protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
try
{
IDentitlement = int.Parse(this.Request.Params["entid"]);
}
catch (Exception)
{
// Whilst debugging
IDentitlement = 64622;
}
IEntitlement engine = new IEntitlement(HELPERS.NewOdbcConn());
THEent = engine.GetEntitlement(IDentitlement);
// There is currently no concept of this page being "read only".
// It creates workspaces as needed; it is not performed in
// any particular workspace.
this.PANELcond_readonly.Visible = false;
}
public void OnBeforeCallback(object sender, EventArgs oArgs)
{
boolMustAbort = false;
MAPsubprToEASet =
new Dictionary<int, HELPERS.infoEASet>();
MAPbroleToSubproc =
new Dictionary<int, int>();
MAPbroleIdToName =
new Dictionary<int, string>();
QUEUEidsBusrolesToADD = new Queue<int>();
QUEUEidsBusrolesToREMOVE = new Queue<int>();
engineBusRole = new IBusRole(HELPERS.NewOdbcConn());
engineEASet = new IEntAssignmentSet(HELPERS.NewOdbcConn());
messages = "";
}
/* This is called when the user submits the page's changes.
It is called once for each checkbox change being submitted.
If necessary, a workspace is launched for the relevant subprocess.
If the subprocess already contains a workspace but it's owned
by some other user, the change is not made and the user
is alerted, but the process of executing the set of changes is
not aborted.
mimic this to create the automatic workspace creation:
AutoRemoveEntitlementStatus in GuidedEditor/...
*/
public void OnAfterCallback(object sender, EventArgs oArgs)
{
if (this.boolMustAbort) {
Grid1.CallbackParameter = "OPERATION ABORTED:\n" + messages;
return;
}
Dictionary<int, HELPERS.infoEASet> readyToUseWorkspaces = new Dictionary<int, HELPERS.infoEASet>();
Dictionary<int, HELPERS.infoEASet> lockedWorkspaces = new Dictionary<int, HELPERS.infoEASet>();
if (messages.Length > 0)
{
messages += "\n-------------------------\n\n";
}
HELPERS.AutoGenWorkspacesInBulk
(session.idUser, ref messages, MAPsubprToEASet, readyToUseWorkspaces, lockedWorkspaces,
"facilitate bulk role assignment/unassignment for a particular entitlement");
// If any problem occurred at all, we abort!
if (lockedWorkspaces.Count > 0)
{
Grid1.CallbackParameter = messages;
return;
}
// We now proceed with the actual edits.
IEntAssignment ENGINEentass = new IEntAssignment(HELPERS.NewOdbcConn());
while (QUEUEidsBusrolesToREMOVE.Count > 0)
{
int idBusrole = QUEUEidsBusrolesToREMOVE.Dequeue();
int idSubpr = MAPbroleToSubproc[idBusrole];
messages += "Detaching from this role: " + MAPbroleIdToName[idBusrole] + "\n";
HELPERS.infoEASet wstouse = readyToUseWorkspaces[idSubpr];
returnListEntAssignmentByEntAssignmentSet[] theEAss =
ENGINEentass.ListEntAssignmentByEntAssignmentSet
(null, "\"BusRole\" = ? AND \"Entitlement\" = ? ", new string[] { idBusrole.ToString(), IDentitlement.ToString() }, "", wstouse.idEntAssSet);
ENGINEentass.SetEntAssignment
(theEAss[0].ID, theEAss[0].EntAssignmentSetID, theEAss[0].BusRoleID,
theEAss[0].EntitlementID, "X");
}
while (QUEUEidsBusrolesToADD.Count > 0)
{
int idBusrole = QUEUEidsBusrolesToADD.Dequeue();
int idSubpr = MAPbroleToSubproc[idBusrole];
messages += "Attaching to this role: " + MAPbroleIdToName[idBusrole] + "\n";
HELPERS.infoEASet wstouse = readyToUseWorkspaces[idSubpr];
returnListEntAssignmentByEntAssignmentSet[] theEAss =
ENGINEentass.ListEntAssignmentByEntAssignmentSet
(null, "\"BusRole\" = ? AND \"Entitlement\" = ? ", new string[] { idBusrole.ToString(), IDentitlement.ToString() }, "", wstouse.idEntAssSet);
if (theEAss.GetLength(0) > 1) {
throw new Exception("Workspace " + wstouse.idEntAssSet + " contains multiple entitlement assignment records for business role " + idBusrole);
}
else if (theEAss.GetLength(0) == 1)
{
switch (theEAss[0].Status)
{
case "A":
messages += "Nothing to do. Workspace already has this match in place.\n";
break;
case "N":
messages += "Nothing to do. Workspace already has this match in place.\n";
break;
case "X":
ENGINEentass.SetEntAssignment
(theEAss[0].ID, theEAss[0].EntAssignmentSetID, theEAss[0].BusRoleID,
theEAss[0].EntitlementID, "N");
break;
}
}
else
{
int baby = ENGINEentass.NewEntAssignment
(wstouse.idEntAssSet, idBusrole, IDentitlement, "N");
}
}
if (messages.Length == 0)
{
messages = "NO MESSAGES TO REPORT.";
}
Grid1.CallbackParameter = messages;
}
private IBusRole engineBusRole;
private IEntAssignmentSet engineEASet;
private String messages;
private bool boolMustAbort;
public void OnItemCheckChanged(object sender, GridItemCheckChangedEventArgs oArgs)
{
int IDbusrole = int.Parse(oArgs.Item["c_id"].ToString());
returnGetBusRole detailsBusRole = engineBusRole.GetBusRole(IDbusrole);
MAPbroleIdToName.Add(IDbusrole, detailsBusRole.Name);
MAPbroleToSubproc.Add(IDbusrole, detailsBusRole.SubProcessID);
if (oArgs.Checked)
{
QUEUEidsBusrolesToADD.Enqueue(IDbusrole);
}
else
{
QUEUEidsBusrolesToREMOVE.Enqueue(IDbusrole);
}
if (MAPsubprToEASet.ContainsKey(detailsBusRole.SubProcessID))
return;
// This role is in a subprocess we have not yet analyzed.
// Must determine if in workspace or ACTIVE status.
// If that subpr is in a workspace owned by someone else,
// the entire operation is aborted with no change being made.
returnListEntAssignmentSetBySubProcess[] ret = engineEASet.ListEntAssignmentSetBySubProcess
(null, "\"Status\" = ?", new string[] { "WORKSPACE" }, "", detailsBusRole.SubProcessID);
if (ret.Length > 1)
{
throw new Exception("More than one WORKSPACE open simultaneously for subprocess " +
oArgs.Item["NamePr"].ToString());
}
if (ret.Length == 1)
{
// A workspace is open for this subprocess.
// OK if userID matches this session's user
if (ret[0].UserID == session.idUser)
{
// It's a match, we can use this workspace.
HELPERS.infoEASet EAS = new HELPERS.infoEASet();
EAS.idEntAssSet = ret[0].ID;
EAS.idEntAssSetCreator = ret[0].UserID;
EAS.nameEntAssSetCreator = ret[0].UserLoginName;
EAS.nameSubprocess = oArgs.Item["NamePr"].ToString();
EAS.strEntAssSetStatus = "WORKSPACE";
MAPsubprToEASet.Add(detailsBusRole.SubProcessID, EAS);
}
else
{
boolMustAbort = true;
messages +=
"ERROR: Cannot make modifications regarding role " +
oArgs.Item["c_u_Name"] + ". The workspace for " +
oArgs.Item["NamePr"] + " is owned by a 3rd party (" +
ret[0].UserLoginName + ").\n";
}
}
else
{
// Make sure there is an ACTIVE EASet to build a workspace from.
ret = engineEASet.ListEntAssignmentSetBySubProcess
(null, "\"Status\" = ?", new string[] { "ACTIVE" }, "", detailsBusRole.SubProcessID);
if (ret.Length > 1)
{
throw new Exception("More than one ACTIVE entitlement-assignment set for " +
oArgs.Item["NamePr"].ToString());
}
if (ret.Length < 1)
{
throw new Exception("Subprocess has NO active entitlement-assignment set yet: " +
oArgs.Item["NamePr"].ToString());
}
if (ret.Length == 1)
{
HELPERS.infoEASet EAS = new HELPERS.infoEASet();
EAS.idEntAssSet = ret[0].ID;
EAS.idEntAssSetCreator = ret[0].UserID;
EAS.nameEntAssSetCreator = ret[0].UserLoginName;
EAS.nameSubprocess = oArgs.Item["NamePr"].ToString();
EAS.strEntAssSetStatus = "ACTIVE";
MAPsubprToEASet.Add(detailsBusRole.SubProcessID, EAS);
}
}
}
/*
IEntAssignment ENGINEentass = new IEntAssignment(HELPERS.NewOdbcConn());
int IDentitlement = int.Parse(oArgs.Item["c_id"].ToString());
string editstatusEAss = "-";
int idEntAss = -1;
if (oArgs.Item["TEassEditStatus"] != null)
{
if (oArgs.Item["TEassEditStatus"].ToString() != "")
{
editstatusEAss = oArgs.Item["TEassEditStatus"].ToString();
idEntAss = int.Parse(oArgs.Item["TEassRowId"].ToString());
}
}
if (oArgs.Checked)
{
if (idEntAss >= 0)
{
returnGetEntAssignment curval = ENGINEentass.GetEntAssignment(idEntAss);
ENGINEentass.SetEntAssignment(idEntAss, curval.EntAssignmentSetID, curval.BusRoleID, curval.EntitlementID,
"A");//ACTIVE
}
else
{
// Create a EAss
int baby = ENGINEentass.NewEntAssignment(session.idWorkspace, IDrole, IDentitlement, "N");
MAPentIdToBabyEAssId.Add(IDentitlement, baby);
}
}
else
{
if (idEntAss < 0)
{
if (MAPentIdToBabyEAssId.ContainsKey(IDentitlement))
{
idEntAss = MAPentIdToBabyEAssId[IDentitlement];
editstatusEAss = "N";
MAPentIdToBabyEAssId.Remove(IDentitlement);
}
}
if (editstatusEAss == "N")
{
try
{
ENGINEentass.DeleteEntAssignment(idEntAss);
}
catch (Exception eee)
{
// Exceptions will occur here naturally, if during a session where row R was
// initially unchecked, someone checked it, and then unchecked it back to its
// original unchecked state, and then hits submit.
ENGINEentass.DeleteEntAssignment(
MAPentIdToBabyEAssId[IDentitlement]);
MAPentIdToBabyEAssId.Remove(IDentitlement);
}
}
else
{
returnGetEntAssignment curval = ENGINEentass.GetEntAssignment(idEntAss);
ENGINEentass.SetEntAssignment(idEntAss, curval.EntAssignmentSetID, curval.BusRoleID, curval.EntitlementID,
"X");
}
}
}
*/
}
}