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.

238 lines
8.7 KiB

  1. using Swift.DAL.OnlineAgent;
  2. using Swift.DAL.SwiftDAL;
  3. using Swift.web.Library;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Script.Serialization;
  11. using System.Web.UI;
  12. using System.Web.UI.WebControls;
  13. namespace Swift.web.AgentPanel.OnlineAgent.CustomerControls
  14. {
  15. public partial class ModifyBank : System.Web.UI.Page
  16. {
  17. private readonly StaticDataDdl _sdd = new StaticDataDdl();
  18. private readonly OnlineCustomerDao _cd = new OnlineCustomerDao();
  19. private const string ViewFunctionIdAdmin = "20111700";
  20. private const string ViewFunctionIdAgent = "40120200";
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. Authenticate();
  24. if (!IsPostBack)
  25. {
  26. PopulateDDL();
  27. acNameInBank.Attributes.Add("readonly", "readonly");
  28. }
  29. }
  30. private void Authenticate()
  31. {
  32. if (GetStatic.GetUserType() == "HO")
  33. {
  34. _sdd.CheckAuthentication(ViewFunctionIdAdmin);
  35. }
  36. else
  37. {
  38. _sdd.CheckAuthentication(ViewFunctionIdAgent);
  39. }
  40. }
  41. protected void PopulateDDL()
  42. {
  43. _sdd.SetDDL(ref newBank, "EXEC proc_customerBankModify @flag='DDL'", "bankCode", "BankName", "", "Select..");
  44. }
  45. protected void searchButton_Click(object sender, EventArgs e)
  46. {
  47. DataRow _dr = null;
  48. if (!string.IsNullOrEmpty(searchValue.Text))
  49. {
  50. _dr = _cd.GetCustomerDetailForBankUpdate(searchBy.SelectedValue, GetStatic.GetUser(), searchValue.Text);
  51. }
  52. if (_dr != null)
  53. {
  54. if (_dr["errorCode"].ToString() == "0")
  55. {
  56. hideDivSearch.Visible = true;
  57. hiddenDivCheck.Visible = false;
  58. hddCustomerId.Value = _dr["customerId"].ToString();
  59. fullName.Text = _dr["fullName"].ToString();
  60. oldAccNumber.Text = _dr["bankAccountNo"].ToString();
  61. alienNationId.Text = _dr["idNumber"].ToString();
  62. oldBank.Text = _dr["BankName"].ToString();
  63. hddHomePhone.Value = _dr["homePhone"].ToString();
  64. hddImageName.Value = _dr["verifyDoc3"].ToString();
  65. if (_dr["verifyDoc3"].ToString() != "")
  66. verfDoc3.ImageUrl = "/AgentPanel/OnlineAgent/CustomerSetup/GetDocumentView.ashx?imageName=" + _dr["verifyDoc3"] + "&idNumber=" + _dr["homePhone"];
  67. }
  68. else
  69. {
  70. hiddenDivCheck.Visible = false;
  71. hideDivSearch.Visible = false;
  72. GetStatic.AlertMessage(this, _dr["msg"].ToString());
  73. }
  74. }
  75. else
  76. {
  77. hiddenDivCheck.Visible = false;
  78. hideDivSearch.Visible = false;
  79. GetStatic.AlertMessage(this, "No data Found!");
  80. }
  81. }
  82. protected void checkBtn_Click(object sender, EventArgs e)
  83. {
  84. if (!string.IsNullOrEmpty(newAccountNumber.Text) && !string.IsNullOrEmpty(newBank.SelectedValue))
  85. {
  86. var response = KJBankAPIConnection.GetAccountDetailKJBank(newAccountNumber.Text, newBank.SelectedValue);
  87. if (response.ErrorCode == "0")
  88. {
  89. hiddenDivCheck.Visible = true;
  90. acNameInBank.Text = response.Msg;
  91. }
  92. else
  93. {
  94. hiddenDivCheck.Visible = false;
  95. GetStatic.AlertMessage(this, "Bank Account Number is wrong, you can not modify the bank details!");
  96. }
  97. }
  98. else
  99. {
  100. GetStatic.AlertMessage(this, "Please input all data first!");
  101. }
  102. }
  103. protected void Modify_Click(object sender, EventArgs e)
  104. {
  105. if (!string.IsNullOrEmpty(hddCustomerId.Value) || !string.IsNullOrWhiteSpace(acNameInBank.Text))
  106. {
  107. string verDoc4 = UploadDocument(VerificationDoc3, hddHomePhone.Value, 4000);
  108. if (verDoc4 == "invalidSize")
  109. {
  110. GetStatic.AlertMessage(this, "File size exceeded for Passbook. Please upload image of size less than 2mb.");
  111. return;
  112. }
  113. DbResult _dbRes = new DbResult();
  114. _dbRes = _cd.UpdateCustomerBankDetail(GetStatic.GetUser(), hddCustomerId.Value, newBank.SelectedValue, newAccountNumber.Text, acNameInBank.Text, verDoc4);
  115. if (_dbRes.ErrorCode != "0")
  116. {
  117. hiddenDivCheck.Visible = false;
  118. hideDivSearch.Visible = false;
  119. searchValue.Text = "";
  120. GetStatic.AlertMessage(this, _dbRes.Msg);
  121. return;
  122. }
  123. //push to kj bank
  124. var dr = _cd.GetCustomerForModification(GetStatic.GetUser(), hddCustomerId.Value);
  125. var obj = new PartnerServiceModificationRequest()
  126. {
  127. processDivision = "02",
  128. institution = dr["bankCode"].ToString(),
  129. depositor = dr["CustomerBankName"].ToString(),
  130. no = dr["bankAccountNo"].ToString(),
  131. virtualAccountNo = dr["walletAccountNo"].ToString(),
  132. obpId = dr["obpId"].ToString()
  133. };
  134. obj.depositor = acNameInBank.Text;
  135. _dbRes = SendNotificationToKjBank(obj);
  136. if (!string.IsNullOrWhiteSpace(_dbRes.Id))
  137. {
  138. ManageSaved();
  139. GetStatic.AlertMessage(Page, "Customer Detail updated");
  140. }
  141. else
  142. {
  143. GetStatic.AlertMessage(Page, "Customer detail not pushed to KJ Bank, please contact HO!");
  144. }
  145. }
  146. else
  147. {
  148. GetStatic.AlertMessage(Page, "Invalid account details, you can not modify this customer!");
  149. hiddenDivCheck.Visible = false;
  150. hideDivSearch.Visible = false;
  151. searchValue.Text = "";
  152. }
  153. }
  154. private void ManageSaved()
  155. {
  156. searchBy.SelectedValue = "idNumber";
  157. searchValue.Text = "";
  158. fullName.Text = "";
  159. alienNationId.Text = "";
  160. oldBank.Text = "";
  161. oldAccNumber.Text = "";
  162. newBank.SelectedValue = "";
  163. newAccountNumber.Text = "";
  164. acNameInBank.Text = "";
  165. verfDoc3.ImageUrl = "";
  166. hiddenDivCheck.Visible = false;
  167. hideDivSearch.Visible = false;
  168. }
  169. private string UploadDocument(FileUpload doc, string customerId, int prefixNum)
  170. {
  171. var maxFileSize = GetStatic.ReadWebConfig("csvFileSize", "2097152");
  172. string fName = "";
  173. try
  174. {
  175. var fileType = doc.PostedFile.ContentType;
  176. if (fileType == "image/jpeg" || fileType == "image/png" || fileType == "application/pdf")
  177. {
  178. if (doc.PostedFile.ContentLength > Convert.ToDouble(maxFileSize))
  179. {
  180. fName = "invalidSize";
  181. }
  182. else
  183. {
  184. string extension = Path.GetExtension(doc.PostedFile.FileName);
  185. string fileName = customerId + "_" + GetTimestamp(DateTime.Now) + prefixNum.ToString() + extension;
  186. string path = GetStatic.GetAppRoot() + "CustomerDocument\\" + customerId;
  187. if (!Directory.Exists(path))
  188. Directory.CreateDirectory(path);
  189. doc.SaveAs(path + "/" + fileName);
  190. fName = fileName;
  191. }
  192. }
  193. else
  194. {
  195. fName = "";
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. fName = "";
  201. }
  202. return fName;
  203. }
  204. public static string GetTimestamp(DateTime value)
  205. {
  206. var timeValue = value.ToString("hhmmssffffff");
  207. return timeValue + DateTime.Now.Ticks;
  208. }
  209. private DbResult SendNotificationToKjBank(PartnerServiceModificationRequest obj)
  210. {
  211. string body = new JavaScriptSerializer().Serialize((obj));
  212. var resp = KJBankAPIConnection.PostToKJBank(body);
  213. return resp;
  214. }
  215. }
  216. }