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.

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