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.

130 lines
5.8 KiB

  1. using Swift.DAL.OnlineAgent;
  2. using Swift.web.Library;
  3. using System;
  4. using System.IO;
  5. using System.Text;
  6. namespace Swift.web.Remit.Administration.CustomerRegistration
  7. {
  8. public partial class DocumentView : System.Web.UI.Page
  9. {
  10. private const string ViewFunctionId = "20208000";
  11. private const string ViewDocFunctionId = "20208020";
  12. private const string ViewFunctionIdAgent = "";
  13. private const string ViewDocFunctionIdAgent = "";
  14. private readonly RemittanceLibrary _sl = new RemittanceLibrary();
  15. private readonly OnlineCustomerDao _oC = new OnlineCustomerDao();
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. //Authenticate();
  19. _sl.CheckSession();
  20. if (!IsPostBack)
  21. {
  22. msg.Visible = false;
  23. string cdId = GetStatic.ReadQueryString("cdId", "");
  24. string fileType = GetStatic.ReadQueryString("fileType", "");
  25. string fileDescription = GetStatic.ReadQueryString("fileDescription", "");
  26. var result = _oC.GetCustomerDocumentByDocumentId(cdId, GetStatic.GetUser(), fileDescription);
  27. if (result != null)
  28. {
  29. if (result["fileName"].ToString() != "")
  30. {
  31. var registerDate = result["createdDate"].ToString();
  32. hdnRegDate.Value = registerDate;
  33. var customerId = result["customerId"].ToString();
  34. hdncustomerId.Value = customerId;
  35. var membershipId = result["membershipId"].ToString();
  36. hdnMembershipId.Value = membershipId;
  37. var fileName = result["fileName"].ToString();
  38. hdnFileName.Value = fileName;
  39. var createdBy = result["createdBy"].ToString();
  40. hdnCreatedBy.Value = createdBy;
  41. string imageUrl = "/Handler/CustomerSignature.ashx?fileDesc="+ result["filedescription"].ToString() + "&registerDate=" + Convert.ToDateTime(registerDate).ToString("yyyy-MM-dd") + "&customerId=" + customerId + "&membershipNo=" + membershipId + "&fileName=" + fileName + "&fileDescription=" + fileDescription ;
  42. if (GetFileType() == "application/pdf")
  43. {
  44. pdfDiv.Src = imageUrl;//GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + Convert.ToDateTime(registerDate).ToString("yyyy-MM-dd").Replace("-", "\\") + "\\" + membershipId + "\\" + fileName; ;
  45. pdfDiv.Visible = true;
  46. imageDiv.Visible = false;
  47. }
  48. else if (GetFileType() == "letter" || GetFileType() == "receiver")
  49. {
  50. pdfDiv.Src = imageUrl;//GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + Convert.ToDateTime(registerDate).ToString("yyyy-MM-dd").Replace("-", "\\") + "\\" + membershipId + "\\" + fileName; ;
  51. pdfDiv.Visible = true;
  52. imageDiv.Visible = false;
  53. }
  54. else
  55. {
  56. fileDisplay.ImageUrl = imageUrl;
  57. pdfDiv.Visible = false;
  58. imageDiv.Visible = true;
  59. }
  60. }
  61. if (fileType == "image")
  62. {
  63. downloadFile.Visible = false;
  64. }
  65. else
  66. {
  67. downloadFile.Visible = true;
  68. }
  69. return;
  70. //}
  71. }
  72. msg.InnerText = "File Not Found";
  73. msg.Visible = true;
  74. }
  75. }
  76. private void Authenticate()
  77. {
  78. _sl.CheckAuthentication(GetFunctionIdByUserType(ViewFunctionIdAgent, ViewFunctionId) + "," + GetFunctionIdByUserType(ViewDocFunctionIdAgent, ViewDocFunctionId));
  79. }
  80. public string GetFunctionIdByUserType(string functionIdAgent, string functionIdAdmin)
  81. {
  82. return (GetStatic.GetUserType() == "HO") ? functionIdAdmin : functionIdAgent;
  83. }
  84. protected void downloadFile_Click(object sender, EventArgs e)
  85. {
  86. try
  87. {
  88. string filePath = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + Convert.ToDateTime(hdnRegDate.Value).ToString("yyyy-MM-dd").Replace("-", "\\") + "\\" + hdnMembershipId.Value + "\\" + hdnFileName.Value;
  89. var imageName = hdnFileName.Value;
  90. //var registrationData = imageName.Split('_')[5].Split('.')[0].ToString() + "\\";
  91. //registrationData = registrationData.Replace("-", "\\");
  92. var path = filePath;
  93. if (!File.Exists(path))
  94. {
  95. msgDiv.Visible = true;
  96. msgLabel.Text = "File Not Found";
  97. Page_Load(sender, e);
  98. return;
  99. }
  100. FileInfo ObjArchivo = new FileInfo(path);
  101. Response.Clear();
  102. Response.AddHeader("Content-Disposition", "attachment; filename=" + hdnFileName.Value);
  103. Response.AddHeader("Content-Length", ObjArchivo.Length.ToString());
  104. Response.ContentType = hdnFileType.Value;
  105. Response.WriteFile(ObjArchivo.FullName);
  106. Response.End();
  107. }
  108. catch (Exception ex)
  109. {
  110. throw ex;
  111. }
  112. }
  113. public string GetFileType()
  114. {
  115. return GetStatic.ReadQueryString("fileType", "");
  116. }
  117. }
  118. }