private void ToExcel_SingleSectionWise()
        {
            //****Maximum Progressber Process Declare**********;
            progressBar1.Maximum = 9;


            //*********************Array Define*********************
            string[] SectionNames = { "b2b", "b2cl", "b2cs", "cdnr", "cdnur", "at", "exem", "hsn", "docs" };
            //*********************Data Table Array Define*********************
            DataTable[] lstDT =
            {
                B2BFormate.B2BInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),    _LastDate.ToString("dd-MMM-yyyy")),
                B2CLFormate.B2CLInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),  _LastDate.ToString("dd-MMM-yyyy")),
                B2CSFormate.B2CSInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),  _LastDate.ToString("dd-MMM-yyyy")),
                CDNRFormate.CDNRnvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),   _LastDate.ToString("dd-MMM-yyyy")),
                CDNURFormate.CDNURnvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy")),
                ATFormate.ATInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),      _LastDate.ToString("dd-MMM-yyyy")),
                EXEMPFormate.EXEMInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy")),
                HSNFormate.HSNInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),    _LastDate.ToString("dd-MMM-yyyy")),
                DOCSFormate.DOCSInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"),  _LastDate.ToString("dd-MMM-yyyy")),
            };
            //*******Create  <ToEX ToEX = delegate> Delegate variable***************
            ToEX ToEX = delegate
            {
                FolderBrowserDialog sfd = new FolderBrowserDialog();
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    Cursor = Cursors.WaitCursor;
                    string path = sfd.SelectedPath + "\\Section_wise_CSV_files"; // or whatever
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    int i = 0;
                    foreach (string item in SectionNames)
                    {
                        ExportToExcel_SingleSectionWise(path + "\\" + item + ".csv", lstDT[i], item);
                        //**********method wise progressber increase**********
                        progressBar1.Value = ++MethodExecutioncount;
                        i++;
                    }
                    Cursor             = Cursors.Default;
                    progressBar1.Value = 0;
                    MessageBox.Show("Export Successfull");
                }
            };

            //*******point  <ToEX ToEX = delegate> Delegate variable***************
            ToEX();
        }
 private void aTREPORTToolStripMenuItem_Click(object sender, EventArgs e)
 {
     mActiveMenuberName = "AT";
     dgvView.DataSource = ATFormate.ATInvoiceGenerate(_FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
     GriedDesign();
 }
        private void ExportToExcel(string fileName)
        {
            Excel.Application oXL;
            Excel._Workbook   oWB;
            //Excel.Range oRng;
            object misValue = System.Reflection.Missing.Value;

            try
            {
                //Start Excel and get Application object.
                oXL         = new Excel.Application();
                oXL.Visible = false;

                //Get a new workbook.
                oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));

                //Delete old Work Sheet
                //oXL.DisplayAlerts = false;
                try
                {
                    int ExcelsheetCount = oXL.ActiveWorkbook.Worksheets.Count;
                    int j = 1;
                    for (j = ExcelsheetCount; j > 1; j--)
                    {
                        ((Excel.Worksheet)oXL.ActiveWorkbook.Sheets[j]).Delete();
                    }
                }
                catch (Exception) { }

                //WorkBook Save
                oWB.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                oWB.Close(true, misValue, misValue);
                oXL.Quit();

                //Maximum Progressber Process Declare;
                progressBar1.Maximum = 9;

                //method wise progressber increase
                progressBar1.Value = ++MethodExecutioncount;
                B2BFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                B2CLFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                B2CSFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                CDNRFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                CDNURFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                ATFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                EXEMPFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                HSNFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));
                progressBar1.Value = ++MethodExecutioncount;
                DOCSFormate.ExportToExcel(fileName, _FirstDate.ToString("dd-MMM-yyyy"), _LastDate.ToString("dd-MMM-yyyy"));

                MessageBox.Show("Export complete.", "Export To Excel", MessageBoxButtons.OK, MessageBoxIcon.Information);

                //Process Complite Then Zero Initialize
                progressBar1.Value   = 0;
                MethodExecutioncount = 0;
            }
            catch (Exception theException)
            {
                String errorMessage;
                errorMessage = "Error: ";
                errorMessage = String.Concat(errorMessage, theException.Message);
                errorMessage = String.Concat(errorMessage, " Line: ");
                errorMessage = String.Concat(errorMessage, theException.Source);

                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }