using Swift.DAL.OnlineAgent; using Swift.web.Library; using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Net; using System.Text.RegularExpressions; using System.Web; namespace Swift.web.AgentNew.Customer { public partial class AddCustomer : System.Web.UI.Page { private readonly RemittanceLibrary _sl = new RemittanceLibrary(); private readonly OnlineCustomerDao _cd = new OnlineCustomerDao(); private const string ViewFunctionId = "20202000"; private const string AddFunctionId = "20202010"; private const string SignatureFunctionId = "20202020"; protected void Page_Load(object sender, EventArgs e) { signatureDiv.Visible = _sl.HasRight(SignatureFunctionId); isDisplaySignature.Value = _sl.HasRight(SignatureFunctionId) ? "true" : "false"; _sl.CheckSession(); GetStatic.PrintMessage(this); var MethodName = Request.Form["MethodName"]; if (!IsPostBack) { Authenticate(); PopulateDdl(); if (MethodName == "GetAddressDetailsByZipCode") { GetAddressDetailsByZipCode(); } } } private void Authenticate() { _sl.CheckAuthentication(ViewFunctionId); string eId = GetStatic.ReadQueryString("customerId", ""); var hasRight = false; hasRight = _sl.HasRight(AddFunctionId); register.Enabled = hasRight; register.Visible = hasRight; } public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin) { return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent; } 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.."); } private void GetAddressDetailsByZipCode() { string zipCode = Request.Form["zipCode"]; if (!Regex.Match(zipCode, @"^\d{7}?$").Success) { GetStatic.JsonResponse(false, Page); }; HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://yubin.senmon.net/en/" + zipCode + ".html"); myRequest.Method = WebRequestMethods.Http.Get; WebResponse response = myRequest.GetResponse(); string json = null; using (Stream stream = response.GetResponseStream()) { json = (new StreamReader(stream)).ReadToEnd(); } int length = (json.Length) / 4; int indexOfTable = json.IndexOf(""); int indexOfTableEnd = json.IndexOf(" Convert.ToDouble(maxFileSize)) { fName = "File size is too large"; ErrorCode = 1; } else { //generate filename string fileExtension = new FileInfo(doc.FileName).Extension; string fileName = customerId + "_" + documentName + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + "_" + registerDate.Replace("-", "_") + fileExtension; fName = fileName; string tempFilePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\TempFiles\\"; //save file string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + registerDate.Replace("-", "\\") + "\\" + membershipId; if (!Directory.Exists(tempFilePath)) Directory.CreateDirectory(tempFilePath); doc.SaveAs(tempFilePath + fileName); if (!Directory.Exists(path)) Directory.CreateDirectory(path); //reduce file size using (Bitmap bitmapObj = new Bitmap(tempFilePath + fileName)) { var fileProp = System.Drawing.Image.FromFile(tempFilePath + fileName); Bitmap reduceBitmapImg = new Bitmap(bitmapObj, fileProp.Width / 3, fileProp.Height / 3); reduceBitmapImg.Save(path + "/" + fileName, ImageFormat.Jpeg); fileProp.Dispose(); } //delete file File.Delete(tempFilePath + fileName); } } catch (Exception ex) { fName = ex.Message; ErrorCode = 1; } return fName; } public void UploadSignatureImage(string imageData, string registerDate, string membershipId, string customerId, out int errorCode) { try { errorCode = 0; 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.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(imageData); bw.Write(data); bw.Close(); } } } catch (Exception) { errorCode = 1; } } } }