Exemplo n.º 1
0
        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();
                    }
                }
            }
        }