PageRenderTime 34ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/SaveSTPlan.aspx.cs

https://github.com/sirivedula/BEST
C# | 104 lines | 96 code | 8 blank | 0 comment | 18 complexity | bbb02867d30d74f25fdc8ed9328bf262 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. namespace BaliEnterpriseSystems
  9. {
  10. public partial class SaveSTPlan : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. }
  15. protected void Page_LoadComplete(object sender, EventArgs e)
  16. {
  17. if (HttpContext.Current.Session["CurrentUser"] == null)
  18. {
  19. Response.Redirect("Logout.aspx");
  20. }
  21. string schType = Request.Form["schType"];
  22. string schGuid = Request.Form["guidfield"];
  23. if (!string.IsNullOrEmpty(schType))
  24. {
  25. string tutGuid = Request.Form["tutGuid"];
  26. string stuGuid = Request.Form["stuGuid"];
  27. string schDay = Request.Form["schDay"];
  28. string schFrom = Request.Form["schFrom"];
  29. string schTo = Request.Form["schTo"];
  30. string isdelete = Request.Form["isDel"];
  31. BestSTPlan bstp = new BestSTPlan();
  32. if (Utils.IsGuid(schGuid))
  33. {
  34. if (schType.Equals("Student") && !(Utils.User.UserRoleByName("Student - Planner").allowEdit))
  35. {
  36. Response.Write("{result:false,Message:'You do not have rights to edit.'}");
  37. return;
  38. }
  39. if (schType.Equals("Tutor") && !(Utils.User.UserRoleByName("Tutor - Planner").allowEdit))
  40. {
  41. Response.Write("{result:false,Message:'You do not have rights to edit.'}");
  42. return;
  43. }
  44. List<BestField> bparams = new List<BestField>();
  45. BestField guid = new BestField() { fieldName = "guidfield", fieldSize = 40, fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, displayField = false };
  46. guid.fieldValue = schGuid;
  47. bparams.Add(guid);
  48. bstp.LoadRows("guidfield = ?", bparams);
  49. if (bstp.TableRows.Count > 0)
  50. {
  51. bstp.schDay = schDay;
  52. bstp.schFrom = schFrom;
  53. bstp.schTo = schTo;
  54. bstp.CenterId = Utils.User.CenterId;
  55. if (Utils.IsGuid(tutGuid))
  56. bstp.tutorguid= new Guid(tutGuid);
  57. if (Utils.IsGuid(stuGuid))
  58. bstp.studentGuid = new Guid(stuGuid);
  59. bstp.CurrentRow.Save();
  60. }
  61. }
  62. else
  63. {
  64. if (schType.Equals("Student") && !(Utils.User.UserRoleByName("Student - Planner").allowAdd))
  65. {
  66. Response.Write("{result:false,Message:'You do not have rights to edit.'}");
  67. return;
  68. }
  69. if (schType.Equals("Tutor") && !(Utils.User.UserRoleByName("Tutor - Planner").allowAdd))
  70. {
  71. Response.Write("{result:false,Message:'You do not have rights to edit.'}");
  72. return;
  73. }
  74. bstp.guidfield = Guid.NewGuid();
  75. bstp.schDay = schDay;
  76. bstp.schFrom = schFrom;
  77. bstp.schTo = schTo;
  78. bstp.CenterId = Utils.User.CenterId;
  79. if (Utils.IsGuid(tutGuid))
  80. bstp.tutorguid = new Guid(tutGuid);
  81. if (Utils.IsGuid(stuGuid))
  82. bstp.studentGuid = new Guid(stuGuid);
  83. }
  84. bstp.isDeleted = isdelete;
  85. if (bstp.CurrentRow.Save())
  86. {
  87. Response.Write("{result:true,guid:'" + bstp.CurrentRow.Fields["guidfield"].fieldValue + "'}");
  88. }
  89. else
  90. {
  91. Response.Write("{result:false,Message:'" + Utils.EnquoteJS(bstp.CurrentRow.lastError) + "'}");
  92. }
  93. }
  94. }
  95. }
  96. }