Beispiel #1
0
        private async Task LoadCategories()
        {
            CategoriesTree.Items.Clear();
            CategoryNameTextBox.Clear();
            NewSubcategoryTextBox.Clear();

            CategoryNameTextBox.IsEnabled   = false;
            NewSubcategoryTextBox.IsEnabled = false;
            UpdateCategory.IsEnabled        = false;
            DeleteCategory.IsEnabled        = false;
            AddSubCategoryButton.IsEnabled  = false;

            GetAllCategoriesResult[] result = await _categoryService.GetAllCategories();

            var baseItem    = result.Single(item => item.ParentId == null);
            var newTreeItem = new TreeViewItem
            {
                Header     = baseItem.Name,
                Uid        = baseItem.Id.ToString(),
                IsExpanded = true
            };

            CategoriesTree.Items.Add(newTreeItem);
            FillCategories(CategoriesTree.Items[0] as TreeViewItem, baseItem, result);
        }
Beispiel #2
0
        /*
         * Event Handler for Adding Category to the Invetory
         */
        private void CategoryButton_Click(object sender, EventArgs e)
        {
            StreamWriter FileWriter;

            FileWriter = File.AppendText(CATEGORYDATABASEFILENAME);
            if (CategoryNameTextBox.Text == "")
            {
                MessageBox.Show("Please enter Category Name");
                CategoryNameTextBox.Focus();
                CategoryNameTextBox.SelectAll();
            }
            else
            {
                if (CategoryList.Contains(CategoryNameTextBox.Text))
                {
                    MessageBox.Show("Category already Exist");
                    CategoryNameTextBox.Focus();
                    CategoryNameTextBox.SelectAll();
                }
                else
                {
                    CategoryList.Add(CategoryNameTextBox.Text);
                    FileWriter.WriteLine(CategoryNameTextBox.Text);
                    FileWriter.Close();
                    MessageBox.Show("Category Added Successfully to the Database");
                    CategoryNameTextBox.Text = "";
                }
            }
        }
Beispiel #3
0
 private void AddCategoryButton_Click(object sender, RoutedEventArgs e)
 {
     if (CategoryNameTextBox.Text.Trim() != "")
     {
         data.AddCategory(CategoryNameTextBox.Text);
         CategoryNameTextBox.Clear();
     }
 }
 private void CategoryNameTextBox_Validating(object sender, CancelEventArgs e)
 {
     if (string.IsNullOrWhiteSpace(CategoryNameTextBox.Text))
     {
         e.Cancel = true;
         CategoryNameTextBox.Focus();
         CategoryNameTextBoxErrorProvider.SetError(CategoryNameTextBox, "Field is mandatory!");
     }
     else
     {
         e.Cancel = false;
         CategoryNameTextBoxErrorProvider.SetError(CategoryNameTextBox, "");
     }
 }
Beispiel #5
0
        private void AddCategoryButton_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();

            //символен низ за връзка към базата данни – взема се от файл с име app.config
            con.ConnectionString = ConfigurationManager.ConnectionStrings["MassiveDynamic.Properties.Settings.MassiveDynamicConnectionString"].ConnectionString;
            //символен низ със заявката към базата данни
            string insertIntoCategoryId          = "'" + CategoryIDTextBox.Text + "'";
            string insertIntoCategoryName        = "'" + CategoryNameTextBox.Text + "'";
            string insertIntoCategoryDescription = "'" + CategoryDescriptionTextBox.Text + "'";

            //INSERT INTO table_name (column1,column2,column3,...)  VALUES(value1, value2, value3,...);  Insert into cheatSheet
            string insertCommand = string.Format("insert into Categories (CategoryID,CategoryName,Description) values({0},{1},{2});", insertIntoCategoryId, insertIntoCategoryName, insertIntoCategoryDescription);

            SqlCommand com = new SqlCommand(insertCommand, con);

            //определяне на типа на командата - в конкретния случай е текст
            com.CommandType = CommandType.Text;

            try
            {
                //отваряме връзката към базата данни
                con.Open();
                //изпълняваме командата / в този случай нямаме връщан резултат
                com.ExecuteNonQuery();

                //извеждаме съобщение, че всичко е преминало успешно
                MessageBox.Show("Данните са добавени успешно!",
                                "Message/Съобщение");
                //изчистваме въведената стойност в текстовото поле
                CategoryIDTextBox.Clear();
                CategoryNameTextBox.Clear();
                CategoryDescriptionTextBox.Clear();
            }
            //ако не е преминало всичко успешно, това означава, че е възникнало изключение
            catch (Exception exe)
            {
                //извеждаме съобщение с възникналото изключение
                MessageBox.Show(exe.ToString(), "Message/Съобщение:");
            }
            //затваря се връзката към базата данни
            con.Close();
            //затваря се отворената форма
            this.Close();
        }