using Swift.DAL.AccountReport; using Swift.DAL.BL.Remit.Transaction; using Swift.DAL.SwiftDAL; using Swift.web.Library; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Text; using System.Threading; using System.Web.UI; namespace Swift.web.AgentPanelReports { public partial class Reports : Page { private Boolean AllowDrillDown; private string cssClass = "TBLReport table table-bordered table-condensed table-striped"; private string fieldAlignment = ""; private string fieldFormat = ""; private string fieldWrap = ""; private string tblCaption = ""; private Boolean mergeColumnHead; private ReportResult reportResult = new ReportResult(); private string excludeColumns = ""; private bool includeSerialNo = false; private bool useDBRowColorCode = false; private int subTotalBy = -1; private int totalTextCol = -1; private int subTotalTextCol = -1; private string subTotalFields = ""; private string subTotalText = ""; private string totalFields = ""; private string totalText = ""; private int totalPage = 0; private int pageNo = 0; private double grandTotal = 0.00; private double grandTotalUsd = 0.00; private double grandTotal_1 = 0.00; private string reportName = ""; private int extraCol = 0; private string flag = ""; protected string Url = GetStatic.GetUrlRoot(); private string isExportFull = ""; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (GetStatic.GetUser() == "") Response.Redirect(GetStatic.GetDefaultPage()); } PrintReport(); } private void PrintHead() { Page.Title = reportResult.ReportHead; head.InnerHtml = reportResult.ReportHead; } private void PrintFilters() { var user = GetStatic.GetUser(); var now = GetStatic.GetUserDateTime(); filters.InnerHtml = "Filters Applied :
" + reportResult.Filters + "

Generated On=" + now + " || Generated By=" + user; } private void PrintError() { rptDiv.InnerHtml = "
" + reportResult.Msg + "
"; } protected string GetURL() { return Request.Url.AbsoluteUri.Replace("&pageNumber=" + GetPageNumber(), ""); } private void PrintReport() { string reportName = GetStatic.ReadQueryString("reportName", "").ToLower(); string mode = GetStatic.ReadQueryString("mode", "").ToLower(); isExportFull = mode.ToLower() == "download" ? "Y" : "N"; reportResult = PrepareReport(reportName); if (mode == "download") { string format = GetStatic.ReadQueryString("format", "xls"); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + reportName + "." + format); exportDiv.Visible = false; } PrintHead(); PrintFilters(); if (reportResult.ErrorCode != "0") { PrintError(); return; } if (reportName == "usermatrix") { PrintUserMatrixReport(); return; } if (reportName == "rsptxnsummaryrpt") { TxnRSPSummaryReport(); return; } DataTable dt; int tableCount = reportResult.Result.Tables.Count; if (tableCount > 4) { if (mode != "download") ShowPaging(reportResult.Result.Tables[0]); dt = reportResult.Result.Tables[1]; } else { dt = reportResult.ResultSet; } string reportText = GenerateReport(ref dt); rptDiv.InnerHtml = reportText; } private void ShowPaging(DataTable dt) { DataTable dtPaging = dt; int totalRecords = Convert.ToInt32(dtPaging.Rows[0]["TXNCOUNT"].ToString()); int PageSizes = Convert.ToInt32(dtPaging.Rows[0]["PAGESIZE"].ToString()); int PageNumber = Convert.ToInt32(dtPaging.Rows[0]["PAGENUMBER"].ToString()); if (dtPaging.Columns.Count > 3) grandTotal = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL"].ToString()); if (dtPaging.Columns.Count > 4) grandTotalUsd = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL_USD"].ToString()); string cssLink = "pagingLink"; totalPage = totalRecords / PageSizes; if ((totalPage * PageSizes) < totalRecords) totalPage++; var sbPaging = new StringBuilder("
"); sbPaging.AppendLine("
"); sbPaging.AppendLine("Results:  " + totalRecords + " records   "); paging.Visible = true; int currPage = GetPageNumber(); int startPage = (currPage - 5 <= 0 ? 1 : currPage - 5); int offSet = (startPage == 1 ? ((currPage - 5) * -1 + 1) : 0); int endPage = currPage + 4 + offSet; endPage = currPage == 0 ? 10 : endPage; endPage = (endPage > totalPage ? totalPage : endPage); if (currPage > 10 && (endPage - startPage) + 1 != 10) { startPage = startPage - (10 - (endPage - startPage + 1)); } if (totalRecords > PageSizes)// Convert.ToInt32(GetStatic.GetReportPagesize())) { string url = GetURL(); sbPaging.AppendLine("First Page"); sbPaging.AppendLine("Previous Page"); for (int i = startPage; i < endPage + 1; i++) { cssLink = PageNumber == i ? "pagingLinkSelected" : "pagingLink"; sbPaging.AppendLine("" + i + ""); } sbPaging.AppendLine("Next Page"); sbPaging.AppendLine(""); } sbPaging.AppendLine("
"); if (totalRecords > PageSizes) //Convert.ToInt32(GetStatic.GetReportPagesize())) sbPaging.AppendLine("Goto Page: " + GotoList(totalPage)); sbPaging.AppendLine("
"); paging.InnerHtml = sbPaging.ToString(); } private string GotoList(int totalPage) { StringBuilder sb = new StringBuilder(""); sb.AppendLine(""); return sb.ToString(); } private ReportResult PrepareReport(string reportName) { if (reportName == "domestictxn") { reportResult = PrepareReport_domestictxn(); } else if (reportName == "userwiserpt") { reportResult = PrepareUserWiseReport(); } else if (reportName == "40111600") { reportResult = PrepareReport_40111600(); } else if (reportName == "cancelreport") { reportResult = PrepareCancelReport(); } else if (reportName == "rsptxnsummaryrpt") reportResult = PrepareRSPTxnSummaryReport(); return reportResult; } #region Report part private ReportResult PrepareRSPTxnSummaryReport() { string pCountry = GetStatic.ReadQueryString("beneficiary", ""); string agentName = GetStatic.ReadQueryString("agentName", ""); string branch = GetStatic.ReadQueryString("branch", ""); string sAgent = GetStatic.ReadQueryString("sAgent", ""); string status = GetStatic.ReadQueryString("status", ""); string dateType = GetStatic.ReadQueryString("date", ""); string fromDate = GetStatic.ReadQueryString("from", ""); string toDate = GetStatic.ReadQueryString("to", ""); string reportType = GetStatic.ReadQueryString("rType", ""); string countryBankId = GetStatic.ReadQueryString("countryBankId", ""); string pageNumber = GetStatic.ReadQueryString("pageNumber", "1"); return (new TranAgentReportDao().GetTxnSummaryReport(GetStatic.GetUser(), branch, sAgent, pCountry, agentName, status, dateType, fromDate, toDate, reportType, countryBankId, pageNumber, GetStatic.GetReportPagesize())); } private void TxnRSPSummaryReport() { string reportType = GetStatic.ReadQueryString("rType", ""); switch (reportType) { case "Detail": GetRSPTxnDetailReport(); break; case "BranchWise": GetTxnBranchwiseReport(); break; case "ReceivingAgentWise": //GetTxnRecAgentwiseReport(); GetRSPTxnSummaryReport("ReceivingAgentWise"); break; case "ReceivingAgentDetail": GetTxnRecAgentDetailReport(); break; case "ReceivingDateWise": //GetTxnRecAgentDatewiseReport(); GetRSPTxnSummaryReport("ReceivingDateWise"); break; case "SettlementReport": //GetTxnRecAgentDatewiseReport(); GetRSPSettlmentReport(); break; case "SettlementReport_Send": //GetTxnRecAgentDatewiseReport(); GetRSPSettlmentReport_Drill(); break; case "SettlementReport_Cancel": GetRSPSettlmentReport_Drill(); break; case "SettlementReport_Paid": GetRSPSettlmentReport_Drill(); break; case "ReceivingAgentCountryWise": // GetTxnCollDetailReport(); GetRSPTxnSummaryReport("ReceivingAgentCountryWise"); break; } } private void GetTxnRecAgentDetailReport() { var rptName = GetStatic.ReadQueryString("reportName", "").ToLower(); var html = new StringBuilder(); DataTable rpt; string rptTest = ""; if (rptName == "oldtxnsummaryrpt") { fieldFormat = "|||N|N|N||N"; fieldAlignment = "||R|R|R|R|R|R|R|R|R|R|L|R"; totalText = "Total"; totalFields = "2|3|4|5|7"; } else { fieldFormat = "|||N|N|N|N|N||N"; fieldAlignment = "||R|R|R|R|R|R|R|R|R|R|L|R"; totalText = "Total"; totalFields = "|2|3|4|5|7|9"; } for (int i = 0; i < reportResult.Result.Tables.Count - 3; i++) { if (i == 1) tblCaption = "Cancel Transaction Detail"; rpt = reportResult.Result.Tables[i]; rptTest = GenerateReport(ref rpt).Replace(""); html.AppendLine(""); html.AppendLine(CreateReportHead(ref dt, mergeColumnHead, ref ExcludeFieldList)); html.AppendLine(CreateReportBody(ref dt, subTotalFields, totalFields, ref ExcludeFieldList, totalTextCol, subTotalTextCol)); html.AppendLine(""); html.AppendLine("
" + tblCaption + "
"); if (totalPage == 0) totalPage = 1; html.AppendLine("Page " + (GetPageNumber() == 0 ? 1 : GetPageNumber()) + " of " + totalPage + ""); html.AppendLine("
"); html.AppendLine(""); return html.ToString(); } private int SerialNo = 0; private String CreateReportBody(ref DataTable dt, string subTotalFieldList, string totalFieldList, ref ArrayList ExcludeFieldList, int totalTextCol, int subTotalTextCol) { int cnt = 0; var body = new StringBuilder(""); var SerialNoColumnValue = ""; bool doSubTotal = subTotalBy > -1 ? true : false; bool doTotal = totalFieldList != "" ? true : false; string[] totalFieldsArray = totalFieldList.Replace(" ", "").Split('|'); var totalValues = new double[totalFieldsArray.Length]; string[] subTotalFieldsArray = subTotalFieldList.Replace(" ", "").Split('|'); var subTotalValues = new double[subTotalFieldsArray.Length]; string[] fieldFormatList = fieldFormat.Replace(" ", "").Split('|'); string tmpSubTotalText = "||"; var hasRowColorCol = dt.Columns.Contains("rowColor"); foreach (DataRow row in dt.Rows) { if (includeSerialNo) { SerialNo++; SerialNoColumnValue = "" + SerialNo.ToString() + ""; } else { SerialNoColumnValue = ""; } if (doSubTotal) { if (tmpSubTotalText == "||") tmpSubTotalText = row[subTotalBy].ToString(); if (tmpSubTotalText != row[subTotalBy].ToString()) { body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray, subTotalValues, fieldFormatList, fieldAlignment, fieldWrap, ref ExcludeFieldList, subTotalTextCol, includeSerialNo)); tmpSubTotalText = row[subTotalBy].ToString(); for (int i = 0; i < subTotalValues.Length; i++) { subTotalValues[i] = 0; } } } if (useDBRowColorCode && hasRowColorCol) { body.AppendLine(""); } else { body.AppendLine(++cnt % 2 == 1 ? "" : ""); } body.AppendLine(SerialNoColumnValue); for (int i = 0; i < dt.Columns.Count; i++) { if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1) { continue; } string format = GetFormat(fieldFormatList, i); string data = row[i].ToString(); if (format != "") { double dataParse; double.TryParse(row[i].ToString(), out dataParse); data = dataParse < 0 ? GetStatic.ParseMinusValue(dataParse) : dataParse.ToString(format); //Parse Minus Value } if (AllowDrillDown) { data = CreateLink(data); } string alignment = GetAlignment(fieldAlignment, i); string noWrapProperty = GetNoWrapping(fieldWrap, i); body.AppendLine("" + data + ""); var data2 = row[i].ToString(); if (doTotal) { int pos = Array.IndexOf(totalFieldsArray, i.ToString()); if (pos >= 0) { if (data2.IndexOf('<') > -1) { data2 = GetStatic.RemoveAllTags(data2); } double value; double.TryParse(data2, out value); totalValues[pos] = totalValues[pos] + value; } } if (doSubTotal) { int pos = Array.IndexOf(subTotalFieldsArray, i.ToString()); if (pos >= 0) { if (data2.IndexOf('<') > -1) { data2 = GetStatic.RemoveAllTags(data2); } double value; double.TryParse(data2, out value); subTotalValues[pos] = subTotalValues[pos] + value; } } } body.AppendLine(""); } if (doSubTotal) { body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray, subTotalValues, fieldFormatList, fieldAlignment, fieldWrap, ref ExcludeFieldList, totalTextCol, includeSerialNo)); } if (doTotal) { if (grandTotal != 0.00) { if (totalPage == GetPageNumber()) body.AppendLine(CreatGrandTotalRow(ref dt, totalText, 0, totalFieldsArray, grandTotal, fieldFormatList, fieldAlignment, fieldWrap, grandTotal, grandTotalUsd, grandTotal_1, ref ExcludeFieldList, includeSerialNo)); } else { body.AppendLine(CreateTotalRow(ref dt, totalText, 0, totalFieldsArray, totalValues, fieldFormatList, fieldAlignment, fieldWrap, ref ExcludeFieldList, totalTextCol, includeSerialNo)); } } return body.ToString(); } private static String CreateTotalRow(ref DataTable dt, string totalText, int totalFieldIndex, string[] totalFields, Double[] totalValues, string[] fieldFormatList, string fieldAlignmentList, string fieldWrapList, ref ArrayList ExcludeFieldList, int totalTextCol, bool includeSerialNo) { var rowText = new StringBuilder(""); rowText.AppendLine(""); if (includeSerialNo) { if (totalText.IndexOf("") == -1) rowText.AppendLine(""); } for (int i = 0; i < dt.Columns.Count; i++) { if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1) { continue; } int pos = Array.IndexOf(totalFields, i.ToString()); string data = ""; string alignment = ""; string nowrapProperty = ""; if (pos >= 0) { string format = GetFormat(fieldFormatList, i); data = totalValues[pos] < 0 ? GetStatic.ParseMinusValue(totalValues[pos]) : totalValues[pos].ToString(format.ToUpper()); alignment = GetAlignment(fieldAlignmentList, i); nowrapProperty = GetNoWrapping(fieldWrapList, i); } if (totalTextCol > -1) { totalFieldIndex = totalTextCol; } if (i == totalFieldIndex) data = totalText; rowText.AppendLine("" + data + ""); } rowText.AppendLine(""); return rowText.ToString(); } private static String CreatGrandTotalRow(ref DataTable dt, string totalText, int totalFieldIndex, string[] totalFields, Double totalValues, string[] fieldFormatList, string fieldAlignmentList, string fieldWrapList, Double grandTotal, Double grandTotalUsd, Double grandTotal_1, ref ArrayList ExcludeFieldList, bool includeSerialNo) { var rowText = new StringBuilder(""); rowText.AppendLine(""); if (includeSerialNo) { if (totalText.IndexOf("") == -1) rowText.AppendLine(""); } for (int i = 0; i < dt.Columns.Count; i++) { if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1) { continue; } int pos = Array.IndexOf(totalFields, i.ToString()); string data = ""; string alignment = ""; string nowrapProperty = ""; if (pos >= 0) { data = GetStatic.ParseMinusValue(grandTotal.ToString()); alignment = GetAlignment(fieldAlignmentList, i); nowrapProperty = GetNoWrapping(fieldWrapList, i); } if (i == totalFieldIndex) data = totalText; if (i == 9 && grandTotal != 0.00) { rowText.AppendLine("" + GetStatic.ParseMinusValue(grandTotal) + ""); } else if (i == 11 && grandTotalUsd != 0.00) { rowText.AppendLine("" + GetStatic.ParseMinusValue(grandTotalUsd) + ""); } else if (i == 13 && grandTotal_1 != 0.00) { rowText.AppendLine("" + GetStatic.ParseMinusValue(grandTotal_1) + ""); } else { rowText.AppendLine("" + data + ""); } } rowText.AppendLine(""); return rowText.ToString(); } private static string GetFormat(string[] fieldFormatList, int currFieldIndex) { return fieldFormatList.Length > currFieldIndex ? fieldFormatList[currFieldIndex] : ""; //return ( pos == -1 ? "": fieldFormatList[pos]); } private static string GetNoWrapping(string fieldWrapList, int currFieldIndex) { if (fieldWrapList == "") return ""; string[] wrapListArray = fieldWrapList.Split('|'); string isWrap = wrapListArray.Length > currFieldIndex ? wrapListArray[currFieldIndex] : ""; string noWrapValue = ""; if (isWrap == "Y") noWrapValue = " nowrap = \"nowrap\""; return noWrapValue; } private static string GetAlignment(string fieldAlignmentList, int currFieldIndex) { if (fieldAlignmentList == "") return ""; string[] alignListArray = fieldAlignmentList.Split('|'); string alignName = alignListArray.Length > currFieldIndex ? alignListArray[currFieldIndex] : ""; string align = ""; switch (alignName.ToUpper()) { case "R": align = " align=\"right\""; break; case "L": align = " align=\"left\""; break; case "C": align = " align=\"center\""; break; default: break; } return align; } private static string CreateLink(string data) { return ""; } private String CreateReportHead(ref DataTable dt, Boolean merge, ref ArrayList ExcludeFieldList) { var head = new StringBuilder(""); var SerialNoColumnHead = ""; if (includeSerialNo) { SerialNoColumnHead = "SN."; extraCol = 1; } if (!merge) { head.AppendLine(""); head.AppendLine(SerialNoColumnHead); foreach (DataColumn col in dt.Columns) { if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1) { extraCol--; continue; } head.AppendLine("" + col.ColumnName + ""); } head.AppendLine(""); } else { var columns = new Dictionary(); foreach (DataColumn col in dt.Columns) { if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1) { extraCol--; continue; } var splitPos = col.ColumnName.IndexOf('_'); if (splitPos == -1) { columns.Add(col.ColumnName, col.ColumnName); } else { var key = col.ColumnName.Substring(0, splitPos); var value = col.ColumnName.Substring(splitPos + 1, col.ColumnName.Length - splitPos - 1); if (!columns.ContainsKey(key)) { columns.Add(key, value); } else { columns[key] = columns[key] + "|" + value; } } } var row1 = ""; var row2 = ""; foreach (var kvp in columns) { string[] values = kvp.Value.Split('|'); if (values.Length == 1) { row1 = row1 + "" + kvp.Key + ""; } else { row1 = row1 + "" + kvp.Key + ""; foreach (string value in values) { row2 = row2 + "" + value + ""; } } } if (includeSerialNo) { SerialNoColumnHead = "SN."; } head.AppendLine("" + SerialNoColumnHead + row1 + ""); head.AppendLine("" + row2 + ""); } return head.ToString(); } #endregion Generate Report private void PrintUserMatrixReport() { const string pStart = "

