コード例 #1
0
        public MakeOrderForm(CategoryForm cat, string customerName)
        {
            InitializeComponent();

            this.order = new Order()
            {
                CustomerName = customerName
            };
            this.context = new ProdContext();
            this.context.Orders.Add(this.order);
            this.context.SaveChanges();

            this.categoryForm = cat;

            this.Load += initialize;
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textName.Text == "")
            {
                MessageBox.Show("Get name of category");
                return;
            }

            Category cat = new Category();

            cat.Name        = textName.Text;
            cat.Description = textDesc.Text;

            using (var context = new ProdContext())
            {
                context.Categories.Add(cat);
                context.SaveChanges();
            }

            this.categoryForm.reload();

            Hide();
            DestroyHandle();
        }
コード例 #3
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (textName.Text == "")
            {
                MessageBox.Show("Get product name");
                return;
            }

            int unitInStock = 0;

            if (textUnitInStock.Text == "" ||
                !Int32.TryParse(textUnitInStock.Text, out unitInStock))
            {
                MessageBox.Show("Get number of unit in stock");
                return;
            }

            decimal unitPrice;

            if (textUnitprice.Text == "" ||
                !Decimal.TryParse(textUnitprice.Text, out unitPrice))
            {
                MessageBox.Show("Get unit price");
                return;
            }

            if (comboBox1.SelectedIndex < 0)
            {
                MessageBox.Show("Select category");
                return;
            }

            using (var context = new ProdContext())
            {
                int?categoryId = (from cat in this.categoryForm.context.Categories
                                  where cat.Name == comboBox1.SelectedItem.ToString()
                                  select cat.CategoryID).FirstOrDefault();

                if (categoryId == null)
                {
                    MessageBox.Show("You need to chose category");
                    return;
                }

                Product product = new Product()
                {
                    Name         = textName.Text,
                    Unitprice    = unitPrice,
                    UnitsInStock = unitInStock,
                    CategoryID   = (int)categoryId,
                };

                context.Products.Add(product);
                context.SaveChanges();
            }

            this.categoryForm.reload();

            Hide();
            DestroyHandle();
        }