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

/BaliEnterpriseSystems/BaliEnterpriseSystems/PaymentsInfo.aspx.cs

https://github.com/sirivedula/BEST
C# | 153 lines | 143 code | 9 blank | 1 comment | 17 complexity | 098bb93e687daa847a7f1318694ca7df 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 System.Collections.Generic;
  14. using BaliEnterpriseSystems.BestObjects;
  15. using System.Text;
  16. namespace BaliEnterpriseSystems
  17. {
  18. public partial class PaymentsInfo : 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.PaymentMenu("paymentdetails");
  27. if (!Utils.User.UserRoleByName("Payment - Details").allowView)
  28. {
  29. ltrGrid.Text = "You do not have rights to view.";
  30. return;
  31. }
  32. string ms = Request.QueryString["ms"];
  33. ltrMScript.Text = Utils.MenuSelectScript(ms);
  34. string saveClicked = Request.Form["SaveClicked"] ?? "";
  35. if (IsPostBack && saveClicked.Equals("1"))
  36. {
  37. PaymentDetails bs = new PaymentDetails();
  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. string stdguid = Request.Form["g_studentGuid"];
  66. string payguid = Request.Form["g_paymentTypeGuid"];
  67. string amt = Request.Form["g_amount"];
  68. string paydate = Request.Form["g_paymentDate"];
  69. string hours = Request.Form["g_hours"];
  70. if (string.IsNullOrEmpty(payguid))
  71. {
  72. ltrValidateMsg.Text = Utils.WarningMessage("Payment Type is Required.");
  73. cansave = false;
  74. }
  75. if (string.IsNullOrEmpty(stdguid))
  76. {
  77. ltrValidateMsg.Text = Utils.WarningMessage("Student is Required.");
  78. cansave = false;
  79. }
  80. if (string.IsNullOrEmpty(paydate))
  81. {
  82. ltrValidateMsg.Text = Utils.WarningMessage("Payment Date is Required.");
  83. cansave = false;
  84. }
  85. if (cansave)
  86. {
  87. bs.studentGuid = new Guid(stdguid);
  88. bs.paymentTypeGuid = new Guid(payguid);
  89. bs.amount = amt;
  90. Decimal dhours;
  91. Decimal.TryParse(hours, out dhours);
  92. bs.hours = dhours;
  93. bs.paymentDate = Convert.ToDateTime(paydate);
  94. bs.CenterId = Utils.User.CenterId;
  95. if (!bs.CurrentRow.Save())
  96. {
  97. ltrValidateMsg.Text = Utils.WarningMessage(bs.CurrentRow.lastError);
  98. }
  99. }
  100. }
  101. }
  102. PaymentTypes bpayTypes = new PaymentTypes();
  103. bpayTypes.LoadRows();
  104. StringBuilder sbc = new StringBuilder();
  105. sbc.Append("<option value=\"\"></option>");
  106. for (int rnum = 0; rnum < bpayTypes.TableRows.Count; rnum++)
  107. {
  108. string paytype = bpayTypes.TableRows[rnum].Fields["paymentType"].fieldValue;
  109. string guid = bpayTypes.TableRows[rnum].Fields["guidfield"].fieldValue;
  110. sbc.Append("<option value=\"" + HttpUtility.HtmlEncode(guid) + "\">" + HttpUtility.HtmlEncode(paytype) + "</option>");
  111. }
  112. ltrPayTypes.Text = sbc.ToString();
  113. /* Auto Student */
  114. string autoSample = "{value:\"[paramValue]\", label:[paramLabel]}";
  115. StringBuilder sb = new StringBuilder();
  116. sb.AppendLine("autoStudents = [");
  117. BestStudents bstd = new BestStudents();
  118. bstd.LoadRows("CenterId=?", Utils.User.CIdParam);
  119. for (int s = 0; s < bstd.TableRows.Count; s++)
  120. {
  121. string result = autoSample;
  122. result = result.Replace("[paramValue]", bstd.TableRows[s].Fields["guidfield"].fieldValue);
  123. result = result.Replace("[paramLabel]", Utils.EnquoteJS((bstd.TableRows[s].Fields["firstName"].fieldValue ?? "") + " " +
  124. (bstd.TableRows[s].Fields["lastName"].fieldValue ?? "")));
  125. sb.Append(result);
  126. if (s < bstd.TableRows.Count - 1) sb.AppendLine(",");
  127. }
  128. sb.AppendLine("];");
  129. ltrScript.Text = @"<script type=""text/javascript"">
  130. $(document).ready(function(){ " + sb.ToString() + @"
  131. $('#studentTag1').autocomplete( { source:autoStudents, delay: 0, select : function( event, ui){
  132. $('#studentGuid').val( ui.item.value );
  133. $( this ).val( ui.item.label );
  134. return false;
  135. } } ); }); </script>";
  136. BestGrid bsGrid = new BestGrid();
  137. bsGrid.PageRequest = Page.Request;
  138. bsGrid.Title = "Payment Details";
  139. bsGrid.GridTable = new PaymentDetails();
  140. bsGrid.securityPage = "Payment - Details";
  141. ltrGrid.Text = bsGrid.ToHTML();
  142. }
  143. }
  144. }