"; const string pEnd = "

"; var html = new StringBuilder(); cssClass = "TBLReportMatrix table table-bordered table-condensed table-striped"; int employeeTable = 0; foreach (DataRow dr in reportResult.Result.Tables[0].Rows) { string name = dr["Name"].ToString(); string department = dr["department"].ToString(); string branch = dr["branch"].ToString(); string supervisor = dr["supervisor"].ToString(); DataTable rptDt = reportResult.Result.Tables[++employeeTable]; string reportText = GenerateReport(ref rptDt).Replace(""); html.AppendLine("User Name: " + name + ""); html.AppendLine("
"); //html.AppendLine("Department: " + department + ""); //html.AppendLine("
"); html.AppendLine("Agent/Branch Name: " + branch + ""); //html.AppendLine("
"); //html.AppendLine("Supervisor: " + supervisor + ""); html.AppendLine(""); html.AppendLine(reportText); html.AppendLine(pEnd); } rptDiv.InnerHtml = html.ToString(); head.Visible = false; filters.Visible = false; //hr1.Visible = false; //hr2.Visible = false; export.Visible = false; } private ColDefinatoin GetColumnNameToIndex(DataTable dt, string totalFieldNameList, string subTotalFieldNameList) { var r = new ColDefinatoin(); var fList = new ArrayList(); r.Alignment = ""; r.Format = " "; r.SubTotalFields = " "; r.TotalFields = " "; for (var i = 0; i < dt.Columns.Count; i++) { var cp = new ColProperties(i); fList.Add(cp); } var cList = totalFieldNameList.Split('|'); foreach (var colName in cList) { var pos = dt.Columns.IndexOf(colName); if (pos >= 0) { var cp = (ColProperties)fList[pos]; cp.IsTotal = true; fList[pos] = cp; } } foreach (var colName in cList) { var pos = dt.Columns.IndexOf(colName); pos = pos - 1; if (pos >= 0) { var cp = (ColProperties)fList[pos]; cp.IsNumeric = true; fList[pos] = cp; } } cList = subTotalFieldNameList.Split('|'); foreach (var colName in cList) { var pos = dt.Columns.IndexOf(colName); if (pos >= 0) { var cp = (ColProperties)fList[pos]; cp.IsSubTotal = true; fList[pos] = cp; } } foreach (ColProperties itm in fList) { r.Alignment = r.Alignment + (r.Alignment.Length > 0 ? "|" : "") + ((itm.IsSubTotal || itm.IsTotal) ? "R" : "L"); r.Format = r.Format + (r.Format.Length > 0 ? "|" : "") + ((itm.IsNumeric) ? "N" : ""); r.SubTotalFields = r.SubTotalFields + (r.SubTotalFields.Length > 0 ? "|" : "") + (itm.IsSubTotal ? itm.Index.ToString() : ""); r.TotalFields = r.TotalFields + (r.TotalFields.Length > 0 ? "|" : "") + (itm.IsTotal ? itm.Index.ToString() : ""); } return r; } public class ColDefinatoin { public string TotalFields { get; set; } public string SubTotalFields { get; set; } public string Alignment { get; set; } public string Format { get; set; } } public class ColProperties { public int Index { get; set; } public bool IsTotal { get; set; } public bool IsNumeric { get; set; } public bool IsSubTotal { get; set; } public ColProperties() { } public ColProperties(int index) { Index = index; IsTotal = false; IsSubTotal = false; IsNumeric = false; } } } }