PageRenderTime 75ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/UserRolesInfo.aspx.cs

https://github.com/sirivedula/BEST
C# | 166 lines | 152 code | 13 blank | 1 comment | 23 complexity | ec82d286b76c13944a9202596f011afb MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Xml.Linq;
  13. using BaliEnterpriseSystems.BestObjects;
  14. using System.Collections.Generic;
  15. using System.Data.OleDb;
  16. using System.Text;
  17. namespace BaliEnterpriseSystems
  18. {
  19. public partial class UserRolesInfo : System.Web.UI.Page
  20. {
  21. protected void Page_LoadComplete(object sender, EventArgs e)
  22. {
  23. if (HttpContext.Current.Session["CurrentUser"] == null)
  24. {
  25. Response.Redirect("Logout.aspx");
  26. }
  27. string ms = Request.QueryString["ms"];
  28. ltrMScript.Text = Utils.MenuSelectScript(ms);
  29. ltrSubMenu.Text = UtilMenu.SetupSubMenu("userroles");
  30. if (!Utils.User.UserRoleByName("Setup - User Roles").allowView)
  31. {
  32. ltrGrid.Text = "You do not have rights to view.";
  33. return;
  34. }
  35. string username = Request.Form["userName"];
  36. if (!string.IsNullOrEmpty(username))
  37. {
  38. UserRoles uroles = new UserRoles();
  39. string insSQL = "insert into bestuserroles (service, username) (select bserv.service, ? from bestservices bserv left join bestuserroles bur on bur.service=bserv.service and bur.username = ? where bur.Service is null)";
  40. OleDbCommand myCmd = uroles.dbCmd;
  41. OleDbParameter p1 = new OleDbParameter("username0", OleDbType.VarChar, 200);
  42. p1.Value = username;
  43. OleDbParameter p2 = new OleDbParameter("username1", OleDbType.VarChar, 200);
  44. p2.Value = username;
  45. myCmd.Parameters.Add(p1);
  46. myCmd.Parameters.Add(p2);
  47. myCmd.CommandText = insSQL;
  48. try
  49. {
  50. myCmd.ExecuteNonQuery();
  51. }
  52. catch { }
  53. string saveclicked = Request.Form["saveClicked"];
  54. bool canSave = (IsPostBack && ((!string.IsNullOrEmpty(saveclicked)) && saveclicked.Equals("1,")));
  55. List<BestField> bparams = new List<BestField>();
  56. BestField paramUName = new BestField() { fieldName = "username", fieldSize = 80, fieldType = "System.String", paramOledbType = System.Data.OleDb.OleDbType.VarChar, displayField = false };
  57. paramUName.fieldValue = username;
  58. bparams.Add(paramUName);
  59. uroles.LoadRows("username = ?", bparams, "service");
  60. StringBuilder sbg = new StringBuilder();
  61. sbg.Append("<table style=\"width:100%;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"bestgrid\"><tr><th>Service Name</th><th>Allow View</th><th>Allow Add</th><th>Allow Edit</th><th>Allow Delete</th></tr>");
  62. for (int rnum = 0; rnum < uroles.TableRows.Count; rnum++)
  63. {
  64. string srclass = " class=" + ((rnum % 2 == 0) ? "\"grideven\"" : "\"gridodd\"");
  65. sbg.Append("<tr" + srclass + ">");
  66. sbg.Append("<td>" + HttpUtility.HtmlEncode(uroles.TableRows[rnum].Fields["Service"].fieldValue) + "</td>");
  67. BestRow curRow = uroles.TableRows[rnum];
  68. if (canSave)
  69. {
  70. string allowview = Request.Form["view_" + rnum.ToString()];
  71. string allowadd = Request.Form["add_" + rnum.ToString()];
  72. string allowedit = Request.Form["edit_" + rnum.ToString()];
  73. string allowdel = Request.Form["delete_" + rnum.ToString()];
  74. if ((!string.IsNullOrEmpty(allowadd)) && allowadd.Equals("on"))
  75. {
  76. curRow.Fields["allowAdd"].fieldValue = "1";
  77. }
  78. else
  79. {
  80. curRow.Fields["allowAdd"].fieldValue = "0";
  81. }
  82. if ((!string.IsNullOrEmpty(allowdel)) && allowdel.Equals("on"))
  83. {
  84. curRow.Fields["allowDelete"].fieldValue = "1";
  85. }
  86. else
  87. {
  88. curRow.Fields["allowDelete"].fieldValue = "0";
  89. }
  90. if ((!string.IsNullOrEmpty(allowedit)) && allowedit.Equals("on"))
  91. {
  92. curRow.Fields["allowEdit"].fieldValue = "1";
  93. }
  94. else
  95. {
  96. curRow.Fields["allowEdit"].fieldValue = "0";
  97. }
  98. if ((!string.IsNullOrEmpty(allowview)) && allowview.Equals("on"))
  99. {
  100. curRow.Fields["allowView"].fieldValue = "1";
  101. }
  102. else
  103. {
  104. curRow.Fields["allowView"].fieldValue = "0";
  105. }
  106. curRow.Save();
  107. }
  108. bool allowAdd = curRow.Fields["allowAdd"].fieldValue.Equals("1");
  109. bool allowView = curRow.Fields["allowView"].fieldValue.Equals("1");
  110. bool allowEdit = curRow.Fields["allowEdit"].fieldValue.Equals("1");
  111. bool allowDelete = curRow.Fields["allowDelete"].fieldValue.Equals("1");
  112. string rowguid = curRow.Fields["guidfield"].fieldValue;
  113. sbg.Append("<input type=\"hidden\" id=\"guid_" + rnum.ToString() + "\" value=\"" + rowguid + "\" />");
  114. sbg.Append("<td class=\"ca\"><input type=\"checkbox\" id=\"view_" + rnum.ToString() + "\" name=\"view_" + rnum.ToString() + "\" ");
  115. if (allowView) { sbg.Append(" checked=\"checked\" "); }
  116. sbg.Append(" /></td>");
  117. sbg.Append("<td class=\"ca\"><input type=\"checkbox\" id=\"add_" + rnum.ToString() + "\" name=\"add_" + rnum.ToString() + "\" ");
  118. if (allowAdd) { sbg.Append(" checked=\"checked\" "); }
  119. sbg.Append(" /></td>");
  120. sbg.Append("<td class=\"ca\"><input type=\"checkbox\" id=\"edit_" + rnum.ToString() + "\" name=\"edit_" + rnum.ToString() + "\" ");
  121. if (allowEdit) { sbg.Append(" checked=\"checked\" "); }
  122. sbg.Append(" /></td>");
  123. sbg.Append("<td class=\"ca\"><input type=\"checkbox\" id=\"delete_" + rnum.ToString() + "\" name=\"delete_" + rnum.ToString() + "\" ");
  124. if (allowDelete) { sbg.Append(" checked=\"checked\" "); }
  125. sbg.Append(" /></td>");
  126. }
  127. /* TODO:User Rights */
  128. sbg.Append("<tr><td colspan=\"5\"><input type=\"button\" id=\"btnSave\" name=\"btnSave\" onclick=\"doSave();\" value=\"Save\" /></td></tr>");
  129. sbg.Append("</table>");
  130. ltrGrid.Text = sbg.ToString();
  131. }
  132. else
  133. {
  134. ltrGrid.Text = "<div style=\"height:200px;\"></div>";
  135. }
  136. BestUser buser = new BestUser();
  137. buser.LoadRows("usertype not in ('Student', 'Tutor')", null);
  138. StringBuilder sb = new StringBuilder();
  139. sb.Append("<option value=\"\"></option>");
  140. for (int rownum = 0; rownum < buser.TableRows.Count; rownum++)
  141. {
  142. string uname = buser.TableRows[rownum].Fields["userName"].fieldValue;
  143. sb.Append("<option value=\"" + HttpUtility.HtmlEncode(uname) + "\" ");
  144. if (uname.Equals(username))
  145. {
  146. sb.Append(" selected=\"selected\" ");
  147. }
  148. sb.Append(">" + HttpUtility.HtmlEncode(uname) + "</option>");
  149. }
  150. ltrSelectUser.Text = sb.ToString();
  151. }
  152. }
  153. }