private void btAdd_Click(object sender, EventArgs e)
        {
            var DTQuery = (from DT in db.staffs
                           where DT.staff_id == txtStaffID.Text
                           select DT).SingleOrDefault();

            if (DTQuery != null)
            {
                MessageBox.Show("Staff ID is already existed", "Lỗi!");
            }
            else
            {
                try
                {
                    staff DT = new staff();
                    DT.staff_id   = txtStaffID.Text;
                    DT.first_name = txtxFname.Text;
                    DT.last_name  = txtLname.Text;
                    DT.email      = txtEmail.Text;
                    DT.phone      = txtPhone.Text;
                    DT.active     = byte.Parse(txtActive.Text);
                    DT.store_id   = cbStore.Text;
                    try
                    {
                        DT.manager_id = txtManagerID.Text;
                    }
                    catch
                    {
                        MessageBox.Show("Manager_id chưa tồn tại trong Bảng   Staff.Vui lòng cập nhật Manager_id trong bảng Staff trước!", "Lỗi khóa ngoại!");
                    }
                    db.staffs.Add(DT);
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("Store_id chưa tồn tại trong Bảng   Store.Vui lòng cập nhật Store_id trong bảng Store trước!", "Lỗi khóa ngoại!");
                }
                MySetStaff();
            }
        }
        private void btSave_Click(object sender, EventArgs e)
        {
            //db = new SalesDBMF();
            int    r       = dtGridView.CurrentCell.RowIndex;
            string tempDID = dtGridView.Rows[r].Cells[0].Value.ToString();
            staff  DTQuery = db.staffs.Single(x => x.staff_id ==
                                              tempDID);

            if (DTQuery != null)
            {
                store StoQuery2 = db.stores.Single(x => x.store_id
                                                   == cbStore.Text);
                staff StaffQuery2 = db.staffs.Single(x => x.staff_id
                                                     == txtStaffID.Text);
                var DTQuery2 = (from DT in db.staffs
                                where
                                DT.staff_id == txtStaffID.Text
                                select DT).SingleOrDefault();
                if (StoQuery2 == null)
                {
                    MessageBox.Show("Store_id chưa tồn tại trong Bảng  Store, Vui lòng cập nhật Store_id trong bảng Store trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (StaffQuery2 == null)
                {
                    MessageBox.Show("Staff_id chưa tồn tại trong Bảng  Staff, Vui lòng cập nhật Staff_id trong bảng Staff trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (DTQuery.staff_id == txtStaffID.Text)
                {
                    //DTQuery.district_id = txtDID.Text;
                    DTQuery.first_name = txtxFname.Text;
                    DTQuery.last_name  = txtLname.Text;
                    DTQuery.email      = txtEmail.Text;
                    DTQuery.phone      = txtPhone.Text;
                    DTQuery.active     = byte.Parse(txtActive.Text);
                    DTQuery.store_id   = cbStore.Text;
                    DTQuery.manager_id = txtManagerID.Text;
                    db.SaveChanges();
                }
                else
                {
                    if (DTQuery2 != null)
                    {
                        MessageBox.Show("Staff_ID đã tồn tại trong Bảng  Staffs không sửa được!", "Lỗi khóa!");
                        return;
                    }

                    db.staffs.Remove(DTQuery);
                    db.SaveChanges(); staff DT = new staff();
                    DT.staff_id   = txtStaffID.Text;
                    DT.first_name = txtxFname.Text;
                    DT.last_name  = txtLname.Text;
                    DT.email      = txtEmail.Text;
                    DT.phone      = txtPhone.Text;
                    DT.active     = byte.Parse(txtActive.Text);
                    DT.store_id   = cbStore.Text;
                    DT.manager_id = txtManagerID.Text;
                    db.staffs.Add(DT);
                    db.SaveChanges();
                }
            }
            MySetStaff();
        }
Beispiel #3
0
        private void btSave_Click(object sender, EventArgs e)
        {
            //db = new SalesDBMF();
            int    r       = dtGridView.CurrentCell.RowIndex;
            string tempDID = dtGridView.Rows[r].Cells[0].Value.ToString();
            order  DTQuery = db.orders.Single(x => x.order_id ==
                                              int.Parse(tempDID));

            if (DTQuery != null)
            {
                store OdrQuery2 = db.stores.Single(x => x.store_id
                                                   == cbStore.Text);
                customer CusQuery2 = db.customers.Single(x => x.customer_id
                                                         == cbCusto.Text);
                staff StaQuery2 = db.staffs.Single(x => x.staff_id
                                                   == cbStaff.Text);
                var DTQuery2 = (from DT in db.orders
                                where
                                DT.order_id == int.Parse(txtOrID.Text)
                                select DT).SingleOrDefault();
                if (OdrQuery2 == null)
                {
                    MessageBox.Show("Store_id chưa tồn tại trong Bảng  Store, Vui lòng cập nhật Store_id trong bảng Store trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (CusQuery2 == null)
                {
                    MessageBox.Show("Customer_id chưa tồn tại trong Bảng  Customer, Vui lòng cập nhật Customer_id trong bảng Customer trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (StaQuery2 == null)
                {
                    MessageBox.Show("Staff_id chưa tồn tại trong Bảng  Staff, Vui lòng cập nhật Staff_id trong bảng Staff trước!", "Lỗi khóa ngoại!");
                    return;
                }
                if (DTQuery.order_id == int.Parse(txtOrID.Text))
                {
                    //DTQuery.district_id = txtDID.Text;
                    DTQuery.customer_id   = cbCusto.Text;
                    DTQuery.order_status  = byte.Parse(txtOrderstatus.Text);
                    DTQuery.order_date    = DateTime.Parse(txtxOrderdate.Text);
                    DTQuery.required_date = DateTime.Parse(txtrequireddate.Text);
                    DTQuery.shipped_date  = DateTime.Parse(txtShipped_date.Text);
                    DTQuery.store_id      = cbStore.Text;
                    DTQuery.staff_id      = cbStaff.Text;
                    db.SaveChanges();
                }
                else
                {
                    if (DTQuery2 != null)
                    {
                        MessageBox.Show("Order_ID đã tồn tại trong Bảng  Order không sửa được!", "Lỗi khóa!");
                        return;
                    }

                    db.orders.Remove(DTQuery);
                    db.SaveChanges(); order DT = new order();
                    DT.customer_id   = cbCusto.Text;
                    DT.order_status  = byte.Parse(txtOrderstatus.Text);
                    DT.order_date    = DateTime.Parse(txtxOrderdate.Text);
                    DT.required_date = DateTime.Parse(txtrequireddate.Text);
                    DT.shipped_date  = DateTime.Parse(txtShipped_date.Text);
                    DT.store_id      = cbStore.Text;
                    DT.staff_id      = cbStaff.Text;
                    db.orders.Add(DT);
                    db.SaveChanges();
                }
            }
            MySetOrder();
        }