Beispiel #1
0
        /// <summary>
        /// Changed an assigned category to another sheet category.
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="category"></param>
        /// <param name="categoryType"></param>
        public static Boolean MoveSheetCategory(Sheet sheet, String categoryName, Category.SheetCategoryType categoryType)
        {
            Boolean returnValue = default(Boolean);

            try
            {
                _ValueChanging = true;

                //move it
                sheet.AssignCategory(categoryName, categoryType, (CategoryItem)null);

                _ValueChanging = false;

                //refresh
                //Refresh();

                returnValue = true;
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                _ValueChanging = false;
                throw;
            }
            return(returnValue);
        }
Beispiel #2
0
        /// <summary>
        /// Add an unassigned category to one of the sheet categories.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public static Boolean AddSheetCategory(Sheet sheet, String categoryName, Category.SheetCategoryType categoryType)
        {
            Boolean      returnValue  = default(Boolean);
            CategoryItem categoryItem = default(CategoryItem);

            try
            {
                //User must select a Category Item.
                categoryItem = SelectCategoryItem(sheet, categoryName, "Select a Category Item to Add to existing Sheet Cells.", 0, false);

                if (categoryItem != null)
                {
                    _ValueChanging = true;

                    //move it
                    sheet.AssignCategory(categoryName, categoryType, categoryItem);

                    _ValueChanging = false;

                    //refresh
                    //Refresh();

                    returnValue = true;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                _ValueChanging = false;
                throw;
            }
            return(returnValue);
        }
Beispiel #3
0
 /// <summary>
 /// Clears grid and builds a new one. Adds rows and columns, and formats them.
 /// Pass sheet name and sheet will be looked up.
 /// </summary>
 /// <param name="grid"></param>
 public static void RenderSheetCategory(DataGridView grid, String sheetName, Category.SheetCategoryType sheetCategoryType)
 {
     try
     {
         RenderSheetCategory(grid, SettingsController <Settings> .Settings.Sheets.Find(s => s.Name == sheetName), sheetCategoryType);
     }
     catch (Exception ex)
     {
         Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
         throw;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Clears grid and builds a new one. Adds rows and columns, and formats them.
        /// Pass sheet index and sheet will be looked up.
        /// </summary>
        /// <param name="grid"></param>
        public static void RenderSheetCategory(DataGridView grid, Int32 sheetIndex, Category.SheetCategoryType sheetCategoryType)
        {
            try
            {
                RenderSheetCategory(grid, SettingsController <Settings> .Settings.Sheets[sheetIndex], sheetCategoryType);
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Clears grid and builds a new one. Adds rows and columns, and formats them.
 /// Pass sheet explicitly.
 /// </summary>
 /// <param name="grid"></param>
 public static void RenderSheetCategory(DataGridView grid, Sheet sheet, Category.SheetCategoryType sheetCategoryType)
 {
     try
     {
         BuildSheetCategory(grid, sheet, sheetCategoryType);
         FormatSheetCategory(grid, sheet, sheetCategoryType);
     }
     catch (Exception ex)
     {
         Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
         throw;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Formats grid.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="sheet"></param>
        /// <param name="sheetCategoryType"></param>
        private static void FormatSheetCategory(DataGridView grid, Sheet sheet, Category.SheetCategoryType sheetCategoryType)
        {
            try
            {
                if (sheet != null)
                {
                    //format cells
                    if (sheetCategoryType == Category.SheetCategoryType.Filter)
                    {
                        for (int x = 0; x < grid.Columns.Count; x++)
                        {
                            for (int y = 0; y < 1; y++)
                            {
                                grid.Rows[y].Cells[x].Style.BackColor = sheet.ColorCategoryItemBackground;
                                grid.Rows[y].Cells[x].Style.ForeColor = sheet.ColorCategoryItemForeground;
                            }
                        }
                    }
                    else if (sheetCategoryType == Category.SheetCategoryType.X)
                    {
                        for (int x = 0; x < 1; x++)
                        {
                            for (int y = 0; y < grid.Rows.Count; y++)
                            {
                                grid.Rows[y].Cells[x].Style.BackColor = sheet.ColorCategoryItemBackground;
                                grid.Rows[y].Cells[x].Style.ForeColor = sheet.ColorCategoryItemForeground;
                            }
                        }
                    }
                    else if (sheetCategoryType == Category.SheetCategoryType.Y)
                    {
                        for (int x = 0; x < grid.Columns.Count; x++)
                        {
                            for (int y = 0; y < 1; y++)
                            {
                                grid.Rows[y].Cells[x].Style.BackColor = sheet.ColorCategoryItemBackground;
                                grid.Rows[y].Cells[x].Style.ForeColor = sheet.ColorCategoryItemForeground;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Clears grid and builds a new one. Adds rows and columns, and formats them.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="sheet"></param>
        /// <param name="sheetCategoryType"></param>
        private static void BuildSheetCategory(DataGridView grid, Sheet sheet, Category.SheetCategoryType sheetCategoryType)
        {
            Int32 columnCount = -1;
            Int32 rowCount    = -1;

            try
            {
                ConfigureVirtualDataGridView(grid);

                // Add columns and rows to the DataGridView.
                grid.Rows.Clear();
                grid.Columns.Clear();

                if (sheet != null)
                {
                    if (sheetCategoryType == Category.SheetCategoryType.Filter)
                    {
                        grid.ColumnHeadersVisible = true;

                        columnCount = sheet.CategoryFilters().Count;
                        rowCount    = 1;

                        ConfigureVirtualDataGridViewTextCells(grid, columnCount, rowCount, (i => sheet.CategoryFilters()[i].Name));
                    }
                    else if (sheetCategoryType == Category.SheetCategoryType.X)
                    {
                        columnCount = 1;
                        rowCount    = sheet.CategoryX().Count;

                        ConfigureVirtualDataGridViewTextCells(grid, columnCount, rowCount, (i => ""));
                    }
                    else if (sheetCategoryType == Category.SheetCategoryType.Y)
                    {
                        columnCount = sheet.CategoryY().Count;
                        rowCount    = 1;

                        ConfigureVirtualDataGridViewTextCells(grid, columnCount, rowCount, (i => ""));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Method to call from Event handler for Sheet-Category DataGridView CellValueNeeded event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void SheetCategoryCellValueNeeded(object sender, DataGridViewCellValueEventArgs e, Sheet sheet, Category.SheetCategoryType sheetCategoryType)
        {
            DataGridView    sheetCategory  = (sender as DataGridView);
            List <Category> filterCategory = default(List <Category>);

            try
            {
                if (sheetCategoryType == Category.SheetCategoryType.Filter)
                {
                    if (!_IsReshapingGrid)
                    {
                        //only works if header is displayed
                        //category item name; category name is put in header when grid is re-configured. SelectedItemIndex must be valid.
                        filterCategory = sheet.CategoryFilters();
                        e.Value        = filterCategory[e.ColumnIndex].Items[filterCategory[e.ColumnIndex].SelectedItemIndex].Name;
                        ////use if header is not displayed
                        ////category name
                        //e.Value = sheet.CategoryFilters()[e.ColumnIndex].Name;
                    }
                    else
                    {
                        e.Value = null;
                    }
                }
                else if (sheetCategoryType == Category.SheetCategoryType.X)
                {
                    if (!_IsReshapingGrid)
                    {
                        //category name
                        e.Value = sheet.CategoryX()[e.RowIndex].Name;
                    }
                    else
                    {
                        e.Value = null;
                    }
                }
                else if (sheetCategoryType == Category.SheetCategoryType.Y)
                {
                    if (!_IsReshapingGrid)
                    {
                        //category name
                        e.Value = sheet.CategoryY()[e.ColumnIndex].Name;
                    }
                    else
                    {
                        e.Value = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
                throw;
            }
        }