Example #1
0
        private void createToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            CrProduct    prodCr = new CrProduct();
            DialogResult result = prodCr.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Product product = new Product();

            product.GroupId     = Convert.ToInt32(prodCr.comboBox2.SelectedItem);
            product.SupplyId    = Convert.ToInt32(prodCr.comboBox1.SelectedItem);
            product.Name        = prodCr.textBox1.Text;
            product.Description = prodCr.textBox2.Text;
            try
            {
                product.BuyCost  = Convert.ToDecimal(prodCr.textBox3.Text);
                product.SellCost = Convert.ToDecimal(prodCr.textBox4.Text);
                product.Quantity = Convert.ToInt32(prodCr.textBox5.Text);
            }
            catch (FormatException f)
            {
                MessageBox.Show("Check! Cost Format:decimal AND Quantity Format:  integer. ");
                return;
            }
            db.Products.Add(product);
            db.SaveChanges();
            MessageBox.Show("New product is added!");
        }
Example #2
0
        private void updateToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            try
            {
                int index = dataGridView1.SelectedRows[0].Index;
                int id    = 0;

                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Product product = db.Products.Find(id);

                CrProduct prodCr = new CrProduct();
                prodCr.comboBox2.SelectedItem = Convert.ToString(product.GroupId);
                prodCr.comboBox1.SelectedItem = Convert.ToString(product.SupplyId);
                prodCr.textBox1.Text          = product.Name;
                prodCr.textBox2.Text          = product.Description;
                prodCr.textBox3.Text          = Convert.ToString(product.BuyCost);
                prodCr.textBox4.Text          = Convert.ToString(product.SellCost);
                prodCr.textBox5.Text          = Convert.ToString(product.Quantity);;

                DialogResult result = prodCr.ShowDialog(this);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                product.GroupId = Convert.ToInt32(prodCr.comboBox2.SelectedItem);

                product.SupplyId    = Convert.ToInt32(prodCr.comboBox1.SelectedItem);
                product.Name        = prodCr.textBox1.Text;
                product.Description = prodCr.textBox2.Text;
                product.BuyCost     = Convert.ToDecimal(prodCr.textBox3.Text);
                product.SellCost    = Convert.ToDecimal(prodCr.textBox4.Text);
                product.Quantity    = Convert.ToInt32(prodCr.textBox5.Text);

                db.SaveChanges();
                dataGridView1.Refresh(); // обновляем грид
                MessageBox.Show("Product is updated!");
            }
            catch (Exception outOfRange)
            {
                MessageBox.Show("Inconsistent operation !");
            }
        }