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.

199 lines
8.0 KiB

  1. using Swift.DAL.Remittance.Transaction;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. namespace Swift.web.Responsive.Send.SendMoneyv2
  10. {
  11. public partial class Calculator : System.Web.UI.Page
  12. {
  13. private TranCalculator st = new TranCalculator();
  14. readonly StaticDataDdl _sdd = new StaticDataDdl();
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if (!IsPostBack)
  18. {
  19. populateCollCurr();
  20. PopulateDdl();
  21. //Misc.MakeNumericTextbox(ref txtCollAmt);
  22. Misc.MakeNumericTextbox(ref txtPayAmt);
  23. }
  24. }
  25. private void populateCollCurr()
  26. {
  27. string currencyCode = st.GetCollCurrency(GetStatic.GetUser(), GetStatic.GetCountryId());
  28. lblCollCurr.Text = currencyCode;
  29. lblSendCurr.Text = currencyCode;
  30. lblServiceChargeCurr.Text = currencyCode;
  31. }
  32. private string GetCountry()
  33. {
  34. return GetStatic.ReadQueryString("pCountry", "");
  35. }
  36. private string GetMode()
  37. {
  38. return GetStatic.ReadQueryString("pMode", "");
  39. }
  40. private string GetAgent()
  41. {
  42. return GetStatic.ReadQueryString("pAgent", "");
  43. }
  44. private void PopulateDdl()
  45. {
  46. LoadRecCountry(ref pCountry, GetCountry(), "Select");
  47. LoadReceivingMode(GetMode());
  48. LoadReceivingAgent(GetAgent());
  49. }
  50. private void LoadRecCountry(ref DropDownList ddl, string defaultValue, string label)
  51. {
  52. var sql = "EXEC proc_sendPageLoadData @flag='pCountry', @countryId='" + GetStatic.GetCountryId() + "', @agentid='" + GetStatic.GetAgentId() + "'";
  53. _sdd.SetDDL(ref ddl, sql, "countryId", "countryName", defaultValue, label);
  54. }
  55. protected void Calculate()
  56. {
  57. string pAgentFv = Request.Form["pAgent"];
  58. var calculateBy = "";
  59. if (txtPayAmt.Enabled)
  60. calculateBy = "pAmt";
  61. else if (txtCollAmt.Enabled)
  62. calculateBy = "cAmt";
  63. string currencyCode = st.GetCollCurrency(GetStatic.GetUser(), GetStatic.GetCountryId());
  64. var dt = st.GetExRate(GetStatic.GetUser(),GetStatic.GetSuperAgent(), GetStatic.GetCountryId(), GetStatic.GetAgent(), GetStatic.GetBranch(),
  65. currencyCode, pCountry.Text, pAgentFv, "", pMode.Text, txtCollAmt.Text, txtPayAmt.Text, calculateBy);
  66. var dr = dt.Rows[0];
  67. lblPayCurr.Text = "";
  68. lblSendAmt.Text = "0.00";
  69. lblServiceChargeAmt.Text = "0.00";
  70. lblExRate.Text = "0.00";
  71. if (dr["ErrCode"].ToString() == "1")
  72. {
  73. GetStatic.AlertMessage(Page, dr["Msg"].ToString());
  74. return;
  75. }
  76. txtCollAmt.Text = dr["CollAmt"].ToString();
  77. //txtCollAmt.Text = txtCollAmt.Text.Substring(0, txtCollAmt.Text.Length - cDecimal);
  78. txtPayAmt.Text = dr["pAmt"].ToString();
  79. txtPayAmt.Text = txtPayAmt.Text.Substring(0, txtPayAmt.Text.Length - 2);
  80. lblPayCurr.Text = dr["pCurr"].ToString();
  81. lblExCurr.Text = dr["pCurr"].ToString();
  82. lblSendAmt.Text = dr["sAmt"].ToString();
  83. lblServiceChargeAmt.Text = GetStatic.ShowDecimal(dr["scCharge"].ToString());
  84. lblExRate.Text = dr["exRate"].ToString();
  85. }
  86. protected void pCountry_SelectedIndexChanged(object sender, EventArgs e)
  87. {
  88. if (string.IsNullOrWhiteSpace(pCountry.Text))
  89. {
  90. pMode.Items.Clear();
  91. return;
  92. }
  93. var sql = "EXEC proc_sendPageLoadData @flag ='recModeByCountry'";
  94. sql += ", @countryId = " + _sdd.FilterString(GetStatic.GetCountryId());
  95. sql += ", @pCountryId = " + _sdd.FilterString(pCountry.Text);
  96. sql += ", @param = " + _sdd.FilterString("");
  97. sql += ", @agentId = " + _sdd.FilterString(GetStatic.GetAgentId());
  98. sql += ", @user = " + _sdd.FilterString(GetStatic.GetUser());
  99. _sdd.SetDDL(ref pMode, sql, "serviceTypeId", "typeTitle", "", "Select");
  100. }
  101. protected void pMode_SelectedIndexChanged(object sender, EventArgs e)
  102. {
  103. if (string.IsNullOrWhiteSpace(pMode.Text))
  104. {
  105. pAgent.Items.Clear();
  106. return;
  107. }
  108. string pCountry = Request.Form["pCountry"];
  109. var sql = "EXEC proc_sendPageLoadData @flag ='recAgentByRecModeAjaxagent'";
  110. sql += ", @countryId = " + _sdd.FilterString(GetStatic.GetCountryId());
  111. sql += ", @pCountryId = " + _sdd.FilterString(pCountry);
  112. sql += ", @param = " + _sdd.FilterString(pMode.SelectedItem.Text);
  113. sql += ", @agentId = " + _sdd.FilterString(GetStatic.GetAgentId());
  114. sql += ", @user = " + _sdd.FilterString(GetStatic.GetUser());
  115. _sdd.SetDDL(ref pAgent, sql, "AGENTID", "AGENTNAME", "", "");
  116. }
  117. private void LoadReceivingMode(string p_Mode)
  118. {
  119. var sql = "EXEC proc_sendPageLoadData @flag ='recModeByCountry'";
  120. sql += ", @countryId = " + _sdd.FilterString(GetStatic.GetCountryId());
  121. sql += ", @pCountryId = " + _sdd.FilterString(pCountry.Text);
  122. sql += ", @param = " + _sdd.FilterString("");
  123. sql += ", @agentId = " + _sdd.FilterString(GetStatic.GetAgentId());
  124. sql += ", @user = " + _sdd.FilterString(GetStatic.GetUser());
  125. _sdd.SetDDL(ref pMode, sql, "serviceTypeId", "typeTitle", p_Mode, "Select");
  126. }
  127. private void LoadReceivingAgent(string p_agent)
  128. {
  129. var sql = "EXEC proc_sendPageLoadData @flag ='recAgentByRecModeAjaxagent'";
  130. sql += ", @countryId = " + _sdd.FilterString(GetStatic.GetCountryId());
  131. sql += ", @pCountryId = " + _sdd.FilterString(pCountry.Text);
  132. sql += ", @param = " + _sdd.FilterString(pMode.SelectedItem.Text);
  133. sql += ", @agentId = " + _sdd.FilterString(GetStatic.GetAgentId());
  134. sql += ", @user = " + _sdd.FilterString(GetStatic.GetUser());
  135. _sdd.SetDDL(ref pAgent, sql, "AGENTID", "AGENTNAME", p_agent, "");
  136. }
  137. protected void btnCalculate_Click(object sender, EventArgs e)
  138. {
  139. lblErr.Text = "";
  140. if (byPayOutAmt.Checked && txtPayAmt.Text == "")
  141. {
  142. GetStatic.AlertMessage(Page, "Please, Enter the Payout Amount !");
  143. lblErr.Text = "Please, Enter the Payout Amount !";
  144. return;
  145. }
  146. if (bySendAmt.Checked && txtCollAmt.Text == "")
  147. {
  148. GetStatic.AlertMessage(Page, "Please, Enter the Collection Amount !");
  149. lblErr.Text = "Please, Enter the Collection Amount !";
  150. return;
  151. }
  152. if (!string.IsNullOrWhiteSpace(txtCollAmt.Text) && Convert.ToDouble(txtCollAmt.Text) > 0)
  153. Calculate();
  154. else if (!string.IsNullOrWhiteSpace(txtPayAmt.Text) && Convert.ToDouble(txtPayAmt.Text) > 0)
  155. Calculate();
  156. else
  157. {
  158. lblPayCurr.Text = "0.00";
  159. lblSendAmt.Text = "0.00";
  160. lblServiceChargeAmt.Text = "0.00";
  161. lblExRate.Text = "0.00";
  162. GetStatic.AlertMessage(Page, "Need Collection Amount or Payout Amount For Calculation");
  163. }
  164. }
  165. protected void bySendAmt_CheckedChanged(object sender, EventArgs e)
  166. {
  167. txtCollAmt.Enabled = true;
  168. txtPayAmt.Enabled = false;
  169. txtPayAmt.Text = "";
  170. }
  171. protected void byPayOutAmt_CheckedChanged(object sender, EventArgs e)
  172. {
  173. txtCollAmt.Enabled = false;
  174. txtPayAmt.Enabled = true;
  175. txtCollAmt.Text = "";
  176. }
  177. }
  178. }