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.Data; using System.IO; using System.Web; namespace Swift.web.MobileRemit.Agent.RenewID { public partial class Manage : 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 = "10112400"; private const string DeleteFunctionId = "10112420"; private const string ProcessFunctionId = "10112410"; private const string GridName = "grid_list_doc_process"; protected void Page_Load(object sender, EventArgs e) { Authenticate(); GetStatic.PrintMessage(Page); if (!IsPostBack) { DDLPopulate(); 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 + "')"); } } DeleteRow(); LoadGrid(); } protected void clickBtnForGetCustomerDetails_Click(object sender, EventArgs e) { LoadGrid(); } private void Authenticate() { _sl.CheckAuthentication(ViewFunctionId); } private void LoadGrid() { string cusId = GetCustomerId(); if (cusId != "") { 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("documentTypeName", "Document Type", "", "T"), new GridColumn("createdBy", "Uploaded 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 = "rowId"; _grid.AllowDelete = false; //_sl.HasRight(DeleteFunctionId); _grid.InputPerRow = 4; _grid.GridMinWidth = 700; _grid.GridWidth = 100; _grid.IsGridWidthInPercent = true; _grid.AllowCustomLink = true; _grid.CustomLinkVariables = "rowId,customerId"; var uploadLink = ""; uploadLink = " "; if (_sl.HasRight(DeleteFunctionId)) uploadLink += "  "; _grid.CustomLinkText = uploadLink; string sql = "EXEC [proc_customerDocumentType] @flag = 's-id',@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 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; } 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.DeleteCustomerDocument(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"); } protected void delete_Click(object sender, EventArgs e) { var id = hdnRowId.Value; DataRow docDetais = _cd.GetCustomerDocPathData(id, "doc-path-tmp", GetStatic.GetUser()); if (docDetais == null) { GetStatic.AlertMessage(this, "Invalid document, no customer data found!"); return; } Exception ex = null; if (MoveDocument(docDetais, out ex)) { DbResult dbResult = _cd.DeleteCustomerDocumentTmp(id, GetStatic.GetUser()); if (dbResult.ErrorCode == "0") { GetStatic.SetMessage(dbResult); LoadGrid(); GetStatic.AlertMessage(this, dbResult.Msg); } else { HttpContext.Current.Session["message"] = dbResult; GetStatic.AlertMessage(this, dbResult.Msg); } } else { string s = ex.Message.Replace("'", "\"").Replace("\\", "|"); GetStatic.AlertMessage(this, "Exception occured while moving Doc: " + ex.Message.Replace("'", "\"").Replace("\\", "/")); } } private bool MoveDocument(DataRow docDetais, out Exception exception) { try { string filePath = docDetais["docPath"].ToString(); string fileName = docDetais["fileName"].ToString(); string sourcePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\VerifyDocumentUpload\\"; string targetPath = sourcePath + "\\deleted"; string sourceFile = Path.Combine(sourcePath, fileName); string destFile = Path.Combine(targetPath, fileName); if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } File.Move(sourceFile, destFile); exception = null; return true; } catch (Exception ex) { exception = ex; return false; } } } }