/* 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();
                }
            }
        }
        private void BuildHeaders()
        {
            if (ValidationLogic.NoItemSelected(LbxSheetNames))
            {
                ErrorActions.NoSheetSelected();
            }
            else
            {
                // set the specific sheet by using the selected sheet name from the list box control.
                string sheetWithData = LbxSheetNames.SelectedItem.ToString();
                ExcelThread.Worksheet = ExcelThread.Worksheets[sheetWithData];
                if (ValidationLogic.NoColumnsFound(ExcelThread.Worksheet))
                {
                    ErrorActions.NoColumnsFound();
                }
                else
                {
                    // Determine the number of columns within the sheet that are actually holding values
                    ExcelThread.DataSet = ExcelThread.Worksheet.UsedRange;
                    int colCount = ExcelThread.DataSet.Columns.Count;

                    /* the following two lines are required to ensure if the user changes the value
                     * of their answer for if headers are included and re-clicks the button the
                     * list box control does not 'grow' with the new selection. In addition columns
                     * to be used in the Aging process are selected by index, therefore the order of
                     * the list box controls must not be sorted. ORDER MATTERS!!!! */
                    LbxDataToAge.Items.Clear();
                    LbxDatesToAgeBy.Items.Clear();

                    /* if headers exist loop through all columns and add the value of the first
                     * row into two list box controls, what to age and what to age by. */
                    if (RbtHeadYes.Checked)
                    {
                        for (int i = 1; i <= colCount; i++)
                        {
                            Microsoft.Office.Interop.Excel.Range cellValue = ExcelThread.DataSet.Cells[1, i];
                            LbxDatesToAgeBy.Items.Add(cellValue.Value.ToString());
                            LbxDataToAge.Items.Add(cellValue.Value.ToString());
                        }
                        // make the next stage of the process/application visible.
                        GrpColumnAndAging.Visible = true;
                    }

                    /* if no headers exist add 'Column X' where X represents the column number,
                     * into two list box controls, what to age and what to age by. */
                    else if (RbtHeadNo.Checked)
                    {
                        for (int i = 1; i <= colCount; i++)
                        {
                            string columnNumber = "Column " + i.ToString();
                            LbxDatesToAgeBy.Items.Add(columnNumber);
                            LbxDataToAge.Items.Add(columnNumber);
                        }
                        // make the next stage of the process/application visible.
                        GrpColumnAndAging.Visible = true;
                    }
                    else
                    {
                        ErrorActions.HeaderNotAnswered();
                    }
                }
            }
        }