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.
 
 
 
 
 

263 lines
10 KiB

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.Remit.Administration.DeleteDocument
{
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 = "10112300";
private const string DeleteFunctionId = "10112310";
private const string GridName = "grid_list_doc_delete";
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 == "")
{
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<GridFilter>
{
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<GridColumn>
{
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; //_sl.HasRight(DeleteFunctionId);
_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";
var uploadLink = "";
uploadLink = "&nbsp;<btn type=\"button\" class=\"btn btn-xs btn-default\" data-toggle=\"tooltip\" data-placement=\"top\" title = \"View\" onclick=\"showDocument(@cdId,'@fileType');\"><i class=\"fa fa-eye\"></i></btn>";
if (_sl.HasRight(DeleteFunctionId))
uploadLink += "&nbsp<btn class=\"btn btn-xs btn-danger\" onclick=\"Delete('@cdId')\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Delete\"> <i class=\"fa fa-trash\"></i></btn>";
_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 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", 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.DeleteCustomerDocument(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("\\", "|").Replace("\r\n", "").Replace("\n", "");
GetStatic.AlertMessage(this, "Exception occured while moving Doc: " + s);
}
}
private bool MoveDocument(DataRow docDetais, out Exception exception)
{
try
{
string filePath = docDetais["docPath"].ToString();
string fileName = docDetais["fileName"].ToString();
string sourcePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + filePath.Split('|')[2].Replace("-", "\\") + "\\" + filePath.Split('|')[1];
string targetPath = sourcePath + "\\deleted";
if (docDetais["filedescription"].ToString() == "Compliance Document")
sourcePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + filePath.Split('|')[2].Replace("-", "\\") + "\\" + filePath.Split('|')[1] + "\\ComplianceDocument\\";
string sourceFile = Path.Combine(sourcePath, fileName);
string destFile = Path.Combine(targetPath, fileName);
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
if (!File.Exists(destFile))
File.Move(sourceFile, destFile);
exception = null;
return true;
}
catch (Exception ex)
{
exception = ex;
return false;
}
}
}
}