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.

328 lines
14 KiB

  1. using Swift.DAL.OnlineAgent;
  2. using Swift.web.Library;
  3. using System;
  4. using System.IO;
  5. using System.Web.UI.WebControls;
  6. namespace Swift.web.AgentPanel.OnlineAgent.CustomerSetup
  7. {
  8. public partial class Manage : System.Web.UI.Page
  9. {
  10. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  11. private readonly OnlineCustomerDao _cd = new OnlineCustomerDao();
  12. private const string ViewFunctionId = "40120000";
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. _sl.CheckSession();
  16. if (!IsPostBack)
  17. {
  18. Authenticate();
  19. PopulateDdl();
  20. string eId = GetStatic.ReadQueryString("id", "");
  21. if (eId != "")
  22. {
  23. PopulateForm(eId);
  24. }
  25. }
  26. }
  27. private void PopulateForm(string eId)
  28. {
  29. var dr = _cd.GetCustomerDetails(eId, GetStatic.GetUser());
  30. if (null != dr)
  31. {
  32. hdnCustomerId.Value = dr["customerId"].ToString();
  33. firstName.Text = dr["firstName"].ToString();
  34. middleName.Text = dr["middleName"].ToString();
  35. lastName.Text = dr["lastName1"].ToString();
  36. genderList.SelectedValue = dr["gender"].ToString();
  37. countryList.Text = dr["country"].ToString();
  38. addressLine1.Text = dr["address"].ToString();
  39. postalCode.Text = dr["postalCode"].ToString();
  40. city.Text = dr["city"].ToString();
  41. email.Text = dr["email"].ToString();
  42. emailConfirm.Text = dr["email"].ToString();
  43. phoneNumber.Text = dr["telNo"].ToString();
  44. mobile.Text = dr["mobile"].ToString();
  45. nativeCountry.SelectedValue = dr["nativeCountry"].ToString();
  46. dob.Text = dr["dob"].ToString();
  47. occupation.Text = dr["occupation"].ToString();
  48. IssueDate.Text = dr["idIssueDate"].ToString();
  49. ExpireDate.Text = dr["idExpiryDate"].ToString();
  50. ddlBankName.SelectedValue = dr["bankName"].ToString();
  51. accountNumber.Text = dr["bankAccountNo"].ToString();
  52. idType.Text = dr["idType"].ToString();
  53. verificationTypeNo.Text = dr["idNumber"].ToString();
  54. hddIdNumber.Value = dr["homePhone"].ToString();
  55. //the value of homePhone is same as idNumber but for record id 1-92 homePhone is mobile number , bcoz of FolderName
  56. if (dr["verifyDoc1"].ToString() != "")
  57. verfDoc1.ImageUrl = "GetDocumentView.ashx?imageName=" + dr["verifyDoc1"] + "&idNumber=" + dr["homePhone"];
  58. if (dr["verifyDoc2"].ToString() != "")
  59. verfDoc2.ImageUrl = "GetDocumentView.ashx?imageName=" + dr["verifyDoc2"] + "&idNumber=" + dr["homePhone"];
  60. if (dr["verifyDoc3"].ToString() != "")
  61. verfDoc3.ImageUrl = "GetDocumentView.ashx?imageName=" + dr["verifyDoc3"] + "&idNumber=" + dr["homePhone"];
  62. if (dr["verifyDoc4"].ToString() != "")
  63. verfDoc4.ImageUrl = "GetDocumentView.ashx?imageName=" + dr["verifyDoc4"] + "&idNumber=" + dr["homePhone"];
  64. hdnVerifyDoc1.Value = dr["verifyDoc1"].ToString();
  65. hdnVerifyDoc2.Value = dr["verifyDoc2"].ToString();
  66. hdnVerifyDoc3.Value = dr["verifyDoc3"].ToString();
  67. hdnVerifyDoc4.Value = dr["verifyDoc4"].ToString();
  68. if (dr["idType"].ToString() == "8008")
  69. {
  70. expiryDiv.Attributes.Add("style", "display:none;");
  71. //expiryDiv.Visible = false;
  72. }
  73. else
  74. {
  75. expiryDiv.Attributes.Add("style", "display:block;");
  76. //expiryDiv.Visible = true;
  77. }
  78. //email.ReadOnly = true;
  79. //emailConfirm.ReadOnly = true;
  80. //mobile.ReadOnly = true;
  81. hddIsApproved.Value = dr["isApproved"].ToString();
  82. register.Enabled = (dr["isApproved"].ToString() == "Y") ? false : true;
  83. }
  84. }
  85. private void Authenticate()
  86. {
  87. _sl.CheckAuthentication(ViewFunctionId);
  88. }
  89. private void PopulateDdl()
  90. {
  91. _sl.SetDDL(ref genderList, "EXEC proc_online_dropDownList @flag='GenderList'", "valueId", "detailTitle", "", "Select..");
  92. _sl.SetDDL(ref countryList, "EXEC proc_online_dropDownList @flag='onlineCountrylist'", "countryId", "countryName", "", "Select..");
  93. _sl.SetDDL(ref nativeCountry, "EXEC proc_online_dropDownList @flag='allCountrylist'", "countryId", "countryName", "", "Select..");
  94. _sl.SetDDL(ref occupation, "EXEC proc_online_dropDownList @flag='occupationList'", "valueId", "detailTitle", "", "Select..");
  95. _sl.SetDDL(ref idType, "EXEC proc_online_dropDownList @flag='idType'", "valueId", "detailTitle", "", "Select..");
  96. _sl.SetDDL(ref ddlBankName, "EXEC proc_dropDownList @flag='banklist'", "value", "text", "", "Select..");
  97. }
  98. protected void register_Click(object sender, EventArgs e)
  99. {
  100. if (hddIsApproved.Value == "Y")
  101. {
  102. GetStatic.AlertMessage(this, "You cannot modify approved customer!");
  103. return;
  104. }
  105. if (string.IsNullOrWhiteSpace(hddIdNumber.Value))
  106. {
  107. hddIdNumber.Value = verificationTypeNo.Text;
  108. }
  109. if (email.Text.Equals(emailConfirm.Text))
  110. {
  111. string verDoc1 = UploadDocument(VerificationDoc1, hddIdNumber.Value, 1000);
  112. if (verDoc1 == "invalidSize")
  113. {
  114. GetStatic.AlertMessage(this, "File size exceeded for passport. Please upload image of size less than 2mb.");
  115. return;
  116. }
  117. string verDoc2 = UploadDocument(VerificationDoc2, hddIdNumber.Value, 2000);
  118. if (verDoc2 == "invalidSize")
  119. {
  120. GetStatic.AlertMessage(this, "File size exceeded for visa. Please upload image of size less than 2mb.");
  121. return;
  122. }
  123. string verDoc3 = UploadDocument(VerificationDoc3, hddIdNumber.Value, 3000);
  124. if (verDoc3 == "invalidSize")
  125. {
  126. GetStatic.AlertMessage(this, "File size exceeded for passport. Please upload image of size less than 2mb.");
  127. return;
  128. }
  129. string verDoc4 = UploadDocument(VerificationDoc4, hddIdNumber.Value, 4000);
  130. if (verDoc4 == "invalidSize")
  131. {
  132. GetStatic.AlertMessage(this, "File size exceeded for passport. Please upload image of size less than 2mb.");
  133. return;
  134. }
  135. OnlineCustomerModel customerModel = new OnlineCustomerModel()
  136. {
  137. flag = "customer-register-core"
  138. ,
  139. firstName = firstName.Text
  140. ,
  141. middleName = middleName.Text
  142. ,
  143. lastName1 = lastName.Text
  144. ,
  145. gender = genderList.SelectedValue
  146. ,
  147. country = countryList.Text
  148. ,
  149. address = addressLine1.Text
  150. ,
  151. zipCode = postalCode.Text
  152. ,
  153. city = city.Text
  154. ,
  155. email = email.Text
  156. ,
  157. homePhone = phoneNumber.Text
  158. ,
  159. mobile = mobile.Text
  160. ,
  161. nativeCountry = nativeCountry.SelectedValue
  162. ,
  163. dob = dob.Text
  164. ,
  165. occupation = occupation.Text
  166. ,
  167. postalCode = postalCode.Text
  168. ,
  169. idIssueDate = IssueDate.Text
  170. ,
  171. idExpiryDate = ExpireDate.Text
  172. ,
  173. idType = idType.Text
  174. ,
  175. idNumber = verificationTypeNo.Text
  176. ,
  177. telNo = phoneNumber.Text
  178. ,
  179. ipAddress = GetStatic.GetIp()
  180. ,
  181. createdBy = GetStatic.GetUser()
  182. ,
  183. verifyDoc1 = verDoc1
  184. ,
  185. verifyDoc2 = verDoc2
  186. ,
  187. verifyDoc3 = verDoc3
  188. ,
  189. verifyDoc4 = verDoc4
  190. ,
  191. bankId = ddlBankName.SelectedValue
  192. ,
  193. accountNumber = accountNumber.Text
  194. ,
  195. HasDeclare = (chkConfirm.Checked ? 1 : 0)
  196. };
  197. if (hdnCustomerId.Value != "")
  198. {
  199. customerModel.customerId = hdnCustomerId.Value;
  200. customerModel.flag = "customer-update-core";
  201. if (verDoc1 == "")
  202. customerModel.verifyDoc1 = hdnVerifyDoc1.Value;
  203. if (verDoc2 == "")
  204. customerModel.verifyDoc2 = hdnVerifyDoc2.Value;
  205. if (verDoc3 == "")
  206. customerModel.verifyDoc3 = hdnVerifyDoc3.Value;
  207. if (verDoc4 == "")
  208. customerModel.verifyDoc4 = hdnVerifyDoc4.Value;
  209. }
  210. var dbResult = _cd.RegisterCustomer(customerModel);
  211. if (dbResult.ErrorCode == "0")
  212. {
  213. //if (hdnCustomerId.Value != "")
  214. //{
  215. // if (!hddIdNumber.Value.Equals(verificationTypeNo.Text))
  216. // {
  217. // if (string.IsNullOrEmpty(verDoc1))
  218. // {
  219. // MoveFilesToNewFolder(hddIdNumber.Value, verificationTypeNo.Text, hdnVerifyDoc1.Value);
  220. // }
  221. // if (string.IsNullOrEmpty(verDoc2))
  222. // {
  223. // MoveFilesToNewFolder(hddIdNumber.Value, verificationTypeNo.Text, hdnVerifyDoc2.Value);
  224. // }
  225. // if (string.IsNullOrEmpty(verDoc3))
  226. // {
  227. // MoveFilesToNewFolder(hddIdNumber.Value, verificationTypeNo.Text, hdnVerifyDoc3.Value);
  228. // }
  229. // if (string.IsNullOrEmpty(verDoc4))
  230. // {
  231. // MoveFilesToNewFolder(hddIdNumber.Value, verificationTypeNo.Text, hdnVerifyDoc4.Value);
  232. // }
  233. // DeleteOldFolder(hddIdNumber.Value);
  234. // }
  235. //}
  236. GetStatic.SetMessage(dbResult);
  237. Response.Redirect("List.aspx");
  238. return;
  239. }
  240. else
  241. {
  242. GetStatic.AlertMessage(this, dbResult.Msg);
  243. return;
  244. }
  245. }
  246. }
  247. private void DeleteOldFolder(string folderName)
  248. {
  249. string dirPath = GetStatic.GetAppRoot() + "CustomerDocument\\" + folderName;
  250. if (Directory.Exists(dirPath))
  251. Directory.Delete(dirPath, true);
  252. }
  253. protected void MoveFilesToNewFolder(string oldFolderName, string newFolderName, string oldFileName)
  254. {
  255. string newFilePath = GetStatic.GetAppRoot() + "CustomerDocument\\" + newFolderName;
  256. if (!Directory.Exists(newFilePath))
  257. Directory.CreateDirectory(newFilePath);
  258. string oldFilePath = GetStatic.GetAppRoot() + "CustomerDocument\\" + oldFolderName + "\\" + oldFileName;
  259. FileInfo fileInfo = new FileInfo(oldFilePath);
  260. if (fileInfo.Exists)
  261. File.Move(oldFilePath, newFilePath + "/" + oldFileName);
  262. }
  263. private string UploadDocument(FileUpload doc, string customerId, int prefixNum)
  264. {
  265. var maxFileSize = GetStatic.ReadWebConfig("csvFileSize", "2097152");
  266. string fName = "";
  267. try
  268. {
  269. var fileType = doc.PostedFile.ContentType;
  270. if (fileType == "image/jpeg" || fileType == "image/png" || fileType == "application/pdf")
  271. {
  272. if (doc.PostedFile.ContentLength > Convert.ToDouble(maxFileSize))
  273. {
  274. fName = "invalidSize";
  275. }
  276. else
  277. {
  278. string extension = Path.GetExtension(doc.PostedFile.FileName);
  279. string fileName = customerId + "_" + prefixNum.ToString() + extension;
  280. string path = GetStatic.GetAppRoot() + "CustomerDocument\\" + customerId;
  281. if (!Directory.Exists(path))
  282. Directory.CreateDirectory(path);
  283. doc.SaveAs(path + "/" + fileName);
  284. fName = fileName;
  285. }
  286. }
  287. else
  288. {
  289. fName = "";
  290. }
  291. }
  292. catch (Exception ex)
  293. {
  294. fName = "";
  295. }
  296. return fName;
  297. }
  298. public static string GetTimestamp(DateTime value)
  299. {
  300. var timeValue = value.ToString("hhmmssffffff");
  301. return timeValue + DateTime.Now.Ticks;
  302. }
  303. }
  304. }