|
|
using Swift.DAL.AccountReport; 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.AccountReport { 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 : <br />" + reportResult.Filters + "<br /><br />Generated On=" + now + " || Generated By=" + user; }
private void PrintError() { rptDiv.InnerHtml = "<div class = \"reportError\">" + reportResult.Msg + "</div>"; }
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; } 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("<table width='100%' class='table table-bordered table-condensed table-striped'><tr><td nowrap='nowrap'>"); sbPaging.AppendLine("<div class='reportFilters' width='100%'>"); sbPaging.AppendLine("<span style='float:left; width:auto; margin-top:5px;'>Results: " + totalRecords + " records </span>"); 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("<img onclick='GotoPage(1);' src='../../Images/paging_Icons/first_page.png' alt='First Page' style='margin-top:5px;float:left;border:none;cursor:pointer' />"); 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>");
for (int i = startPage; i < endPage + 1; i++) { cssLink = PageNumber == i ? "pagingLinkSelected" : "pagingLink"; sbPaging.AppendLine("<span onclick ='GotoPage(" + i + ");' class='" + cssLink + "'>" + i + "</span>"); }
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>"); sbPaging.AppendLine("<img onclick=GotoPage(" + totalPage + "); src='../../Images/paging_Icons/last_page.png' style='margin-top:5px;border:none;cursor:pointer' />"); } sbPaging.AppendLine("</div></td><td nowrap='nowrap' width='135' align=\"right\">");
if (totalRecords > PageSizes) //Convert.ToInt32(GetStatic.GetReportPagesize()))
sbPaging.AppendLine("Goto Page: " + GotoList(totalPage)); sbPaging.AppendLine("</td></tr></table>"); paging.InnerHtml = sbPaging.ToString(); }
private string GotoList(int totalPage) { StringBuilder sb = new StringBuilder(""); sb.AppendLine("<select id='gotoLabel' onchange=GotoPage(this.value); style='min-width:50px'>"); for (int i = 0; i < totalPage; i++) { sb.AppendLine("<option value='" + (i + 1) + "' " + (GetPageNumber() == (i + 1) ? "Selected=Selected" : "") + " >" + (i + 1) + "</option>"); } sb.AppendLine("</select>"); return sb.ToString(); }
private ReportResult PrepareReport(string reportName) { if (reportName == "intoldreport") { reportResult = PrepareReport_IntOldReport(); } else if (reportName == "intmonthlyreport") { reportResult = PrepareReport_IntMonthlyReport(); } else if (reportName == "intshowcentralizereport") { reportResult = PrepareReport_IntShowCentralizeReport(); } else if (reportName == "intnewreport") { reportResult = PrepareReport_IntNewReport(); } else if (reportName == "intshowreport") { reportResult = PrepareReport_IntShowReport(); } else if (reportName == "intlreconcilerpt") { reportResult = PrepareReport_IntlReconcileRpt(); } else if (reportName == "domestictxn") { reportResult = PrepareReport_domestictxn(); } else if (reportName == "domestictxnreceiving") { reportResult = PrepareReport_domestictxnreceiving(); } else if (reportName == "agentsummaryrpt") { reportResult = PrepareAgentSummaryRpt(); } else if (reportName == "nrbreport") { reportResult = PrepareNRBRpt(); } else if (reportName == "paidtxnrpt") { reportResult = PreparePaidTxnRpt(); } else if (reportName == "dsettlementreport") { reportResult = PreparedSettlementRpt(); } else if (reportName == "settlementdetailrpt") { reportResult = PrepareTxnDetailRpt(); } else if (reportName == "settlementhoreport") { reportResult = PrepareSettlementHoRpt(); } else if (reportName == "settlementhoreportdrilldown") { reportResult = PrepareSettlementHoRptDrillDown(); } else if (reportName == "nrbprocessrpt") { reportResult = PrepareNrbProcessRpt(); } else if (reportName == "dailysettlementrpt") { reportResult = DailySettlemetReport(); } else if (reportName == "individualtxnrpt") { reportResult = IndividualTxnRpt(); } else if (reportName == "tdsrpt") { reportResult = PrepareTdsRpt(); } else if (reportName == "compiletoweb") { reportResult = PrepareCompileToWebRpt(); } else if (reportName == "currpositionreport") { reportResult = PrepareReport_currpositionReport(); } else if (reportName == "multicurrencyclosingreport") { reportResult = PrepareReport_multicurrencyclosingReport(); } return reportResult; }
private ReportResult PrepareReport_multicurrencyclosingReport() { string asOnDate = GetStatic.ReadQueryString("asOnDate", ""); string partner = GetStatic.ReadQueryString("partner", ""); string user = GetStatic.GetUser(); includeSerialNo = true;
totalFields = "1||3|4|5|6|7|8"; fieldFormat = "|N|N|N|N|N|N|N|N|"; fieldAlignment = "|R|R|R|R|R|R|R|"; totalText = "Total";
return (new AccountReportDao().MultiCurrencyClosingRpt(user, asOnDate, partner)); }
#region Report part
private ReportResult DailySettlemetReport() { string fromDate = GetStatic.ReadQueryString("fromDate", ""); string toDate = GetStatic.ReadQueryString("toDate", "");
fieldAlignment = "|||R|R|R|R|R|R|R|R"; totalFields = "3|4|5|6|7|8|9|10|11"; totalText = "Net Settlement"; fieldFormat = "||||N|N";
return (new AccountReportDao().GetDailySettlemetReport(fromDate, toDate)); }
private ReportResult IndividualTxnRpt() { string icn = GetStatic.ReadQueryString("icn", ""); string toDate = GetStatic.ReadQueryString("toDate", "");
fieldAlignment = "|||R|R|R|R|R|R|R|R"; totalFields = "3|4|5|6|7|8|9|10|11"; totalText = "Net Settlement"; fieldFormat = "||||N|N";
return (new AccountReportDao().GetIndividualTxnRpt(icn)); }
private ReportResult PrepareSettlementHoRpt() { string branch = GetStatic.ReadQueryString("branch", ""); string agentId = GetStatic.ReadQueryString("agentId", ""); string fromDate = GetStatic.ReadQueryString("fromDate", ""); string toDate = GetStatic.ReadQueryString("toDate", ""); string user = GetStatic.GetUser(); includeSerialNo = true;
fieldAlignment = "|||R|R|R|R|R|R|R|R"; totalFields = "3|4|5|6|7|8|9|10|11"; totalText = "Net Settlement"; fieldFormat = "||||N|N";
return (new AccountReportDao().GetSettlementHoRpt(fromDate, toDate, agentId, branch, user)); }
private ReportResult PrepareSettlementHoRptDrillDown() { string flag = GetStatic.ReadQueryString("FLAG", ""); string branch = GetStatic.ReadQueryString("BRANCH", ""); string agentId = GetStatic.ReadQueryString("AGENT", ""); string fromDate = GetStatic.ReadQueryString("DATE1", ""); string toDate = GetStatic.ReadQueryString("DATE2", ""); string country = GetStatic.ReadQueryString("COUNTRY", ""); string user = GetStatic.GetUser();
includeSerialNo = true; fieldAlignment = "|||R|R|R|R|R|R|R|R"; totalFields = "4|5"; totalText = "Total"; fieldFormat = "||||N|N||";
return (new AccountReportDao().GetSettlementHoRptDrillDown(fromDate, toDate, agentId, branch, user, country, flag)); }
private ReportResult PrepareTxnDetailRpt() { string agentId = GetStatic.ReadQueryString("agentId", ""); string fromDate = GetStatic.ReadQueryString("fromDate", ""); string toDate = GetStatic.ReadQueryString("toDate", "");
fieldAlignment = "||||R|R|R|R|R|R|R|R"; totalFields = "4|5|6|7|8|9|10|11"; totalText = "Grand Total"; mergeColumnHead = true; fieldFormat = "||||N||N||N||N|N";
return (new AccountReportDao().GetTxnDetailRpt(fromDate, toDate, agentId)); }
private ReportResult PreparedSettlementRpt() { string fromDate = GetStatic.ReadQueryString("fromDate", ""); fieldFormat = "|||N"; fieldAlignment = "|||R"; return (new AccountReportDao().GetDomesticSettlementReport(fromDate)); }
private ReportResult PrepareAgentSummaryRpt() { string agentGrp = GetStatic.ReadQueryString("agentGrp", ""); string agentId = GetStatic.ReadQueryString("agentId", ""); string date = GetStatic.ReadQueryString("date", ""); string tranType = GetStatic.ReadQueryString("tranType", "");
includeSerialNo = true; fieldAlignment = "|||R|R|R|R|R|R|R|R"; fieldFormat = "|||N|N|N|N|N|N|N|N"; totalFields = "3|4|5|6|7|8|9|10|11"; totalText = "Total";
return (new AccountReportDao().GetAgentSummaryRpt(agentGrp, date, tranType, agentId)); }
// Intl Rpt start ...
private ReportResult PrepareReport_IntMonthlyReport() { var sagentId = GetStatic.ReadQueryString("ragentId", ""); var ragentId = GetStatic.ReadQueryString("sagentId", ""); var fromDate = GetStatic.ReadQueryString("fromDate", ""); var toDate = GetStatic.ReadQueryString("toDate", ""); var dateType = GetStatic.ReadQueryString("dateType", ""); var paymentStatus = GetStatic.ReadQueryString("paymentStatus", ""); var reportType = GetStatic.ReadQueryString("reportType", ""); includeSerialNo = true; mergeColumnHead = true; return (new AccountReportDao().GetIntMonthlyReport(sagentId, ragentId, fromDate, toDate, dateType, paymentStatus, reportType)); }
private ReportResult PrepareReport_IntShowReport() { var agentId = GetStatic.ReadQueryString("agentId", ""); var fromDate = GetStatic.ReadQueryString("fromDate", ""); var toDate = GetStatic.ReadQueryString("toDate", ""); var dateType = GetStatic.ReadQueryString("dateType", ""); var paymentStatus = GetStatic.ReadQueryString("paymentStatus", ""); includeSerialNo = true; subTotalBy = 1; subTotalFields = "2|3|4"; subTotalText = "<B>Total</B>"; fieldFormat = "|N|N|N"; fieldAlignment = "|R|R|R|R"; return (new AccountReportDao().GetIntShowReport(agentId, fromDate, toDate, dateType, paymentStatus)); }
private ReportResult PrepareReport_IntShowCentralizeReport() { var agentId = GetStatic.ReadQueryString("agentId", ""); var fromDate = GetStatic.ReadQueryString("fromDate", ""); var toDate = GetStatic.ReadQueryString("toDate", ""); var dateType = GetStatic.ReadQueryString("dateType", ""); var paymentStatus = GetStatic.ReadQueryString("paymentStatus", ""); includeSerialNo = true; subTotalBy = 1; subTotalFields = "2|3|4"; subTotalText = "<B>Total</B>"; fieldFormat = "|N|N|N"; fieldAlignment = "|R|R|R|R"; return (new AccountReportDao().GetIntShowCentralizeReport(agentId, fromDate, toDate, dateType, paymentStatus)); }
private ReportResult PrepareReport_IntNewReport() { var agentId = GetStatic.ReadQueryString("agentId", ""); var fromDate = GetStatic.ReadQueryString("fromDate", ""); var toDate = GetStatic.ReadQueryString("toDate", ""); var dateType = GetStatic.ReadQueryString("dateType", ""); var paymentStatus = GetStatic.ReadQueryString("paymentStatus", ""); includeSerialNo = true; subTotalBy = 1; subTotalFields = "2|3|4"; subTotalText = "<B>Total</B>"; fieldFormat = "|N|N|N"; fieldAlignment = "|R|R|R|R"; return (new AccountReportDao().GetIntNewReport(agentId, fromDate, toDate, dateType, paymentStatus)); }
private ReportResult PrepareReport_IntOldReport() { var agentId = GetStatic.ReadQueryString("agentId", ""); var fromDate = GetStatic.ReadQueryString("fromDate", ""); var toDate = GetStatic.ReadQueryString("toDate", ""); var dateType = GetStatic.ReadQueryString("dateType", ""); var paymentStatus = GetStatic.ReadQueryString("paymentStatus", ""); includeSerialNo = true; subTotalBy = 1; subTotalFields = "2|3|4"; subTotalText = "<B>Total</B>"; fieldFormat = "|N|N|N"; fieldAlignment = "|R|R|R|R"; return (new AccountReportDao().GetIntOldReport(agentId, fromDate, toDate, dateType, paymentStatus)); }
// Intl Rpt end ...
private ReportResult PrepareReport_IntlReconcileRpt() { var sDate = GetStatic.ReadQueryString("fromDate", ""); var eDate = GetStatic.ReadQueryString("toDate", ""); includeSerialNo = true; subTotalBy = 1; mergeColumnHead = true; subTotalFields = "3|5|7|9|11"; subTotalText = "<B>Sub Total</B>"; subTotalTextCol = 1; totalFields = "3|5|7|9|11"; fieldFormat = "|||N||N||N||N||N"; totalText = "<B>Grand Total</B>"; return (new AccountReportDao().GetIntlReconcileRpt(sDate, eDate)); }
private ReportResult PrepareReport_domestictxn() { string fromDate = GetStatic.ReadQueryString("fromDate", ""); string todate = GetStatic.ReadQueryString("todate", ""); string agentId = GetStatic.ReadQueryString("agentId", ""); string DateType = GetStatic.ReadQueryString("DateType", ""); string payment_status = GetStatic.ReadQueryString("payment_status", ""); string type = GetStatic.ReadQueryString("type", ""); string user = GetStatic.GetUser(); includeSerialNo = true; fieldFormat = "||||N|N||||"; fieldAlignment = "||||R|R||||"; return (new AccountReportDao().GetDomesticTxnReport(user, agentId, fromDate, todate, DateType, payment_status, type)); }
private ReportResult PrepareReport_domestictxnreceiving() { string fromDate = GetStatic.ReadQueryString("fromDate", ""); string todate = GetStatic.ReadQueryString("todate", ""); string agentId = GetStatic.ReadQueryString("agentId", ""); string DateType = GetStatic.ReadQueryString("DateType", ""); string payment_status = GetStatic.ReadQueryString("payment_status", ""); string type = GetStatic.ReadQueryString("type", ""); string user = GetStatic.GetUser(); includeSerialNo = true; fieldFormat = "||||N|N|"; fieldAlignment = "||||R||"; return (new AccountReportDao().GetDomesticReceivingTxnReport(user, agentId, fromDate, todate, DateType, payment_status, type)); }
private ReportResult PrepareNRBRpt() { mergeColumnHead = true; string fromDate = GetStatic.ReadQueryString("fromDate", ""); string todate = GetStatic.ReadQueryString("todate", ""); string agentId = GetStatic.ReadQueryString("agentId", ""); string flag = GetStatic.ReadQueryString("flag", ""); includeSerialNo = true;
return (new AccountReportDao().GetNrbDetailReport(flag, fromDate, todate, agentId)); }
private ReportResult PrepareNrbProcessRpt() { mergeColumnHead = true; string fromDate = GetStatic.ReadQueryString("fromDate", ""); string todate = GetStatic.ReadQueryString("todate", ""); string agentId = GetStatic.ReadQueryString("agentId", ""); totalFields = "3|4|6"; fieldFormat = "|||||N||N|"; fieldAlignment = "|||||R||R|"; totalText = "Total"; includeSerialNo = true; return (new AccountReportDao().GetNrbProcessReport(fromDate, todate, agentId)); }
private ReportResult PreparePaidTxnRpt() { mergeColumnHead = true; includeSerialNo = true; totalFields = "1|2|3|4|5|6"; fieldFormat = "|N|N|N|N|N|N|"; fieldAlignment = "|R|R|R|R|R|R|"; totalText = "Total"; string fromDate = GetStatic.ReadQueryString("fromDate", ""); string todate = GetStatic.ReadQueryString("todate", ""); string dateType = GetStatic.ReadQueryString("dateType", ""); string reportType = GetStatic.ReadQueryString("reportType", ""); return (new AccountReportDao().GetPaidTxnReport(fromDate, todate, dateType, reportType)); }
private ReportResult PrepareTdsRpt() { mergeColumnHead = true; includeSerialNo = true; string fromDate = GetStatic.ReadQueryString("fromDate", ""); string party = GetStatic.ReadQueryString("party", ""); return (new AccountReportDao().GetTdsReport(fromDate, party)); }
private ReportResult PrepareCompileToWebRpt() { mergeColumnHead = true; includeSerialNo = true; string agentCode = GetStatic.ReadQueryString("agentcode", ""); string asOnDate = GetStatic.ReadQueryString("asOnDate", ""); string includeZeroValue = GetStatic.ReadQueryString("includeZeroValue", ""); string fromDrAmt = GetStatic.ReadQueryString("fromDrAmt", ""); string toDrAmt = GetStatic.ReadQueryString("toDrAmt", ""); string fromCrAmt = GetStatic.ReadQueryString("fromCrAmt", ""); string toCrAmt = GetStatic.ReadQueryString("toCrAmt", ""); string bankCode = GetStatic.ReadQueryString("bankCode", ""); totalFields = "4|5"; totalText = "Total"; fieldFormat = "||||N|N|"; fieldAlignment = "||||R|R|"; return (new AccountReportDao().GetCompileReport(asOnDate, agentCode, includeZeroValue, bankCode, fromDrAmt, toDrAmt, fromCrAmt, toCrAmt)); }
private ReportResult PrepareReport_currpositionReport() { string startDate = GetStatic.ReadQueryString("startDate", ""); string endDate = GetStatic.ReadQueryString("endDate", ""); string flag = GetStatic.ReadQueryString("flag", ""); string user = GetStatic.GetUser(); includeSerialNo = true; if (flag == "p") { totalFields = "1|2|3"; fieldFormat = "|||||N||N|"; fieldAlignment = "R|R|R|"; totalText = "Total"; }
return (new AccountReportDao().CurrencyPositionRpt(user, startDate, endDate, flag)); }
private int GetPageNumber() { return Convert.ToInt32(GetStatic.ReadNumericDataFromQueryString("pageNumber") == 0 ? 1 : GetStatic.ReadNumericDataFromQueryString("pageNumber")); }
#endregion Report part
#region Generate Report
public String GenerateReport(ref DataTable dt) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); var ExcludeFieldList = new ArrayList(); foreach (var col in excludeColumns.Split('|')) { ExcludeFieldList.Add(col.ToLower()); } ExcludeFieldList.Add("rowcolor");
var html = new StringBuilder(""); html.AppendLine("<div style = \"float:left;clear:both\">");
html.AppendLine("<table border=\"0\" class=\"table table-condensed table-bordered table-striped\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\">"); if (tblCaption != "") html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol).ToString() + "\">" + tblCaption + "</td></tr>"); html.AppendLine(CreateReportHead(ref dt, mergeColumnHead, ref ExcludeFieldList)); html.AppendLine(CreateReportBody(ref dt, subTotalFields, totalFields, ref ExcludeFieldList, totalTextCol, subTotalTextCol));
html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol) + "\" align=\"center\">");
if (totalPage == 0) totalPage = 1;
html.AppendLine("Page " + (GetPageNumber() == 0 ? 1 : GetPageNumber()) + " of " + totalPage + ""); html.AppendLine("</td></tr>"); html.AppendLine("</table>"); html.AppendLine("</div>"); 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 = "<td style='td' align=\"right\">" + SerialNo.ToString() + "</td>"; } 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("<tr style=\"background:" + row["rowColor"].ToString() + ";\">"); } else { body.AppendLine(++cnt % 2 == 1 ? "<tr>" : "<tr style=\"background: #F0F0F0;\">"); }
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("<td style='td' " + alignment + noWrapProperty + ">" + data + "</td>");
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("</tr>"); }
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("<tr>");
if (includeSerialNo) { if (totalText.IndexOf("<td>") == -1) rowText.AppendLine("<td></td>"); } 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("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>"); }
rowText.AppendLine("</tr>"); 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("<tr>"); if (includeSerialNo) { if (totalText.IndexOf("<td>") == -1) rowText.AppendLine("<td></td>"); } 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("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal) + "</td>"); } else if (i == 11 && grandTotalUsd != 0.00) { rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotalUsd) + "</td>"); } else if (i == 13 && grandTotal_1 != 0.00) { rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal_1) + "</td>"); } else { rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>"); } }
rowText.AppendLine("</tr>"); 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 = "<th style='th'>SN.</th>"; extraCol = 1; }
if (!merge) { head.AppendLine("<tr>");
head.AppendLine(SerialNoColumnHead); foreach (DataColumn col in dt.Columns) { if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1) { extraCol--; continue; } head.AppendLine("<th style='th'>" + col.ColumnName + "</th>"); } head.AppendLine("</tr>"); } else { var columns = new Dictionary<string, string>();
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 + "<th style='th' rowspan=\"2\">" + kvp.Key + "</th>"; } else { row1 = row1 + "<th style='th' align=\"center\" colspan=\"" + values.Length + "\">" + kvp.Key + "</th>";
foreach (string value in values) { row2 = row2 + "<th style='th'>" + value + "</th>"; } } }
if (includeSerialNo) { SerialNoColumnHead = "<th style='th' rowspan=\"2\">SN.</th>"; }
head.AppendLine("<tr>" + SerialNoColumnHead + row1 + "</tr>"); head.AppendLine("<tr>" + row2 + "</tr>"); }
return head.ToString(); }
#endregion Generate Report
private void PrintUserMatrixReport() { const string pStart = "<p style=\"page-break-after: always\">"; const string pEnd = "</p>"; 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("<td", "<td nowrap = \"nowrap\""); html.AppendLine(pStart);
html.AppendLine("<div class = \"welcome-div\">"); html.AppendLine("User Name: " + name + ""); html.AppendLine("<br />"); //html.AppendLine("Department: " + department + "");
//html.AppendLine("<br />");
html.AppendLine("Agent/Branch Name: " + branch + ""); //html.AppendLine("<br />");
//html.AppendLine("Supervisor: " + supervisor + "");
html.AppendLine("</div>"); 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; } } } }
|