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.

295 lines
12 KiB

  1. using Swift.DAL.VoucherReport;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Web;
  11. using System.Web.UI;
  12. using System.Web.UI.WebControls;
  13. namespace Swift.web.BillVoucher.DollarVoucher
  14. {
  15. public partial class VoucherEntry : System.Web.UI.Page
  16. {
  17. private const string ViewFunctionId = "20150080";
  18. private const string DateFunctionId = "20150040";
  19. private readonly RemittanceLibrary _sdd = new RemittanceLibrary();
  20. private readonly VoucherReportDAO _vrd = new VoucherReportDAO();
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. _sdd.CheckSession();
  24. if (!IsPostBack)
  25. {
  26. Authenticate();
  27. AllowChangeDate();
  28. transactionDate.Text = DateTime.Today.ToString("d");
  29. transactionDate.Attributes.Add("readonly", "readonly");
  30. PopulateDDL();
  31. }
  32. divuploadMsg.Visible = false;
  33. }
  34. private void PopulateDDL()
  35. {
  36. _sdd.SetDDL(ref voucherType, "EXEC Proc_dropdown_remit @FLAG='voucherDDL'", "value", "functionName", "", "");
  37. _sdd.SetDDL(ref FCY, "EXEC Proc_dropdown_remit @FLAG='Currency'", "val", "Name", "", "FCY");
  38. _sdd.SetDDL(ref Department, "EXEC Proc_dropdown_remit @FLAG='Department'", "RowId", "DepartmentName", "", "Select Department");
  39. _sdd.SetDDL(ref Branch, "EXEC Proc_dropdown_remit @FLAG='Branch'", "agentId", "agentName", "", "Select Branch");
  40. }
  41. private void Authenticate()
  42. {
  43. _sdd.CheckAuthentication(ViewFunctionId);
  44. }
  45. protected bool AllowChangeDate()
  46. {
  47. return _sdd.HasRight(DateFunctionId);
  48. }
  49. protected void addBtn_Click(object sender, EventArgs e)
  50. {
  51. if (GetStatic.ParseDouble(FCYAmt.Text) <= 0)
  52. {
  53. GetStatic.AlertMessage(this, "Please enter valid Amount! ");
  54. FCYAmt.Focus();
  55. return;
  56. }
  57. var result = _vrd.InsertDollarTransferCharge(GetStatic.GetSessionId(), GetStatic.GetUser(), acInfo.Value, dropDownDrCr.Text,Department.Text, Branch.Text
  58. , EmpName.Text, Field1.Text,FCY.Text, FCYAmt.Text);
  59. if (result.ErrorCode == "1")
  60. {
  61. GetStatic.AlertMessage(this, result.Msg);
  62. }
  63. else
  64. {
  65. ShowTempVoucher();
  66. }
  67. }
  68. private void ShowTempVoucher()
  69. {
  70. //show data on div
  71. int sno = 0, drCount = 0, crCount = 0;
  72. double drTotal = 0, crTotal = 0;
  73. var dt = _vrd.GetTempTransferChargeData(GetStatic.GetSessionId());
  74. var sb = new StringBuilder("");
  75. sb.AppendLine("<div class=\"table-responsive\">");
  76. sb.AppendLine("<table class=\"table table-bordered\">");
  77. sb.AppendLine("<tr >");
  78. sb.AppendLine("<th >S. No</th>");
  79. sb.AppendLine("<th >AC information</th>");
  80. sb.AppendLine("<th >FCY</th>");
  81. sb.AppendLine("<th >FCY Amount</th>");
  82. sb.AppendLine("<th >Rate</th>");
  83. sb.AppendLine("<th >Department</th>");
  84. sb.AppendLine("<th >Branch</th>");
  85. sb.AppendLine("<th >EmployeeName</th>");
  86. sb.AppendLine("<th >Type</th>");
  87. sb.AppendLine("<th>KRW Amount</th>");
  88. sb.AppendLine("<th>Select</th>");
  89. sb.AppendLine("</tr>");
  90. if (dt == null || dt.Rows.Count == 0)
  91. {
  92. sb.AppendLine("<tr><td colspan='11' align='center'>No transaction found!</td></tr></table></div>");
  93. rpt_tempVoucherTrans.InnerHtml = sb.ToString();
  94. return;
  95. }
  96. foreach (DataRow item in dt.Rows)
  97. {
  98. sno++;
  99. if (item["part_tran_type"].ToString().ToLower() == "dr")
  100. {
  101. drCount++;
  102. drTotal = drTotal + Convert.ToDouble(item["tran_amt"]);
  103. }
  104. else if (item["part_tran_type"].ToString().ToLower() == "cr")
  105. {
  106. crCount++;
  107. crTotal = crTotal + Convert.ToDouble(item["tran_amt"]);
  108. }
  109. sb.AppendLine("<tr>");
  110. sb.AppendLine("<td nowrap='nowrap' width='5%'>" + sno.ToString() + " </td>");
  111. sb.AppendLine("<td nowrap='nowrap' width='40%'> " + item["acct_num"].ToString() + "</td>");
  112. sb.AppendLine("<td nowrap='nowrap' width='5%'> " + item["trn_currency"].ToString() + "</td>");
  113. sb.AppendLine("<td nowrap='nowrap' width='10%'> " + item["usd_amt"].ToString() + "</td>");
  114. sb.AppendLine("<td nowrap='nowrap' width='10%'> " + item["ex_rate"].ToString() + "</td>");
  115. sb.AppendLine("<td nowrap='nowrap' width='20%'> " + item["DepartmentName"].ToString() + "</td>");
  116. sb.AppendLine("<td nowrap='nowrap' width='20%'> " + item["agentName"].ToString() + "</td>");
  117. sb.AppendLine("<td nowrap='nowrap' width='20%'> " + item["emp_name"].ToString() + "</td>");
  118. sb.AppendLine("<td nowrap='nowrap' width='5%'>" + item["part_tran_type"].ToString() + " </td>");
  119. sb.AppendLine("<td nowrap='nowrap' align='right' width='15%'> <div align='right' style='font-size:12px !important'> " + GetStatic.ShowDecimal(item["tran_amt"].ToString()) + "</div> </td>");
  120. sb.AppendLine("<td nowrap='nowrap' width='5%'><div align='center'><span class=\"action-icon\"><a class=\"btn btn-xs btn-primary\" title=\"Delete\" data-placement=\"top\" data-toggle=\"tooltip\" href=\"#\" data-original-title=\"Delete\" style='text-decoration:none;' onclick='deleteRecord(" + item["tran_id"].ToString() + ")'><i class=\"fa fa-trash-o\"></i></a></span></div></td>");
  121. sb.AppendLine("</tr>");
  122. }
  123. sb.AppendLine("<tr>");
  124. sb.AppendLine("<td nowrap='nowrap' align='right' colspan='10' > <div align='right' style='font-size:12px !important'><strong>Total Dr</strong><span style=' text-align:right; font-weight: bold;' > (" + drCount.ToString() + "): &nbsp; &nbsp;" + GetStatic.ShowDecimal(drTotal.ToString()) + "</span></div> </td>");
  125. sb.AppendLine("</tr>");
  126. sb.AppendLine("<tr>");
  127. sb.AppendLine("<td nowrap='nowrap' align='right' colspan='10' > <div align='right' style='font-size:12px !important'><strong>Total Cr</strong><span style=' text-align:right; font-weight: bold;' > (" + crCount.ToString() + "): &nbsp; &nbsp;" + GetStatic.ShowDecimal(crTotal.ToString()) + "</span></div> </td>");
  128. sb.AppendLine("</tr>");
  129. sb.AppendLine("</table>");
  130. sb.AppendLine("</div>");
  131. rpt_tempVoucherTrans.InnerHtml = sb.ToString();
  132. }
  133. protected void btnDelete_Click(object sender, EventArgs e)
  134. {
  135. var res = _vrd.DeleteRecordVoucherEntry(hdnRowId.Value);
  136. if (res.ErrorCode == "0")
  137. {
  138. GetStatic.AlertMessage(this, res.Msg);
  139. }
  140. ShowTempVoucher();
  141. }
  142. protected void btnUnSave_Click(object sender, EventArgs e)
  143. {
  144. ShowTempVoucher();
  145. }
  146. protected void btnSave_Click(object sender, EventArgs e)
  147. {
  148. string voucherPath = "";
  149. if (VImage.HasFile)
  150. {
  151. // Get the file extension
  152. string fileExtension = System.IO.Path.GetExtension(VImage.FileName);
  153. if (!IsImage(VImage))
  154. {
  155. msg.Visible = true;
  156. mes.InnerHtml = "File types other than image are not acceptable.";
  157. return;
  158. }
  159. else
  160. {
  161. // Get the file size
  162. int fileSize = VImage.PostedFile.ContentLength;
  163. // If file size is greater than 2 MB
  164. if (fileSize > Convert.ToInt32(GetStatic.GetUploadFileSize()))
  165. {
  166. msg.Visible = true;
  167. mes.InnerHtml = "File size cannot be greater than 2 MB";
  168. return;
  169. }
  170. else
  171. {
  172. // Upload the file
  173. voucherPath = "/VerificationDoc/" + "UploadedVoucher-" + GetTimestamp(DateTime.Now) + fileExtension;
  174. var filePath = GetStatic.ReadWebConfig("filePath") + voucherPath;
  175. VImage.SaveAs(filePath);
  176. }
  177. }
  178. }
  179. string date = transactionDate.Text;
  180. var res = _vrd.SaveTransferCharge(GetStatic.GetSessionId(), date, narrationField.Text,GetStatic.GetUser(), voucherPath);
  181. if (res.ErrorCode == "0")
  182. {
  183. chequeNo.Text = "";
  184. narrationField.Text = "";
  185. rpt_tempVoucherTrans.InnerHtml = res.Msg;
  186. }
  187. else
  188. {
  189. GetStatic.AlertMessage(this, res.Msg);
  190. }
  191. }
  192. public static bool IsImage(FileUpload fileUpload)
  193. {
  194. if (Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpg"
  195. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".png"
  196. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".gif"
  197. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpeg")
  198. {
  199. return false;
  200. }
  201. if (fileUpload.PostedFile.ContentType.ToLower() != "image/jpg" &&
  202. fileUpload.PostedFile.ContentType.ToLower() != "image/jpeg" &&
  203. fileUpload.PostedFile.ContentType.ToLower() != "image/pjpeg" &&
  204. fileUpload.PostedFile.ContentType.ToLower() != "image/gif" &&
  205. fileUpload.PostedFile.ContentType.ToLower() != "image/x-png" &&
  206. fileUpload.PostedFile.ContentType.ToLower() != "image/png")
  207. {
  208. return false;
  209. }
  210. try
  211. {
  212. byte[] buffer = new byte[512];
  213. fileUpload.PostedFile.InputStream.Read(buffer, 0, 512);
  214. string content = Encoding.UTF8.GetString(buffer);
  215. if (Regex.IsMatch(content, @"<script|<html|<head|<title|<body|<pre|<table|<a\s+href|<img|<plaintext|<cross\-domain\-policy|<?php",
  216. RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline))
  217. {
  218. return false;
  219. }
  220. }
  221. catch (Exception)
  222. {
  223. return false;
  224. }
  225. try
  226. {
  227. using (var bitmap = new System.Drawing.Bitmap(fileUpload.PostedFile.InputStream))
  228. {
  229. }
  230. }
  231. catch (Exception)
  232. {
  233. return false;
  234. }
  235. return true;
  236. }
  237. public static string GetTimestamp(DateTime value)
  238. {
  239. return value.ToString("yyyyMMddHHmmssffff");
  240. }
  241. protected void btnUpload_Click(object sender, EventArgs e)
  242. {
  243. if (fileUpload.FileContent.Length > 0)
  244. {
  245. if (fileUpload.FileName.ToLower().Contains(".csv"))
  246. {
  247. string path = Server.MapPath("..\\..\\") + "\\doc\\tmp\\" + fileUpload.FileName;
  248. string Remitpath = Server.MapPath("..\\..\\") + "\\SampleFile\\FCYVoucherEntry\\" + fileUpload.FileName;
  249. fileUpload.SaveAs(path);
  250. var xml = GetStatic.GetCSVFileInTable(path, true);
  251. //File.Move(path, Remitpath);
  252. File.Delete(path);
  253. var rs = _vrd.InsertTempVoucherEntryFCYFromFile(GetStatic.GetSessionId(), GetStatic.GetUser(), xml);
  254. if (rs.ErrorCode == "1")
  255. {
  256. GetStatic.AlertMessage(this, rs.Msg);
  257. }
  258. else
  259. {
  260. ShowTempVoucher();
  261. }
  262. }
  263. else
  264. {
  265. divuploadMsg.Visible = true;
  266. divuploadMsg.InnerHtml = "Invalid file format uploaded";
  267. }
  268. }
  269. }
  270. }
  271. }