PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/StudentNotes.aspx.cs

https://github.com/sirivedula/BEST
C# | 132 lines | 123 code | 8 blank | 1 comment | 16 complexity | 464143984634e3108627e9b9963ec5ab 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.Text;
  16. namespace BaliEnterpriseSystems
  17. {
  18. public partial class StudentNotes : System.Web.UI.Page
  19. {
  20. protected void Page_LoadComplete(object sender, EventArgs e)
  21. {
  22. if (HttpContext.Current.Session["CurrentUser"] == null)
  23. {
  24. Response.Redirect("Logout.aspx");
  25. }
  26. ltrSubMenu.Text = UtilMenu.StudentMenu("studentnotes");
  27. if (!Utils.User.UserRoleByName("Student - Notes").allowView)
  28. {
  29. ltrGrid.Text = "You do not have rights to view.";
  30. return;
  31. }
  32. string ms = Request.QueryString["ms"];
  33. this.ltrMScript.Text = Utils.MenuSelectScript(ms);
  34. string saveClicked = Request.Form["SaveClicked"] ?? "";
  35. if (IsPostBack && saveClicked.Equals("1"))
  36. {
  37. BestStudentNotes bs = new BestStudentNotes();
  38. string isnew = Request.Form["isnew"];
  39. bool cansave = true;
  40. if (string.IsNullOrEmpty(isnew))
  41. {
  42. List<BestField> bparams = new List<BestField>();
  43. BestField guid = new BestField() { fieldName = "guidfield", fieldSize = 40, fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, displayField = false };
  44. guid.fieldValue = Request.Form["guidfield"];
  45. bparams.Add(guid);
  46. if (!string.IsNullOrEmpty(guid.fieldValue))
  47. {
  48. bs.LoadRows("guidfield=?", bparams);
  49. }
  50. else
  51. {
  52. string delguid = Request.Form["deleteguid"];
  53. if (!string.IsNullOrEmpty(delguid))
  54. {
  55. bparams[0].fieldValue = delguid;
  56. bs.LoadRows("guidfield=?", bparams);
  57. bs.CurrentRow.IsDelete = true;
  58. bs.CurrentRow.Save();
  59. }
  60. cansave = false;
  61. }
  62. }
  63. if (cansave)
  64. {
  65. if (!string.IsNullOrEmpty(isnew)) {
  66. string guid = Request.Form["g_studentGuid"];
  67. if (string.IsNullOrEmpty(guid))
  68. {
  69. ltrValidateMsg.Text = Utils.WarningMessage("Student Name is Required.");
  70. cansave = false;
  71. }
  72. bs.studentGuid = new Guid(guid);
  73. BestStudents bestStd = new BestStudents();
  74. bestStd.LoadRows("guidfield=?", "studentguid", bs.studentGuid, "");
  75. bs.StudentId = bestStd.StudentId;
  76. }
  77. if (cansave)
  78. {
  79. string notedate = Request.Form["g_noteDate"];
  80. if (!string.IsNullOrEmpty(notedate))
  81. {
  82. bs.noteDate = Convert.ToDateTime(notedate);
  83. }
  84. bs.notes = Request.Form["g_notes"];
  85. bs.CenterId = Utils.User.CenterId;
  86. if (!bs.CurrentRow.Save())
  87. {
  88. ltrValidateMsg.Text = Utils.WarningMessage(bs.CurrentRow.lastError);
  89. }
  90. }
  91. }
  92. }
  93. /* Auto Student */
  94. string autoSample = "{value:\"[paramValue]\", label:[paramLabel]}";
  95. StringBuilder sb = new StringBuilder();
  96. sb.AppendLine("autoStudents = [");
  97. BestStudents bstd = new BestStudents();
  98. bstd.LoadRows("CenterId=?", Utils.User.CIdParam);
  99. for (int s = 0; s < bstd.TableRows.Count; s++)
  100. {
  101. string result = autoSample;
  102. result = result.Replace("[paramValue]", bstd.TableRows[s].Fields["guidfield"].fieldValue);
  103. result = result.Replace("[paramLabel]", Utils.EnquoteJS((bstd.TableRows[s].Fields["firstName"].fieldValue ?? "") + " " +
  104. (bstd.TableRows[s].Fields["lastName"].fieldValue ?? "")));
  105. sb.Append(result);
  106. if (s < bstd.TableRows.Count - 1) sb.AppendLine(",");
  107. }
  108. sb.AppendLine("];");
  109. ltrScript.Text = @"<script type=""text/javascript"">
  110. $(document).ready(function(){ " + sb.ToString() + @"
  111. $('#studentTag1').autocomplete( { source:autoStudents, delay: 0, select : function( event, ui){
  112. $('#studentGuid').val( ui.item.value );
  113. $( this ).val( ui.item.label );
  114. return false;
  115. } } ); }); </script>";
  116. BestGrid bsGrid = new BestGrid();
  117. bsGrid.PageRequest = Page.Request;
  118. bsGrid.Title = "Student Notes";
  119. bsGrid.GridTable = new BestStudentNotes();
  120. bsGrid.securityPage = "Student - Notes";
  121. ltrGrid.Text = bsGrid.ToHTML();
  122. }
  123. }
  124. }