PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/StudentDocuments.aspx.cs

https://github.com/sirivedula/BEST
C# | 141 lines | 129 code | 11 blank | 1 comment | 17 complexity | f4b0276bdc365e131b75c6d15ceebd56 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using BaliEnterpriseSystems.BestObjects;
  8. using System.Text;
  9. namespace BaliEnterpriseSystems
  10. {
  11. public partial class StudentDocuments : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. }
  16. protected void Page_LoadComplete(object sender, EventArgs e)
  17. {
  18. if (HttpContext.Current.Session["CurrentUser"] == null)
  19. {
  20. Response.Redirect("Logout.aspx");
  21. }
  22. ltrSubMenu.Text = UtilMenu.StudentMenu("studentdocument");
  23. if (!Utils.User.UserRoleByName("Student - Documents").allowView)
  24. {
  25. ltrGrid.Text = "You do not have rights to view.";
  26. return;
  27. }
  28. string ms = Request.QueryString["ms"];
  29. this.ltrMScript.Text = Utils.MenuSelectScript(ms);
  30. string saveClicked = Request.Form["SaveClicked"] ?? "";
  31. if (IsPostBack && saveClicked.Equals("1"))
  32. {
  33. BestDocuments bs = new BestDocuments();
  34. string isnew = Request.Form["isnew"];
  35. bool cansave = true;
  36. if (string.IsNullOrEmpty(isnew))
  37. {
  38. List<BestField> bparams = new List<BestField>();
  39. BestField guid = new BestField() { fieldName = "guidfield", fieldSize = 40, fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, displayField = false };
  40. guid.fieldValue = Request.Form["guidfield"];
  41. bparams.Add(guid);
  42. if (!string.IsNullOrEmpty(guid.fieldValue))
  43. {
  44. bs.LoadRows("guidfield=?", bparams);
  45. }
  46. else
  47. {
  48. string delguid = Request.Form["deleteguid"];
  49. if (!string.IsNullOrEmpty(delguid))
  50. {
  51. bparams[0].fieldValue = delguid;
  52. bs.LoadRows("guidfield=?", bparams);
  53. bs.CurrentRow.IsDelete = true;
  54. bs.CurrentRow.Save();
  55. }
  56. cansave = false;
  57. }
  58. }
  59. if (cansave)
  60. {
  61. if (!string.IsNullOrEmpty(isnew))
  62. {
  63. string guid = Request.Form["g_studentGuid"];
  64. if (string.IsNullOrEmpty(guid))
  65. {
  66. ltrValidateMsg.Text = Utils.WarningMessage("Student Name is Required.");
  67. cansave = false;
  68. }
  69. bs.studentGuid = new Guid(guid);
  70. }
  71. if (cansave)
  72. {
  73. bool showToStudent = (Request.Form["g_showToStudent"] ?? "").ToLower().Equals("true");
  74. bs.showToStudent = showToStudent;
  75. string docdate = Request.Form["g_documentDate"];
  76. if (!string.IsNullOrEmpty(docdate))
  77. {
  78. bs.documentDate = Convert.ToDateTime(docdate);
  79. }
  80. bs.documentTitle = Request.Form["g_documentTitle"];
  81. string expdate = Request.Form["g_documentExpiry"];
  82. if (!string.IsNullOrEmpty(expdate))
  83. {
  84. bs.documentExpiry = Convert.ToDateTime(expdate);
  85. }
  86. bs.CenterId = Utils.User.CenterId;
  87. BestStudents bestStd = new BestStudents();
  88. bestStd.LoadRows("guidfield=?", "studentguid", bs.studentGuid, "");
  89. bs.StudentId = bestStd.StudentId;
  90. if (!bs.CurrentRow.Save())
  91. {
  92. ltrValidateMsg.Text = Utils.WarningMessage(bs.CurrentRow.lastError);
  93. }
  94. }
  95. }
  96. }
  97. /* Auto Student */
  98. string autoSample = "{value:\"[paramValue]\", label:[paramLabel]}";
  99. StringBuilder sb = new StringBuilder();
  100. sb.AppendLine("autoStudents = [");
  101. BestStudents bstd = new BestStudents();
  102. bstd.LoadRows("CenterId=?", Utils.User.CIdParam);
  103. for (int s = 0; s < bstd.TableRows.Count; s++)
  104. {
  105. string result = autoSample;
  106. result = result.Replace("[paramValue]", bstd.TableRows[s].Fields["guidfield"].fieldValue);
  107. result = result.Replace("[paramLabel]", Utils.EnquoteJS((bstd.TableRows[s].Fields["firstName"].fieldValue ?? "") + " " +
  108. (bstd.TableRows[s].Fields["lastName"].fieldValue ?? "")));
  109. sb.Append(result);
  110. if (s < bstd.TableRows.Count - 1) sb.AppendLine(",");
  111. }
  112. sb.AppendLine("];");
  113. ltrScript.Text = @"<script type=""text/javascript"">
  114. $(document).ready(function(){ " + sb.ToString() + @"
  115. $('#studentTag1').autocomplete( { source:autoStudents, delay: 0, select : function( event, ui){
  116. $('#studentGuid').val( ui.item.value );
  117. $( this ).val( ui.item.label );
  118. return false;
  119. } } ); }); </script>";
  120. BestGrid bsGrid = new BestGrid();
  121. bsGrid.PageRequest = Page.Request;
  122. bsGrid.Title = "Student Documents";
  123. bsGrid.securityPage = "Student - Documents";
  124. bsGrid.GridTable = new BestDocuments();
  125. bsGrid.extraRowHTML = "<span><a href=\"javascript:void(0);\" onclick=\"showUploadDocument('[paramCID]','[paramSID]','[paramGuid]', [paramRowNum]);\" title=\"Upload Document\" ><img src=\"images\\folder_page.png\" alt=\"upload\" /></a></span><span><a href=\"javascript:void(0);\" onclick=\"DownloadDocument('[paramGuid]','[paramCID]','[paramSID]');\" title=\"Download Document\"><img src=\"images\\page_white_put.png\" alt=\"upload\" /></a></span>";
  126. bsGrid.whereClause = "";
  127. ltrGrid.Text = bsGrid.ToHTML();
  128. }
  129. }
  130. }