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.

204 lines
8.4 KiB

  1. using Swift.DAL.VoucherReport;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. namespace Swift.web.BillVoucher.VoucherUpload
  9. {
  10. public partial class Upload : System.Web.UI.Page
  11. {
  12. private readonly RemittanceLibrary _sdd = new RemittanceLibrary();
  13. private readonly VoucherReportDAO _vrd = new VoucherReportDAO();
  14. private const string ViewFunctionId = "20201900";
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. Authenticate();
  18. if (!IsPostBack)
  19. {
  20. ShowTempVoucher();
  21. }
  22. }
  23. private void Authenticate()
  24. {
  25. _sdd.CheckAuthentication(ViewFunctionId);
  26. }
  27. protected void btnUpload_Click(object sender, EventArgs e)
  28. {
  29. if (fileUpload.FileContent.Length > 0)
  30. {
  31. if (fileUpload.FileName.ToLower().Contains(".csv"))
  32. {
  33. string path = Server.MapPath("..\\..\\") + "\\doc\\tmp\\" + fileUpload.FileName;
  34. fileUpload.SaveAs(path);
  35. var xml = GetStatic.GetCSVFileInTable(path, true, 5);
  36. string fileName = fileUpload.FileName.ToString();
  37. File.Delete(path);
  38. var rs = _vrd.InsertTempVoucherEntryFCYFromFileNew(GetStatic.GetSessionId(), GetStatic.GetUser(), xml, fileName);
  39. if (rs.ErrorCode == "1")
  40. {
  41. GetStatic.AlertMessage(this, rs.Msg);
  42. }
  43. else
  44. {
  45. ShowTempVoucher();
  46. }
  47. }
  48. else
  49. {
  50. GetStatic.AlertMessage(this, "Invalid file format uploaded");
  51. }
  52. }
  53. else
  54. {
  55. GetStatic.AlertMessage(this, "Choose file first");
  56. }
  57. }
  58. private void ShowTempVoucher()
  59. {
  60. //show data on div
  61. int sno = 0;
  62. var dt = _vrd.GetTempVoucherEntryDataNew(GetStatic.GetSessionId());
  63. StringBuilder sb = new StringBuilder();
  64. if (dt == null || dt.Rows.Count == 0)
  65. {
  66. tblBody.InnerHtml = "<tr><td colspan='7'>No data to view</td></tr>";
  67. divBtn.Visible = false;
  68. btnSaveFinal.Enabled = false;
  69. return;
  70. }
  71. divBtn.Visible = true;
  72. btnSaveFinal.Enabled = true;
  73. int forColor = 0;
  74. string color = "";
  75. int len = dt.Rows.Count;
  76. for (int i = 0; i < dt.Rows.Count; i += 2)
  77. {
  78. forColor++;
  79. sno++;
  80. color = "#F5F5E8";
  81. if (forColor % 2 != 0)
  82. {
  83. color = "#EEEEEE";
  84. }
  85. sb.AppendLine("<tr style=\"background-color:" + color + " !important;\">");
  86. //sb.AppendLine("<td><input type='checkbox' name='voucherEntryList' value='" + dt.Rows[i]["ROW_ID"].ToString() + "' checked='true'/></td>");
  87. sb.AppendLine("<td nowrap='nowrap'>" + sno.ToString() + " </td>");
  88. sb.AppendLine("<td nowrap='nowrap'> " + dt.Rows[i]["ACCT_NAME"].ToString() + "</td>");
  89. sb.AppendLine("<td nowrap='nowrap' align='right'> <div align='right' style='font-size:12px !important'> " + GetStatic.ShowDecimal(dt.Rows[i]["AMOUNT"].ToString()) + "</div> </td>");
  90. sb.AppendLine("<td nowrap='nowrap'>" + dt.Rows[i]["TRAN_DATE"].ToString() + "</td>");
  91. sb.AppendLine("<td nowrap='nowrap'>" + dt.Rows[i]["TRAN_TYPE"].ToString() + "</td>");
  92. sb.AppendLine("<td nowrap='nowrap'>" + dt.Rows[i]["field2"].ToString() + "</div></td>");
  93. sb.AppendLine("<td nowrap='nowrap' rowspan='2'>" + dt.Rows[i]["NARRATION"].ToString() + "</div></td>");
  94. sb.AppendLine("</tr>");
  95. sno++;
  96. sb.AppendLine("<tr style=\"background-color:" + color + " !important;\">");
  97. //sb.AppendLine("<td><input type='checkbox' name='voucherEntryList' value='" + dt.Rows[i + 1]["ROW_ID"].ToString() + "' checked='true'/></td>");
  98. sb.AppendLine("<td nowrap='nowrap'>" + (sno).ToString() + " </td>");
  99. sb.AppendLine("<td nowrap='nowrap'> " + dt.Rows[i + 1]["ACCT_NAME"].ToString() + "</td>");
  100. sb.AppendLine("<td nowrap='nowrap' align='right'> <div align='right' style='font-size:12px !important'> " + GetStatic.ShowDecimal(dt.Rows[i + 1]["AMOUNT"].ToString()) + "</div> </td>");
  101. sb.AppendLine("<td nowrap='nowrap'>" + dt.Rows[i + 1]["TRAN_DATE"].ToString() + "</td>");
  102. sb.AppendLine("<td nowrap='nowrap'>" + dt.Rows[i + 1]["TRAN_TYPE"].ToString() + "</td>");
  103. sb.AppendLine("<td nowrap='nowrap'>" + dt.Rows[i]["field2"].ToString() + "</div></td>");
  104. sb.AppendLine("</tr>");
  105. //var isConsecutive = list.Select((n, index) => n == index + list.ElementAt(i)).All(n => n);
  106. }
  107. //foreach (DataRow item in dt.Rows)
  108. //{
  109. // sno++;
  110. // color = "#F5F5F5";
  111. // for (int i = 1; i < list.Length; i += 2)
  112. // {
  113. // Console.WriteLine(i);
  114. // Console.WriteLine(i + 1);
  115. // if (i % 2)
  116. // {
  117. // }
  118. // }
  119. // sb.AppendLine("<tr style=\"background-color:" + color + " !important;\">");
  120. // sb.AppendLine("<td><input type='checkbox' name='voucherEntryList' value='" + item["ROW_ID"].ToString() + "' checked='true'/></td>");
  121. // sb.AppendLine("<td nowrap='nowrap'>" + sno.ToString() + " </td>");
  122. // sb.AppendLine("<td nowrap='nowrap'> " + item["ACCT_NAME"].ToString() + "</td>");
  123. // sb.AppendLine("<td nowrap='nowrap' align='right'> <div align='right' style='font-size:12px !important'> " + GetStatic.ShowDecimal(item["AMOUNT"].ToString()) + "</div> </td>");
  124. // sb.AppendLine("<td nowrap='nowrap'>" + item["TRAN_DATE"].ToString() + "</td>");
  125. // sb.AppendLine("<td nowrap='nowrap'>" + item["TRAN_TYPE"].ToString() + "</td>");
  126. // if (sno % 2 != 0)
  127. // {
  128. // sb.AppendLine("<td nowrap='nowrap' rowspan='2'>" + item["NARRATION"].ToString() + "</div></td>");
  129. // }
  130. // else
  131. // {
  132. // i = 1;
  133. // }
  134. // sb.AppendLine("</tr>");
  135. //}
  136. tblBody.InnerHtml = sb.ToString();
  137. }
  138. protected void btnSaveFinal_Click(object sender, EventArgs e)
  139. {
  140. finalResult.Visible = true;
  141. divReUpload.Visible = true;
  142. divBtn.Visible = false;
  143. tblTempUpload.Visible = false;
  144. divUpload.Visible = false;
  145. DataTable dt = _vrd.FinalSave(GetStatic.GetUser(), GetStatic.GetSessionId());
  146. if (null == dt || dt.Rows.Count == 0)
  147. {
  148. tblResult.InnerHtml = "<tr><td colspan='6'>No data to view</td></tr>";
  149. return;
  150. }
  151. int sno = 1;
  152. StringBuilder sb = new StringBuilder();
  153. foreach (DataRow item in dt.Rows)
  154. {
  155. sb.AppendLine("<tr>");
  156. sb.AppendLine("<td>" + sno.ToString() + "</td>");
  157. sb.AppendLine("<td>" + item["ERROR_CODE"].ToString() + "</td>");
  158. sb.AppendLine("<td>" + item["tran_particular"].ToString() + "</td>");
  159. sb.AppendLine("<td>" + item["MSG"].ToString() + "</td>");
  160. sb.AppendLine("</tr>");
  161. sno++;
  162. }
  163. tblResult.InnerHtml = sb.ToString();
  164. }
  165. protected void btnClearData_Click(object sender, EventArgs e)
  166. {
  167. _vrd.ClearData(GetStatic.GetUser(), GetStatic.GetSessionId());
  168. ShowTempVoucher();
  169. }
  170. protected void btnReUpload_Click(object sender, EventArgs e)
  171. {
  172. finalResult.Visible = false;
  173. divReUpload.Visible = false;
  174. divBtn.Visible = false;
  175. tblTempUpload.Visible = true;
  176. divUpload.Visible = true;
  177. ShowTempVoucher();
  178. }
  179. }
  180. }