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.

262 lines
10 KiB

  1. using Swift.DAL.OnlineAgent;
  2. using Swift.DAL.SwiftDAL;
  3. using Swift.web.Component.Grid;
  4. using Swift.web.Component.Grid.gridHelper;
  5. using Swift.web.Library;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.IO;
  10. using System.Web;
  11. namespace Swift.web.Remit.Administration.DeleteDocument
  12. {
  13. public partial class CustomerDocument : System.Web.UI.Page
  14. {
  15. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  16. private readonly OnlineCustomerDao _cd = new OnlineCustomerDao();
  17. private readonly SwiftGrid _grid = new SwiftGrid();
  18. private const string ViewFunctionId = "10112300";
  19. private const string DeleteFunctionId = "10112310";
  20. private const string GridName = "grid_list_doc_delete";
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. Authenticate();
  24. GetStatic.PrintMessage(Page);
  25. if (!IsPostBack)
  26. {
  27. DDLPopulate();
  28. if (GetCustomerId() == "")
  29. {
  30. GetStatic.CallBackJs1(Page, "hideDive", "HideFormDisplay()");
  31. }
  32. else
  33. {
  34. string customerId = GetStatic.ReadQueryString("customerId", "");
  35. var customerName = GetCustomerName(customerId);
  36. string custInfo = customerId + "," + customerName;
  37. GetStatic.CallBackJs1(Page, "customerDoc", "PopulateAutoComplete('" + custInfo + "')");
  38. }
  39. }
  40. DeleteRow();
  41. LoadGrid();
  42. }
  43. protected void clickBtnForGetCustomerDetails_Click(object sender, EventArgs e)
  44. {
  45. LoadGrid();
  46. }
  47. private void Authenticate()
  48. {
  49. _sl.CheckAuthentication(ViewFunctionId);
  50. }
  51. private void LoadGrid()
  52. {
  53. string cusId = GetCustomerId();
  54. if (cusId == "")
  55. {
  56. return;
  57. }
  58. var dr = _cd.GetCustomerDetails(cusId, GetStatic.GetUser());
  59. customerName.InnerText = dr["fullName"].ToString();
  60. hdnMembershipId.Value = dr["membershipId"].ToString();
  61. hdnRegisterDate.Value = Convert.ToDateTime(dr["createdDate"]).ToString("yyyy/MM/dd");
  62. _grid.FilterList = new List<GridFilter>
  63. {
  64. new GridFilter("fileType", "Document Type", "1:EXEC proc_online_dropDownList @flag='dropdownGridList',@parentId='8103'"),
  65. new GridFilter("fileDescription", "File Description", "T"),
  66. new GridFilter("createdDate", "Created Date", "d"),
  67. };
  68. _grid.ColumnList = new List<GridColumn>
  69. {
  70. new GridColumn("SN", "SN", "", "T"),
  71. //new GridColumn("sessionId", "Filing No.", "", ""),
  72. new GridColumn("fileName", "File Name", "", "T"),
  73. new GridColumn("fileType", "File Type", "", "T"),
  74. new GridColumn("fileDescription", "File Description", "", "T"),
  75. new GridColumn("documentTypeName", "Document Type", "", "T"),
  76. new GridColumn("createdBy", "Created By", "", "T"),
  77. new GridColumn("createdDate","Uploaded Date","","D"),
  78. };
  79. _grid.GridType = 1;
  80. _grid.GridDataSource = SwiftGrid.GridDS.RemittanceDB;
  81. _grid.GridName = GridName;
  82. _grid.ShowPagingBar = true;
  83. //_grid.ShowAddButton = _sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId));
  84. _grid.ShowAddButton = false;
  85. _grid.AlwaysShowFilterForm = true;
  86. _grid.ShowFilterForm = true;
  87. _grid.SortOrder = "ASC";
  88. _grid.RowIdField = "cdId";
  89. _grid.AllowDelete = false; //_sl.HasRight(DeleteFunctionId);
  90. _grid.InputPerRow = 4;
  91. if (ReqFromCustDetail() == "true")
  92. {
  93. _grid.AddPage = "CustomerDocument.aspx?fromCustDetail=true&customerId=" + cusId;
  94. }
  95. else
  96. {
  97. _grid.AddPage = "CustomerDocument.aspx?customerId=" + cusId;
  98. }
  99. _grid.GridMinWidth = 700;
  100. _grid.GridWidth = 100;
  101. _grid.IsGridWidthInPercent = true;
  102. _grid.AllowCustomLink = true;
  103. _grid.CustomLinkVariables = "cdId,customerId,fileType";
  104. var uploadLink = "";
  105. 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>";
  106. if (_sl.HasRight(DeleteFunctionId))
  107. 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>";
  108. _grid.CustomLinkText = uploadLink;
  109. string sql = "EXEC [proc_customerDocumentType] @flag = 's',@customerId='" + cusId + "' ";
  110. _grid.SetComma();
  111. rpt_grid.InnerHtml = _grid.CreateGrid(sql);
  112. }
  113. public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin)
  114. {
  115. return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent;
  116. }
  117. private void DDLPopulate()
  118. {
  119. _sl.SetDDL(ref ddlSearchBy, "exec proc_sendPageLoadData @flag='search-cust-by'", "VALUE", "TEXT", "", "");
  120. }
  121. private string GetCustomerId()
  122. {
  123. string customerId = hdncustomerId.Value;
  124. if (customerId == "")
  125. customerId = GetStatic.ReadQueryString("customerId", "");
  126. hdncustomerId.Value = customerId;
  127. return customerId;
  128. }
  129. private string GetCustomerDocumentId()
  130. {
  131. string customerDocId = GetStatic.ReadQueryString("cdId", "");
  132. if (customerDocId == "")
  133. customerDocId = hdnDocumentTypeId.Value;
  134. return customerDocId;
  135. }
  136. protected string GetCustomerName(string cusId)
  137. {
  138. OnlineCustomerDao _cd = new OnlineCustomerDao();
  139. var dr = _cd.GetCustomerDetails(cusId, GetStatic.GetUser());
  140. return dr["fullName"].ToString();
  141. }
  142. protected void test_Click(object sender, EventArgs e)
  143. {
  144. LoadGrid();
  145. }
  146. protected string ReqFromCustDetail()
  147. {
  148. var a = GetStatic.ReadQueryString("hideSearchDiv", "");
  149. hideSearchDiv.Value = a;
  150. return a;
  151. }
  152. private void DeleteRow()
  153. {
  154. string id = _grid.GetCurrentRowId(GridName);
  155. if (string.IsNullOrEmpty(id))
  156. return;
  157. DbResult dbResult = _cd.DeleteCustomerDocument(id, GetStatic.GetUser());
  158. ManageMessage(dbResult);
  159. }
  160. private void ManageMessage(DbResult dbResult)
  161. {
  162. GetStatic.SetMessage(dbResult);
  163. if (GetMode() == 1)
  164. GetStatic.AlertMessage(Page);
  165. else
  166. GetStatic.PrintMessage(Page);
  167. }
  168. protected long GetMode()
  169. {
  170. return GetStatic.ReadNumericDataFromQueryString("mode");
  171. }
  172. protected void delete_Click(object sender, EventArgs e)
  173. {
  174. var id = hdnRowId.Value;
  175. DataRow docDetais = _cd.GetCustomerDocPathData(id, "doc-path", GetStatic.GetUser());
  176. if (docDetais == null)
  177. {
  178. GetStatic.AlertMessage(this, "Invalid document, no customer data found!");
  179. return;
  180. }
  181. Exception ex = null;
  182. if (MoveDocument(docDetais, out ex))
  183. {
  184. DbResult dbResult = _cd.DeleteCustomerDocument(id, GetStatic.GetUser());
  185. if (dbResult.ErrorCode == "0")
  186. {
  187. GetStatic.SetMessage(dbResult);
  188. LoadGrid();
  189. GetStatic.AlertMessage(this, dbResult.Msg);
  190. }
  191. else
  192. {
  193. HttpContext.Current.Session["message"] = dbResult;
  194. GetStatic.AlertMessage(this, dbResult.Msg);
  195. }
  196. }
  197. else
  198. {
  199. string s = ex.Message.Replace("'", "\"").Replace("\\", "|").Replace("\r\n", "").Replace("\n", "");
  200. GetStatic.AlertMessage(this, "Exception occured while moving Doc: " + s);
  201. }
  202. }
  203. private bool MoveDocument(DataRow docDetais, out Exception exception)
  204. {
  205. try
  206. {
  207. string filePath = docDetais["docPath"].ToString();
  208. string fileName = docDetais["fileName"].ToString();
  209. string sourcePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + filePath.Split('|')[2].Replace("-", "\\") + "\\" + filePath.Split('|')[1];
  210. string targetPath = sourcePath + "\\deleted";
  211. if (docDetais["filedescription"].ToString() == "Compliance Document")
  212. sourcePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + filePath.Split('|')[2].Replace("-", "\\") + "\\" + filePath.Split('|')[1] + "\\ComplianceDocument\\";
  213. string sourceFile = Path.Combine(sourcePath, fileName);
  214. string destFile = Path.Combine(targetPath, fileName);
  215. if (!Directory.Exists(targetPath))
  216. {
  217. Directory.CreateDirectory(targetPath);
  218. }
  219. if (!File.Exists(destFile))
  220. File.Move(sourceFile, destFile);
  221. exception = null;
  222. return true;
  223. }
  224. catch (Exception ex)
  225. {
  226. exception = ex;
  227. return false;
  228. }
  229. }
  230. }
  231. }