private void btnhanhang_Click(object sender, EventArgs e) { if (txtmahd.Text == "") { XtraMessageBox.Show("Chưa chọn hợp đồng!", "Thông báo"); } else { try { EnterWarehouse enterWarehouse = new EnterWarehouse() { EnterWarehouseID = int.Parse(txtmahd.Text), EnterDate = DateTime.Now.Date, EmployeeID = Session.EmployeeID, Status = "Đã nhập", Notes = "" }; var temp = contract.GetById(enterWarehouse.EnterWarehouseID); temp.Status = "Hoàn thành"; this.enterWarehouse.Add(enterWarehouse); //thêm phiếu nhận hàng contract.Update(temp); //Sửa trạng thái hợp đồng sau khi nhận hàng. var list = detail.GetByIdList(enterWarehouse.EnterWarehouseID); var warehouse = this.warehouse.GetAll(); var update = false; foreach (var itemlist in list) { update = false; foreach (var item in warehouse) { if (itemlist.ProductID == item.ProductID) { Warehouse w = new Warehouse() { ProductID = item.ProductID, Quantity = item.Quantity + itemlist.Quantity, QuantityExactly = item.QuantityExactly + itemlist.Quantity }; this.warehouse.Delete(item.ProductID); this.warehouse.Add(w);//nếu laoji sản phẩm này còn trong kho thì update lại số lượng update = true; break; } } if (update == false) { Warehouse w = new Warehouse() { ProductID = itemlist.ProductID, Quantity = itemlist.Quantity, QuantityExactly = itemlist.Quantity }; this.warehouse.Add(w); //trong kho chưa có thì thêm mới } } XtraMessageBox.Show("Thêm mới phiếu nhận hàng thành công!, Đã cập nhật kho hàng!", "Thông báo"); txtmahd.Text = ""; LoadHoaDon(); } catch { XtraMessageBox.Show("Please try again!", "Thông báo"); } } }
private void btluu_Click(object sender, EventArgs e) { if (insert)//thêm mới { if (cbmahd.Text == "") { XtraMessageBox.Show("Chưa nhập đủ thông tin!", "Thông báo"); } else { try { EnterWarehouse enterWarehouse = new EnterWarehouse() { EnterWarehouseID = int.Parse(cbmahd.Text), EnterDate = DateTime.Now.Date, EmployeeID = Session.EmployeeID, Status = "Đã nhập", Notes = txtghichu.Text }; var temp = contract.GetById(enterWarehouse.EnterWarehouseID); temp.Status = "Hoàn thành"; this.enterWarehouse.Add(enterWarehouse); //thêm phiếu nhận hàng contract.Update(temp); //Sửa trạng thái hợp đồng sau khi nhận hàng. var list = detail.GetByIdList(enterWarehouse.EnterWarehouseID); var warehouse = this.warehouse.GetAll(); var update = false; foreach (var itemlist in list) { update = false; foreach (var item in warehouse) { if (itemlist.ProductID == item.ProductID) { Warehouse w = new Warehouse() { ProductID = item.ProductID, Quantity = item.Quantity + itemlist.Quantity, QuantityExactly = item.QuantityExactly + itemlist.Quantity }; this.warehouse.Delete(item.ProductID); this.warehouse.Add(w);//nếu laoji sản phẩm này còn trong kho thì update lại số lượng update = true; break; } } if (update == false) { Warehouse w = new Warehouse() { ProductID = itemlist.ProductID, Quantity = itemlist.Quantity, QuantityExactly = itemlist.Quantity }; this.warehouse.Add(w); //trong kho chưa có thì thêm mới } } XtraMessageBox.Show("Thêm mới thành công!, Đã cập nhật kho hàng!", "Thông báo"); Reset(); LoadData(); cbmahd.Properties.Items.Remove(enterWarehouse.EnterWarehouseID); KhoaDieuKhien(); } catch { XtraMessageBox.Show("Please try again!", "Thông báo"); } } } else //sửa { if (cbmahd.Text == "") { XtraMessageBox.Show("Chưa nhập đủ thông tin!", "Thông báo"); } else { cbmahd.Enabled = false; try { var temp = enterWarehouse.GetById(int.Parse(cbmahd.Text)); EnterWarehouse enter = new EnterWarehouse() { EnterWarehouseID = int.Parse(cbmahd.Text), EnterDate = DateTime.Now.Date, EmployeeID = Session.EmployeeID, Status = temp.Status, Notes = txtghichu.Text, }; enterWarehouse.Update(enter); XtraMessageBox.Show("Sửa thành công!", "Thông báo"); } catch { XtraMessageBox.Show("Please try again!", "Thông báo"); } } } }