/* this method is designed to allow the user to perform a soft reset and reset
         * the application to the state direcly after pressin the 'get headers or
         * columns' button. The intent is to allow mutiple agings of the same data
         * making use of different headers on subsquent agings. */
        private void ReAgeCurrentFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // subset of get sheets button event.
            ExcelThread.Reset();
            string file = TbxFilePath.Text.ToString();

            ExcelThread.OpenWorkbook(file);
            ExcelThread.GetSheets();

            // subset of the get headers button event.
            if (ValidationLogic.NoItemSelected(LbxSheetNames))
            {
                ErrorActions.NoSheetSelected();
            }
            else
            {
                string sheetWithData = LbxSheetNames.SelectedItem.ToString();
                ExcelThread.Worksheet = ExcelThread.Worksheets[sheetWithData];
                if (ValidationLogic.NoColumnsFound(ExcelThread.Worksheet))
                {
                    ErrorActions.NoColumnsFound();
                }
                else
                {
                    BuildHeaders();
                    PrepForAging();
                }
            }
        }
        // the saving process writes a formated excel file to a location of the users choice.
        private void BtnSave_Click(object sender, EventArgs e)
        {
            saveFileDialog.Filter = "Excel (*.xlsx)|*.xlsx";
            saveFileDialog.ShowDialog();
            // clear thread of our dataset connection and add a connection to our new in memory file.
            ExcelThread.Reset();
            ExcelThread.Workbook  = ExcelThread.App.Workbooks.Add();
            ExcelThread.Worksheet = ExcelThread.Workbook.Worksheets[1];

            // Write the title and header information.
            ExcelThread.Worksheet.Cells[1, 1] = "Aging results for file " +
                                                TbxFilePath.Text.ToString();
            ExcelThread.Worksheet.Cells[2, 1] = "being performed on " +
                                                LbxDatesToAgeBy.SelectedItem.ToString() +
                                                " from " +
                                                DtpAnchorDate.Value.ToString("MM/dd/yyyy");
            ExcelThread.Worksheet.Cells[4, 1] = "Days Included";
            ExcelThread.Worksheet.Cells[4, 2] = "Summary of " +
                                                LbxDataToAge.SelectedItem.ToString();

            // Write the names and values of our aging buckets.
            ExcelThread.Worksheet.Cells[5, 1]  = "'000 - 030";
            ExcelThread.Worksheet.Cells[6, 1]  = "'031 - 060";
            ExcelThread.Worksheet.Cells[7, 1]  = "'061 - 090";
            ExcelThread.Worksheet.Cells[8, 1]  = "'091 - 120";
            ExcelThread.Worksheet.Cells[9, 1]  = "'121 - 150";
            ExcelThread.Worksheet.Cells[10, 1] = "'151 - 180";
            ExcelThread.Worksheet.Cells[11, 1] = "'181 - 270";
            ExcelThread.Worksheet.Cells[12, 1] = "'271 - 360";
            ExcelThread.Worksheet.Cells[13, 1] = "'361 - +++";
            ExcelThread.Worksheet.Cells[5, 2]  = AgedData.Day0To30;
            ExcelThread.Worksheet.Cells[6, 2]  = AgedData.Day31To60;
            ExcelThread.Worksheet.Cells[7, 2]  = AgedData.Day61To90;
            ExcelThread.Worksheet.Cells[8, 2]  = AgedData.Day91To120;
            ExcelThread.Worksheet.Cells[9, 2]  = AgedData.Day121To150;
            ExcelThread.Worksheet.Cells[10, 2] = AgedData.Day151To180;
            ExcelThread.Worksheet.Cells[11, 2] = AgedData.Day181To270;
            ExcelThread.Worksheet.Cells[12, 2] = AgedData.Day271To360;
            ExcelThread.Worksheet.Cells[13, 2] = AgedData.Day361Plus;

            // perform some formatting to ensure good readability of the final file.
            ExcelThread.Worksheet.Range["A:A"].ColumnWidth            = 13;
            ExcelThread.Worksheet.Range["B:B"].ColumnWidth            = 16;
            ExcelThread.Worksheet.Range["A4:A13"].HorizontalAlignment = HorizontalAlignment.Center;
            ExcelThread.Worksheet.Range["B5:B13"].NumberFormat        = "_($* #,##0.00_)";

            // finally write our file from memory to our location on disk.
            ExcelThread.Workbook.SaveAs(saveFileDialog.FileName);
        }
        private void ConfigureApplication()
        {
            // ensuring all properties are clear except for the 'App' Excel application pointer
            ExcelThread.Reset();

            // ensure form components are in a state ready to accept used input
            DtpAnchorDate.Value       = DateTime.Today;
            RbtHeadNo.Checked         = false;
            RbtHeadYes.Checked        = false;
            GrpSheetAndHeader.Visible = false;
            GrpColumnAndAging.Visible = false;
            BtnGetHeaders.Visible     = false;
            TbxFilePath.ResetText();
            saveFileDialog.Reset();
            openFileDialog.Reset();
            LbxSheetNames.Items.Clear();
            PrepForAging(); /* broke out some of the application configuration to
                             * support 'reseting' the application in order to allow
                             * the user to age the same excel data set based on
                             * differing input conditions */

            // ensure our results accumilator is ready for use.
            AgedData.Zero();
        }
 private void ResetApplicationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ConfigureApplication();
     ExcelThread.Reset();
 }