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.

1168 lines
46 KiB

  1. using Swift.DAL.AccountReport;
  2. using Swift.DAL.BL.Remit.Transaction;
  3. using Swift.DAL.SwiftDAL;
  4. using Swift.web.Library;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Globalization;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Web;
  14. using System.Web.UI;
  15. using System.Web.UI.WebControls;
  16. namespace Swift.web.Responsive.AgentPanelReports
  17. {
  18. public partial class Reports : Page
  19. {
  20. private Boolean AllowDrillDown;
  21. private string cssClass = "TBLReport table table-bordered table-condensed table-striped";
  22. private string fieldAlignment = "";
  23. private string fieldFormat = "";
  24. private string fieldWrap = "";
  25. private string tblCaption = "";
  26. private Boolean mergeColumnHead;
  27. private ReportResult reportResult = new ReportResult();
  28. private string excludeColumns = "";
  29. private bool includeSerialNo = false;
  30. private bool useDBRowColorCode = false;
  31. private int subTotalBy = -1;
  32. private int totalTextCol = -1;
  33. private int subTotalTextCol = -1;
  34. private string subTotalFields = "";
  35. private string subTotalText = "";
  36. private string totalFields = "";
  37. private string totalText = "";
  38. private int totalPage = 0;
  39. private int pageNo = 0;
  40. private double grandTotal = 0.00;
  41. private double grandTotalUsd = 0.00;
  42. private double grandTotal_1 = 0.00;
  43. private string reportName = "";
  44. private int extraCol = 0;
  45. private string flag = "";
  46. protected string Url = GetStatic.GetUrlRoot();
  47. private string isExportFull = "";
  48. protected void Page_Load(object sender, EventArgs e)
  49. {
  50. if (!IsPostBack)
  51. {
  52. if (GetStatic.GetUser() == "")
  53. Response.Redirect(GetStatic.GetDefaultPage());
  54. }
  55. PrintReport();
  56. }
  57. private void PrintHead()
  58. {
  59. Page.Title = reportResult.ReportHead;
  60. head.InnerHtml = reportResult.ReportHead;
  61. }
  62. private void PrintFilters()
  63. {
  64. var user = GetStatic.GetUser();
  65. var now = GetStatic.GetUserDateTime();
  66. filters.InnerHtml = "Filters Applied : <br />" + reportResult.Filters +
  67. "<br /><br />Generated On=" + now +
  68. " || Generated By=" + user;
  69. }
  70. private void PrintError()
  71. {
  72. rptDiv.InnerHtml = "<div class = \"reportError\">" + reportResult.Msg + "</div>";
  73. }
  74. protected string GetURL()
  75. {
  76. return Request.Url.AbsoluteUri.Replace("&pageNumber=" + GetPageNumber(), "");
  77. }
  78. private void PrintReport()
  79. {
  80. string reportName = GetStatic.ReadQueryString("reportName", "").ToLower();
  81. string mode = GetStatic.ReadQueryString("mode", "").ToLower();
  82. isExportFull = mode.ToLower() == "download" ? "Y" : "N";
  83. reportResult = PrepareReport(reportName);
  84. if (mode == "download")
  85. {
  86. string format = GetStatic.ReadQueryString("format", "xls");
  87. Response.Clear();
  88. Response.ClearContent();
  89. Response.ClearHeaders();
  90. Response.ContentType = "application/vnd.ms-excel";
  91. Response.AddHeader("Content-Disposition", "attachment; filename=" + reportName + "." + format);
  92. exportDiv.Visible = false;
  93. }
  94. PrintHead();
  95. PrintFilters();
  96. if (reportResult.ErrorCode != "0")
  97. {
  98. PrintError();
  99. return;
  100. }
  101. if (reportName == "usermatrix")
  102. {
  103. PrintUserMatrixReport();
  104. return;
  105. }
  106. if (reportName == "rsptxnsummaryrpt")
  107. {
  108. TxnRSPSummaryReport();
  109. return;
  110. }
  111. DataTable dt;
  112. int tableCount = reportResult.Result.Tables.Count;
  113. if (tableCount > 4)
  114. {
  115. if (mode != "download")
  116. ShowPaging(reportResult.Result.Tables[0]);
  117. dt = reportResult.Result.Tables[1];
  118. }
  119. else
  120. {
  121. dt = reportResult.ResultSet;
  122. }
  123. string reportText = GenerateReport(ref dt);
  124. rptDiv.InnerHtml = reportText;
  125. }
  126. private void ShowPaging(DataTable dt)
  127. {
  128. DataTable dtPaging = dt;
  129. int totalRecords = Convert.ToInt32(dtPaging.Rows[0]["TXNCOUNT"].ToString());
  130. int PageSizes = Convert.ToInt32(dtPaging.Rows[0]["PAGESIZE"].ToString());
  131. int PageNumber = Convert.ToInt32(dtPaging.Rows[0]["PAGENUMBER"].ToString());
  132. if (dtPaging.Columns.Count > 3)
  133. grandTotal = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL"].ToString());
  134. if (dtPaging.Columns.Count > 4)
  135. grandTotalUsd = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL_USD"].ToString());
  136. string cssLink = "pagingLink";
  137. totalPage = totalRecords / PageSizes;
  138. if ((totalPage * PageSizes) < totalRecords)
  139. totalPage++;
  140. var sbPaging = new StringBuilder("<table class='table table-bordered table-striped table-responsive '><tr><td nowrap='nowrap'>");
  141. sbPaging.AppendLine("<div class='reportFilters' width='100%'>");
  142. sbPaging.AppendLine("<span style='width:auto; margin-top:5px;'>Results:&nbsp; " + totalRecords + " records &nbsp; </span>");
  143. paging.Visible = true;
  144. int currPage = GetPageNumber();
  145. int startPage = (currPage - 5 <= 0 ? 1 : currPage - 5);
  146. int offSet = (startPage == 1 ? ((currPage - 5) * -1 + 1) : 0);
  147. int endPage = currPage + 4 + offSet;
  148. endPage = currPage == 0 ? 10 : endPage;
  149. endPage = (endPage > totalPage ? totalPage : endPage);
  150. if (currPage > 10 && (endPage - startPage) + 1 != 10)
  151. {
  152. startPage = startPage - (10 - (endPage - startPage + 1));
  153. }
  154. if (totalRecords > PageSizes)// Convert.ToInt32(GetStatic.GetReportPagesize()))
  155. {
  156. string url = GetURL();
  157. sbPaging.AppendLine("<img onclick='GotoPage(1);' src='../../Images/paging_Icons/first_page.png' alt='First Page' style='margin-top:5px;float:left;border:none;cursor:pointer' />");
  158. sbPaging.AppendLine("<img " + (GetPageNumber() != 1 ? " onclick='GotoPage(" + (GetPageNumber() - 1) + ");'" : "") + " src='../../Images/paging_Icons/" + (GetPageNumber() == 1 ? "previous_page_dis" : "previous_page") + ".png' style='margin-top:5px;float:left;border:none;cursor:pointer' alt='Previous Page' /></a>");
  159. for (int i = startPage; i < endPage + 1; i++)
  160. {
  161. cssLink = PageNumber == i ? "pagingLinkSelected" : "pagingLink";
  162. sbPaging.AppendLine("<span onclick ='GotoPage(" + i + ");' class='" + cssLink + "'>" + i + "</span>");
  163. }
  164. sbPaging.AppendLine("<img " + (GetPageNumber() != totalPage ? "onclick=GotoPage(" + (GetPageNumber() + 1) + ");" : "") + " src='../../Images/paging_Icons/" + (GetPageNumber() == totalPage ? "next_page_dis" : "next_page") + ".png' style='margin-top:5px;border:none;cursor:pointer' alt='Next Page' /></a>");
  165. sbPaging.AppendLine("<img onclick=GotoPage(" + totalPage + "); src='../../Images/paging_Icons/last_page.png' style='margin-top:5px;border:none;cursor:pointer' />");
  166. }
  167. sbPaging.AppendLine("</div></td><td nowrap='nowrap' width='135' align=\"right\">");
  168. if (totalRecords > PageSizes) //Convert.ToInt32(GetStatic.GetReportPagesize()))
  169. sbPaging.AppendLine("Goto Page: " + GotoList(totalPage));
  170. sbPaging.AppendLine("</td></tr></table>");
  171. paging.InnerHtml = sbPaging.ToString();
  172. }
  173. private string GotoList(int totalPage)
  174. {
  175. StringBuilder sb = new StringBuilder("");
  176. sb.AppendLine("<select id='gotoLabel' onchange=GotoPage(this.value); style='min-width:50px'>");
  177. for (int i = 0; i < totalPage; i++)
  178. {
  179. sb.AppendLine("<option value='" + (i + 1) + "' " + (GetPageNumber() == (i + 1) ? "Selected=Selected" : "") + " >" + (i + 1) + "</option>");
  180. }
  181. sb.AppendLine("</select>");
  182. return sb.ToString();
  183. }
  184. private ReportResult PrepareReport(string reportName)
  185. {
  186. if (reportName == "domestictxn")
  187. {
  188. reportResult = PrepareReport_domestictxn();
  189. }
  190. else if (reportName == "userwiserpt")
  191. {
  192. reportResult = PrepareUserWiseReport();
  193. }
  194. else if (reportName == "40111600")
  195. {
  196. reportResult = PrepareReport_40111600();
  197. }
  198. else if (reportName == "cancelreport")
  199. {
  200. reportResult = PrepareCancelReport();
  201. }
  202. else if (reportName == "rsptxnsummaryrpt")
  203. reportResult = PrepareRSPTxnSummaryReport();
  204. return reportResult;
  205. }
  206. #region Report part
  207. private ReportResult PrepareRSPTxnSummaryReport()
  208. {
  209. string pCountry = GetStatic.ReadQueryString("beneficiary", "");
  210. string agentName = GetStatic.ReadQueryString("agentName", "");
  211. string branch = GetStatic.ReadQueryString("branch", "");
  212. string sAgent = GetStatic.ReadQueryString("sAgent", "");
  213. string status = GetStatic.ReadQueryString("status", "");
  214. string dateType = GetStatic.ReadQueryString("date", "");
  215. string fromDate = GetStatic.ReadQueryString("from", "");
  216. string toDate = GetStatic.ReadQueryString("to", "");
  217. string reportType = GetStatic.ReadQueryString("rType", "");
  218. string countryBankId = GetStatic.ReadQueryString("countryBankId", "");
  219. string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
  220. return (new TranAgentReportDao().GetTxnSummaryReport(GetStatic.GetUser(), branch, sAgent, pCountry, agentName, status, dateType, fromDate, toDate,
  221. reportType, countryBankId, pageNumber, GetStatic.GetReportPagesize()));
  222. }
  223. private void TxnRSPSummaryReport()
  224. {
  225. string reportType = GetStatic.ReadQueryString("rType", "");
  226. switch (reportType)
  227. {
  228. case "Detail":
  229. GetRSPTxnDetailReport();
  230. break;
  231. case "BranchWise":
  232. GetTxnBranchwiseReport();
  233. break;
  234. case "ReceivingAgentWise":
  235. //GetTxnRecAgentwiseReport();
  236. GetRSPTxnSummaryReport("ReceivingAgentWise");
  237. break;
  238. case "ReceivingAgentDetail":
  239. GetTxnRecAgentDetailReport();
  240. break;
  241. case "ReceivingDateWise":
  242. //GetTxnRecAgentDatewiseReport();
  243. GetRSPTxnSummaryReport("ReceivingDateWise");
  244. break;
  245. case "SettlementReport":
  246. //GetTxnRecAgentDatewiseReport();
  247. GetRSPSettlmentReport();
  248. break;
  249. case "SettlementReport_Send":
  250. //GetTxnRecAgentDatewiseReport();
  251. GetRSPSettlmentReport_Drill();
  252. break;
  253. case "SettlementReport_Cancel":
  254. GetRSPSettlmentReport_Drill();
  255. break;
  256. case "SettlementReport_Paid":
  257. GetRSPSettlmentReport_Drill();
  258. break;
  259. case "ReceivingAgentCountryWise":
  260. // GetTxnCollDetailReport();
  261. GetRSPTxnSummaryReport("ReceivingAgentCountryWise");
  262. break;
  263. }
  264. }
  265. private void GetTxnRecAgentDetailReport()
  266. {
  267. var rptName = GetStatic.ReadQueryString("reportName", "").ToLower();
  268. var html = new StringBuilder();
  269. DataTable rpt;
  270. string rptTest = "";
  271. if (rptName == "oldtxnsummaryrpt")
  272. {
  273. fieldFormat = "|||N|N|N||N";
  274. fieldAlignment = "||R|R|R|R|R|R|R|R|R|R|L|R";
  275. totalText = "<b>Total</b>";
  276. totalFields = "2|3|4|5|7";
  277. }
  278. else
  279. {
  280. fieldFormat = "|||N|N|N|N|N||N";
  281. fieldAlignment = "||R|R|R|R|R|R|R|R|R|R|L|R";
  282. totalText = "<b>Total</b>";
  283. totalFields = "|2|3|4|5|7|9";
  284. }
  285. for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
  286. {
  287. if (i == 1)
  288. tblCaption = "Cancel Transaction Detail";
  289. rpt = reportResult.Result.Tables[i];
  290. rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
  291. html.AppendLine(rptTest);
  292. }
  293. rptDiv.InnerHtml = html.ToString();
  294. }
  295. private void GetRSPSettlmentReport_Drill()
  296. {
  297. var html = new StringBuilder();
  298. DataTable rpt;
  299. string rptTest = "";
  300. fieldFormat = "|||N|N|N|N|N|N";
  301. fieldAlignment = "|||R|R|R|R|R|R";
  302. totalText = "<b>Total</b>";
  303. totalFields = "3|4|5|6|7|8|9";
  304. rpt = reportResult.Result.Tables[0];
  305. rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
  306. html.AppendLine(rptTest);
  307. rptDiv.InnerHtml = html.ToString();
  308. }
  309. private void GetRSPSettlmentReport()
  310. {
  311. var html = new StringBuilder();
  312. DataTable rpt;
  313. string rptTest = "";
  314. for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
  315. {
  316. if (i == 0)
  317. {
  318. tblCaption = "Summary Report";
  319. fieldFormat = "|||N|N|N|N|N||N";
  320. fieldAlignment = "|||R|R|R|R|R|R";
  321. totalText = "<b>Total</b>";
  322. totalFields = "3|4|5|6|7|8|9";
  323. }
  324. if (i == 1)
  325. {
  326. tblCaption = "Settlment Summary Report";
  327. fieldFormat = "||N";
  328. fieldAlignment = "|R|R";
  329. totalText = "<b>Net Settlement</b>";
  330. totalFields = "1|2";
  331. }
  332. rpt = reportResult.Result.Tables[i];
  333. rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
  334. html.AppendLine(rptTest);
  335. }
  336. rptDiv.InnerHtml = html.ToString();
  337. }
  338. private void GetRSPTxnSummaryReport(string reportType)
  339. {
  340. var html = new StringBuilder();
  341. DataTable rpt;
  342. string rptTest = "";
  343. if (reportType == "BankWise")
  344. {
  345. fieldFormat = "||||N|N";
  346. fieldAlignment = "|R|R|R|R|R";
  347. subTotalBy = 0;
  348. subTotalFields = "2|3|4|5";
  349. subTotalText = "<b >Total</b>";
  350. totalText = "<b>Grand Total</b>";
  351. totalFields = "2|3|4|5";
  352. }
  353. else if (reportType == "ReceivingAgentWise")
  354. {
  355. fieldFormat = "||N|N|N||N";
  356. fieldAlignment = "|R|R|R|R|R|R|R";
  357. totalText = "<b>Total</b>";
  358. totalFields = "1|2|3|4|6";
  359. }
  360. else if (reportType == "ReceivingAgentCountryWise")
  361. {
  362. fieldFormat = "||N|N|N||N|";
  363. fieldAlignment = "|R|R|R|R|R|R|R";
  364. totalText = "<b>Total</b>";
  365. totalFields = "1|2|3|4|6";
  366. }
  367. else if (reportType == "ReceivingDateWise")
  368. {
  369. fieldFormat = "|||||N|N|N|N|N";
  370. fieldAlignment = "|||||R|R|R|R|R|R|R|";
  371. totalText = "<b>Total</b>";
  372. totalFields = "6|7|8|9";
  373. }
  374. else if (reportType == "CashCollectionDetails")
  375. {
  376. fieldFormat = "||||||N|";
  377. fieldAlignment = "||||C|C|R|";
  378. totalText = "<b>Total</b>";
  379. totalFields = "6";
  380. }
  381. else if (reportType == "bankCollectionDetail")
  382. {
  383. fieldFormat = "||||||N|";
  384. fieldAlignment = "||||C|C|R|";
  385. totalText = "<b>Total</b>";
  386. totalFields = "6";
  387. }
  388. rpt = reportResult.Result.Tables[0];
  389. rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
  390. html.AppendLine(rptTest);
  391. rptDiv.InnerHtml = html.ToString();
  392. }
  393. private void GetTxnBranchwiseReport()
  394. {
  395. var html = new StringBuilder();
  396. DataTable rpt;
  397. string rptTest = "";
  398. fieldFormat = "||||||||||";
  399. fieldAlignment = "||R|R|R|R|R|R|R|R";
  400. totalText = "<b>Total</b>";
  401. totalFields = "2|3|4|5|6|7|8|9";
  402. for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
  403. {
  404. if (i == 1)
  405. tblCaption = "Cancel Transaction Detail";
  406. rpt = reportResult.Result.Tables[i];
  407. rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
  408. html.AppendLine(rptTest);
  409. }
  410. rptDiv.InnerHtml = html.ToString();
  411. }
  412. private void GetRSPTxnDetailReport()
  413. {
  414. var html = new StringBuilder();
  415. DataTable rpt;
  416. string rptTest = "";
  417. for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++)
  418. {
  419. if (i == 0)
  420. {
  421. tblCaption = "Transaction Summary Report";
  422. fieldFormat = "||";
  423. fieldAlignment = "|R|R";
  424. }
  425. if (i == 1)
  426. {
  427. tblCaption = "Summary Report";
  428. fieldFormat = "||||N|";
  429. fieldAlignment = "|||R|R|R";
  430. totalText = "<b>Total</b>";
  431. totalFields = "3|4";
  432. }
  433. rpt = reportResult.Result.Tables[i];
  434. rptTest = GenerateReport(ref rpt).Replace("<td", "<td nowrap = \"nowrap\"");
  435. html.AppendLine(rptTest);
  436. }
  437. rptDiv.InnerHtml = html.ToString();
  438. }
  439. private ReportResult PrepareCancelReport()
  440. {
  441. fieldFormat = "|||||||N|N";
  442. fieldAlignment = "|||||||R|R|";
  443. totalText = "<b>Total</b>";
  444. totalFields = "7";
  445. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  446. string toDate = GetStatic.ReadQueryString("toDate", "");
  447. string sBranch = GetStatic.ReadQueryString("branchId", "");
  448. string pcountry = GetStatic.ReadQueryString("pcountry", "");
  449. string cancelType = GetStatic.ReadQueryString("cancelType", "");
  450. string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
  451. string user = GetStatic.GetUser();
  452. return (new TranAgentReportDao().GetCancelReport(user, pcountry, sBranch, fromDate, toDate, cancelType, pageNumber, GetStatic.GetReportPagesize()));
  453. }
  454. private ReportResult PrepareReport_40111600()
  455. {
  456. string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
  457. string rptType = GetStatic.ReadQueryString("rptType", "");
  458. string pCountry = GetStatic.ReadQueryString("pCountry", "");
  459. string pAgent = GetStatic.ReadQueryString("pAgent", "");
  460. string sBranch = GetStatic.ReadQueryString("sbranch", "");
  461. string depositType = GetStatic.ReadQueryString("depositType", "");
  462. string searchBy = GetStatic.ReadQueryString("searchBy", "");
  463. string searchByValue = GetStatic.ReadQueryString("searchByValue", "");
  464. string orderBy = GetStatic.ReadQueryString("orderBy", "");
  465. string status = GetStatic.ReadQueryString("status", "");
  466. string paymentType = GetStatic.ReadQueryString("paymentType", "");
  467. string dateField = GetStatic.ReadQueryString("dateField", "");
  468. string from = GetStatic.ReadQueryString("from", "");
  469. string to = GetStatic.ReadQueryString("to", "");
  470. string transType = GetStatic.ReadQueryString("transType", "");
  471. string displayTranNo = GetStatic.ReadQueryString("displayTranNo", "");
  472. useDBRowColorCode = true;
  473. mergeColumnHead = true;
  474. includeSerialNo = true;
  475. subTotalText = "<b><i>Sub Total</i></b>";
  476. totalTextCol = 3;
  477. subTotalTextCol = 3;
  478. subTotalFields = "8|10|12|14";
  479. fieldFormat = "|||||||N||N||N||N|";
  480. fieldAlignment = "|||||||R||R||R||R|";
  481. totalFields = "7|9|11|13";
  482. totalText = "<b>Grand Total</b>";
  483. return (new TranAgentReportDao().Get_40111600_Report(GetStatic.GetUser(), pCountry, pAgent, sBranch, depositType, orderBy, status, paymentType, dateField, from, to, transType, displayTranNo, searchBy, searchByValue, pageNumber, GetStatic.GetReportPagesize(), rptType));
  484. }
  485. private ReportResult PrepareUserWiseReport()
  486. {
  487. mergeColumnHead = true;
  488. fieldFormat = "|||||||||||N||N";
  489. fieldAlignment = "|||||||R||R||R||R";
  490. totalFields = "7|9|11";
  491. totalText = "<b>Total</b>";
  492. string branch = GetStatic.ReadQueryString("branch", "");
  493. string userName = GetStatic.ReadQueryString("userName", "");
  494. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  495. string toDate = GetStatic.ReadQueryString("toDate", "");
  496. string reportType = GetStatic.ReadQueryString("type", "");
  497. string rCountry = GetStatic.ReadQueryString("rCountry", "");
  498. string pageNumber = GetStatic.ReadQueryString("pageNumber", "1");
  499. return (new TranAgentReportDao().GetUserwiseReport(GetStatic.GetUser(), GetStatic.GetAgent(), branch, userName, fromDate, toDate,
  500. reportType, rCountry, pageNumber, GetStatic.GetReportPagesize()));
  501. }
  502. private ReportResult PrepareReport_domestictxn()
  503. {
  504. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  505. string todate = GetStatic.ReadQueryString("todate", "");
  506. string agentId = GetStatic.ReadQueryString("agentId", "");
  507. string DateType = GetStatic.ReadQueryString("DateType", "");
  508. string payment_status = GetStatic.ReadQueryString("payment_status", "");
  509. string type = GetStatic.ReadQueryString("type", "");
  510. string user = GetStatic.GetUser();
  511. includeSerialNo = true;
  512. fieldFormat = "||||N|N||||";
  513. fieldAlignment = "||||R|R||||";
  514. return (new AccountReportDao().GetDomesticTxnReport(user, agentId, fromDate, todate, DateType, payment_status, type));
  515. }
  516. private int GetPageNumber()
  517. {
  518. return
  519. Convert.ToInt32(GetStatic.ReadNumericDataFromQueryString("pageNumber") == 0
  520. ? 1
  521. : GetStatic.ReadNumericDataFromQueryString("pageNumber"));
  522. }
  523. #endregion
  524. #region Generate Report
  525. public String GenerateReport(ref DataTable dt)
  526. {
  527. Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
  528. var ExcludeFieldList = new ArrayList();
  529. foreach (var col in excludeColumns.Split('|'))
  530. {
  531. ExcludeFieldList.Add(col.ToLower());
  532. }
  533. ExcludeFieldList.Add("rowcolor");
  534. var html = new StringBuilder("");
  535. html.AppendLine("<div style = \"clear:both;margin-top:20px;\">");
  536. html.AppendLine("<table class=\"table table-responsive table-bordered table-striped\" ");
  537. if (tblCaption != "")
  538. html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol).ToString() +
  539. "\">" + tblCaption + "</td></tr>");
  540. html.AppendLine(CreateReportHead(ref dt, mergeColumnHead, ref ExcludeFieldList));
  541. html.AppendLine(CreateReportBody(ref dt, subTotalFields, totalFields, ref ExcludeFieldList, totalTextCol,
  542. subTotalTextCol));
  543. html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol) + "\" align=\"center\">");
  544. if (totalPage == 0)
  545. totalPage = 1;
  546. html.AppendLine("Page " + (GetPageNumber() == 0 ? 1 : GetPageNumber()) + " of " + totalPage +
  547. "");
  548. html.AppendLine("</td></tr>");
  549. html.AppendLine("</table>");
  550. html.AppendLine("</div>");
  551. return html.ToString();
  552. }
  553. private int SerialNo = 0;
  554. private String CreateReportBody(ref DataTable dt, string subTotalFieldList, string totalFieldList,
  555. ref ArrayList ExcludeFieldList, int totalTextCol, int subTotalTextCol)
  556. {
  557. int cnt = 0;
  558. var body = new StringBuilder("");
  559. var SerialNoColumnValue = "";
  560. bool doSubTotal = subTotalBy > -1 ? true : false;
  561. bool doTotal = totalFieldList != "" ? true : false;
  562. string[] totalFieldsArray = totalFieldList.Replace(" ", "").Split('|');
  563. var totalValues = new double[totalFieldsArray.Length];
  564. string[] subTotalFieldsArray = subTotalFieldList.Replace(" ", "").Split('|');
  565. var subTotalValues = new double[subTotalFieldsArray.Length];
  566. string[] fieldFormatList = fieldFormat.Replace(" ", "").Split('|');
  567. string tmpSubTotalText = "||";
  568. var hasRowColorCol = dt.Columns.Contains("rowColor");
  569. foreach (DataRow row in dt.Rows)
  570. {
  571. if (includeSerialNo)
  572. {
  573. SerialNo++;
  574. SerialNoColumnValue = "<td style='td' align=\"right\">" + SerialNo.ToString() + "</td>";
  575. }
  576. else
  577. {
  578. SerialNoColumnValue = "";
  579. }
  580. if (doSubTotal)
  581. {
  582. if (tmpSubTotalText == "||")
  583. tmpSubTotalText = row[subTotalBy].ToString();
  584. if (tmpSubTotalText != row[subTotalBy].ToString())
  585. {
  586. body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray,
  587. subTotalValues, fieldFormatList, fieldAlignment, fieldWrap,
  588. ref ExcludeFieldList, subTotalTextCol, includeSerialNo));
  589. tmpSubTotalText = row[subTotalBy].ToString();
  590. for (int i = 0; i < subTotalValues.Length; i++)
  591. {
  592. subTotalValues[i] = 0;
  593. }
  594. }
  595. }
  596. if (useDBRowColorCode && hasRowColorCol)
  597. {
  598. body.AppendLine("<tr style=\"background:" + row["rowColor"].ToString() + ";\">");
  599. }
  600. else
  601. {
  602. body.AppendLine(++cnt % 2 == 1 ? "<tr>" : "<tr style=\"background: #F0F0F0;\">");
  603. }
  604. body.AppendLine(SerialNoColumnValue);
  605. for (int i = 0; i < dt.Columns.Count; i++)
  606. {
  607. if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
  608. {
  609. continue;
  610. }
  611. string format = GetFormat(fieldFormatList, i);
  612. string data = row[i].ToString();
  613. if (format != "")
  614. {
  615. double dataParse;
  616. double.TryParse(row[i].ToString(), out dataParse);
  617. data = dataParse < 0 ? GetStatic.ParseMinusValue(dataParse) : dataParse.ToString(format);
  618. //Parse Minus Value
  619. }
  620. if (AllowDrillDown)
  621. {
  622. data = CreateLink(data);
  623. }
  624. string alignment = GetAlignment(fieldAlignment, i);
  625. string noWrapProperty = GetNoWrapping(fieldWrap, i);
  626. body.AppendLine("<td style='td' " + alignment + noWrapProperty + ">" + data + "</td>");
  627. var data2 = row[i].ToString();
  628. if (doTotal)
  629. {
  630. int pos = Array.IndexOf(totalFieldsArray, i.ToString());
  631. if (pos >= 0)
  632. {
  633. if (data2.IndexOf('<') > -1)
  634. {
  635. data2 = GetStatic.RemoveAllTags(data2);
  636. }
  637. double value;
  638. double.TryParse(data2, out value);
  639. totalValues[pos] = totalValues[pos] + value;
  640. }
  641. }
  642. if (doSubTotal)
  643. {
  644. int pos = Array.IndexOf(subTotalFieldsArray, i.ToString());
  645. if (pos >= 0)
  646. {
  647. if (data2.IndexOf('<') > -1)
  648. {
  649. data2 = GetStatic.RemoveAllTags(data2);
  650. }
  651. double value;
  652. double.TryParse(data2, out value);
  653. subTotalValues[pos] = subTotalValues[pos] + value;
  654. }
  655. }
  656. }
  657. body.AppendLine("</tr>");
  658. }
  659. if (doSubTotal)
  660. {
  661. body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray, subTotalValues,
  662. fieldFormatList, fieldAlignment, fieldWrap, ref ExcludeFieldList,
  663. totalTextCol, includeSerialNo));
  664. }
  665. if (doTotal)
  666. {
  667. if (grandTotal != 0.00)
  668. {
  669. if (totalPage == GetPageNumber())
  670. body.AppendLine(CreatGrandTotalRow(ref dt, totalText, 0, totalFieldsArray, grandTotal,
  671. fieldFormatList,
  672. fieldAlignment, fieldWrap, grandTotal, grandTotalUsd,
  673. grandTotal_1, ref ExcludeFieldList, includeSerialNo));
  674. }
  675. else
  676. {
  677. body.AppendLine(CreateTotalRow(ref dt, totalText, 0, totalFieldsArray, totalValues, fieldFormatList,
  678. fieldAlignment, fieldWrap, ref ExcludeFieldList, totalTextCol, includeSerialNo));
  679. }
  680. }
  681. return body.ToString();
  682. }
  683. private static String CreateTotalRow(ref DataTable dt, string totalText, int totalFieldIndex,
  684. string[] totalFields, Double[] totalValues, string[] fieldFormatList,
  685. string fieldAlignmentList, string fieldWrapList,
  686. ref ArrayList ExcludeFieldList, int totalTextCol, bool includeSerialNo)
  687. {
  688. var rowText = new StringBuilder("");
  689. rowText.AppendLine("<tr>");
  690. if (includeSerialNo)
  691. {
  692. if (totalText.IndexOf("<td>") == -1)
  693. rowText.AppendLine("<td></td>");
  694. }
  695. for (int i = 0; i < dt.Columns.Count; i++)
  696. {
  697. if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
  698. {
  699. continue;
  700. }
  701. int pos = Array.IndexOf(totalFields, i.ToString());
  702. string data = "";
  703. string alignment = "";
  704. string nowrapProperty = "";
  705. if (pos >= 0)
  706. {
  707. string format = GetFormat(fieldFormatList, i);
  708. data = totalValues[pos] < 0
  709. ? GetStatic.ParseMinusValue(totalValues[pos])
  710. : totalValues[pos].ToString(format.ToUpper());
  711. alignment = GetAlignment(fieldAlignmentList, i);
  712. nowrapProperty = GetNoWrapping(fieldWrapList, i);
  713. }
  714. if (totalTextCol > -1)
  715. {
  716. totalFieldIndex = totalTextCol;
  717. }
  718. if (i == totalFieldIndex) data = totalText;
  719. rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>");
  720. }
  721. rowText.AppendLine("</tr>");
  722. return rowText.ToString();
  723. }
  724. private static String CreatGrandTotalRow(ref DataTable dt, string totalText, int totalFieldIndex,
  725. string[] totalFields, Double totalValues, string[] fieldFormatList,
  726. string fieldAlignmentList, string fieldWrapList, Double grandTotal,
  727. Double grandTotalUsd, Double grandTotal_1,
  728. ref ArrayList ExcludeFieldList, bool includeSerialNo)
  729. {
  730. var rowText = new StringBuilder("");
  731. rowText.AppendLine("<tr>");
  732. if (includeSerialNo)
  733. {
  734. if (totalText.IndexOf("<td>") == -1)
  735. rowText.AppendLine("<td></td>");
  736. }
  737. for (int i = 0; i < dt.Columns.Count; i++)
  738. {
  739. if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
  740. {
  741. continue;
  742. }
  743. int pos = Array.IndexOf(totalFields, i.ToString());
  744. string data = "";
  745. string alignment = "";
  746. string nowrapProperty = "";
  747. if (pos >= 0)
  748. {
  749. data = GetStatic.ParseMinusValue(grandTotal.ToString());
  750. alignment = GetAlignment(fieldAlignmentList, i);
  751. nowrapProperty = GetNoWrapping(fieldWrapList, i);
  752. }
  753. if (i == totalFieldIndex)
  754. data = totalText;
  755. if (i == 9 && grandTotal != 0.00)
  756. {
  757. rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal) +
  758. "</td>");
  759. }
  760. else if (i == 11 && grandTotalUsd != 0.00)
  761. {
  762. rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotalUsd) +
  763. "</td>");
  764. }
  765. else if (i == 13 && grandTotal_1 != 0.00)
  766. {
  767. rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal_1) +
  768. "</td>");
  769. }
  770. else
  771. {
  772. rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>");
  773. }
  774. }
  775. rowText.AppendLine("</tr>");
  776. return rowText.ToString();
  777. }
  778. private static string GetFormat(string[] fieldFormatList, int currFieldIndex)
  779. {
  780. return fieldFormatList.Length > currFieldIndex ? fieldFormatList[currFieldIndex] : "";
  781. //return ( pos == -1 ? "": fieldFormatList[pos]);
  782. }
  783. private static string GetNoWrapping(string fieldWrapList, int currFieldIndex)
  784. {
  785. if (fieldWrapList == "")
  786. return "";
  787. string[] wrapListArray = fieldWrapList.Split('|');
  788. string isWrap = wrapListArray.Length > currFieldIndex ? wrapListArray[currFieldIndex] : "";
  789. string noWrapValue = "";
  790. if (isWrap == "Y")
  791. noWrapValue = " nowrap = \"nowrap\"";
  792. return noWrapValue;
  793. }
  794. private static string GetAlignment(string fieldAlignmentList, int currFieldIndex)
  795. {
  796. if (fieldAlignmentList == "")
  797. return "";
  798. string[] alignListArray = fieldAlignmentList.Split('|');
  799. string alignName = alignListArray.Length > currFieldIndex ? alignListArray[currFieldIndex] : "";
  800. string align = "";
  801. switch (alignName.ToUpper())
  802. {
  803. case "R":
  804. align = " align=\"right\"";
  805. break;
  806. case "L":
  807. align = " align=\"left\"";
  808. break;
  809. case "C":
  810. align = " align=\"center\"";
  811. break;
  812. default:
  813. break;
  814. }
  815. return align;
  816. }
  817. private static string CreateLink(string data)
  818. {
  819. return "";
  820. }
  821. private String CreateReportHead(ref DataTable dt, Boolean merge, ref ArrayList ExcludeFieldList)
  822. {
  823. var head = new StringBuilder("");
  824. var SerialNoColumnHead = "";
  825. if (includeSerialNo)
  826. {
  827. SerialNoColumnHead = "<th style='th'>SN.</th>";
  828. extraCol = 1;
  829. }
  830. if (!merge)
  831. {
  832. head.AppendLine("<tr>");
  833. head.AppendLine(SerialNoColumnHead);
  834. foreach (DataColumn col in dt.Columns)
  835. {
  836. if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1)
  837. {
  838. extraCol--;
  839. continue;
  840. }
  841. head.AppendLine("<th style='th'>" + col.ColumnName + "</th>");
  842. }
  843. head.AppendLine("</tr>");
  844. }
  845. else
  846. {
  847. var columns = new Dictionary<string, string>();
  848. foreach (DataColumn col in dt.Columns)
  849. {
  850. if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1)
  851. {
  852. extraCol--;
  853. continue;
  854. }
  855. var splitPos = col.ColumnName.IndexOf('_');
  856. if (splitPos == -1)
  857. {
  858. columns.Add(col.ColumnName, col.ColumnName);
  859. }
  860. else
  861. {
  862. var key = col.ColumnName.Substring(0, splitPos);
  863. var value = col.ColumnName.Substring(splitPos + 1, col.ColumnName.Length - splitPos - 1);
  864. if (!columns.ContainsKey(key))
  865. {
  866. columns.Add(key, value);
  867. }
  868. else
  869. {
  870. columns[key] = columns[key] + "|" + value;
  871. }
  872. }
  873. }
  874. var row1 = "";
  875. var row2 = "";
  876. foreach (var kvp in columns)
  877. {
  878. string[] values = kvp.Value.Split('|');
  879. if (values.Length == 1)
  880. {
  881. row1 = row1 + "<th style='th' rowspan=\"2\">" + kvp.Key + "</th>";
  882. }
  883. else
  884. {
  885. row1 = row1 + "<th style='th' align=\"center\" colspan=\"" + values.Length + "\">" + kvp.Key +
  886. "</th>";
  887. foreach (string value in values)
  888. {
  889. row2 = row2 + "<th style='th'>" + value + "</th>";
  890. }
  891. }
  892. }
  893. if (includeSerialNo)
  894. {
  895. SerialNoColumnHead = "<th style='th' rowspan=\"2\">SN.</th>";
  896. }
  897. head.AppendLine("<tr>" + SerialNoColumnHead + row1 + "</tr>");
  898. head.AppendLine("<tr>" + row2 + "</tr>");
  899. }
  900. return head.ToString();
  901. }
  902. #endregion
  903. private void PrintUserMatrixReport()
  904. {
  905. const string pStart = "<p style=\"page-break-after: always\">";
  906. const string pEnd = "</p>";
  907. var html = new StringBuilder();
  908. cssClass = "TBLReportMatrix table table-bordered table-condensed table-striped";
  909. int employeeTable = 0;
  910. foreach (DataRow dr in reportResult.Result.Tables[0].Rows)
  911. {
  912. string name = dr["Name"].ToString();
  913. string department = dr["department"].ToString();
  914. string branch = dr["branch"].ToString();
  915. string supervisor = dr["supervisor"].ToString();
  916. DataTable rptDt = reportResult.Result.Tables[++employeeTable];
  917. string reportText = GenerateReport(ref rptDt).Replace("<td", "<td nowrap = \"nowrap\"");
  918. html.AppendLine(pStart);
  919. html.AppendLine("<div class = \"welcome-div\">");
  920. html.AppendLine("User Name: " + name + "");
  921. html.AppendLine("<br />");
  922. //html.AppendLine("Department: " + department + "");
  923. //html.AppendLine("<br />");
  924. html.AppendLine("Agent/Branch Name: " + branch + "");
  925. //html.AppendLine("<br />");
  926. //html.AppendLine("Supervisor: " + supervisor + "");
  927. html.AppendLine("</div>");
  928. html.AppendLine(reportText);
  929. html.AppendLine(pEnd);
  930. }
  931. rptDiv.InnerHtml = html.ToString();
  932. head.Visible = false;
  933. filters.Visible = false;
  934. //hr1.Visible = false;
  935. //hr2.Visible = false;
  936. export.Visible = false;
  937. }
  938. private ColDefinatoin GetColumnNameToIndex(DataTable dt, string totalFieldNameList, string subTotalFieldNameList)
  939. {
  940. var r = new ColDefinatoin();
  941. var fList = new ArrayList();
  942. r.Alignment = "";
  943. r.Format = " ";
  944. r.SubTotalFields = " ";
  945. r.TotalFields = " ";
  946. for (var i = 0; i < dt.Columns.Count; i++)
  947. {
  948. var cp = new ColProperties(i);
  949. fList.Add(cp);
  950. }
  951. var cList = totalFieldNameList.Split('|');
  952. foreach (var colName in cList)
  953. {
  954. var pos = dt.Columns.IndexOf(colName);
  955. if (pos >= 0)
  956. {
  957. var cp = (ColProperties)fList[pos];
  958. cp.IsTotal = true;
  959. fList[pos] = cp;
  960. }
  961. }
  962. foreach (var colName in cList)
  963. {
  964. var pos = dt.Columns.IndexOf(colName);
  965. pos = pos - 1;
  966. if (pos >= 0)
  967. {
  968. var cp = (ColProperties)fList[pos];
  969. cp.IsNumeric = true;
  970. fList[pos] = cp;
  971. }
  972. }
  973. cList = subTotalFieldNameList.Split('|');
  974. foreach (var colName in cList)
  975. {
  976. var pos = dt.Columns.IndexOf(colName);
  977. if (pos >= 0)
  978. {
  979. var cp = (ColProperties)fList[pos];
  980. cp.IsSubTotal = true;
  981. fList[pos] = cp;
  982. }
  983. }
  984. foreach (ColProperties itm in fList)
  985. {
  986. r.Alignment = r.Alignment + (r.Alignment.Length > 0 ? "|" : "") +
  987. ((itm.IsSubTotal || itm.IsTotal) ? "R" : "L");
  988. r.Format = r.Format + (r.Format.Length > 0 ? "|" : "") + ((itm.IsNumeric) ? "N" : "");
  989. r.SubTotalFields = r.SubTotalFields + (r.SubTotalFields.Length > 0 ? "|" : "") +
  990. (itm.IsSubTotal ? itm.Index.ToString() : "");
  991. r.TotalFields = r.TotalFields + (r.TotalFields.Length > 0 ? "|" : "") +
  992. (itm.IsTotal ? itm.Index.ToString() : "");
  993. }
  994. return r;
  995. }
  996. public class ColDefinatoin
  997. {
  998. public string TotalFields { get; set; }
  999. public string SubTotalFields { get; set; }
  1000. public string Alignment { get; set; }
  1001. public string Format { get; set; }
  1002. }
  1003. public class ColProperties
  1004. {
  1005. public int Index { get; set; }
  1006. public bool IsTotal { get; set; }
  1007. public bool IsNumeric { get; set; }
  1008. public bool IsSubTotal { get; set; }
  1009. public ColProperties()
  1010. {
  1011. }
  1012. public ColProperties(int index)
  1013. {
  1014. Index = index;
  1015. IsTotal = false;
  1016. IsSubTotal = false;
  1017. IsNumeric = false;
  1018. }
  1019. }
  1020. }
  1021. }