private void btnTaoPhieuNhapHang_Click(object sender, EventArgs e) { if (lvwChiTietPhieuNhap.Items.Count == 0) { MessageBox.Show(Instance.TBChuaThemHHVaoDDH, Instance.Loi, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { double tongTien = 0; foreach (ListViewItem item in lvwChiTietPhieuNhap.Items) { if (item.SubItems[2].Text == "") { MessageBox.Show(Instance.TBChuaNhapDayDuGia, Instance.CanhBao, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { tongTien += Convert.ToDouble(item.SubItems[1].Text) * Convert.ToDouble(item.SubItems[2].Text); } } PhieuNhapHangDTO pnhDTO = new PhieuNhapHangDTO(); pnhDTO.Manvlap = tkGlobal.Manv; pnhDTO.Maddh = Convert.ToInt32(cboDonDatHang.SelectedValue); pnhDTO.Mancc = Convert.ToInt32(cboNhaCungCap.SelectedValue); pnhDTO.Tongtien = tongTien; PhieuNhapHangBUS pnhBUS = new PhieuNhapHangBUS(); int mapnh; if (pnhBUS.ThemPNH(pnhDTO, out mapnh)) { foreach (ListViewItem item in lvwChiTietPhieuNhap.Items) { ChiTietPhieuNhapHangBUS ctBUS = new ChiTietPhieuNhapHangBUS(); ChiTietPhieuNhapHangDTO ctDTO = new ChiTietPhieuNhapHangDTO(); ctDTO.Mapnh = mapnh; ctDTO.Mahh = Convert.ToInt32(item.SubItems[4].Text); ctDTO.Soluong = Convert.ToInt32(item.SubItems[1].Text); ctDTO.Gia = Convert.ToInt32(item.SubItems[2].Text); ctBUS.ThemChiTietPNH(ctDTO); } MessageBox.Show(Instance.TBTaoPhieuNhapThanhCong, Instance.ThanhCong, MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDsPNH(); } else { MessageBox.Show(Instance.TBTaoPhieuNhapThatBai, Instance.Loi, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnTaoPhieuNhapHang_Click(object sender, EventArgs e) { if (lvwChiTietPhieuNhap.Items.Count == 0) { MessageBox.Show("Bạn chưa thêm hàng hóa vào đơn đặt hàng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { double tongTien = 0; foreach (ListViewItem item in lvwChiTietPhieuNhap.Items) { if (item.SubItems[2].Text == "") { MessageBox.Show("Bạn chưa nhập đầy đủ giá, hãy nhập thêm giá!", "Nhập thiếu thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { tongTien += Convert.ToDouble(item.SubItems[1].Text) * Convert.ToDouble(item.SubItems[2].Text); } } PhieuNhapHangDTO pnhDTO = new PhieuNhapHangDTO(); pnhDTO.Manvlap = tkGlobal.Manv; pnhDTO.Maddh = Convert.ToInt32(cboDonDatHang.SelectedValue); pnhDTO.Mancc = Convert.ToInt32(cboNhaCungCap.SelectedValue); pnhDTO.Tongtien = tongTien; PhieuNhapHangBUS pnhBUS = new PhieuNhapHangBUS(); int mapnh; if (pnhBUS.ThemPNH(pnhDTO, out mapnh)) { foreach (ListViewItem item in lvwChiTietPhieuNhap.Items) { ChiTietPhieuNhapHangBUS ctBUS = new ChiTietPhieuNhapHangBUS(); ChiTietPhieuNhapHangDTO ctDTO = new ChiTietPhieuNhapHangDTO(); ctDTO.Mapnh = mapnh; ctDTO.Mahh = Convert.ToInt32(item.SubItems[4].Text); ctDTO.Soluong = Convert.ToInt32(item.SubItems[2].Text); ctDTO.Gia = Convert.ToInt32(item.SubItems[1].Text); ctBUS.ThemChiTietPNH(ctDTO); } MessageBox.Show("Tạo phiếu nhập thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDsPNH(); } else { MessageBox.Show("Tạo phiếu nhập thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public bool SuaChiTietPNH(ChiTietPhieuNhapHangDTO ctpnh) { try { CHI_TIET_PHIEU_NHAP_HANG ct = db.CHI_TIET_PHIEU_NHAP_HANG.SingleOrDefault(p => p.MAPNH == ctpnh.Mapnh && p.MAHH == ctpnh.Mahh); ct.SL = ctpnh.Soluong; ct.GIA = ctpnh.Gia; db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public bool ThemChiTietPNH(ChiTietPhieuNhapHangDTO ctpnh) { try { CHI_TIET_PHIEU_NHAP_HANG ctpn = new CHI_TIET_PHIEU_NHAP_HANG(); ctpn.MAPNH = ctpnh.Mapnh; ctpn.MAHH = ctpnh.Mahh; ctpn.GIA = ctpnh.Gia; ctpn.SL = ctpnh.Soluong; db.CHI_TIET_PHIEU_NHAP_HANG.Add(ctpn); db.SaveChanges(); return(true); } catch (Exception r) { return(false); } }
public bool SuaChiTietPNH(ChiTietPhieuNhapHangDTO ctpnh) { return(ctpnhDAO.SuaChiTietPNH(ctpnh)); }
public bool ThemChiTietPNH(ChiTietPhieuNhapHangDTO ctpnh) { return(ctpnhDAO.ThemChiTietPNH(ctpnh)); }