// This method will create txt report file and inserts into portfolio reports..... public static void GenerateTextReport(Schedule report) { DataSet tables = ExtecuteReport(report); if (tables.Tables[0].Rows.Count >= 1 || report.StoredProcedureName.Contains("spSelectDepartmentalBreakdownreportLevel")) { TextWriter twWriter = new StreamWriter("c:\\temp\\" + report.Selectedname + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".txt"); try { twWriter.WriteLine(); twWriter.Write("Report: " + " " + report.ReportName); twWriter.WriteLine(); twWriter.Write("Schedule Name:" + " " + report.Selectedname); twWriter.WriteLine(); twWriter.Write("Date range:" + " " + report.ListofFilters.Split('=', ',')[5].TrimStart('\'').TrimEnd('\'') + " TO " + report.ListofFilters.Split('=', ',')[7].TrimStart('\'').TrimEnd('\'')); twWriter.WriteLine(); twWriter.WriteLine(); if (report.StoredProcedureName.Contains("spSelectDepartmentalBreakdownreportLevel")) { // TextReports.GenerateTXTData(twWriter, " " + '\t', tables.Tables[0], GetColumns(report.Columns), Listoftotals(report.Totals)); TextReports.Departmentalreport(twWriter, " " + '\t', tables, GetColumns(report.Columns), report.ListofFilters.Split('=', ',')[93], GetLevels(tables), Listoftotals(report.Totals)); } else { if (tables.Tables.Count >= 3) { foreach (DataTable dt in tables.Tables) { List <string> columns = new List <string>(); foreach (DataColumn dc in dt.Columns) { columns.Add(dc.ColumnName); } TextReports.GenerateTXTData(twWriter, " " + '\t', dt, columns, Listoftotals(report.Totals)); twWriter.WriteLine(); } } else { TextReports.GenerateTXTData(twWriter, " " + '\t', tables.Tables[0], GetColumns(report.Columns), Listoftotals(report.Totals)); } } SendEmail.InsertPortfoliodetails("c:\\temp\\" + report.Selectedname + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".txt", report.EmailAddresses, report.Portfolioreportid, report.ID); } catch { ReportStatus(report.ID, "ERROR"); } finally { twWriter.Close(); } } else { ReportStatus(report.ID, "No Data"); } }
// This method will create CSV report file and inserts into portfolio reports..... public static void GenerateCSVReport(Schedule report) { DataSet tables = ExtecuteReport(report); if (tables.Tables[0].Rows.Count >= 1) { TextWriter twWriter = new StreamWriter("c:\\temp\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".csv", false, Encoding.UTF8); try { twWriter.WriteLine(); twWriter.Write(report.ReportName); twWriter.WriteLine(); twWriter.WriteLine(); twWriter.Write("Schedule Name:" + " " + report.Selectedname); twWriter.WriteLine(); twWriter.WriteLine(); twWriter.Write("Date range:" + " " + report.ListofFilters.Split('=', ',')[5].TrimStart('\'').TrimEnd('\'') + " TO " + report.ListofFilters.Split('=', ',')[7].TrimStart('\'').TrimEnd('\'')); twWriter.WriteLine(); twWriter.WriteLine(); if (report.StoredProcedureName == "spSelectDepartmentalBreakdownreportLevel") { //TextReports.GenerateTXTData(twWriter, ",", tables.Tables[0], GetColumns(report.Columns), Listoftotals(report.Totals)); TextReports.Departmentalreport(twWriter, ",", tables, GetColumns(report.Columns), report.ListofFilters.Split('=', ',')[93], GetLevels(tables), Listoftotals(report.Totals)); } else { if (tables.Tables.Count >= 3) { int i = 0; foreach (DataTable dt in tables.Tables) { List <string> columns = new List <string>(); foreach (DataColumn dc in dt.Columns) { columns.Add(dc.ColumnName); } twWriter.Write(report.Columns.Split(',')[i]); TextReports.GenerateTXTData(twWriter, ",", dt, columns, Listoftotals(report.Totals)); twWriter.WriteLine(); i++; } } else { TextReports.GenerateTXTData(twWriter, ",", tables.Tables[0], GetColumns(report.Columns), Listoftotals(report.Totals)); } } if (report.GraphBindings != string.Empty) { List <string> pics = new List <string>(); int repid = 0; foreach (string graph in report.GraphBindings.Split('-')) { GraphicalReport.GenerateGraph("Z:\\inetpub\\wwwroot\\proimages\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png", tables.Tables[0], graph, report.ReportName, report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png", report.GraphType); pics.Add("Z:\\inetpub\\wwwroot\\proimages\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png"); repid++; } GraphicalReport.CreateGraphsinExcel(pics, "c:\\temp\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".xls", report.ReportName); SendEmail.InsertPortfoliodetails("c:\\temp\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".xls", report.EmailAddresses, report.Portfolioreportid, report.ID); } SendEmail.InsertPortfoliodetails("c:\\temp\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".csv", report.EmailAddresses, report.Portfolioreportid, report.ID); } catch { ReportStatus(report.ID, "ERROR"); } finally { twWriter.Close(); } } else { ReportStatus(report.ID, "No Data"); } }