using Newtonsoft.Json; using Swift.API.Common; using Swift.API.Common.SyncModel; using Swift.API.ThirdPartyApiServices; using Swift.DAL.BL.System.Utility; using Swift.DAL.OnlineAgent; using Swift.DAL.SwiftDAL; using Swift.web.Library; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Net; using System.Text.RegularExpressions; using System.Web; using System.Web.Script.Serialization; using System.Web.Services; using System.Web.UI.WebControls; namespace Swift.web.Remit.Administration.CustomerRegistration { public partial class Manage : System.Web.UI.Page { private readonly RemittanceLibrary _sl = new RemittanceLibrary(); private readonly OnlineCustomerDao _cd = new OnlineCustomerDao(); private readonly StaticDataDdl _sdd = new StaticDataDdl(); private const string AddViewFunctionId = "20212000"; private const string EditViewFunctionId = "20212020"; private const string AddFunctionId = "20212010"; private const string EditFunctionId = "20212020"; private const string SignatureFunctionId = "20212030"; private bool isEdit = Convert.ToBoolean(GetStatic.ReadQueryString("edit", "false")); protected void Page_Load(object sender, EventArgs e) { Authenticate(); signatureDiv.Visible = !CheckAddOrEdit() && _sl.HasRight(SignatureFunctionId); isDisplaySignature.Value = !CheckAddOrEdit() && _sl.HasRight(SignatureFunctionId) ? "true" : "false"; agreementDiv.Visible = !CheckAddOrEdit(); GetStatic.PrintMessage(Page); displayOnlyOnEdit.Visible = CheckAddOrEdit(); addEditPanel.Attributes.Add("style", "display:" + (CheckAddOrEdit() ? "none" : "")); //displayCounterVisit.Visible = !CheckAddOrEdit(); if (GetStatic.ReadQueryString("hdnId", "").ToString() != "") { ShowPrintLink(GetStatic.ReadQueryString("hdnId", "").ToString()); } else { linkDiv.Visible = false; } var MethodName = Request.Form["MethodName"]; if (!IsPostBack) { //if (GetStatic.ReadQueryString("customerId", "") != "" || GetStatic.ReadQueryString("edit", "") == "true") // divUploadImage.Visible = false; //else // divUploadImage.Visible = true; PopulateDdl(); if (MethodName == "GetCustomerDetails") { GetCustomerDetails(); } string methodName = GetStatic.ReadQueryString("MethodName", ""); if (methodName == "GetCustomerDetailsForEdit") { string eId = GetStatic.ReadQueryString("customerId", ""); PopulateForm(eId); } if (IsCallFromList().ToLower() == "true") { if (GetStatic.ReadQueryString("customerId", "") != "") { GetStatic.CallJSFunction(this, "CallFromListPage('" + GetStatic.ReadQueryString("customerId", "") + "')"); } } } } private string IsCallFromList() { return GetStatic.ReadQueryString("isCallFromList", "False"); } public void ShowPrintLink(string membershipId) { linkDiv.Visible = true; printLink.Attributes["href"] = "PrintDetails.aspx?membershipId=" + membershipId; printLink.InnerText = "Print Details of " + membershipId + ""; } private void Authenticate() { if (CheckAddOrEdit()) _sl.CheckAuthentication(EditViewFunctionId); else _sl.CheckAuthentication(AddViewFunctionId); string eId = GetStatic.ReadQueryString("customerId", ""); var hasRight = true; if (eId == "") { hasRight = _sl.HasRight(AddFunctionId); register.Enabled = hasRight; register.Visible = hasRight; } else { hasRight = _sl.HasRight(EditFunctionId); register.Enabled = hasRight; register.Visible = hasRight; } } private bool CheckAddOrEdit() { if (isEdit) { customerType.Attributes.Add("hidden", "hidden"); } else { customerType.Attributes.Remove("hidden"); } return isEdit; } private void PopulateForm(string eId) { var dr = _cd.GetCustomerDetails(eId, GetStatic.GetUser()); if (null != dr) { hdnCustomerId.Value = dr["customerId"].ToString(); firstName.Text = dr["firstName"].ToString(); middleName.Text = dr["middleName"].ToString(); lastName.Text = dr["lastName1"].ToString(); txtCompanyName.Text = dr["firstName"].ToString(); genderList.SelectedValue = dr["gender"].ToString(); countryList.SelectedValue = dr["country"].ToString(); address1.Text = dr["address"].ToString(); zipCode.Text = dr["zipCode"].ToString(); city.Text = dr["city"].ToString(); email.Text = dr["email"].ToString(); hddOldEmailValue.Value = dr["email"].ToString(); emailConfirm.Text = dr["email"].ToString(); phoneNumber.Text = dr["telNo"].ToString(); mobile.Text = dr["mobile"].ToString(); nativeCountry.SelectedValue = dr["nativeCountryId"].ToString(); //nativeCountry.SelectedItem.Value = dr["nativeCountryId"].ToString(); dob.Text = dr["dob"].ToString(); occupation.Text = dr["occupation"].ToString(); IssueDate.Text = dr["idIssueDate"].ToString(); ExpireDate.Text = dr["idExpiryDate"].ToString(); idType.SelectedValue = dr["idType"].ToString(); verificationTypeNo.Text = dr["idNumber"].ToString(); hddIdNumber.Value = dr["homePhone"].ToString(); txtMembershipId.Text = dr["membershipId"].ToString(); hdnMembershipNo.Value = dr["membershipId"].ToString(); txtMembershipId.Attributes.Add("readonly", "readonly"); txtRegistrationNo.Text = dr["registerationNo"].ToString(); txtAdditionalAddress.Text = dr["additionalAddress"].ToString(); txtDateOfIncorporation.Text = dr["dateofIncorporation"].ToString(); txtNameofAuthoPerson.Text = dr["nameOfAuthorizedPerson"].ToString(); //txtStreet.Text = dr["street"].ToString(); txtsenderCityjapan.Text = dr["cityUnicode"].ToString(); //txtstreetJapanese.Text = dr["streetUnicode"].ToString(); txtNameofEmployeer.Text = dr["nameOfEmployeer"].ToString(); rbRemitanceAllowed.SelectedValue = (dr["remittanceAllowed"].ToString().ToLower() == "true" ? "Enabled" : "Disabled"); rbOnlineLogin.SelectedValue = (dr["onlineUser"].ToString() == "Y" ? "Enabled" : "Disabled"); rbMobileLogin.SelectedValue = (dr["mobileUser"].ToString() == "Y" ? "Enabled" : "Disabled"); txtRemarks.Text = dr["remarks"].ToString(); txtSSnNo.Text = dr["SSNNO"].ToString(); //ddlSalary.Text = dr["monthlyIncome"].ToString(); ddlDocType.SelectedValue = dr["documentType"].ToString(); //rbKycType.SelectedValue = dr["RegistrationType"].ToString(); if (!string.IsNullOrEmpty(dr["customerType"].ToString()) && !string.IsNullOrWhiteSpace(dr["customerType"].ToString())) { ddlCustomerType.SelectedValue = dr["customerType"].ToString(); } if (!string.IsNullOrEmpty(dr["employeeBusinessType"].ToString()) && !string.IsNullOrWhiteSpace(dr["employeeBusinessType"].ToString())) { ddlEmployeeBusType.SelectedValue = dr["employeeBusinessType"].ToString(); } if (!string.IsNullOrEmpty(dr["natureOfCompany"].ToString()) && !string.IsNullOrWhiteSpace(dr["natureOfCompany"].ToString())) { ddlnatureOfCompany.SelectedValue = dr["natureOfCompany"].ToString(); } if (!string.IsNullOrEmpty(dr["organizationType"].ToString()) && !string.IsNullOrWhiteSpace(dr["organizationType"].ToString())) { ddlOrganizationType.SelectedValue = dr["organizationType"].ToString(); } ddlPosition.SelectedValue = dr["position"].ToString(); //ddlVisaStatus.SelectedValue = dr["visaStatus"].ToString(); ddSourceOfFound.SelectedValue = dr["sourceOfFund"].ToString(); //setStateDll(countryList.SelectedValue, zipCode.Text, dr["state"].ToString()); email.Enabled = (dr["isTxnMade"].ToString() == "Y") ? false : true; emailConfirm.Enabled = (dr["isTxnMade"].ToString() == "Y") ? false : true; hddTxnsMade.Value = dr["isTxnMade"].ToString(); if (dr["isTxnMade"].ToString() == "Y") { msgDiv.Visible = true; msgLabel.Text = "Note: The customer has already made transactions in JME system, so the email can not be modified. For more info please contact HO."; } if (dr["idType"].ToString() == "8008") { expiryDiv.Attributes.Add("class", "col-md-4 col-sm-4 hidden"); } else { expiryDiv.Attributes.Remove("class"); expiryDiv.Attributes.Add("class", "col-md-4 col-sm-4"); } membershipDiv.Visible = true; } } private void PopulateDdl() { _sl.SetDDL(ref genderList, "EXEC proc_online_dropDownList @flag='GenderList',@user='" + GetStatic.GetUser() + "'", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref countryList, "EXEC proc_online_dropDownList @flag='onlineCountrylist',@user='" + GetStatic.GetUser() + "'", "countryId", "countryName", "", ""); _sl.SetDDL(ref nativeCountry, "EXEC proc_online_dropDownList @flag='allCountrylist',@user='" + GetStatic.GetUser() + "'", "countryId", "countryName", "", "Select.."); _sl.SetDDL(ref occupation, "EXEC proc_online_dropDownList @flag='occupationList',@user='" + GetStatic.GetUser() + "'", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref idType, "EXEC proc_online_dropDownList @flag='IdTypeWithDetails',@user='" + GetStatic.GetUser() + "',@countryId='" + countryList.SelectedValue + "'", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref ddlCustomerType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=4700", "valueId", "detailTitle", ddlCustomerType.SelectedValue, ""); _sl.SetDDL(ref ddlOrganizationType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7002", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref ddlnatureOfCompany, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7003", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref ddSourceOfFound, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=3900", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref ddlEmployeeBusType, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7004", "valueId", "detailTitle", "", ""); // _sl.SetDDL(ref ddlVisaStatus, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7005", "valueId", "detailTitle", "", "Select.."); _sl.SetDDL(ref ddlPosition, "EXEC proc_online_dropDownList @flag='dropdownList',@user='" + GetStatic.GetUser() + "',@parentId=7006", "valueId", "detailTitle", "", "Select.."); //_sl.SetDDL(ref ddlState, "EXEC proc_online_dropDownList @flag='state',@countryId='" + countryList.SelectedValue + "'", "stateId", "stateName", "", "Select.."); _sdd.SetDDL(ref ddlSearchBy, "exec proc_sendPageLoadData @flag='search-cust-by'", "VALUE", "TEXT", "", ""); _sdd.SetStaticDdl(ref ddlDocType, "7009", "", "Select"); } protected void register_Click(object sender, EventArgs e) { string eId = GetStatic.ReadQueryString("customerId", ""); //if (eId == "") //{ // if (!_sl.HasRight(GetFunctionIdByUserType(AddFunctionIdAgent, AddFunctionId))) // { // GetStatic.AlertMessage(this, "You are not authorized to Add Customer!"); // return; // } //} //else //{ // if (!_sl.HasRight(GetFunctionIdByUserType(EditFunctionIdAgent, EditFunctionId))) // { // GetStatic.AlertMessage(this, "You are not authorized to Edit Customer!"); // return; // } //} if (hddTxnsMade.Value == "Y" && (!email.Text.Equals(hddOldEmailValue.Value.ToString()))) { GetStatic.AlertMessage(this, "You can not change the email of customer who have already done transaction!"); return; } if (_sl.HasRight(SignatureFunctionId) && !isEdit && (string.IsNullOrEmpty(customerPassword.Text) || string.IsNullOrWhiteSpace(customerPassword.Text)) && (string.IsNullOrEmpty(hddImgURL.Value) || string.IsNullOrWhiteSpace(hddImgURL.Value))) { GetStatic.AlertMessage(this, "Customer signature or customer password is required!"); return; } string trimmedfirstName = firstName.Text.Trim() == "" ? null : firstName.Text.Trim(); string trimmedMiddleName = middleName.Text.Trim() == "" ? null : middleName.Text.Trim(); string trimmedlastName = lastName.Text.Trim() == "" ? null : lastName.Text.Trim(); string occupationVal = occupationHidden.Value; string additionalAddress = txtAdditionalAddress.Text; string city = cityHidden.Value; OnlineCustomerModel customerModel = new OnlineCustomerModel() { flag = "customer-register-core", firstName = trimmedfirstName, middleName = trimmedMiddleName, lastName1 = trimmedlastName, gender = genderList.SelectedValue, customerType = ddlCustomerType.SelectedValue, country = countryList.Text, AdditionalAddress = additionalAddress, //txtAdditionalAddress.Text, address = address1.Text, zipCode = zipCode.Text, street = hf_editable_townArea.Value, city = city, //cityHidden.Value, //state = ddlStateHidden.Value, senderCityjapan = txtsenderCityjapan.Text, email = email.Text, streetJapanese = Request.Form["txtStreet"], homePhone = phoneNumber.Text, mobile = mobile.Text, // visaStatus = ddlVisaStatus.SelectedValue, employeeBusinessType = ddlEmployeeBusType.SelectedValue, nativeCountry = nativeCountry.SelectedValue, dob = dob.Text, ssnNo = txtSSnNo.Text, sourceOfFound = ddSourceOfFound.SelectedValue, occupation = occupationVal, telNo = phoneNumber.Text, ipAddress = GetStatic.GetIp(), createdBy = GetStatic.GetUser(), idNumber = verificationTypeNo.Text, idIssueDate = IssueDate.Text, idExpiryDate = ExpireDate.Text, idType = idType.Text.Split('|')[0].ToString(), membershipId = txtMembershipId.Text, remitanceAllowed = (rbRemitanceAllowed.SelectedValue == "Enabled" ? true : false), onlineUser = (rbOnlineLogin.SelectedValue == "Enabled" ? true : false), mobileUser = (rbMobileLogin.SelectedValue == "Enabled" ? true : false), remarks = txtRemarks.Text, registrationNo = txtRegistrationNo.Text, natureOfCompany = ddlnatureOfCompany.Text, organizationType = ddlOrganizationType.SelectedValue, dateOfIncorporation = txtDateOfIncorporation.Text, position = ddlPosition.SelectedValue, nameofAuthoPerson = txtNameofAuthoPerson.Text, nameofEmployeer = txtNameofEmployeer.Text, companyName = txtCompanyName.Text, //MonthlyIncome = ddlSalary.Text.ToUpper(), IsCounterVisited = customerCounterVisit.Checked ? "Y" : "N", customerPassword = customerPassword.Text, DocumentType = ddlDocType.SelectedValue, agentId = GetStatic.GetAgent().ToInt(), occupationOther = occupationText.Text, ReferralId = referralText.Value, otherIdNumber = otherVerificationTypeNo.Text, serviceUsedFor = Request.Form["chkSkip"], //RegistrationType = rbKycType.SelectedValue }; if (hdnCustomerId.Value != "") { customerModel.customerId = hdnCustomerId.Value; customerModel.flag = "customer-editeddata"; } else { var custom = PasswordGenerator.GenerateRandomPassword(); customerModel.password = custom; } var dbResult = _cd.RegisterCustomerNew(customerModel); if (dbResult.ErrorCode == "0" && !string.IsNullOrEmpty(hddImgURL.Value) && !string.IsNullOrWhiteSpace(hddImgURL.Value)) { var customerDetails = _cd.GetRequiredCustomerDetails(dbResult.Id, GetStatic.GetUser()); string membershipId = Convert.ToString(customerDetails["membershipId"]); string registrationDate = Convert.ToString(customerDetails["createdDate"]); var verificationCode = dbResult.Id; var customerId = dbResult.Id; var fileCollection = Request.Files; if (UploadSignatureImage(hddImgURL.Value, registrationDate, membershipId, customerId) == 0) { _cd.AddCustomerSignature(customerId, GetStatic.GetUser(), customerId + "_signature.png"); } } GetStatic.SetMessage(dbResult.ErrorCode, dbResult.Msg); if (dbResult.ErrorCode == "0") { saveCustomerDocument(dbResult); string memberId = ""; if (dbResult.Msg.Split(':').Length > 1) { memberId = dbResult.Msg.Split(':')[1].Trim(); } hdnCustomerId.Value = null; if (IsCallFromList().ToLower() == "true") { Response.Redirect("/Remit/Administration/CustomerSetup/List.aspx"); } else { if (CheckAddOrEdit()) { PrintMessage(dbResult.Msg); txtSearchData.Text = ""; //Response.Redirect("Manage.aspx?edit=true&hdnId=" + memberId + ""); } else { PrintMessage(dbResult.Msg); txtSearchData.Text = ""; //Response.Redirect("Manage.aspx?hdnId=" + memberId + ""); } } } else { GetStatic.AlertMessage(this, dbResult.Msg); } Page_Load(sender, e); return; } private void PrintMessage(string msg) { GetStatic.CallBackJs1(Page, "Msg", "alert('" + msg + "');"); } private void saveCustomerDocument(DbResult dbresult) { var result = dbresult.Extra.Split('|'); var customerId = result[0]; var membershipId = result[1]; var registerDate = result[2]; HttpFileCollection fileCollection = Request.Files; for (int i = 0; i < fileCollection.AllKeys.Length; i++) { HttpPostedFile file = fileCollection[i]; if (file != null) { string documentTypeName = ""; string documentType = ""; string fileType = ""; var keyName = fileCollection.AllKeys[i]; if (keyName.ToLower().Equals("reg_front_id")) { documentTypeName = "ID_Front"; documentType = "11394";//11386 } if (keyName.ToLower().Equals("reg_back_id")) { documentTypeName = "ID_Back"; documentType = "11395";//"11387"; } if (keyName.ToLower().Equals("add_id_front")) { documentTypeName = "Additional_ID_Front"; documentType = "11396";// "11389"; } if (keyName.ToLower().Equals("add_id_back")) { documentTypeName = "Additional_ID_Back"; documentType = "11397";// "11395"; } if (keyName.ToLower().Equals("other_document")) { documentTypeName = "Other_Document"; documentType = "11398";// "11390"; } if (keyName.ToLower().Equals("reg_form")) { documentTypeName = "Registration_Form"; documentType = "11399";// "11393"; } string fileName = (!string.IsNullOrWhiteSpace(file.FileName) ? GetStatic.UploadDocument(file, customerId, documentTypeName, membershipId, registerDate, out fileType) : GetStatic.UploadDocument(file, customerId, documentType, membershipId, registerDate, out fileType)); CustomerDocument cm = new CustomerDocument(); if (!string.IsNullOrEmpty(fileName) && fileName.ToLower() != "notvalid") _cd.UpdateCustomerDocument("", customerId, fileName, documentTypeName, fileType, documentType, GetStatic.GetUser()); } } } public int UploadSignatureImage(string imageData, string registerDate, string membershipId, string customerId) { int errorCode = 0; try { string path = GetStatic.ReadWebConfig("customerDocPath", "") + "CustomerDocument\\" + registerDate.Replace("-", "\\") + "\\" + membershipId; if (!Directory.Exists(path)) Directory.CreateDirectory(path); string fileName = path + "\\" + customerId + "_signature" + ".png"; using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(imageData); bw.Write(data); bw.Close(); } } } catch (Exception) { errorCode = 1; } return errorCode; } public class CustomerAddress { public string errrorCode { get; set; } public string msg { get; set; } public string State { get; set; } public string City { get; set; } public string Street { get; set; } } [WebMethod] public static string GetAddressByPostCode(string zipCode) { var postCode = zipCode.ToUpper(); string ProcessId = Guid.NewGuid().ToString().Replace("-", "") + ":" + postCode; string methodType = Utility.ReadWebConfig("methodType", ""); string countryName = "United Kingdom"; AddressRequest requestObj = new AddressRequest() { CountryIsoCode = countryName, ProviderId = ProcessId, MethodType = methodType, TownName = postCode, }; SyncStateCityTownService serviceObj = new SyncStateCityTownService(); var response = serviceObj.GetAddressList(requestObj); string jsonResponse = JsonConvert.SerializeObject(response); return jsonResponse; } private void GetAddressDetailsByZipCode() { string customerId = Request.Form["customerId"]; string zipCode = Request.Form["zipCode"]; string rowID = Request.Form["RowID"]; string action = Request.Form["action"]; var dr = _cd.GetAddressByZipCodeAdmin(zipCode, GetStatic.GetUser(), rowID, customerId, action); var json = GetStatic.DataTableToJson(dr); GetStatic.JsonResponse(json, this); } private void GetCustomerDetails() { string eId = Request.Form["Id"]; var dt = _cd.GetDetailsForEditCustomer(eId, GetStatic.GetUser()); Response.ContentType = "text/plain"; var json = DataTableToJson(dt); Response.Write(json); Response.End(); } private void GetCustomerDetailsForEdit() { string eId = GetStatic.ReadQueryString("customerId", ""); var dt = _cd.GetDetailsForEditCustomer(eId, GetStatic.GetUser()); Response.ContentType = "text/plain"; var json = DataTableToJson(dt); Response.Write(json); Response.End(); } public static string DataTableToJson(DataTable table) { if (table == null) return ""; var list = new List>(); foreach (DataRow row in table.Rows) { var dict = new Dictionary(); foreach (DataColumn col in table.Columns) { dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col]; } list.Add(dict); } var serializer = new JavaScriptSerializer(); string json = serializer.Serialize(list); return json; } //private void setStateDll(string countryId, string zipCode, string stateId) //{ // if (countryId != "") // { // _sl.SetDDL(ref ddlState, "EXEC proc_online_dropDownList @flag='state',@countryId='" + countryList.SelectedValue + "'", "stateId", "stateName", stateId, "Select.."); // } //} public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin) { return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent; } protected void clickBtnForGetCustomerDetails_Click(object sender, EventArgs e) { string eId = hdnCustomerId.Value; if (eId != "") { PopulateForm(eId); } } } }