Friday, 2 March 2012

Creating summary report using c#code

* Create this class
* calling report method at on buton click
* function to generate report


* Create this class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace BPSM_Server
{
    public static class Report
    {
        #region: Write Message to Reportfile :

        public static void Write(string FileName, string message)
        {
            try
            {
                string filePath = FileName;
                string logLine = System.String.Format("{0}", message);
                if (!File.Exists(filePath))
                {
                    StreamWriter sw;
                    //sw = File.AppendText(filePath);
                    sw = File.CreateText(filePath);
                    sw.WriteLine(logLine);
                    sw.Close();
                }
                else
                {

                    ArrayList lines = new ArrayList();
                    StreamReader rdr = new StreamReader(filePath);
                    string line;
                    while ((line = rdr.ReadLine()) != null)
                        lines.Add(line);
                    rdr.Close();
                    lines.Add(logLine);
                    StreamWriter wrtr = new StreamWriter(filePath);
                    foreach (string strNewLine in lines)
                        wrtr.WriteLine(strNewLine);
                    wrtr.Close();
                }
            }
            catch (Exception ex)
            {
                Logging.Logflatfile_Ex(ex);
            }

        }

        #endregion


    }
}
* calling report method at on buton click

 private void btnReport_Click(object sender, EventArgs e)
        {
            GeneratePacketsReport(txtPDFPath.Text);
        }

* function to generate report
  public void GeneratePacketsReport(string pdfspath)
        {
            try
            {
               

                    //SetControlPropertyValue(lblCopyfolder, "Text", "Writing SummaryReport..");
                    string ReportPath = pdfspath + "\\" + "ReportSummary" + System.DateTime.Now.ToString("ddMMyyyyhhmmss") + ".txt";
                    //Report.Write(ReportPath, "Operation Summary for 'DIsc'  " + XMLPath.Substring(0, 3));
                    //Report.Write(ReportPath, "========================================================================================================================");
                    //Report.Write(ReportPath, "Application : " + System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName.Split(',')[0] + " " + System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName.Split(',')[1]);

                    //Report.Write(ReportPath, "Data As Per 'Disc' ");
                    //Report.Write(ReportPath, "************************");
                    //Report.Write(ReportPath, "CIDR :" + TotalCIDR.Count);
                    //Report.Write(ReportPath, "Registrar :" + TotalRegistrar.Count);
                    //Report.Write(ReportPath, "Docs :" + TotalDocs.Count);
                    //Report.Write(ReportPath, "");
                    //Report.Write(ReportPath, "");

                    //Report.Write(ReportPath, "Summary of Current Operation");
                    //Report.Write(ReportPath, "**********************************");

                    //Report.Write(ReportPath, "Records Inserted");
                    //Report.Write(ReportPath, "*****************");
                    //Report.Write(ReportPath, "TotalInsertedPackets: " + InsertedRecords.Count);
                    //Report.Write(ReportPath, "Records Updated");
                    //Report.Write(ReportPath, "*****************");
                    //Report.Write(ReportPath, "CIDR: " + CIDRDeletedCount.Count);
                    //Report.Write(ReportPath, "Registrar: " + RegistrarDeletedCount.Count);
                    //Report.Write(ReportPath, "Docs: " + DocsDeletedCount.Count);
                    //Report.Write(ReportPath, "Manifest File Updated Count :" + ManifetCopYied.Count);

                   
                    if (pdfcount!=null && pdfcount.Count > 0)
                    {
                        Report.Write(ReportPath, "Total PDF FILES:" + pdfcount.Count);
                        Report.Write(ReportPath, "*****************");
                        foreach (FileInfo name in pdfcount)
                        {
                            Report.Write(ReportPath, "File Name: " + name.ToString());
                        }
                        pdfcount.Clear();
                    }
                    Report.Write(ReportPath, "");
                    Report.Write(ReportPath, "");

                    if (SkippedPDFFiles!=null&&SkippedPDFFiles.Count > 0)
                    {
                        Report.Write(ReportPath, "Skipped PDF Files:" + SkippedPDFFiles.Count);
                        Report.Write(ReportPath, "*****************");
                        foreach (string name in SkippedPDFFiles)
                        {
                            Report.Write(ReportPath, "File Name " + name.ToString());
                        }
                        SkippedPDFFiles.Clear();
                    }
                    Report.Write(ReportPath, "");
                    Report.Write(ReportPath, "");
                    if (UIDGeneratedPDFFILES!=null&& UIDGeneratedPDFFILES.Count > 0)
                    {
                        Report.Write(ReportPath, "Unique Id generated pdf files:" + UIDGeneratedPDFFILES.Count);
                        Report.Write(ReportPath, "*****************");
                        foreach (string name in UIDGeneratedPDFFILES)
                        {
                            Report.Write(ReportPath, "File Name: " + name.ToString());
                        }
                        UIDGeneratedPDFFILES.Clear();

                    }
                    Report.Write(ReportPath, "");
                    Report.Write(ReportPath, "");
                    if (UIDUpdatedFlagsCount!=null&& UIDUpdatedFlagsCount.Count > 0)
                    {
                        Report.Write(ReportPath, "Unique Id Updated flags :" + UIDUpdatedFlagsCount.Count);
                        Report.Write(ReportPath, "*****************");
                        foreach (string name in UIDUpdatedFlagsCount)
                        {
                            Report.Write(ReportPath, "File Name: " + name.ToString());
                        }
                        UIDUpdatedFlagsCount.Clear();
                    }
                    Report.Write(ReportPath, "");
                    Report.Write(ReportPath, "");
                                       
                    MessageBox.Show(ReportPath + "Generated Successfully");
               
                //TotalCIDR.Clear();
                //InsertedRecords.Clear();
                //TotalRegistrar.Clear();
                //TotalDocs.Clear();
                //CIDRDeletedCount.Clear();
                //RegistrarDeletedCount.Clear();
                //filesnotprocessed.Clear();
                //ManifetCopYied.Clear();
                //CIDRCopiedCount.Clear();
                //Invoke(new MethodInvoker(GetWoleText));
                //DocsDeletedCount.Clear();
                //SetControlPropertyValue(lblStatusd1, "Text", "Completed.");
                //SetControlPropertyValue(button3, "Enabled", true);
                //SetControlPropertyValue(lblCopyfolder, "Text", ReportPath + " Generated Successfully.");
                //SetControlPropertyValue(button1, "Enabled", true);
                //SetControlPropertyValue(button2, "Enabled", true);
              
            }
            catch (Exception ee)
            {
                Logging.Logflatfile_Ex(ee);
            }

        }

No comments:

Post a Comment