-
Notifications
You must be signed in to change notification settings - Fork 0
/
EthicsInvestMain.aspx.cs
419 lines (379 loc) · 20.4 KB
/
EthicsInvestMain.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Web.UI.HtmlControls;
/**
* The Investigator main page.
* Displays four lists. One for unsubmitted applications were the investigator is lead, one for submitted applications were the investigator is lead,
* one for unsubmitted applications were the investigator is not lead and one for submitted applications were the investigator is not lead,
*/
public partial class EthicsInvestMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection mySqlConnection = new Connector().MySQLConnect();
MySqlCommand command = mySqlConnection.CreateCommand();
int staffID = Convert.ToInt32(Context.Request["StaffID"]);
//Populate labels.
command.CommandText = "SELECT * FROM Staff LEFT JOIN AccountTypeList ON Staff.AccountType = AccountTypeList.ID WHERE StaffID = " + staffID;
MySqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
lblWelcome.InnerText = "Welcome " + reader["NameFirst"].ToString() + " " + reader["NameLast"].ToString();
LblAccnt.InnerText = "Account Type: " + reader["AccntType"].ToString();
}
else
divMsg.InnerText = "Error: Could not find staff member in database";
reader.Dispose();
//Populate Principal investigator unsubmitted table.
buildPIUnsubmittedTbl(mySqlConnection);
//Populate Principal investigator submitted table.
command.CommandText = @"SELECT Application.AppID, Application.a1_ProjTitle, StatusList.ID, StatusList.AppStatus, RiskLow_Bool, RiskNonLow_Bool
FROM Application LEFT JOIN StatusList ON Application.AppStatus = StatusList.ID
WHERE a4_InvestStaffID = " + staffID + " AND Application.AppStatus != 0 AND Application.AppStatus != 2 AND Application.AppStatus != 5";
reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read()) //Build each row.
{
HtmlTableRow row = new HtmlTableRow();
string riskLevel = "";
//Build view button.
HtmlInputButton btnView = new HtmlInputButton();
btnView.ID = "ViewPI" + reader["AppID"].ToString();
btnView.Value = "View";
btnView.ServerClick += btnView_ServerClick;
//Determine if low or non low risk.
if (Convert.ToBoolean(reader["RiskLow_Bool"]))
riskLevel = "Low risk";
else if (Convert.ToBoolean(reader["RiskNonLow_Bool"]))
riskLevel = "Non low risk";
//If status is declined add a hyperlink to the comment.
HtmlTableCell statusCell = HTMLFactory.buildCell("200", "left", reader["AppStatus"].ToString());
if (Convert.ToInt32(reader["ID"]) == 7) //Declined.
{
statusCell.InnerText += " - ";
HyperLink hl = new HyperLink();
hl.Text = "Comment";
hl.NavigateUrl = "EthicsEditAppS7.aspx?Mode=R&AppID=" + reader["AppID"].ToString() + "&StaffID=" + staffID + "&Type=" + Context.Request["Type"];
statusCell.Controls.Add(hl);
}
row.Cells.Add(HTMLFactory.buildCell("50", "left", reader["AppID"].ToString()));
row.Cells.Add(HTMLFactory.buildCell("400", "left", reader["a1_ProjTitle"].ToString()));
row.Cells.Add(statusCell);
row.Cells.Add(HTMLFactory.buildCell("120", "left", riskLevel));
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnView));
tblPISubmitted.Rows.Add(row);
}
}
else //Display none.
{
if (tblPISubmitted.Rows.Count != 0)
{
HtmlTableRow blnkRow = new HtmlTableRow();
HtmlTableCell blnk = new HtmlTableCell();
blnk.InnerText = "None";
blnk.ColSpan = 5;
blnkRow.Cells.Add(blnk);
tblPISubmitted.Rows.Add(blnkRow);
}
}
reader.Dispose();
//Populate Co-investigator unsubmitted table.
buildCIUnsubmittedTbl(mySqlConnection);
//Populate Co-investigator submitted table.
command.CommandText = @"SELECT Application.AppID, Application.a1_ProjTitle, StatusList.ID, StatusList.AppStatus, RiskLow_Bool, RiskNonLow_Bool
FROM Application INNER JOIN a5_coinvestigators ON Application.AppID = a5_coinvestigators.AppID LEFT JOIN StatusList ON Application.AppStatus = StatusList.ID
WHERE a5_CoInvestigators.StaffID = " + staffID + " AND Application.AppStatus != 0 AND Application.AppStatus != 2 AND Application.AppStatus != 5";
reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read()) //Build each row.
{
HtmlTableRow row = new HtmlTableRow();
string riskLevel = "";
//Build view button.
HtmlInputButton btnView = new HtmlInputButton();
btnView.ID = "ViewCI" + reader["AppID"].ToString();
btnView.Value = "View";
btnView.ServerClick += btnView_ServerClick;
//Determine if low or non low risk.
if (Convert.ToBoolean(reader["RiskLow_Bool"]))
riskLevel = "Low risk";
else if (Convert.ToBoolean(reader["RiskNonLow_Bool"]))
riskLevel = "Non low risk";
//If status is declined add a hyperlink to the comment.
HtmlTableCell statusCell = HTMLFactory.buildCell("200", "left", reader["AppStatus"].ToString());
if (Convert.ToInt32(reader["ID"]) == 7) //Declined.
{
statusCell.InnerText += " - ";
HyperLink hl = new HyperLink();
hl.Text = "Comment";
hl.NavigateUrl = "EthicsEditAppS7.aspx?Mode=R&AppID=" + reader["AppID"].ToString() + "&StaffID=" + staffID + "&Type=" + Context.Request["Type"];
statusCell.Controls.Add(hl);
}
row.Cells.Add(HTMLFactory.buildCell("50", "left", reader["AppID"].ToString()));
row.Cells.Add(HTMLFactory.buildCell("400", "left", reader["a1_ProjTitle"].ToString()));
row.Cells.Add(statusCell);
row.Cells.Add(HTMLFactory.buildCell("120", "left", riskLevel));
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnView));
tblCISubmitted.Rows.Add(row);
}
}
else //Display none.
{
if (tblCISubmitted.Rows.Count != 0)
{
HtmlTableRow blnkRow = new HtmlTableRow();
HtmlTableCell blnk = new HtmlTableCell();
blnk.InnerText = "None";
blnk.ColSpan = 5;
blnkRow.Cells.Add(blnk);
tblCISubmitted.Rows.Add(blnkRow);
}
}
reader.Dispose(); //Cleanup.
command.Dispose();
mySqlConnection.Close();
}
//Build the PI unsubmitted table.
private void buildPIUnsubmittedTbl(MySqlConnection mySqlConnection)
{
if (tblPIUnsubmitted.Rows.Count > 1)
{
for (int i = tblPIUnsubmitted.Rows.Count-1; i > 0; i--)
{
tblPIUnsubmitted.Rows.RemoveAt(i);
}
}
MySqlCommand command = mySqlConnection.CreateCommand();
int staffID = Convert.ToInt32(Context.Request["StaffID"]);
command.CommandText = @"SELECT Application.AppID, Application.a1_ProjTitle, StatusList.ID, StatusList.AppStatus, Application.Ownership_StaffID, Application.RiskLow_Bool,
Application.RiskNonLow_Bool
FROM Application LEFT JOIN StatusList ON Application.AppStatus = StatusList.ID
WHERE a4_InvestStaffID = " + staffID + " AND (Application.AppStatus = 0 OR Application.AppStatus = 2 OR Application.AppStatus = 5)";
MySqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read()) //Build each row.
{
HtmlTableRow row = new HtmlTableRow();
string riskLevel = "";
//Build buttons.
HtmlInputButton btnView = new HtmlInputButton();
btnView.ID = "ViewCI" + reader["AppID"].ToString();
btnView.Value = "View";
btnView.ServerClick += btnView_ServerClick;
HtmlInputButton btnEdit = new HtmlInputButton();
btnEdit.ID = "EditCI" + reader["AppID"].ToString();
btnEdit.Value = "Edit";
btnEdit.ServerClick += btnEdit_ServerClick;
Button btnDel = new Button(); //Need to use an ASP button to add the client side confirmation.
btnDel.ID = "DelCI" + reader["AppID"].ToString();
btnDel.Text = "Delete";
btnDel.OnClientClick = "return(beforeDelete( ))"; //Asks user if they are sure they want to delete.
btnDel.Click += btnDel_ServerClick;
//Determine if low or non low risk.
if (Convert.ToBoolean(reader["RiskLow_Bool"]))
riskLevel = "Low risk";
else if (Convert.ToBoolean(reader["RiskNonLow_Bool"]))
riskLevel = "Non low risk";
//If status is HOS declined add a hyperlink to the comment.
HtmlTableCell statusCell = HTMLFactory.buildCell("200", "left", reader["AppStatus"].ToString());
if (Convert.ToInt32(reader["ID"]) == 2 || Convert.ToInt32(reader["ID"]) == 5) //HOS declined or incomplete.
{
statusCell.InnerText += " - ";
HyperLink hl = new HyperLink();
hl.Text = "Comment";
hl.NavigateUrl = "EthicsEditAppS7.aspx?Mode=W&AppID=" + reader["AppID"].ToString() + "&StaffID=" + staffID + "&Type=" + Context.Request["Type"];
statusCell.Controls.Add(hl);
}
row.Cells.Add(HTMLFactory.buildCell("50", "left", reader["AppID"].ToString()));
row.Cells.Add(HTMLFactory.buildCell("400", "left", reader["a1_ProjTitle"].ToString()));
row.Cells.Add(statusCell);
row.Cells.Add(HTMLFactory.buildCell("120", "left", riskLevel));
//If CI has been given control, disallow editing.
if (staffID == Convert.ToInt32(reader["Ownership_StaffID"].ToString()))
{
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnEdit));
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnDel));
}
else
{
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnView));
row.Cells.Add(HTMLFactory.buildCell("97", "center", "No control"));
}
tblPIUnsubmitted.Rows.Add(row);
}
}
else //Display none.
{
if (tblPIUnsubmitted.Rows.Count != 0)
{
HtmlTableRow blnkRow = new HtmlTableRow();
HtmlTableCell blnk = new HtmlTableCell();
blnk.InnerText = "None";
blnk.ColSpan = 6;
blnkRow.Cells.Add(blnk);
tblPIUnsubmitted.Rows.Add(blnkRow);
}
}
reader.Dispose(); //Cleanup.
command.Dispose();
}
//Build the CI unsubmitted table.
private void buildCIUnsubmittedTbl(MySqlConnection mySqlConnection)
{
if (tblCIUnsubmitted.Rows.Count > 1)
{
for (int i = tblCIUnsubmitted.Rows.Count - 1; i > 0; i--)
{
tblCIUnsubmitted.Rows.RemoveAt(i);
}
}
MySqlCommand command = mySqlConnection.CreateCommand();
int staffID = Convert.ToInt32(Context.Request["StaffID"]);
command.CommandText = @"SELECT Application.AppID, Application.a1_ProjTitle, StatusList.ID, StatusList.AppStatus, Application.Ownership_StaffID, a5_coinvestigators.Declaration,
Application.RiskLow_Bool, Application.RiskNonLow_Bool
FROM Application INNER JOIN a5_coinvestigators ON Application.AppID = a5_coinvestigators.AppID LEFT JOIN
StatusList ON Application.AppStatus = StatusList.ID
WHERE a5_CoInvestigators.StaffID = " + staffID + " AND (Application.AppStatus = 0 OR Application.AppStatus = 2 OR Application.AppStatus = 5)";
MySqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read()) //Build each row.
{
HtmlTableRow row = new HtmlTableRow();
string riskLevel = "";
//Build buttons.
HtmlInputButton btnView = new HtmlInputButton();
btnView.ID = "ViewCI" + reader["AppID"].ToString();
btnView.Value = "View";
btnView.ServerClick += btnView_ServerClick;
HtmlInputButton btnDec = new HtmlInputButton();
btnDec.ID = "DecCI" + reader["AppID"].ToString();
btnDec.Value = "Declaration";
btnDec.ServerClick += btnDec_ServerClick;
HtmlInputButton btnEdit = new HtmlInputButton();
btnEdit.ID = "EditCI" + reader["AppID"].ToString();
btnEdit.Value = "Edit";
btnEdit.ServerClick += btnEdit_ServerClick;
Button btnDel = new Button(); //Need to use an ASP button to add the client side confirmation.
btnDel.ID = "DelPI" + reader["AppID"].ToString();
btnDel.Text = "Delete";
btnDel.OnClientClick = "return(beforeDelete( ))"; //Asks user if they are sure they want to delete.
btnDel.Click += btnDel_ServerClick;
//Determine if low or non low risk.
if (Convert.ToBoolean(reader["RiskLow_Bool"]))
riskLevel = "Low risk";
else if (Convert.ToBoolean(reader["RiskNonLow_Bool"]))
riskLevel = "Non low risk";
//If status is HOS declined add a hyperlink to the comment.
HtmlTableCell statusCell = HTMLFactory.buildCell("200", "left", reader["AppStatus"].ToString());
if (Convert.ToInt32(reader["ID"]) == 2 || Convert.ToInt32(reader["ID"]) == 5) //HOS declined or incomplete.
{
statusCell.InnerText += " - ";
HyperLink hl = new HyperLink();
hl.Text = "Comment";
char mode = 'R';
if (staffID == Convert.ToInt32(reader["Ownership_StaffID"].ToString())) //If CI has control, set to write access.
mode = 'W';
hl.NavigateUrl = "EthicsEditAppS7.aspx?Mode=" + mode + "&AppID=" + reader["AppID"].ToString() + "&StaffID=" + staffID + "&Type=" + Context.Request["Type"];
statusCell.Controls.Add(hl);
}
row.Cells.Add(HTMLFactory.buildCell("50", "left", reader["AppID"].ToString()));
row.Cells.Add(HTMLFactory.buildCell("400", "left", reader["a1_ProjTitle"].ToString()));
row.Cells.Add(statusCell);
row.Cells.Add(HTMLFactory.buildCell("120", "left", riskLevel));
//If CI has not made declaration, display a button.
if (Convert.ToBoolean(reader["Declaration"]) == true)
row.Cells.Add(HTMLFactory.buildCell("97", "center", "Completed"));
else
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnDec));
//If CI has been given control, allow editing.
if (staffID == Convert.ToInt32(reader["Ownership_StaffID"].ToString()))
{
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnEdit));
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnDel));
}
else
{
row.Cells.Add(HTMLFactory.buildCell("97", "center", btnView));
row.Cells.Add(HTMLFactory.buildCell("97", "center", "No control"));
}
tblCIUnsubmitted.Rows.Add(row);
}
}
else //Display none.
{
if (tblCIUnsubmitted.Rows.Count != 0)
{
HtmlTableRow blnkRow = new HtmlTableRow();
HtmlTableCell blnk = new HtmlTableCell();
blnk.InnerText = "None";
blnk.ColSpan = 7;
blnkRow.Cells.Add(blnk);
tblCIUnsubmitted.Rows.Add(blnkRow);
}
}
reader.Dispose(); //Cleanup.
command.Dispose();
}
//Inserts new application into database and redirects to first page of application.
protected void btnNew_ServerClick(object sender, EventArgs e)
{
MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new Connector().MySQLConnect();
MySqlCommand command = mySqlConnection.CreateCommand();
int staffID = Convert.ToInt32(Context.Request["StaffID"]);
command.CommandText = "INSERT INTO Application (a4_InvestStaffID, a6_ContactStaffID, Ownership_StaffID) VALUES (" + staffID + ", " + staffID + ", " + staffID + ")";
int rtn = command.ExecuteNonQuery(); //rtn indicates number of rows added (ie success or failure).
command.CommandText = "SELECT LAST_INSERT_ID()";
MySqlDataReader reader = command.ExecuteReader();
if (reader.HasRows && rtn == 1)
{
reader.Read();
Response.Redirect("EthicsEditAppTriage.aspx?Mode=W&AppID=" + reader[0] + "&StaffID=" + Context.Request["StaffID"] + "&Type=" + Context.Request["Type"]); //Load application.
}
else
divMsg.InnerText = "Error: Could not add new application to database";
command.Dispose(); //Cleanup.
mySqlConnection.Close();
}
//Extract App ID from button name and delete.
public void btnDel_ServerClick(object sender, EventArgs e)
{
Button source = (Button)sender;
MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new Connector().MySQLConnect();
MySqlCommand command = mySqlConnection.CreateCommand();
command.CommandText = "DELETE FROM Application WHERE AppID = " + source.ID.Remove(0, 5);
command.ExecuteNonQuery();
command.Dispose();
buildPIUnsubmittedTbl(mySqlConnection); //Rebuild unsubmitted tables.
buildCIUnsubmittedTbl(mySqlConnection);
mySqlConnection.Close();
}
//Button click handlers, redirect to new page.
public void btnEdit_ServerClick(object sender, EventArgs e)
{
HtmlInputButton source = (HtmlInputButton)sender;
Response.Redirect("EthicsEditAppTriage.aspx?Mode=W&AppID=" + source.ID.Remove(0,6) + "&StaffID=" + Context.Request["StaffID"] + "&Type=" + Context.Request["Type"]);
}
public void btnView_ServerClick(object sender, EventArgs e)
{
HtmlInputButton source = (HtmlInputButton)sender;
Response.Redirect("EthicsEditAppTriage.aspx?Mode=R&AppID=" + source.ID.Remove(0, 6) + "&StaffID=" + Context.Request["StaffID"] + "&Type=" + Context.Request["Type"]);
}
public void btnDec_ServerClick(object sender, EventArgs e)
{
HtmlInputButton source = (HtmlInputButton)sender;
Response.Redirect("EthicsCIDeclaration.aspx?AppID=" + source.ID.Remove(0, 5) + "&StaffID=" + Context.Request["StaffID"] + "&Type=" + Context.Request["Type"]);
}
}