You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.0 KiB

  1. using Swift.DAL.Remittance.CashAndVault;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Web.Script.Serialization;
  7. namespace Swift.web.Remit.CashAndVault
  8. {
  9. public partial class ManageBranchWise : System.Web.UI.Page
  10. {
  11. protected const string GridName = "cashAndVault";
  12. private string ViewFunctionId = "20178000";
  13. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  14. private CashAndVaultDao cavDao = new CashAndVaultDao();
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. Authenticate();
  18. string reqMethod = Request.Form["MethodName"];
  19. if (String.IsNullOrEmpty(reqMethod))
  20. {
  21. Misc.MakeNumericTextbox(ref cashHoldLimit);
  22. Misc.MakeNumericTextbox(ref perTopUpLimit);
  23. }
  24. switch (reqMethod)
  25. {
  26. case "PopulateBranchAndAgents":
  27. PopulateBranchAndAgents();
  28. break;
  29. case "PopulateForm":
  30. PopulateForm();
  31. break;
  32. case "SaveCashAndVault":
  33. Save_Click();
  34. break;
  35. }
  36. if (!IsPostBack)
  37. {
  38. GetStatic.PrintMessage(Page);
  39. }
  40. }
  41. protected string GetRuleId()
  42. {
  43. return GetStatic.ReadQueryString("cashHoldLimitId", "");
  44. }
  45. protected string GetAgentId()
  46. {
  47. return GetStatic.ReadQueryString("agentId", "");
  48. }
  49. private void PopulateBranchAndAgents()
  50. {
  51. string flag = Request.Form["Flag"];
  52. var dt = cavDao.PopulateDdl(GetStatic.GetUser(), flag);
  53. if (dt == null)
  54. {
  55. Response.Write("");
  56. Response.End();
  57. return;
  58. }
  59. Response.ContentType = "text/plain";
  60. string json = DataTableToJson(dt);
  61. Response.Write(json);
  62. Response.End();
  63. }
  64. public static string DataTableToJson(DataTable table)
  65. {
  66. if (table == null)
  67. return "";
  68. var list = new List<Dictionary<string, object>>();
  69. foreach (DataRow row in table.Rows)
  70. {
  71. var dict = new Dictionary<string, object>();
  72. foreach (DataColumn col in table.Columns)
  73. {
  74. dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col];
  75. }
  76. list.Add(dict);
  77. }
  78. var serializer = new JavaScriptSerializer();
  79. string json = serializer.Serialize(list);
  80. return json;
  81. }
  82. private void Authenticate()
  83. {
  84. _sl.CheckAuthentication(ViewFunctionId);
  85. }
  86. private void PopulateForm()
  87. {
  88. string eId = Request.Form["RuleId"];
  89. string agentId = Request.Form["AgentId"];
  90. var dr = cavDao.GetCashAndVaultDetails(eId, GetStatic.GetUser(), agentId);
  91. Response.ContentType = "text/plain";
  92. string json = DataTableToJson(dr);
  93. Response.Write(json);
  94. Response.End();
  95. }
  96. protected void Save_Click()
  97. {
  98. var agentId = Request.Form["ddlAgentBranch"];
  99. var cashLimit = Request.Form["cashHoldLimit"];
  100. var perTopUpLimitVal = Request.Form["perTopUpLimit"];
  101. var ruleType = Request.Form["ddlruleType"];
  102. var ruleId = Request.Form["ruleId"];
  103. var res = cavDao.SaveCashAndVault(GetStatic.GetUser(), agentId, cashLimit, perTopUpLimitVal, ruleType, ruleId);
  104. if (res == null)
  105. {
  106. Response.Write("");
  107. Response.End();
  108. return;
  109. }
  110. Response.ContentType = "text/plain";
  111. string json = DataTableToJson(res);
  112. Response.Write(json);
  113. Response.End();
  114. }
  115. }
  116. }