private void btAdd_Click(object sender, EventArgs e) { var StoQuery = (from DT in db.stores where DT.store_id == txtSID.Text select DT).SingleOrDefault(); if (StoQuery != null) { MessageBox.Show("Store ID is already existed", "Lỗi!"); } else { store DT = new store(); DT.store_id = txtSID.Text; DT.store_name = txtSName.Text; DT.phone = txtPhone.Text; DT.email = txtEmail.Text; DT.street = txtStreet.Text; DT.city = txtCity.Text; DT.state = txtState.Text; DT.zip_code = txtZipcode.Text; db.stores.Add(DT); db.SaveChanges(); MySetStore(); } }
private void btSave_Click(object sender, EventArgs e) { //db = new SalesDBMF(); int r = dtGridView.CurrentCell.RowIndex; string tempID = dtGridView.Rows[r].Cells[0].Value.ToString(); store StoQuery = db.stores.Single(x => x.store_id == tempID); if (StoQuery != null) { var PrQuery2 = (from DT in db.stores where DT.store_id == txtSID.Text select DT).SingleOrDefault(); if (StoQuery.store_id == txtSID.Text) { //StoQuery.district_id = txtDID.Text; StoQuery.store_name = txtSName.Text; StoQuery.phone = txtPhone.Text; StoQuery.email = txtEmail.Text; StoQuery.street = txtStreet.Text; StoQuery.city = txtCity.Text; StoQuery.state = txtState.Text; StoQuery.zip_code = txtZipcode.Text; db.SaveChanges(); } else { if (PrQuery2 != null) { MessageBox.Show("Store_ID đã tồn tại trong Bảng Stores không sửa được!", "Lỗi khóa!"); return; } try { db.stores.Remove(StoQuery); db.SaveChanges(); store DT = new store(); DT.store_id = txtSID.Text; DT.store_name = txtSName.Text; DT.phone = txtPhone.Text; DT.email = txtEmail.Text; DT.street = txtStreet.Text; DT.city = txtCity.Text; DT.state = txtState.Text; DT.zip_code = txtZipcode.Text; db.stores.Add(DT); db.SaveChanges(); } catch { MessageBox.Show("Store_ID đã tồn tại khóa ngoại trong bảng staff, stock và order, Vui lòng cập nhật Store_ID trong bảng đó trước!", "Lỗi khóa ngoại!"); } } } MySetStore(); }
private void btDelete_Click(object sender, EventArgs e) { int r = dtGridView.CurrentCell.RowIndex; string tempID = dtGridView.Rows[r].Cells[0].Value.ToString(); store CtQ = db.stores.Single(x => x.store_id == tempID); //db.districts.DeleteOnSubmit(DistQ); //db.SubmitChanges(); db.stores.Remove(CtQ); db.SaveChanges(); MySetStore(); }
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(); }
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(); }