Esempio n. 1
0
        private void btAdd_Click(object sender, EventArgs e)
        {
            var DTQuery = (from DT in db.order_item
                           where DT.item_id == int.Parse(txtitemID.Text)
                           select DT).SingleOrDefault();

            if (DTQuery != null)
            {
                MessageBox.Show("Item ID is already existed", "Lỗi!");
            }
            else
            {
                try
                {
                    order_item DT = new order_item();
                    DT.order_id   = int.Parse(cbOrdersID.Text);
                    DT.item_id    = int.Parse(txtitemID.Text);
                    DT.product_id = int.Parse(cbProductID.Text);
                    DT.quantity   = txtQuanity.Text;
                    DT.list_price = textListprice.Text;
                    DT.discount   = txtdiscount.Text; db.order_item.Add(DT);
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("Order_id chưa tồn tại trong Bảng   Order.Vui lòng cập nhật Order_id trong bảng Order trước!", "Lỗi khóa ngoại!");
                    MessageBox.Show("Product_id chưa tồn tại trong Bảng   Product.Vui lòng cập nhật Product_id trong bảng OrdProducter trước!", "Lỗi khóa ngoại!");
                }
                MySetOrder_item();
            }
        }
Esempio n. 2
0
        private void btSave_Click(object sender, EventArgs e)
        {
            //db = new SalesDBMF();
            int        r       = dtGridView.CurrentCell.RowIndex;
            string     tempDID = dtGridView.Rows[r].Cells[1].Value.ToString();
            order_item DTQuery = db.order_item.Single(x => x.item_id ==
                                                      int.Parse(tempDID));

            if (DTQuery != null)
            {
                order OdrQuery2 = db.orders.Single(x => x.order_id
                                                   == int.Parse(cbOrdersID.Text));
                product PrQuery2 = db.products.Single(x => x.product_id
                                                      == int.Parse(cbProductID.Text));
                var DTQuery2 = (from DT in db.order_item
                                where
                                DT.item_id == int.Parse(txtitemID.Text)
                                select DT).SingleOrDefault();
                if (OdrQuery2 == null)
                {
                    MessageBox.Show("order_id chưa tồn tại trong Bảng  Order, Vui lòng cập nhật order_id trong bảng Order trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (PrQuery2 == null)
                {
                    MessageBox.Show("Product_id chưa tồn tại trong Bảng  Product, Vui lòng cập nhật Product_id trong bảng Product trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (DTQuery.item_id == int.Parse(txtitemID.Text))
                {
                    //DTQuery.district_id = txtDID.Text;
                    DTQuery.order_id   = int.Parse(cbOrdersID.Text);
                    DTQuery.product_id = int.Parse(cbProductID.Text);
                    DTQuery.quantity   = txtQuanity.Text;
                    DTQuery.list_price = textListprice.Text;
                    DTQuery.discount   = txtdiscount.Text;
                    db.SaveChanges();
                }
                else
                {
                    if (DTQuery2 != null)
                    {
                        MessageBox.Show("item_ID đã tồn tại trong Bảng  Order_item không sửa được!", "Lỗi khóa!");
                        return;
                    }

                    db.order_item.Remove(DTQuery);
                    db.SaveChanges(); order_item DT = new order_item();
                    DT.order_id   = int.Parse(cbOrdersID.Text);
                    DT.item_id    = int.Parse(txtitemID.Text);
                    DT.product_id = int.Parse(cbProductID.Text);
                    DT.quantity   = txtQuanity.Text;
                    DT.list_price = textListprice.Text;
                    DT.discount   = txtdiscount.Text;
                    db.order_item.Add(DT);
                    db.SaveChanges();
                }
            }
            MySetOrder_item();
        }
Esempio n. 3
0
        private void btDelete_Click(object sender, EventArgs e)
        {
            int        r       = dtGridView.CurrentCell.RowIndex;
            string     tempDID = dtGridView.Rows[r].Cells[1].Value.ToString();
            order_item OrdiQ   = db.order_item.Single(x => x.item_id ==
                                                      int.Parse(tempDID));

            //db.districts.DeleteOnSubmit(OrdiQ);
            //db.SubmitChanges();
            db.order_item.Remove(OrdiQ);
            db.SaveChanges();
            MySetOrder_item();
        }