PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/TutorNotes.aspx.cs

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