public bool SaveOrUpdate(DTO_ChiTietPhieuBanHang obj) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { ChiTietPhieuBanHang chiTietPhieuBanHang = new ChiTietPhieuBanHang(); chiTietPhieuBanHang.MaChiTietPhieuBan = obj.MaChiTietPhieuBan; chiTietPhieuBanHang.MaPhieuBanHang = obj.MaPhieuBanHang; chiTietPhieuBanHang.MaHangHoa = obj.MaHangHoa; chiTietPhieuBanHang.SoLuong = obj.SoLuong; chiTietPhieuBanHang.Gia = obj.Gia; chiTietPhieuBanHang.ThanhTien = obj.ThanhTien; if (db.ChiTietPhieuBanHangs.Any(e => e.MaChiTietPhieuBan == chiTietPhieuBanHang.MaChiTietPhieuBan)) { db.ChiTietPhieuBanHangs.Attach(chiTietPhieuBanHang); db.Entry(chiTietPhieuBanHang).State = System.Data.Entity.EntityState.Modified; if (db.SaveChanges() > 0) { return(true); } return(false); } db.ChiTietPhieuBanHangs.Add(chiTietPhieuBanHang); if (db.SaveChanges() > 0) { return(true); } return(false); } }
private void BtnUpdate_Click(object sender, RoutedEventArgs e) { DTO_ChiTietPhieuBanHang obj = listHangHoa.FirstOrDefault(x => x.MaHangHoa == cbSanPham.SelectedValue.ToString()); if (obj != null) { obj.SoLuong = int.Parse(txtSoLuong.Text); obj.ThanhTien = decimal.Parse(txtThanhTien.Text); } dgvChiTietPhieuBanHang.ItemsSource = null; dgvChiTietPhieuBanHang.ItemsSource = listHangHoa; RefreshChiTiet(); }
private void DgvChiTietPhieuBanHang_SelectionChanged(object sender, SelectionChangedEventArgs e) { DTO_ChiTietPhieuBanHang chiTietPhieuBanHang = dgvChiTietPhieuBanHang.SelectedItem as DTO_ChiTietPhieuBanHang; if (chiTietPhieuBanHang != null) { cbSanPham.SelectedValue = chiTietPhieuBanHang.MaHangHoa; txtSoLuong.Text = chiTietPhieuBanHang.SoLuong.ToString(); txtGiaNhap.Text = chiTietPhieuBanHang.Gia.ToString(); txtThanhTien.Text = chiTietPhieuBanHang.ThanhTien.ToString(); btnUpdate.IsEnabled = true; } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Bạn có muốn xóa dòng này?", "Confirmation", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { if (dgvChiTietPhieuBanHang.SelectedItem != null) { DTO_ChiTietPhieuBanHang obj = dgvChiTietPhieuBanHang.SelectedItem as DTO_ChiTietPhieuBanHang; listHangHoa.Remove(obj); deleteList.Add(obj); dgvChiTietPhieuBanHang.ItemsSource = null; dgvChiTietPhieuBanHang.ItemsSource = listHangHoa; } } }
private void calSoLuongNhap(DTO_ChiTietPhieuBanHang item, bool isDelete = false) { var soLuong = BUS_HangHoa.Instance.getSoLuong(item.TenHangHoa); if (isDelete) { soLuong = soLuong + (int)item.SoLuong; } else { soLuong = soLuong - (int)item.SoLuong; } var hangHoa = new DTO_HangHoa(); hangHoa.TenHangHoa = item.TenHangHoa; hangHoa.SoLuongTon = soLuong; BUS_HangHoa.Instance.UpdateSoLuong(hangHoa); }
public bool InsertCTPBH(DTO_ChiTietPhieuBanHang obj) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { ChiTietPhieuBanHang chiTietPhieuBanHang = new ChiTietPhieuBanHang(); chiTietPhieuBanHang.MaChiTietPhieuBan = obj.MaChiTietPhieuBan; chiTietPhieuBanHang.MaPhieuBanHang = obj.MaPhieuBanHang; chiTietPhieuBanHang.MaHangHoa = obj.MaHangHoa; chiTietPhieuBanHang.SoLuong = obj.SoLuong; chiTietPhieuBanHang.Gia = obj.Gia; chiTietPhieuBanHang.ThanhTien = obj.ThanhTien; db.ChiTietPhieuBanHangs.Add(chiTietPhieuBanHang); if (db.SaveChanges() > 0) { return(true); } return(false); } }
public bool SaveOrUpdateCTPBH(DTO_ChiTietPhieuBanHang obj) { return(ChiTietPhieuBanHang.Instance.SaveOrUpdate(obj)); }
public bool InsertCTPBH(DTO_ChiTietPhieuBanHang obj) { return(ChiTietPhieuBanHang.Instance.InsertCTPBH(obj)); }