예제 #1
0
        private void bt_addProduct_Click(object sender, EventArgs e)
        {
            frm_Product frm = new frm_Product();

            if (frm.ShowDialog() == DialogResult.OK)
            {
                context.Products.Add(frm.Product);
                context.SaveChanges();
                FreshListBox();
            }
        }
예제 #2
0
        private void bt_modifyProduct_Click(object sender, EventArgs e)
        {
            if (lb_products.SelectedIndex == -1)
            {
                MessageBox.Show("You have to select a product to modify it.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                Product     p   = (Product)lb_products.SelectedItem;
                frm_Product frm = new frm_Product(p);

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    int index = lb_products.SelectedIndex;
                    context.Products.Update(frm.Product);
                    context.SaveChanges();
                    FreshListBox();
                    lb_products.SelectedIndex = index;
                }
            }
        }