private void AddCategoriesToSelector()
        {
            var categoriesList = databaseController.GetAllCategoriesNames();

            foreach (var categoryName in categoriesList)
            {
                CategoryComboBox.Items.Add(new TextBlock {
                    Text = categoryName
                });
            }
        }
示例#2
0
        private void OnClickCategoryCreateConfirmButton(object sender, RoutedEventArgs e)
        {
            void highlightBoxesWithParamName(string name)
            {
                foreach (ListBoxItem item in CategoryCreateParamsListBox.Items)
                {
                    var textBox = (TextBox)item.Content;
                    if (textBox.Text == name)
                    {
                        textBox.BorderBrush = Brushes.Red;
                    }
                }
            }

            void disableHighlight()
            {
                foreach (ListBoxItem item in CategoryCreateParamsListBox.Items)
                {
                    ((TextBox)item.Content).BorderBrush = new SolidColorBrush(new Color {
                        R = 171, G = 173, B = 179
                    });
                }
            }

            var canCreate = true;

            disableHighlight();
            var paramsNames = new List <string>();

            foreach (ListBoxItem item in CategoryCreateParamsListBox.Items)
            {
                var textBox = (TextBox)item.Content;
                if (textBox.Text == "")
                {
                    canCreate           = false;
                    textBox.BorderBrush = Brushes.Red;
                }
                else if (paramsNames.Contains(textBox.Text))
                {
                    canCreate = false;
                    highlightBoxesWithParamName(textBox.Text);
                }
                else
                {
                    paramsNames.Add(textBox.Text);
                }
            }

            var categoryName = CategoryCreateCategoryNameTextBox.Text;

            if (categoryName == "" || databaseController.GetAllCategoriesNames().Contains(categoryName))
            {
                canCreate = false;
                CategoryCreateCategoryNameTextBox.BorderBrush = Brushes.Red;
            }
            else
            {
                CategoryCreateCategoryNameTextBox.BorderBrush = new SolidColorBrush(new Color {
                    R = 171, G = 173, B = 179
                });
            }

            if (canCreate)
            {
                if (databaseController.CreateNewCategory(paramsNames, categoryName))
                {
                    UpdateCategoryCreateCategoryList();
                    CategoryCreateGrid.Visibility = Visibility.Hidden;
                }
            }
        }