Пример #1
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            CategoryForm categoryForm = new CategoryForm();

            Hide();
            categoryForm.ShowDialog();
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text) ||
                String.IsNullOrEmpty(textBox3.Text) || String.IsNullOrEmpty(textBox4.Text))
            {
                MessageBox.Show(
                    "Wystąpił błąd. Błędnie wypełniony formularz. Nie dodano produktu. ",
                    "Zamknij",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else
            {
                string  name         = textBox1.Text;
                int     number       = int.Parse(textBox2.Text);
                decimal price        = decimal.Parse(textBox3.Text);
                int     id_kategorii = int.Parse(textBox4.Text);
                Product product      = new Product()
                {
                    Name         = name,
                    UnitsInStock = number,
                    CategoryID   = id_kategorii,
                    UnitPrice    = price
                };

                prodContext.Products.Add(product);
                prodContext.SaveChanges();
                MessageBox.Show(
                    "Dodano produkt",
                    "Zamknij",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                this.Close();
                CategoryForm categoryForm = new CategoryForm();
                categoryForm.ShowDialog();
            }
        }