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.

311 lines
15 KiB

  1. using Swift.DAL.OnlineAgent;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.IO;
  7. using System.Net;
  8. using System.Text.RegularExpressions;
  9. using System.Web;
  10. namespace Swift.web.AgentNew.Customer
  11. {
  12. public partial class AddCustomer : System.Web.UI.Page
  13. {
  14. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  15. private readonly OnlineCustomerDao _cd = new OnlineCustomerDao();
  16. private const string ViewFunctionId = "20202000";
  17. private const string AddFunctionId = "20202010";
  18. private const string SignatureFunctionId = "20202020";
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. signatureDiv.Visible = _sl.HasRight(SignatureFunctionId);
  22. isDisplaySignature.Value = _sl.HasRight(SignatureFunctionId) ? "true" : "false";
  23. _sl.CheckSession();
  24. GetStatic.PrintMessage(this);
  25. var MethodName = Request.Form["MethodName"];
  26. if (!IsPostBack)
  27. {
  28. Authenticate();
  29. PopulateDdl();
  30. if (MethodName == "GetAddressDetailsByZipCode")
  31. {
  32. GetAddressDetailsByZipCode();
  33. }
  34. }
  35. }
  36. private void Authenticate()
  37. {
  38. _sl.CheckAuthentication(ViewFunctionId);
  39. string eId = GetStatic.ReadQueryString("customerId", "");
  40. var hasRight = false;
  41. hasRight = _sl.HasRight(AddFunctionId);
  42. register.Enabled = hasRight;
  43. register.Visible = hasRight;
  44. }
  45. public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin)
  46. {
  47. return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent;
  48. }
  49. private void PopulateDdl()
  50. {
  51. _sl.SetDDL(ref genderList, "EXEC proc_online_dropDownList @flag='GenderList',@user='" + GetStatic.GetUser() + "'", "valueId", "detailTitle", "", "Select..");
  52. _sl.SetDDL(ref countryList, "EXEC proc_online_dropDownList @flag='onlineCountrylist',@user='" + GetStatic.GetUser() + "'", "countryId", "countryName", "", "");
  53. _sl.SetDDL(ref nativeCountry, "EXEC proc_online_dropDownList @flag='allCountrylist',@user='" + GetStatic.GetUser() + "'", "countryId", "countryName", "", "Select..");
  54. _sl.SetDDL(ref occupation, "EXEC proc_online_dropDownList @flag='occupationList',@user='" + GetStatic.GetUser() + "'", "valueId", "detailTitle", "", "Select..");
  55. _sl.SetDDL(ref idType, "EXEC proc_online_dropDownList @flag='IdTypeWithDetails',@user='" + GetStatic.GetUser() + "',@countryId='" + countryList.SelectedValue + "'", "valueId", "detailTitle", "", "Select..");
  56. _sl.SetDDL(ref ddlCustomerType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=4700", "valueId", "detailTitle", ddlCustomerType.SelectedValue, "");
  57. _sl.SetDDL(ref ddlOrganizationType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7002", "valueId", "detailTitle", "", "Select..");
  58. _sl.SetDDL(ref ddlnatureOfCompany, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7003", "valueId", "detailTitle", "", "Select..");
  59. _sl.SetDDL(ref ddSourceOfFound, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=3900", "valueId", "detailTitle", "", "Select..");
  60. _sl.SetDDL(ref ddlEmployeeBusType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7004", "valueId", "detailTitle", "", "");
  61. _sl.SetDDL(ref ddlVisaStatus, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7005", "valueId", "detailTitle", "", "Select..");
  62. _sl.SetDDL(ref ddlPosition, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7006", "valueId", "detailTitle", "", "Select..");
  63. _sl.SetDDL(ref ddlState, "EXEC proc_online_dropDownList @flag='state',@countryId='" + countryList.SelectedValue + "'", "stateId", "stateName", "", "Select..");
  64. }
  65. private void GetAddressDetailsByZipCode()
  66. {
  67. string zipCode = Request.Form["zipCode"];
  68. if (!Regex.Match(zipCode, @"^\d{7}?$").Success)
  69. {
  70. GetStatic.JsonResponse(false, Page);
  71. };
  72. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://yubin.senmon.net/en/" + zipCode + ".html");
  73. myRequest.Method = WebRequestMethods.Http.Get;
  74. WebResponse response = myRequest.GetResponse();
  75. string json = null;
  76. using (Stream stream = response.GetResponseStream())
  77. {
  78. json = (new StreamReader(stream)).ReadToEnd();
  79. }
  80. int length = (json.Length) / 4;
  81. int indexOfTable = json.IndexOf("<table class=\"info\">");
  82. int indexOfTableEnd = json.IndexOf("<iframe");
  83. if (indexOfTable != -1)
  84. {
  85. length = indexOfTableEnd - indexOfTable;
  86. }
  87. json = json.Substring(indexOfTable, length);
  88. json = json.Replace("class=\"info\"", "Id=\"info\"");
  89. GetStatic.JsonResponse(json, Page);
  90. }
  91. protected void register_Click(object sender, EventArgs e)
  92. {
  93. string eId = GetStatic.ReadQueryString("customerId", "");
  94. if (!_sl.HasRight(AddFunctionId))
  95. {
  96. GetStatic.AlertMessage(this, "You are not authorized to Add Customer!");
  97. return;
  98. }
  99. if (_sl.HasRight(SignatureFunctionId) && (string.IsNullOrEmpty(customerPassword.Text) || string.IsNullOrWhiteSpace(customerPassword.Text)) && (string.IsNullOrEmpty(hddImgURL.Value) || string.IsNullOrWhiteSpace(hddImgURL.Value)))
  100. {
  101. GetStatic.AlertMessage(this, "Customer signature or customer password is required!");
  102. return;
  103. }
  104. OnlineCustomerModel customerModel = new OnlineCustomerModel()
  105. {
  106. flag = "customer-register-core",
  107. firstName = firstName.Text,
  108. middleName = middleName.Text,
  109. lastName1 = lastName.Text,
  110. gender = genderList.SelectedValue,
  111. customerType = hdnCustomerType.Value,
  112. country = countryList.Text,
  113. zipCode = zipCode.Text,
  114. street = txtStreet.Text,
  115. city = city.Text,
  116. state = ddlState.Text,
  117. senderCityjapan = txtsenderCityjapan.Text,
  118. email = email.Text,
  119. streetJapanese = txtstreetJapanese.Text,
  120. homePhone = phoneNumber.Text,
  121. mobile = mobile.Text,
  122. visaStatus = ddlVisaStatus.SelectedValue,
  123. employeeBusinessType = ddlEmployeeBusType.SelectedValue,
  124. nativeCountry = nativeCountry.SelectedValue,
  125. dob = dob.Text,
  126. ssnNo = txtSSnNo.Text,
  127. sourceOfFound = ddSourceOfFound.SelectedValue,
  128. occupation = occupation.Text,
  129. telNo = phoneNumber.Text,
  130. ipAddress = GetStatic.GetIp(),
  131. createdBy = GetStatic.GetUser(),
  132. idNumber = verificationTypeNo.Text,
  133. idIssueDate = IssueDate.Text,
  134. idExpiryDate = ExpireDate.Text,
  135. idType = idType.Text.Split('|')[0].ToString(),
  136. remitanceAllowed = (rbRemitanceAllowed.SelectedValue == "Enabled" ? true : false),
  137. onlineUser = (rbOnlineLogin.SelectedValue == "Enabled" ? true : false),
  138. mobileUser = (rbMobileLogin.SelectedValue == "Enabled" ? true : false),
  139. remarks = txtRemarks.Text,
  140. registrationNo = txtRegistrationNo.Text,
  141. natureOfCompany = ddlnatureOfCompany.Text,
  142. organizationType = ddlOrganizationType.SelectedValue,
  143. dateOfIncorporation = txtDateOfIncorporation.Text,
  144. position = ddlPosition.SelectedValue,
  145. nameofAuthoPerson = txtNameofAuthoPerson.Text,
  146. nameofEmployeer = txtNameofEmployeer.Text,
  147. companyName = txtCompanyName.Text,
  148. MonthlyIncome = ddlSalary.SelectedValue,
  149. customerPassword = customerPassword.Text
  150. };
  151. if (hdnCustomerId.Value != "")
  152. {
  153. customerModel.customerId = hdnCustomerId.Value;
  154. customerModel.flag = "customer-update-new";
  155. }
  156. var dbResult = _cd.RegisterCustomerNew(customerModel);
  157. GetStatic.SetMessage(dbResult.ErrorCode, dbResult.Msg);
  158. if (dbResult.ErrorCode == "0")
  159. {
  160. var customerDetails = _cd.GetRequiredCustomerDetails(dbResult.Id, GetStatic.GetUser());
  161. string membershipId = Convert.ToString(customerDetails["membershipId"]);
  162. string registrationDate = Convert.ToString(customerDetails["createdDate"]);
  163. var verificationCode = dbResult.Id;
  164. var customerId = dbResult.Id;
  165. var fileCollection = Request.Files;
  166. string customerSignature = hddImgURL.Value;
  167. int ErrorCode = 0;
  168. if (!string.IsNullOrEmpty(customerSignature) && (dbResult.ErrorCode == "0" || dbResult.ErrorCode == "100" || dbResult.ErrorCode == "101"))
  169. {
  170. UploadSignatureImage(customerSignature, registrationDate, membershipId, customerId, out ErrorCode);
  171. if (ErrorCode == 0)
  172. {
  173. _cd.AddCustomerSignature(customerId, GetStatic.GetUser(), customerId + "_signature.png");
  174. }
  175. }
  176. for (int i = 0; i < fileCollection.AllKeys.Length; i++)
  177. {
  178. HttpPostedFile file = fileCollection[i];
  179. if (file != null)
  180. {
  181. string documentTypeName = "";
  182. string documentTypeValue = "";
  183. string fileType = "";
  184. if (i == 0)
  185. {
  186. documentTypeName = "Alien Registration Card(Front)";
  187. documentTypeValue = "11054";
  188. }
  189. else
  190. {
  191. documentTypeName = "Alien Registration Card(Back)";
  192. documentTypeValue = "11055";
  193. }
  194. var filename = SaveDocument(file, customerId, membershipId, documentTypeName, registrationDate, out fileType, out ErrorCode);
  195. if (ErrorCode == 0)
  196. {
  197. dbResult = _cd.UpdateCustomerDocument("", customerId, filename, "", fileType, documentTypeValue, GetStatic.GetUser());
  198. }
  199. else
  200. {
  201. dbResult = new DAL.SwiftDAL.DbResult
  202. {
  203. Msg = filename,
  204. ErrorCode = "1",
  205. };
  206. }
  207. }
  208. }
  209. Response.Redirect("AddCustomer.aspx");
  210. return;
  211. }
  212. else
  213. {
  214. if (hdnCustomerType.Value == "4701")
  215. {
  216. ddlCustomerType.SelectedValue = hdnCustomerType.Value;
  217. }
  218. return;
  219. }
  220. }
  221. private string SaveDocument(HttpPostedFile doc, string customerId, string membershipId, string documentName, string registerDate, out string fileType, out int ErrorCode)
  222. {
  223. var maxFileSize = GetStatic.ReadWebConfig("csvFileSize", "2097152");
  224. fileType = "";
  225. ErrorCode = 0;
  226. string fName = "";
  227. try
  228. {
  229. fileType = doc.ContentType;
  230. if (false)
  231. //if (doc.ContentLength > Convert.ToDouble(maxFileSize))
  232. {
  233. fName = "File size is too large";
  234. ErrorCode = 1;
  235. }
  236. else
  237. {
  238. //generate filename
  239. string fileExtension = new FileInfo(doc.FileName).Extension;
  240. string fileName = customerId + "_" + documentName + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + "_" + registerDate.Replace("-", "_") + fileExtension;
  241. fName = fileName;
  242. string tempFilePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\TempFiles\\";
  243. //save file
  244. string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + registerDate.Replace("-", "\\") + "\\" + membershipId;
  245. if (!Directory.Exists(tempFilePath))
  246. Directory.CreateDirectory(tempFilePath);
  247. doc.SaveAs(tempFilePath + fileName);
  248. if (!Directory.Exists(path))
  249. Directory.CreateDirectory(path);
  250. //reduce file size
  251. using (Bitmap bitmapObj = new Bitmap(tempFilePath + fileName))
  252. {
  253. var fileProp = System.Drawing.Image.FromFile(tempFilePath + fileName);
  254. Bitmap reduceBitmapImg = new Bitmap(bitmapObj, fileProp.Width / 3, fileProp.Height / 3);
  255. reduceBitmapImg.Save(path + "/" + fileName, ImageFormat.Jpeg);
  256. fileProp.Dispose();
  257. }
  258. //delete file
  259. File.Delete(tempFilePath + fileName);
  260. }
  261. }
  262. catch (Exception ex)
  263. {
  264. fName = ex.Message;
  265. ErrorCode = 1;
  266. }
  267. return fName;
  268. }
  269. public void UploadSignatureImage(string imageData, string registerDate, string membershipId, string customerId, out int errorCode)
  270. {
  271. try
  272. {
  273. errorCode = 0;
  274. string path = GetStatic.ReadWebConfig("customerDocPath", "") + "CustomerDocument\\" + registerDate.Replace("-", "\\") + "\\" + membershipId;
  275. if (!Directory.Exists(path))
  276. Directory.CreateDirectory(path);
  277. string fileName = path + "\\" + customerId + "_signature" + ".png";
  278. using (FileStream fs = new FileStream(fileName, FileMode.Create))
  279. {
  280. using (BinaryWriter bw = new BinaryWriter(fs))
  281. {
  282. byte[] data = Convert.FromBase64String(imageData);
  283. bw.Write(data);
  284. bw.Close();
  285. }
  286. }
  287. }
  288. catch (Exception)
  289. {
  290. errorCode = 1;
  291. }
  292. }
  293. }
  294. }