public bool UpdateDetailCoupon(ChiTietPhieu DetailCouponToEdit) { try { SanPham product = _productrepository.GetProduct(DetailCouponToEdit.MaSP); Kho target = getWareHouse(DetailCouponToEdit.MaSP); PhieuNhapXuat Phieu = getCoupon(DetailCouponToEdit.MaPhieu); ChiTietPhieu chitiet = getDetailCoupon(DetailCouponToEdit.MaPhieu, DetailCouponToEdit.MaSP); if (Phieu.TrangThai.Equals("Nhập")) { target.SoLuong = target.SoLuong - chitiet.SoLuong + DetailCouponToEdit.SoLuong; target.NgayLap = Phieu.NgayLap; } else { target.SoLuong = target.SoLuong + chitiet.SoLuong - DetailCouponToEdit.SoLuong; product.SoLuong = product.SoLuong - chitiet.SoLuong + DetailCouponToEdit.SoLuong; target.NgayXuat = Phieu.NgayLap; _productrepository.EditProduct(product); } _warehouserepository.UpdateWareHouse(target); } catch { return(false); } _detailCouponrepository.editDetailCoupon(DetailCouponToEdit); return(true); }
//Lưu sản phẩm nhập private void btnLuuNhap_Click(object sender, EventArgs e) { Decimal TotalMoney = 0; DialogResult dlr = Decimal.Parse(txtTotaltoEdit.Text) > 0 ? MessageBox.Show("Bạn có muốn thay đổi chi tiết phiếu ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) : MessageBox.Show("Bạn có muốn lưu không? ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (dlr == DialogResult.Yes) { for (int row = 0; row < dgvDetailIn.Rows.Count; row++) { String IDProduct = dgvDetailIn.Rows[row].Cells[0].Value.ToString(); Decimal Price = decimal.Parse(dgvDetailIn.Rows[row].Cells[3].Value.ToString()); int Quality = int.Parse(dgvDetailIn.Rows[row].Cells[2].Value.ToString()); ChiTietPhieu coupondetailto = getCouponDetail(txtIDCouponDetailIn.Text, IDProduct, Price, Quality); if (_service.getDetailCoupon(txtIDCouponDetailIn.Text, IDProduct) == null) { _service.CreateDetailCoupon(coupondetailto); } else { _service.UpdateDetailCoupon(coupondetailto); } TotalMoney += Price * Quality; } PhieuNhapXuat Target = _service.getCoupon(txtIDCouponDetailIn.Text); Target.TongTien = TotalMoney; _service.EditCoupon(Target); View(); } }
public bool CreateDetailCoupon(ChiTietPhieu DetailCouponToCreate) { // if (!ValidateDetailCoupon(DetailCouponToCreate)) // return false; try { _detailCouponrepository.createDetailCoupon(DetailCouponToCreate); SanPham product = _productrepository.GetProduct(DetailCouponToCreate.MaSP); Kho target = getWareHouse(DetailCouponToCreate.MaSP); PhieuNhapXuat Phieu = getCoupon(DetailCouponToCreate.MaPhieu); if (Phieu.TrangThai.Equals("Nhập")) { target.SoLuong = target.SoLuong + DetailCouponToCreate.SoLuong; target.NgayLap = Phieu.NgayLap; } else { target.SoLuong = target.SoLuong - DetailCouponToCreate.SoLuong; product.SoLuong = product.SoLuong + DetailCouponToCreate.SoLuong; target.NgayXuat = Phieu.NgayLap; _productrepository.EditProduct(product); } _warehouserepository.UpdateWareHouse(target); } catch { return(false); } return(true); }
public ChiTietPhieu editDetailCoupon(ChiTietPhieu DetailCouponToEdit) { var originalBill = getDetailCoupon(DetailCouponToEdit.MaPhieu, DetailCouponToEdit.MaSP); _entities.Entry(originalBill).CurrentValues.SetValues(DetailCouponToEdit); // _entities.Update_ChiTietPhieu(DetailCouponToEdit.MaSP, DetailCouponToEdit.MaPhieu, DetailCouponToEdit.DonGia, DetailCouponToEdit.SoLuong); _entities.SaveChanges(); return(DetailCouponToEdit); }
public bool DeleteDetailCoupon(ChiTietPhieu DetailCouponToDelete) { try { _detailCouponrepository.deleteDetailCoupon(DetailCouponToDelete); } catch { return(false); } return(true); }
//Xóa san phẩm nhập private void button2_Click(object sender, EventArgs e) { foreach (DataGridViewCell oneCell in dgvDetailIn.SelectedCells) { if (oneCell.Selected) { ChiTietPhieu ct = _service.getDetailCoupon(txtIDCouponDetailOut.Text, dgvDetailIn[0, oneCell.RowIndex].Value.ToString()); _service.DeleteDetailCoupon(ct); dgvDetailIn.Rows.RemoveAt(oneCell.RowIndex); } } }
//Xóa sản phẩm phiếu xuất trên datagridview private void btnXoasp_Click(object sender, EventArgs e) { foreach (DataGridViewCell oneCell in dgvDetailOut.SelectedCells) { if (oneCell.Selected) { ChiTietPhieu ct = _service.getDetailCoupon(txtIDCouponDetailOut.Text, dgvDetailOut[0, oneCell.RowIndex].Value.ToString()); _service.DeleteDetailCoupon(ct); dgvDetailOut.Rows.RemoveAt(oneCell.RowIndex); } } txtTotalFakeOut.Text = String.Format("{0:#,0 vnđ}", CalculatorTotal(dgvDetailOut)); }
//Thêm chi tiet phiếu - Xuất dữ liệu private void btnSaveOfDetailOut_Click(object sender, EventArgs e) { int flag = 0; Decimal TotalMoney = 0; DialogResult dlr = Decimal.Parse(txtTotaltoEdit.Text) > 0 ? MessageBox.Show("Bạn có muốn thay đổi chi tiết phiếu ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) : MessageBox.Show("Bạn có muốn lưu không? ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (dlr == DialogResult.Yes) { for (int row = 0; row < dgvDetailOut.Rows.Count; row++) { String IDProduct = dgvDetailOut.Rows[row].Cells[0].Value.ToString(); Decimal Price = decimal.Parse(dgvDetailOut.Rows[row].Cells[3].Value.ToString()); int Quality = int.Parse(dgvDetailOut.Rows[row].Cells[2].Value.ToString()); ChiTietPhieu coupondetailto = getCouponDetail(txtIDCouponDetailOut.Text, IDProduct, Price, Quality); if (_service.getDetailCoupon(txtIDCouponDetailOut.Text, IDProduct) == null) { if (!_service.CreateDetailCoupon(coupondetailto)) { flag = 1; } MessageBox.Show("1"); } else { if (!_service.UpdateDetailCoupon(coupondetailto)) { flag = 1; } MessageBox.Show("2"); } TotalMoney += Price * Quality; } if (flag == 0) { PhieuNhapXuat Target = _service.getCoupon(txtIDCouponDetailOut.Text); Target.TongTien = TotalMoney; _service.EditCoupon(Target); View(); } else { MessageBox.Show("Lỗi: Hệ thống đang bận vui lòng thử lại sau", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void deleteDetailCoupon(ChiTietPhieu DetailCouponToDelete) { _entities.ChiTietPhieux.Remove(DetailCouponToDelete); _entities.SaveChanges(); }
public ChiTietPhieu createDetailCoupon(ChiTietPhieu DetailCouponToCreate) { _entities.ChiTietPhieux.Add(DetailCouponToCreate); _entities.SaveChanges(); return(DetailCouponToCreate); }
public ChiTietPhieu createDetailCoupon(ChiTietPhieu DetailCouponToCreate) { throw new NotImplementedException(); }
public ChiTietPhieu editDetailCoupon(ChiTietPhieu DetailCouponToEdit) { throw new NotImplementedException(); }
public void deleteDetailCoupon(ChiTietPhieu DetailCouponToDelete) { throw new NotImplementedException(); }