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.

320 lines
15 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.IO;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.UI;
  12. using System.Web.UI.WebControls;
  13. namespace Swift.web.AgentNew.Administration.CustomerSetup.CustomerRegistration
  14. {
  15. public partial class CustomerDocument : System.Web.UI.Page
  16. {
  17. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  18. private readonly OnlineCustomerDao _cd = new OnlineCustomerDao();
  19. private readonly SwiftGrid _grid = new SwiftGrid();
  20. private const string ViewFunctionId = "20111300";
  21. private const string ViewFunctionIdAgent = "20205000";
  22. private const string ViewDocFunctionId = "20111330";
  23. private const string UploadDocFunctionId = "20111340";
  24. private const string ViewDocFunctionIdAgent = "20205010";
  25. private const string UploadDocFunctionIdAgent = "20205020";
  26. private const string GridName = "grid_list";
  27. protected void Page_Load(object sender, EventArgs e)
  28. {
  29. Authenticate();
  30. downloadFile.Visible = false;
  31. if (!IsPostBack)
  32. {
  33. HideSearchDiv();
  34. GetStatic.PrintMessage(Page);
  35. DDLPopulate();
  36. //fileDisplay.ImageUrl = "../../../GetFileView.ashx?imageName=";
  37. }
  38. if (GetCustomerId() != "")
  39. {
  40. LoadGrid();
  41. }
  42. else
  43. {
  44. GetStatic.CallBackJs1(Page, "hideDive", "HideFormDisplay()");
  45. }
  46. }
  47. private void HideSearchDiv()
  48. {
  49. string hide = GetStatic.ReadQueryString("hideSearchDiv", "").ToString();
  50. if (hide == "true")
  51. {
  52. displayOnlyOnEdit.Visible = false;
  53. hideSearchDiv.Value = "true";
  54. }
  55. }
  56. private void Authenticate()
  57. {
  58. _sl.CheckAuthentication(GetFunctionIdByUserType(ViewFunctionIdAgent, ViewFunctionId) + "," + GetFunctionIdByUserType(ViewDocFunctionIdAgent, ViewDocFunctionId));
  59. var hasRight = _sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId));
  60. saveDocument.Enabled = hasRight;
  61. saveDocument.Visible = hasRight;
  62. }
  63. private void LoadGrid()
  64. {
  65. string cusId = GetCustomerId();
  66. if (cusId == "")
  67. {
  68. return;
  69. }
  70. var dr = _cd.GetCustomerDetails(cusId, GetStatic.GetUser());
  71. customerName.InnerText = dr["fullName"].ToString();
  72. hdnMembershipId.Value = dr["membershipId"].ToString();
  73. hdnRegisterDate.Value = Convert.ToDateTime(dr["createdDate"]).ToString("yyyy/MM/dd");
  74. _grid.FilterList = new List<GridFilter>
  75. {
  76. new GridFilter("fileType", "File Type", "1:EXEC proc_online_dropDownList @flag='dropdownGridList',@parentId='8103'"),
  77. new GridFilter("fileDescription", "File Description", "T"),
  78. new GridFilter("createdDate", "Created Date", "d"),
  79. };
  80. _grid.ColumnList = new List<GridColumn>
  81. {
  82. new GridColumn("SN", "SN", "", "T"),
  83. new GridColumn("fileName", "File Name", "", "T"),
  84. new GridColumn("fileType", "File Type", "", "T"),
  85. new GridColumn("fileDescription", "File Description", "", "T"),
  86. new GridColumn("documentTypeName", "Document Type", "", "T"),
  87. new GridColumn("createdBy", "Created By", "", "T"),
  88. new GridColumn("createdDate","Uploaded Date","","D"),
  89. };
  90. _grid.GridType = 1;
  91. _grid.GridDataSource = SwiftGrid.GridDS.RemittanceDB;
  92. _grid.GridName = GridName;
  93. _grid.ShowPagingBar = true;
  94. _grid.AlwaysShowFilterForm = true;
  95. _grid.ShowFilterForm = true;
  96. _grid.SortOrder = "ASC";
  97. _grid.RowIdField = "cdId";
  98. _grid.InputPerRow = 4;
  99. _grid.AddPage = "CustomerDocument.aspx?customerId=" + cusId;
  100. _grid.GridMinWidth = 700;
  101. _grid.GridWidth = 100;
  102. _grid.IsGridWidthInPercent = true;
  103. _grid.AllowCustomLink = true;
  104. _grid.CustomLinkVariables = "cdId,customerId,fileType";
  105. var uploadLink = "";// _sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId)) ? "<btn type=\"button\" class=\"btn btn-xs btn-default\" data-toggle=\"tooltip\" data-placement=\"top\" title = \"Edit\" onclick=\"editPage(@cdId);\"><i class=\"fa fa-edit\" ></i></btn>" : "";
  106. _grid.CustomLinkText = 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>";
  107. string sql = "EXEC [proc_customerDocumentType] @flag = 's',@customerId='" + cusId + "' ";
  108. _grid.SetComma();
  109. rpt_grid.InnerHtml = _grid.CreateGrid(sql);
  110. }
  111. public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin)
  112. {
  113. return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent;
  114. }
  115. private void DDLPopulate()
  116. {
  117. _sl.SetDDL(ref ddlDocumentType, "EXEC proc_online_dropDownList @flag='dropdownList',@parentId='8103'", "valueId", "detailTitle", ddlDocumentType.SelectedValue, "Select..");
  118. _sl.SetDDL(ref ddlSearchBy, "exec proc_sendPageLoadData @flag='search-cust-by'", "VALUE", "TEXT", "", "");
  119. }
  120. private string GetCustomerId()
  121. {
  122. string customerId = GetStatic.ReadQueryString("customerId", "");
  123. if (customerId == "")
  124. customerId = hdncustomerId.Value;
  125. return customerId;
  126. }
  127. private string GetCustomerDocumentId()
  128. {
  129. string customerDocId = GetStatic.ReadQueryString("cdId", "");
  130. if (customerDocId == "")
  131. customerDocId = hdnDocumentTypeId.Value;
  132. return customerDocId;
  133. }
  134. private void populateForm()
  135. {
  136. msgDiv.Visible = false;
  137. if (GetCustomerDocumentId() == "")
  138. return;
  139. var dr = _cd.GetCustomerDocumentByDocumentId(GetCustomerDocumentId(), GetStatic.GetUser());
  140. if (dr["fileType"].ToString() == "signature")
  141. {
  142. //saveDocument.Enabled = false;
  143. hdnDocumentTypeId.Value = "";
  144. GetStatic.AlertMessage(this, "Sorry signature cannot be edited");
  145. return;
  146. }
  147. saveDocument.Enabled = true;
  148. txtSearchData.Value = dr["customerId"].ToString();
  149. txtSearchData.Text = dr["fullName"].ToString();
  150. if (dr != null)
  151. {
  152. hdnDocumentTypeId.Value = dr["cdId"].ToString();
  153. hdncustomerId.Value = dr["customerId"].ToString();
  154. hdnFileName.Value = dr["fileName"].ToString();
  155. ddlDocumentType.SelectedValue = dr["documentType"].ToString();
  156. txtDocumentDescription.Text = dr["fileDescription"].ToString();
  157. hdnMembershipId.Value = dr["membershipId"].ToString();
  158. hdnFileType.Value = dr["fileType"].ToString();
  159. //if (dr["fileName"].ToString() != "")
  160. // fileDisplay.ImageUrl = "../../../GetFileView.ashx?imageName=" + dr["fileName"] + "&customerId=" + hdnMembershipId.Value + "&fileType=" + dr["fileType"].ToString();
  161. downloadFile.Visible = true;
  162. }
  163. }
  164. protected void saveDocument_Click(object sender, EventArgs e)
  165. {
  166. if (hdncustomerId.ToString() == "" || hdncustomerId.ToString() == null)
  167. {
  168. GetStatic.AlertMessage(this, "Please choose customer first");
  169. }
  170. DbResult _dbRes = new DbResult();
  171. if (!_sl.HasRight(GetFunctionIdByUserType(UploadDocFunctionIdAgent, UploadDocFunctionId)))
  172. {
  173. _dbRes.SetError("1", "You are not authorized to Update Data", null);
  174. GetStatic.AlertMessage(this, _dbRes.Msg);
  175. return;
  176. }
  177. string fileType = "";
  178. string fileName = (!string.IsNullOrWhiteSpace(fileDocument.FileName) ? UploadDocument(fileDocument, ddlDocumentType.SelectedValue, out fileType) : hdnFileName.Value);
  179. if (fileName == "invalidSize")
  180. {
  181. GetStatic.AlertMessage(this, "File size exceeded for passport. Please upload image of size less than 2mb.");
  182. return;
  183. }
  184. else if (fileName == "notValid")
  185. {
  186. if (ddlDocumentType.SelectedValue == "11398" || ddlDocumentType.SelectedValue == "11399" || ddlDocumentType.SelectedValue == "11400")
  187. {
  188. GetStatic.AlertMessage(this, "Only " + GetStatic.ReadWebConfig("customerDocFileExtensionForOtherDoc", "") + " files are allowed");
  189. }
  190. else
  191. {
  192. GetStatic.AlertMessage(this, "Only " + GetStatic.ReadWebConfig("customerDocFileExtension", "") + " files are allowed");
  193. }
  194. return;
  195. }
  196. string custId = GetCustomerId();
  197. hdncustomerId.Value = hdncustomerId.Value == "" ? custId : hdncustomerId.Value;
  198. var result = _cd.UpdateCustomerDocument(hdnDocumentTypeId.Value, hdncustomerId.Value, fileName, txtDocumentDescription.Text, fileType, ddlDocumentType.SelectedValue, GetStatic.GetUser());
  199. if (result.ErrorCode == "0")
  200. {
  201. //GetStatic.SetMessage(result);
  202. ////Response.Redirect("CustomerDocument.aspx?customerId=" + hdncustomerId.Value);
  203. //Response.Redirect("CustomerDocument.aspx");
  204. GetStatic.AlertMessage(this, result.Msg);
  205. ddlDocumentType.Text = "";
  206. txtDocumentDescription.Text = "";
  207. string custInfo = hdncustomerId.Value + "," + (hdncustomerName.Value == "" ? GetCustomerName(custId) : hdncustomerName.Value) + "," + result.Msg;
  208. GetStatic.CallBackJs1(Page, "customerDoc", "PopulateAutoComplete('" + custInfo + "')");
  209. LoadGrid();
  210. return;
  211. }
  212. else
  213. {
  214. GetStatic.AlertMessage(this, result.Msg);
  215. return;
  216. }
  217. }
  218. private string UploadDocument(FileUpload doc, string documentTypeName, out string fileType)
  219. {
  220. fileType = "";
  221. string fName = "";
  222. string documentExtension = "";
  223. try
  224. {
  225. fileType = doc.PostedFile.ContentType;
  226. string fileExtension = new FileInfo(doc.PostedFile.FileName).Extension;
  227. //if (documentTypeName.ToLower() == "11404")
  228. if (documentTypeName.ToLower() == "11398" || documentTypeName.ToLower() == "11399" || documentTypeName.ToLower() == "11400")
  229. {
  230. documentExtension = GetStatic.ReadWebConfig("customerDocFileExtensionForOtherDoc", "");
  231. }
  232. else
  233. {
  234. documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", "");
  235. }
  236. if (documentExtension.ToLower().Contains(fileExtension.ToLower()))
  237. {
  238. string fileName = hdncustomerId.Value + "_" + ddlDocumentType.SelectedItem.Text + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + "_" + hdnRegisterDate.Value.Replace("/", "_") + fileExtension;
  239. string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + hdnRegisterDate.Value.Replace("_", "\\") + "\\" + hdnMembershipId.Value;
  240. if (!Directory.Exists(path))
  241. Directory.CreateDirectory(path);
  242. doc.SaveAs(path + "/" + fileName);
  243. fName = fileName;
  244. }
  245. else
  246. {
  247. fName = "notValid";
  248. }
  249. }
  250. catch (Exception ex)
  251. {
  252. fName = "";
  253. }
  254. return fName;
  255. }
  256. protected void downloadFile_Click(object sender, EventArgs e)
  257. {
  258. try
  259. {
  260. msgDiv.Visible = false;
  261. if (string.IsNullOrEmpty(hdnFileName.Value) && string.IsNullOrWhiteSpace(hdnFileName.Value) || hdnFileName.Value.Split('_').Count() < 6)
  262. return;
  263. var dirLocation = hdnFileName.Value.Split('_')[3].ToString() + "\\" + hdnFileName.Value.Split('_')[4].ToString() + "\\" + hdnFileName.Value.Split('_')[5].Split('.')[0].ToString() + "\\";
  264. var path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + dirLocation + hdnMembershipId.Value + "\\" + hdnFileName.Value;
  265. if (!File.Exists(path))
  266. {
  267. msgDiv.Visible = true;
  268. msgLabel.Text = "File Not Found";
  269. Page_Load(sender, e);
  270. return;
  271. }
  272. FileInfo ObjArchivo = new FileInfo(path);
  273. Response.Clear();
  274. Response.AddHeader("Content-Disposition", "attachment; filename=" + hdnFileName.Value);
  275. Response.AddHeader("Content-Length", ObjArchivo.Length.ToString());
  276. Response.ContentType = hdnFileType.Value;
  277. Response.WriteFile(ObjArchivo.FullName);
  278. Response.End();
  279. }
  280. catch (Exception ex)
  281. {
  282. throw ex;
  283. }
  284. }
  285. protected void clickBtnForGetCustomerDetails_Click(object sender, EventArgs e)
  286. {
  287. downloadFile.Visible = false;
  288. hdnFileName.Value = null;
  289. //fileDisplay.ImageUrl = "/AgentNew/GetFileView.ashx?imageName=" + hdnFileName.Value + "&customerId=" + hdnMembershipId.Value + "&fileType=" + hdnFileType.Value;
  290. populateForm();
  291. }
  292. protected void clickEditCustomerDocument_Click(object sender, EventArgs e)
  293. {
  294. populateForm();
  295. }
  296. protected string GetCustomerName(string cusId)
  297. {
  298. OnlineCustomerDao _cd = new OnlineCustomerDao();
  299. var dr = _cd.GetCustomerDetails(cusId, GetStatic.GetUser());
  300. return dr["fullName"].ToString();
  301. }
  302. }
  303. }