using Swift.DAL.BL.System.UserManagement; using Swift.DAL.OnlineAgent; using Swift.DAL.SwiftDAL; using Swift.web.Component.Grid; using Swift.web.Component.Grid.gridHelper; using Swift.web.Library; using System; using System.Collections.Generic; using System.IO; using System.Web.UI.WebControls; namespace Swift.web.Remit.Administration.CustomerRegistration { public partial class CustomerDocument : System.Web.UI.Page { private readonly RemittanceLibrary _sl = new RemittanceLibrary(); private readonly OnlineCustomerDao _cd = new OnlineCustomerDao(); private readonly SwiftGrid _grid = new SwiftGrid(); private const string ViewFunctionId = "20208000"; private const string UploadDocFunctionId = "20208010"; private const string ViewFunctionIdAgent = ""; private const string UploadDocFunctionIdAgent = ""; private const string ViewDocFunctionIdAgent = "20205010"; private const string ViewDocFunctionId = "20208020"; private const string GridName = "grid_list"; protected void Page_Load(object sender, EventArgs e) { Authenticate(); downloadFile.Visible = false; GetStatic.PrintMessage(Page); if (!IsPostBack) { DDLPopulate(); if (GetCustomerDocumentId() != "") { populateForm(); } else { //fileDisplay.ImageUrl = "/Remit/GetFileView.ashx?imageName="; if (GetCustomerId() == "") { GetStatic.CallBackJs1(Page, "hideDive", "HideFormDisplay()"); } else { string customerId = GetStatic.ReadQueryString("customerId", ""); var customerName = GetCustomerName(customerId); string custInfo = customerId + "," + customerName; GetStatic.CallBackJs1(Page, "customerDoc", "PopulateAutoComplete('" + custInfo + "')"); } } //if (ReqFromCustDetail() == "true") //{ // GetStatic.CallBackJs1(Page, "customerDoc", "HideSearchDiv()"); //} } DeleteRow(); LoadGrid(); } private void Authenticate() { _sl.CheckAuthentication(GetFunctionIdByUserType(ViewFunctionIdAgent, ViewFunctionId) + "," + GetFunctionIdByUserType(ViewDocFunctionIdAgent, ViewDocFunctionId)); var hasRight = _sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId)); saveDocument.Enabled = hasRight; saveDocument.Visible = hasRight; } private void LoadGrid() { string cusId = GetCustomerId(); if (cusId == "") { return; } var dr = _cd.GetCustomerDetails(cusId, GetStatic.GetUser()); customerName.InnerText = dr["fullName"].ToString(); hdnMembershipId.Value = dr["membershipId"].ToString(); hdnRegisterDate.Value = Convert.ToDateTime(dr["createdDate"]).ToString("yyyy/MM/dd"); _grid.FilterList = new List { new GridFilter("fileType", "Document Type", "1:EXEC proc_online_dropDownList @flag='dropdownGridList',@parentId='8103'"), new GridFilter("fileDescription", "File Description", "T"), new GridFilter("createdDate", "Created Date", "d"), }; _grid.ColumnList = new List { new GridColumn("SN", "SN", "", "T"), //new GridColumn("sessionId", "Filing No.", "", ""), new GridColumn("fileName", "File Name", "", "T"), new GridColumn("fileType", "File Type", "", "T"), new GridColumn("fileDescription", "File Description", "", "T"), new GridColumn("documentTypeName", "Document Type", "", "T"), new GridColumn("createdBy", "Created By", "", "T"), new GridColumn("createdDate","Uploaded Date","","D"), }; _grid.GridType = 1; _grid.GridDataSource = SwiftGrid.GridDS.RemittanceDB; _grid.GridName = GridName; _grid.ShowPagingBar = true; //_grid.ShowAddButton = _sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId)); _grid.ShowAddButton = false; _grid.AlwaysShowFilterForm = true; _grid.ShowFilterForm = true; _grid.SortOrder = "ASC"; _grid.RowIdField = "cdId"; _grid.AllowDelete = false; _grid.InputPerRow = 4; if (ReqFromCustDetail() == "true") { _grid.AddPage = "CustomerDocument.aspx?fromCustDetail=true&customerId=" + cusId; } else { _grid.AddPage = "CustomerDocument.aspx?customerId=" + cusId; } _grid.GridMinWidth = 700; _grid.GridWidth = 100; _grid.IsGridWidthInPercent = true; _grid.AllowCustomLink = true; _grid.CustomLinkVariables = "cdId,customerId,fileType,fileDescription"; //var uploadLink = _sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId)) ? "" : ""; var uploadLink = ""; _grid.CustomLinkText = uploadLink + " "; string sql = "EXEC [proc_customerDocumentType] @flag = 's',@customerId='" + cusId + "' "; _grid.SetComma(); rpt_grid.InnerHtml = _grid.CreateGrid(sql); } public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin) { return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent; } private void DDLPopulate() { _sl.SetDDL(ref ddlDocumentType, "EXEC proc_online_dropDownList @flag='dropdownList',@parentId='8103'", "valueId", "detailTitle", ddlDocumentType.SelectedValue, "Select.."); _sl.SetDDL(ref ddlSearchBy, "exec proc_sendPageLoadData @flag='search-cust-by'", "VALUE", "TEXT", "", ""); } private string GetCustomerId() { string customerId = hdncustomerId.Value; if (customerId == "") customerId = GetStatic.ReadQueryString("customerId", ""); hdncustomerId.Value = customerId; return customerId; } private string GetCustomerDocumentId() { string customerDocId = GetStatic.ReadQueryString("cdId", ""); if (customerDocId == "") customerDocId = hdnDocumentTypeId.Value; return customerDocId; } private void populateForm() { msgDiv.Visible = false; if (GetCustomerDocumentId() == "") return; hdnDocumentTypeId.Value = GetCustomerDocumentId(); var dr = _cd.GetCustomerDocumentByDocumentId(GetCustomerDocumentId(), GetStatic.GetUser()); if (dr["fileType"].ToString() == "signature") { //saveDocument.Enabled = false; hdnDocumentTypeId.Value = ""; GetStatic.AlertMessage(this, "Signature cannot be edited"); return; } saveDocument.Enabled = true; txtSearchData.Value = dr["customerId"].ToString(); txtSearchData.Text = dr["fullName"].ToString(); if (dr != null) { hdnDocumentTypeId.Value = dr["cdId"].ToString(); hdncustomerId.Value = dr["customerId"].ToString(); hdnFileName.Value = dr["fileName"].ToString(); ddlDocumentType.SelectedValue = dr["documentType"].ToString(); txtDocumentDescription.Text = dr["fileDescription"].ToString(); hdnMembershipId.Value = dr["membershipId"].ToString(); hdnFileType.Value = dr["fileType"].ToString(); //if (dr["fileName"].ToString() != "") // fileDisplay.ImageUrl = "/Remit/GetFileView.ashx?imageName=" + dr["fileName"] + "&customerId=" + hdnMembershipId.Value + "&fileType=" + dr["fileType"].ToString(); downloadFile.Visible = true; } } protected void saveDocument_Click(object sender, EventArgs e) { if (hdncustomerId.ToString() == "" || hdncustomerId.ToString() == null) { GetStatic.AlertMessage(this, "Please choose customer first"); } DbResult _dbRes = new DbResult(); if (!_sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId))) { _dbRes.SetError("1", "You are not authorized to Update Data", null); GetStatic.AlertMessage(this, _dbRes.Msg); return; } string fileType = ""; string fileName = (!string.IsNullOrWhiteSpace(fileDocument.FileName) ? UploadDocument(fileDocument, ddlDocumentType.SelectedValue, out fileType) : hdnFileName.Value); if (fileName == "invalidSize") { GetStatic.AlertMessage(this, "File size exceeded for passport. Please upload image of size less than 2mb."); return; } else if (fileName == "VideoFormat") { if (ddlDocumentType.SelectedValue == "11398" || ddlDocumentType.SelectedValue == "11399" || ddlDocumentType.SelectedValue == "11400") { GetStatic.AlertMessage(this, "Only " + GetStatic.ReadWebConfig("customerDocFileExtensionForOtherDoc", "") + " files are allowed"); } else { GetStatic.AlertMessage(this, "Only " + GetStatic.ReadWebConfig("customerDocFileExtension", "") + " files are allowed"); } return; } string custId = GetCustomerId(); hdncustomerId.Value = hdncustomerId.Value == "" ? custId : hdncustomerId.Value; var result = _cd.UpdateCustomerDocument(hdnDocumentTypeId.Value, hdncustomerId.Value, fileName, txtDocumentDescription.Text, fileType, ddlDocumentType.SelectedValue, GetStatic.GetUser()); if (result.ErrorCode == "0") { GetStatic.AlertMessage(this, result.Msg); string custInfo = hdncustomerId.Value + "," + (hdncustomerName.Value == "" ? GetCustomerName(custId) : hdncustomerName.Value) + "," + result.Msg; GetStatic.CallBackJs1(Page, "customerDoc", "PopulateAutoComplete('" + custInfo + "')"); LoadGrid(); return; } else { GetStatic.AlertMessage(this, result.Msg); return; } } private string UploadDocument(FileUpload doc, string documentTypeName, out string fileType) { fileType = ""; string fName = ""; string documentExtension = ""; try { fileType = doc.PostedFile.ContentType; //if (doc.PostedFile.ContentLength > Convert.ToDouble(maxFileSize)) if (false) { fName = "invalidSize"; } else { string fileExtension = new FileInfo(doc.PostedFile.FileName).Extension; //if (documentTypeName.ToLower() == "11404") if (documentTypeName.ToLower() == "11398" || documentTypeName.ToLower() == "11399" || documentTypeName.ToLower() == "11400") { documentExtension = GetStatic.ReadWebConfig("customerDocFileExtensionForOtherDoc", ""); } else { documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", ""); } if (documentExtension.ToLower().Contains(fileExtension.ToLower())) { string fileName = hdncustomerId.Value + "_" + ddlDocumentType.SelectedItem.Text + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + "_" + hdnRegisterDate.Value.Replace("/", "_") + fileExtension; //fileName = Regex.Replace(fileName, @"[;,/:\t\r ]|[\n]{2}", "_"); string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + hdnRegisterDate.Value.Replace("_", "\\") + "\\" + hdnMembershipId.Value; if (!Directory.Exists(path)) Directory.CreateDirectory(path); doc.SaveAs(path + "/" + fileName); fName = fileName; } else { fName = "VideoFormat"; } } } catch (Exception ex) { fName = ""; } return fName; } protected void downloadFile_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(hdnFileName.Value) && string.IsNullOrWhiteSpace(hdnFileName.Value)) return; var dirLocation = hdnFileName.Value.Split('_')[3].ToString() + "\\" + hdnFileName.Value.Split('_')[4].ToString() + "\\" + hdnFileName.Value.Split('_')[5].Split('.')[0].ToString() + "\\"; var path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + dirLocation + hdnMembershipId.Value + "\\" + hdnFileName.Value; if (!File.Exists(path)) { msgDiv.Visible = true; msgLabel.Text = "File Not Found"; Page_Load(sender, e); return; } FileInfo ObjArchivo = new FileInfo(path); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + hdnFileName.Value); Response.AddHeader("Content-Length", ObjArchivo.Length.ToString()); Response.ContentType = hdnFileType.Value; Response.WriteFile(ObjArchivo.FullName); Response.End(); } catch (Exception ex) { throw ex; } } protected void clickBtnForGetCustomerDetails_Click(object sender, EventArgs e) { downloadFile.Visible = false; //fileDisplay.ImageUrl = "/Remit/GetFileView.ashx?imageName=" + hdnFileName.Value + "&customerId=" + hdnMembershipId.Value + "&fileType=" + hdnFileType.Value; LoadGrid(); populateForm(); } protected void clickEditCustomerDocument_Click(object sender, EventArgs e) { populateForm(); //string customerId = GetStatic.ReadQueryString("customerId", ""); //if (customerId != "") //{ // GetStatic.CallBackJs1(Page, "Hide Search Div", "HideSearchDiv()"); //} } protected string GetCustomerName(string cusId) { OnlineCustomerDao _cd = new OnlineCustomerDao(); var dr = _cd.GetCustomerDetails(cusId, GetStatic.GetUser()); return dr["fullName"].ToString(); } protected void test_Click(object sender, EventArgs e) { LoadGrid(); } protected string ReqFromCustDetail() { var a = GetStatic.ReadQueryString("hideSearchDiv", ""); hideSearchDiv.Value = a; return a; } private void DeleteRow() { string id = _grid.GetCurrentRowId(GridName); if (string.IsNullOrEmpty(id)) return; DbResult dbResult = _cd.DeleteCustomerDoc(id, GetStatic.GetUser()); ManageMessage(dbResult); } private void ManageMessage(DbResult dbResult) { GetStatic.SetMessage(dbResult); if (GetMode() == 1) GetStatic.AlertMessage(Page); else GetStatic.PrintMessage(Page); } protected long GetMode() { return GetStatic.ReadNumericDataFromQueryString("mode"); } } }