PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/SaveSchedule.aspx.cs

https://github.com/sirivedula/BEST
C# | 229 lines | 200 code | 27 blank | 2 comment | 39 complexity | ce476de21abc357a233792e54c3ecd63 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.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using BaliEnterpriseSystems.BestObjects;
  14. using System.Collections.Generic;
  15. namespace BaliEnterpriseSystems
  16. {
  17. public partial class SaveSchedule : System.Web.UI.Page
  18. {
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. }
  22. protected void Page_LoadComplete(object sender, EventArgs e)
  23. {
  24. if (HttpContext.Current.Session["CurrentUser"] == null)
  25. {
  26. Response.Redirect("Logout.aspx");
  27. }
  28. string tutGuid = Request.Form["tutGuid"];
  29. string stuGuid1 = Request.Form["stuGuid1"];
  30. string stuGuid2 = Request.Form["stuGuid2"];
  31. string stuGuid3 = Request.Form["stuGuid3"];
  32. string stuGuid4 = Request.Form["stuGuid4"];
  33. string stuGuid5 = Request.Form["stuGuid5"];
  34. string schGuid = Request.Form["schGuid"];
  35. string schDate = Request.Form["schDate"];
  36. string schFrom = Request.Form["schFrom"];
  37. string schTo = Request.Form["schTo"];
  38. string isdelete = Request.Form["isDel"];
  39. string attend1 = Request.Form["attend0"];
  40. string attend2 = Request.Form["attend1"];
  41. string attend3 = Request.Form["attend2"];
  42. string attend4 = Request.Form["attend3"];
  43. string attend5 = Request.Form["attend4"];
  44. string note1 = Request.Form["note0"];
  45. string note2 = Request.Form["note1"];
  46. string note3 = Request.Form["note2"];
  47. string note4 = Request.Form["note3"];
  48. string note5 = Request.Form["note4"];
  49. string progGuid1 = Request.Form["progGuid1"];
  50. string progGuid2 = Request.Form["progGuid2"];
  51. string progGuid3 = Request.Form["progGuid3"];
  52. string progGuid4 = Request.Form["progGuid4"];
  53. string progGuid5 = Request.Form["progGuid5"];
  54. string tutorattend = Request.Form["tutorattend"];
  55. BestSchedules bsch = new BestSchedules();
  56. if (Utils.IsGuid(schGuid))
  57. {
  58. /* Update */
  59. if (!(Utils.User.UserRoleByName("5.Schedules").allowEdit))
  60. {
  61. Response.Write("{result:false,Message:'You do not have rights to edit.'}");
  62. return;
  63. }
  64. List<BestField> bparams = new List<BestField>();
  65. BestField guid = new BestField() { fieldName = "guidfield", fieldSize = 40, fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, displayField = false };
  66. guid.fieldValue = schGuid;
  67. bparams.Add(guid);
  68. bsch.LoadRows("guidfield = ?", bparams);
  69. if (bsch.TableRows.Count > 0)
  70. {
  71. bsch.schDate = schDate;
  72. bsch.schFrom = schFrom;
  73. bsch.schTo = schTo;
  74. if(! string.IsNullOrEmpty(isdelete))
  75. bsch.isDeleted = isdelete;
  76. }
  77. }
  78. else
  79. {
  80. /* Add New */
  81. if (!(Utils.User.UserRoleByName("5.Schedules").allowAdd))
  82. {
  83. Response.Write("{result:false,Message:'You do not have rights to add.'}");
  84. return;
  85. }
  86. bsch.guidfield = Guid.NewGuid();
  87. bsch.schDate = schDate;
  88. bsch.schFrom = schFrom;
  89. bsch.schTo = schTo;
  90. }
  91. if (Utils.IsGuid(tutGuid))
  92. bsch.tutGuid = new Guid(tutGuid);
  93. bsch.stuGuid1 = new Guid(stuGuid1);
  94. if (Utils.IsGuid(stuGuid2))
  95. bsch.stuGuid2 = new Guid(stuGuid2);
  96. else
  97. bsch.stuGuid2 = null;
  98. if (Utils.IsGuid(stuGuid3))
  99. bsch.stuGuid3 = new Guid(stuGuid3);
  100. else
  101. bsch.stuGuid3 = null;
  102. if (Utils.IsGuid(stuGuid4))
  103. bsch.stuGuid4 = new Guid(stuGuid4);
  104. else
  105. bsch.stuGuid4 = null;
  106. if (Utils.IsGuid(stuGuid5))
  107. bsch.stuGuid5 = new Guid(stuGuid5);
  108. else
  109. bsch.stuGuid5 = null;
  110. bsch.isDeleted = isdelete;
  111. bsch.attended1 = attend1;
  112. if (!string.IsNullOrEmpty(attend2))
  113. bsch.attended2 = attend2;
  114. if (!string.IsNullOrEmpty(attend3))
  115. bsch.attended3 = attend3;
  116. if (!string.IsNullOrEmpty(attend4))
  117. bsch.attended4 = attend4;
  118. if (!string.IsNullOrEmpty(attend5))
  119. bsch.attended5 = attend5;
  120. if (!string.IsNullOrEmpty(note1))
  121. bsch.note1 = note1;
  122. if (!string.IsNullOrEmpty(note2))
  123. bsch.note2 = note2;
  124. if (!string.IsNullOrEmpty(note3))
  125. bsch.note3 = note3;
  126. if (!string.IsNullOrEmpty(note4))
  127. bsch.note4 = note4;
  128. if (!string.IsNullOrEmpty(note5))
  129. bsch.note5 = note5;
  130. if (!string.IsNullOrEmpty(progGuid1))
  131. bsch.progGuid1 = new Guid(progGuid1);
  132. else
  133. bsch.progGuid1 = null;
  134. if (!string.IsNullOrEmpty(progGuid2))
  135. bsch.progGuid2 = new Guid(progGuid2);
  136. else
  137. bsch.progGuid2 = null;
  138. if (!string.IsNullOrEmpty(progGuid3))
  139. bsch.progGuid3 = new Guid(progGuid3);
  140. else
  141. bsch.progGuid3 = null;
  142. if (!string.IsNullOrEmpty(progGuid4))
  143. bsch.progGuid4 = new Guid(progGuid4);
  144. else
  145. bsch.progGuid4 = null;
  146. if (!string.IsNullOrEmpty(progGuid5))
  147. bsch.progGuid5 = new Guid(progGuid5);
  148. else
  149. bsch.progGuid5 = null;
  150. if (!string.IsNullOrEmpty(tutorattend))
  151. bsch.tutorattend = tutorattend;
  152. if (!string.IsNullOrEmpty(stuGuid1) && !string.IsNullOrEmpty(progGuid1))
  153. bsch.Amount1 = getProgramAmount(bsch.stuGuid1, bsch.progGuid1);
  154. else
  155. bsch.Amount1 = 0;
  156. if (!string.IsNullOrEmpty(stuGuid2) && !string.IsNullOrEmpty(progGuid2))
  157. bsch.Amount2 = getProgramAmount(bsch.stuGuid2, bsch.progGuid2);
  158. else
  159. bsch.Amount2 = 0;
  160. if (!string.IsNullOrEmpty(stuGuid3) && !string.IsNullOrEmpty(progGuid3))
  161. bsch.Amount3 = getProgramAmount(bsch.stuGuid3, bsch.progGuid3);
  162. else
  163. bsch.Amount3 = 0;
  164. if (!string.IsNullOrEmpty(stuGuid4) && !string.IsNullOrEmpty(progGuid4))
  165. bsch.Amount4 = getProgramAmount(bsch.stuGuid4, bsch.progGuid4);
  166. else
  167. bsch.Amount4 = 0;
  168. if (!string.IsNullOrEmpty(stuGuid5) && !string.IsNullOrEmpty(progGuid5))
  169. bsch.Amount5 = getProgramAmount(bsch.stuGuid5, bsch.progGuid5);
  170. else
  171. bsch.Amount5 = 0;
  172. bsch.CenterId = Utils.User.CenterId;
  173. if (bsch.CurrentRow.Save())
  174. {
  175. Response.Write("{result:true,guid:'" + bsch.CurrentRow.Fields["guidfield"].fieldValue + "'}");
  176. }
  177. else
  178. {
  179. Response.Write("{result:false,Message:'" + Utils.EnquoteJS( bsch.CurrentRow.lastError )+ "'}");
  180. }
  181. }
  182. private Decimal getProgramAmount(Guid? stuguid, Guid? progGuid)
  183. {
  184. Decimal result = 0;
  185. BestField p1 = new BestField() { fieldName = "studentguid", fieldType = "System.Guid", fieldSize = 40, paramOledbType = System.Data.OleDb.OleDbType.Guid };
  186. p1.fieldValue = stuguid.ToString();
  187. BestField p2 = new BestField() { fieldName = "guidfield", fieldType = "System.Guid", fieldSize = 40, paramOledbType = System.Data.OleDb.OleDbType.Guid };
  188. p2.fieldValue = progGuid.ToString();
  189. List<BestField> bparams = new List<BestField>();
  190. bparams.Add(p1);
  191. bparams.Add(p2);
  192. BestStudentPrograms bstdProgs = new BestStudentPrograms();
  193. bstdProgs.LoadRows("studentguid=? and guidfield=?", bparams);
  194. if (bstdProgs.HasRows)
  195. {
  196. bstdProgs.currentRowId = 0;
  197. result = bstdProgs.Amount;
  198. }
  199. return result;
  200. }
  201. }
  202. }