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.

516 lines
24 KiB

  1. using Newtonsoft.Json;
  2. using Swift.DAL.OnlineAgent;
  3. using Swift.DAL.SwiftDAL;
  4. using Swift.web.Library;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Web;
  12. using System.Web.Script.Serialization;
  13. using System.Web.UI;
  14. using System.Web.UI.WebControls;
  15. namespace Swift.web.AgentNew.Transaction.ApproveCustomerFromAgent
  16. {
  17. public partial class EditCustomer : System.Web.UI.Page
  18. {
  19. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  20. private readonly OnlineCustomerDao _cd = new OnlineCustomerDao();
  21. private readonly StaticDataDdl _sdd = new StaticDataDdl();
  22. private const string ViewFunctionIdFromMobile = "20450000";
  23. private const string AddFunctionIdFromMobile = "20450030";
  24. private const string SaveEditIdFromMobile = "20203000";
  25. private const string SignatureFunctionIdFromMobile = "20450040";
  26. private const string ViewFunctionIdFromAgent = "20400000";
  27. private const string AddFunctionIdFromAgent = "20400030";
  28. private const string SaveEditIdFromAgent = "20400020";
  29. private const string SignatureFunctionIdFromAgent = "20400040";
  30. private bool isEdit = Convert.ToBoolean(GetStatic.ReadQueryString("edit", "false"));
  31. protected void Page_Load(object sender, EventArgs e)
  32. {
  33. Authenticate();
  34. signatureDiv.Visible = !CheckAddOrEdit() && _sl.HasRight(SignatureFunctionIdFromAgent);
  35. isDisplaySignature.Value = !CheckAddOrEdit() && _sl.HasRight(GetFunctionIdByUserType(ViewFunctionIdFromAgent, ViewFunctionIdFromMobile)) ? "true" : "false";
  36. GetStatic.PrintMessage(Page);
  37. displayOnlyOnEdit.Visible = CheckAddOrEdit();
  38. addEditPanel.Attributes.Add("style", "display:" + (CheckAddOrEdit() ? "none" : ""));
  39. displayCounterVisit.Visible = !CheckAddOrEdit();
  40. var MethodName = Request.Form["MethodName"];
  41. if (!IsPostBack)
  42. {
  43. PopulateDdl();
  44. if (MethodName == "GetAddressDetailsByZipCode")
  45. {
  46. GetAddressDetailsByZipCode();
  47. }
  48. if (MethodName == "GetCustomerDetails")
  49. {
  50. GetCustomerDetails();
  51. }
  52. if (MethodName == "GetImageUrl")
  53. {
  54. GetImageUrl();
  55. }
  56. if (MethodName == "GetSignature")
  57. {
  58. GetSignature();
  59. }
  60. }
  61. }
  62. protected string GetCustomerId()
  63. {
  64. return GetStatic.ReadQueryString("customerId", "");
  65. }
  66. protected string GetRequestFrom()
  67. {
  68. return GetStatic.ReadQueryString("requestFrom", "");
  69. }
  70. private void Authenticate()
  71. {
  72. if (CheckAddOrEdit())
  73. _sl.CheckAuthentication(GetFunctionIdByUserType(SaveEditIdFromAgent, SaveEditIdFromMobile));
  74. else
  75. _sl.CheckAuthentication(GetFunctionIdByUserType(AddFunctionIdFromAgent, AddFunctionIdFromMobile));
  76. string eId = GetStatic.ReadQueryString("customerId", "");
  77. var hasRight = false;
  78. if (eId == "")
  79. {
  80. hasRight = _sl.HasRight(GetFunctionIdByUserType(AddFunctionIdFromAgent, AddFunctionIdFromMobile));
  81. }
  82. else
  83. {
  84. hasRight = _sl.HasRight(GetFunctionIdByUserType(SaveEditIdFromAgent, SaveEditIdFromMobile));
  85. }
  86. }
  87. private bool CheckAddOrEdit()
  88. {
  89. if (isEdit)
  90. {
  91. customerType.Attributes.Add("hidden", "hidden");
  92. }
  93. else
  94. {
  95. customerType.Attributes.Remove("hidden");
  96. }
  97. return isEdit;
  98. }
  99. public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin)
  100. {
  101. return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent;
  102. }
  103. private void GetAddressDetailsByZipCode()
  104. {
  105. string zipCode = Request.Form["zipCode"];
  106. string rowID = Request.Form["RowID"];
  107. string customerId = GetCustomerId();
  108. var dr = _cd.GetAddressByZipCodeNew(zipCode, GetStatic.GetUser(), rowID, customerId);
  109. //CustomerAddress _cAddress = new CustomerAddress();
  110. //if (dr != null)
  111. //{
  112. // _cAddress.errrorCode = dr["errorCode"].ToString();
  113. // _cAddress.msg = dr["msg"].ToString();
  114. // if (dr["errorCode"].ToString() == "0")
  115. // {
  116. // _cAddress.State = dr["STATE_ID"].ToString();
  117. // _cAddress.City = dr["CITY_NAME"].ToString();
  118. // _cAddress.Street = dr["STREET_NAME"].ToString();
  119. // }
  120. //}
  121. var json = GetStatic.DataTableToJson(dr);
  122. GetStatic.JsonResponse(json, this);
  123. }
  124. private void GetCustomerDetails()
  125. {
  126. string eId = Request.Form["Id"];
  127. var dt = _cd.GetDetailsForEditCustomer(eId, GetStatic.GetUser());
  128. //hdnDocument.Value = populateDocument();
  129. Response.ContentType = "text/plain";
  130. var json = DataTableToJson(dt);
  131. Response.Write(json);
  132. Response.End();
  133. }
  134. public static string DataTableToJson(DataTable table)
  135. {
  136. if (table == null)
  137. return "";
  138. var list = new List<Dictionary<string, object>>();
  139. foreach (DataRow row in table.Rows)
  140. {
  141. var dict = new Dictionary<string, object>();
  142. foreach (DataColumn col in table.Columns)
  143. {
  144. dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col];
  145. }
  146. list.Add(dict);
  147. }
  148. var serializer = new JavaScriptSerializer();
  149. string json = serializer.Serialize(list);
  150. return json;
  151. }
  152. private void PopulateDdl()
  153. {
  154. _sl.SetDDL(ref genderList, "EXEC proc_online_dropDownList @flag='GenderList',@user='" + GetStatic.GetUser() + "'", "valueId", "detailTitle", "", "Select..");
  155. _sl.SetDDL(ref countryList, "EXEC proc_online_dropDownList @flag='onlineCountrylist',@user='" + GetStatic.GetUser() + "'", "countryId", "countryName", "", "");
  156. _sl.SetDDL(ref nativeCountry, "EXEC proc_online_dropDownList @flag='allCountrylist',@user='" + GetStatic.GetUser() + "'", "countryId", "countryName", "", "Select..");
  157. _sl.SetDDL(ref occupation, "EXEC proc_online_dropDownList @flag='occupationList',@user='" + GetStatic.GetUser() + "'", "valueId", "detailTitle", "", "Select..");
  158. _sl.SetDDL(ref idType, "EXEC proc_online_dropDownList @flag='IdTypeWithDetails',@user='" + GetStatic.GetUser() + "',@countryId='" + countryList.SelectedValue + "'", "valueId", "detailTitle", "", "Select..");
  159. _sl.SetDDL(ref ddlCustomerType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=4700", "valueId", "detailTitle", ddlCustomerType.SelectedValue, "");
  160. _sl.SetDDL(ref ddlOrganizationType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7002", "valueId", "detailTitle", "", "Select..");
  161. _sl.SetDDL(ref ddlnatureOfCompany, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7003", "valueId", "detailTitle", "", "Select..");
  162. //_sl.SetDDL(ref ddSourceOfFound, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=3900", "valueId", "detailTitle", "", "Select..");
  163. _sl.SetDDL(ref ddlEmployeeBusType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7004", "valueId", "detailTitle", "", "");
  164. // _sl.SetDDL(ref ddlVisaStatus, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7005", "valueId", "detailTitle", "", "Select..");
  165. _sl.SetDDL(ref ddlPosition, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7006", "valueId", "detailTitle", "", "Select..");
  166. //_sl.SetDDL(ref ddlState, "EXEC proc_online_dropDownList @flag='state',@countryId='" + countryList.SelectedValue + "'", "stateId", "stateName", "", "Select..");
  167. _sdd.SetDDL(ref ddlSearchBy, "exec proc_sendPageLoadData @flag='search-cust-by'", "VALUE", "TEXT", "", "");
  168. _sdd.SetStaticDdl(ref ddlDocType, "7009", "", "Select");
  169. }
  170. protected void register_Click(object sender, EventArgs e)
  171. {
  172. string eId = GetStatic.ReadQueryString("customerId", "");
  173. if (eId == "")
  174. {
  175. if (!_sl.HasRight(GetFunctionIdByUserType(AddFunctionIdFromAgent, AddFunctionIdFromMobile)))
  176. {
  177. GetStatic.AlertMessage(this, "You are not authorized to Add Customer!");
  178. return;
  179. }
  180. }
  181. else
  182. {
  183. if (!_sl.HasRight(GetFunctionIdByUserType(SaveEditIdFromAgent, SaveEditIdFromMobile)))
  184. {
  185. GetStatic.AlertMessage(this, "You are not authorized to Edit Customer!");
  186. return;
  187. }
  188. }
  189. if (hddTxnsMade.Value == "Y" && (!email.Text.Equals(hddOldEmailValue.Value.ToString())))
  190. {
  191. GetStatic.AlertMessage(this, "You can not change the email of customer who have already done transaction!");
  192. return;
  193. }
  194. //if (_sl.HasRight(SignatureFunctionIdFromAgent) && !isEdit && (string.IsNullOrEmpty(customerPassword.Text) || string.IsNullOrWhiteSpace(customerPassword.Text)) && (string.IsNullOrEmpty(hddImgURL.Value) || string.IsNullOrWhiteSpace(hddImgURL.Value)))
  195. //{
  196. // GetStatic.AlertMessage(this, "Customer signature or customer password is required!");
  197. // return;
  198. //}
  199. //if (_sl.HasRight(SignatureFunctionIdFromMobile) && !isEdit && (string.IsNullOrEmpty(customerPassword.Text) || string.IsNullOrWhiteSpace(customerPassword.Text)) && (string.IsNullOrEmpty(hddImgURL.Value) || string.IsNullOrWhiteSpace(hddImgURL.Value)))
  200. //{
  201. // GetStatic.AlertMessage(this, "Customer signature or customer password is required!");
  202. // return;
  203. //}
  204. string trimmedfirstName = firstName.Text.Trim() == "" ? null : firstName.Text.Trim();
  205. string trimmedMiddleName = middleName.Text.Trim() == "" ? null : middleName.Text.Trim();
  206. string trimmedlastName = lastName.Text.Trim() == "" ? null : lastName.Text.Trim();
  207. string area = Request.Form["ctl00$ContentPlaceHolder1$txtStreet"];
  208. OnlineCustomerModel customerModel = new OnlineCustomerModel()
  209. {
  210. flag = "customer-register-core",
  211. firstName = trimmedfirstName,
  212. middleName = trimmedMiddleName,
  213. lastName1 = trimmedlastName,
  214. gender = genderList.SelectedValue,
  215. customerType = ddlCustomerType.SelectedValue,
  216. country = countryList.Text,
  217. address = address1.Text,
  218. zipCode = zipCode.Text,
  219. street = Request.Form["ctl00$ContentPlaceHolder1$txtStreet"],
  220. AdditionalAddress = txtAdditionalAddress.Text,
  221. city = cityHidden.Value,
  222. state = ddlStateHidden.Value,
  223. //senderCityjapan = txtsenderCityjapan.Text,
  224. email = email.Text,
  225. //streetJapanese = txtstreetJapanese.Text,
  226. homePhone = phoneNumber.Text,
  227. mobile = mobile.Text,
  228. //visaStatus = ddlVisaStatus.SelectedValue,
  229. employeeBusinessType = ddlEmployeeBusType.SelectedValue,
  230. nativeCountry = nativeCountry.SelectedValue,
  231. dob = dob.Text,
  232. //sourceOfFound = ddSourceOfFound.SelectedValue,
  233. occupation = occupation.Text,
  234. telNo = phoneNumber.Text,
  235. ipAddress = GetStatic.GetIp(),
  236. createdBy = GetStatic.GetUser(),
  237. idNumber = verificationTypeNo.Text,
  238. idIssueDate = IssueDate.Text,
  239. idExpiryDate = ExpireDate.Text,
  240. idType = idType.Text.Split('|')[0].ToString(),
  241. membershipId = txtMembershipId.Text,
  242. remitanceAllowed = (rbRemitanceAllowed.SelectedValue == "Enabled" ? true : false),
  243. onlineUser = (rbOnlineLogin.SelectedValue == "Enabled" ? true : false),
  244. mobileUser = (rbMobileLogin.SelectedValue == "Enabled" ? true : false),
  245. remarks = txtRemarks.Text,
  246. registrationNo = txtRegistrationNo.Text,
  247. natureOfCompany = ddlnatureOfCompany.Text,
  248. organizationType = ddlOrganizationType.SelectedValue,
  249. dateOfIncorporation = txtDateOfIncorporation.Text,
  250. position = ddlPosition.SelectedValue,
  251. nameofAuthoPerson = txtNameofAuthoPerson.Text,
  252. nameofEmployeer = txtNameofEmployeer.Text,
  253. companyName = txtCompanyName.Text,
  254. //MonthlyIncome = ddlSalary.SelectedValue,
  255. IsCounterVisited = customerCounterVisit.Checked ? "Y" : "N",
  256. customerPassword = customerPassword.Text,
  257. agentId = GetStatic.GetAgent().ToInt(),
  258. DocumentType = ddlDocType.SelectedValue
  259. };
  260. if (hdnCustomerId.Value != "")
  261. {
  262. customerModel.customerId = hdnCustomerId.Value;
  263. customerModel.flag = "customer-editeddata";
  264. }
  265. var dbResult = _cd.RegisterCustomerNewAgent(customerModel);
  266. if (dbResult.ErrorCode == "0" && !string.IsNullOrEmpty(hddImgURL.Value) && !string.IsNullOrWhiteSpace(hddImgURL.Value))
  267. {
  268. var customerDetails = _cd.GetRequiredCustomerDetails(dbResult.Id, GetStatic.GetUser());
  269. string membershipId = Convert.ToString(customerDetails["membershipId"]);
  270. string registrationDate = Convert.ToString(customerDetails["createdDate"]);
  271. var verificationCode = dbResult.Id;
  272. var customerId = dbResult.Id;
  273. var fileCollection = Request.Files;
  274. if (UploadSignatureImage(hddImgURL.Value, registrationDate, membershipId, customerId) == 0)
  275. {
  276. _cd.AddCustomerSignature(customerId, GetStatic.GetUser(), customerId + "_signature.png");
  277. }
  278. }
  279. GetStatic.SetMessage(dbResult.ErrorCode, dbResult.Msg);
  280. if (dbResult.ErrorCode == "0")
  281. {
  282. saveCustomerDocument(dbResult);
  283. Approve();
  284. }
  285. Page_Load(sender, e);
  286. return;
  287. }
  288. public int UploadSignatureImage(string imageData, string registerDate, string membershipId, string customerId)
  289. {
  290. int errorCode = 0;
  291. try
  292. {
  293. string path = GetStatic.ReadWebConfig("customerDocPath", "") + "CustomerDocument\\" + registerDate.Replace("-", "\\") + "\\" + membershipId;
  294. if (!Directory.Exists(path))
  295. Directory.CreateDirectory(path);
  296. string fileName = path + "\\" + customerId + "_signature" + ".png";
  297. using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
  298. {
  299. using (BinaryWriter bw = new BinaryWriter(fs))
  300. {
  301. byte[] data = Convert.FromBase64String(imageData);
  302. bw.Write(data);
  303. bw.Close();
  304. }
  305. }
  306. }
  307. catch (Exception)
  308. {
  309. errorCode = 1;
  310. }
  311. return errorCode;
  312. }
  313. protected void Approve()
  314. {
  315. var verifyType = "";
  316. DataSet ds = new DataSet();
  317. if (GetRequestFrom() == "agent")
  318. {
  319. ds = _cd.ApprovePending(GetCustomerId(), GetStatic.GetUser(), "");
  320. }
  321. else
  322. {
  323. ds = _cd.ApprovePendingFromMobile(GetCustomerId(), GetStatic.GetUser(), "", verifyType, "");
  324. }
  325. DbResult dbRes = _cd.ParseDbResult(ds.Tables[0]);
  326. if (dbRes.ErrorCode == "1")
  327. {
  328. GetStatic.AlertMessage(this.Page, dbRes.Msg);
  329. }
  330. else
  331. {
  332. if (dbRes.Extra2.ToLower() == "approved")
  333. {
  334. dbRes.Msg = "Customer saved and approved successfully!!!";
  335. GetStatic.SetMessage(dbRes);
  336. }
  337. if (dbRes.Extra2.ToLower() == "verified")
  338. {
  339. dbRes.Msg = "Customer verified successfully!!!";
  340. GetStatic.SetMessage(dbRes);
  341. }
  342. if (GetRequestFrom() == "mobile")
  343. {
  344. Response.Redirect("/AgentNew/Transaction/Letters/LetterForCustomerFromMobile.aspx?customerId=" + GetCustomerId() + "&membershipId=" + ds.Tables[1].Rows[0]["account"].ToString() + "");
  345. }
  346. else
  347. {
  348. Response.Redirect("/AgentNew/Transaction/Letters/LetterForCustomerFromOthers.aspx?customerId=" + GetCustomerId() + "&membershipId=" + ds.Tables[1].Rows[0]["account"].ToString() + "");
  349. }
  350. }
  351. }
  352. public void GetImageUrl()
  353. {
  354. var customerId = Request.Form["customerId"];
  355. var membershipId = Request.Form["membershipId"];
  356. var registerDate = Request.Form["registerDate"];
  357. var documentDetails = _cd.GetDocumentByCustomerId(customerId);
  358. string[] imageUrlArray = new string[5];
  359. if (documentDetails != null)
  360. {
  361. int i = 0;
  362. int j = 1;
  363. foreach (DataRow item in documentDetails.Rows)
  364. {
  365. string imageUrl = "";
  366. string docName = "";
  367. if (item["documentType"].ToString() == "0")
  368. {
  369. docName = "Signature";
  370. imageUrl = "/Handler/CustomerSignature.ashx?registerDate=" + Convert.ToDateTime(registerDate).ToString("yyyy-MM-dd") + "&customerId=" + customerId + "&membershipNo=" + membershipId;
  371. imageUrlArray[i] = imageUrl;
  372. }
  373. else
  374. {
  375. docName = item["documentName"].ToString();
  376. imageUrl = "/Handler/CustomerSignature.ashx?registerDate=" + Convert.ToDateTime(registerDate).ToString("yyyy-MM-dd") + "&customerId=" + customerId + "&membershipNo=" + membershipId + "&fileName=" + item["fileName"];
  377. imageUrlArray[j] = imageUrl;
  378. j++;
  379. }
  380. }
  381. }
  382. Response.ContentType = "text/plain";
  383. var serializer = new JavaScriptSerializer();
  384. var json = serializer.Serialize(imageUrlArray);
  385. Response.Write(json);
  386. Response.End();
  387. }
  388. private void saveCustomerDocument(DbResult dbresult)
  389. {
  390. var result = dbresult.Id.Split('|');
  391. var customerId = result[0];
  392. var membershipId = result[1];
  393. var registerDate = result[2];
  394. HttpFileCollection fileCollection = Request.Files;
  395. for (int i = 0; i < fileCollection.AllKeys.Length; i++)
  396. {
  397. HttpPostedFile file = fileCollection[i];
  398. if (file != null)
  399. {
  400. string documentTypeName = "";
  401. string documentType = "";
  402. string fileType = "";
  403. if (i == 0)
  404. {
  405. documentTypeName = "Alien Registration Card(Front)";
  406. documentType = "11054";
  407. }
  408. else
  409. {
  410. documentTypeName = "Alien Registration Card(Back)";
  411. documentType = "11055";
  412. }
  413. string fileName = (!string.IsNullOrWhiteSpace(file.FileName) ? UploadDocument(file, customerId, documentTypeName, membershipId, registerDate, out fileType) : UploadDocument(file, customerId, documentType, membershipId, registerDate, out fileType));
  414. CustomerDocument cm = new CustomerDocument();
  415. cm.customerId = result[0];
  416. cm.fileDescription = "";
  417. cm.documentType = documentType;
  418. cm.fileUrl = fileName;
  419. cm.fileType = fileType;
  420. var res = _cd.UpdateCustomerDocument("", customerId, fileName, documentTypeName, fileType, documentType, GetStatic.GetUser());
  421. }
  422. }
  423. }
  424. private string UploadDocument(HttpPostedFile doc, string customerId, string documentType, string membershipId, string registeredDate, out string fileType)
  425. {
  426. fileType = "";
  427. string fName = "";
  428. try
  429. {
  430. fileType = doc.ContentType;
  431. string fileExtension = new FileInfo(doc.FileName).Extension;
  432. string documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", "");
  433. if (documentExtension.ToLower().Contains(fileExtension.ToLower()))
  434. {
  435. string fileName = customerId + "_" + documentType + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + "_" + registeredDate.Replace("-", "_") + fileExtension;
  436. string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + registeredDate.Replace("-", "\\") + "\\" + membershipId;
  437. if (!Directory.Exists(path))
  438. Directory.CreateDirectory(path);
  439. doc.SaveAs(path + "/" + fileName);
  440. fName = fileName;
  441. }
  442. else
  443. {
  444. fName = "notValid";
  445. }
  446. }
  447. catch (Exception ex)
  448. {
  449. fName = "";
  450. }
  451. return fName;
  452. }
  453. private void GetSignature()
  454. {
  455. var customerId = Request.Form["customerId"];
  456. var response = GetSignatrueHtml("Staff Visit - Customer Register(Customer Signature)", customerId);
  457. Response.ContentType = "text/plain";
  458. var serializer = new JavaScriptSerializer();
  459. var json = serializer.Serialize(response);
  460. Response.Write(json);
  461. Response.End();
  462. }
  463. public string GetSignatrueHtml(string fileDescription, string sessionId)
  464. {
  465. var membershipId = Request.Form["membershipId"];
  466. var customerId = Request.Form["customerId"];
  467. var registerDate = Request.Form["registerDate"];
  468. var documentDetails = _cd.GetDocumentByCustomerIdNew(customerId, fileDescription, sessionId);
  469. string imageUrl = "";
  470. if (documentDetails != null)
  471. {
  472. foreach (DataRow item in documentDetails.Rows)
  473. {
  474. var fileName = item["fileName"].ToString();
  475. imageUrl = "/Handler/CustomerSignature.ashx?registerDate=" + Convert.ToDateTime(registerDate).ToString("yyyy-MM-dd") + "&customerId=" + customerId + "&membershipNo=" + membershipId + "&fileName=" + fileName;
  476. }
  477. }
  478. return imageUrl;
  479. }
  480. }
  481. }