public void AddHDCT(HoaDonCT hdct) { PBL3 db = new PBL3(); db.HoaDonCT.Add(hdct); db.SaveChanges(); }
public HoaDonCT getHDCTByMHDCT(int x) { PBL3 db = new PBL3(); HoaDonCT s = db.HoaDonCT.Find(x); return(s); }
public bool InsertHoaDonCT_DAL(HoaDonCT hoaDonCT) { string query = "INSERT dbo.CHITIETHOADON ( MaHD, MaHH, SalesDc, QtyHD) VALUES ( @maHD , @maHH , @giam , @qty )"; int result = DataProvider.Instance.ExecuteNonQuery(query, new object[] { hoaDonCT.HoaDon.Mã_HĐơn, hoaDonCT.Mã_HH, hoaDonCT.Giảm_giá, hoaDonCT.SL }); return(result > 0); }
public int CreateHoaDonCTs(List <HoaDonCT_Model> hd, int id_khachhang, int id_hoadon) { if (hd != null) { HoaDonCT result = new HoaDonCT(); string now = DateTime.Now.ToString("MM/dd/yyyy h:mm tt"); foreach (var item in hd) { var modal_To_EF = new HoaDonCT() { id_sanpham = item.idsanpham, id_loai = item.idloai, id_hoadon = id_hoadon, discount = 0, dongia = item.giasp, soluong = item.soluong, id_khachhang = id_khachhang }; result = db.HoaDonCTs.Add(modal_To_EF); db.SaveChanges(); } if (result != null) { return(1); } return(-1); } return(0); }
private void ThanhToan() { if (lsvHHThanhToan.Items.Count > 0) { string maHD = lblMaHD.Text; string maKH = (cmbTenKH.SelectedItem as KhachHang).Mã_KHàng; DateTime ngayGD = DateTime.Now; string maNV = frmDangnhap.nv.Mã_NViên; int giamGia = Convert.ToInt32(nmDiscount.Value); HoaDon hoadon = new HoaDon(maHD, ngayGD, maNV, maKH, TOTAL); if (BLL_HoaDon.Instance.InsertHoaDon_BLL(hoadon)) { for (int i = 0; i < lsvHHThanhToan.Items.Count; i++) { string maHH = lsvHHThanhToan.Items[i].SubItems[0].Text; int slHH = Convert.ToInt32(lsvHHThanhToan.Items[i].SubItems[2].Text); HoaDonCT hoaDonCT = new HoaDonCT(hoadon, maHH, giamGia, slHH); BLL_HoaDonCT.Instance.InsertHoaDonCT_BLL(hoaDonCT); } frmTinhtien f = new frmTinhtien(hoadon); f.ShowDialog(); TangKeyValueHD(); HuyHD(); LoadListProductsTT(); } else { MessageBox.Show("Lỗi khi thanh toán", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Danh sách mua hàng trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void DeleteHDCT(int x) { PBL3 db = new PBL3(); HoaDonCT s = db.HoaDonCT.Find(x); db.HoaDonCT.Remove(s); db.SaveChanges(); }
public List <HoaDonCT> GetListHDCT_DAL(string idHD) { List <HoaDonCT> list = new List <HoaDonCT>(); string query = "EXEC dbo.PROC_GetListCTHDByID @idhd = '" + idHD + "' "; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { HoaDonCT hdct = new HoaDonCT(item); list.Add(hdct); } return(list); }
//Lấy chi tiết hoá đơn public List <HoaDonCT> LoadChiTiet(string mahd) { List <Model.HoaDon_CT> dsct = (from dhct in db.HoaDon_CT where dhct.MaHoaDon == mahd select dhct).ToList(); List <HoaDonCT> kq = new List <HoaDonCT>(); foreach (Model.HoaDon_CT ct in dsct) { HoaDonCT kqct = new HoaDonCT(); kqct.MaHoaDon = ct.MaHoaDon; kqct.MaSanPham = ct.MaSanPham; kqct.DonGia = ct.DonGia.Value; kqct.SoLuong = ct.SoLuong; kq.Add(kqct); } return(kq); }
public bool InsertHoaDonCT_BLL(HoaDonCT hoaDonCT) { return(DAO_HoaDonCT.Instance.InsertHoaDonCT_DAL(hoaDonCT)); }
//Nút lưu private void btn_Luu_Click(object sender, EventArgs e) { try { HoaDonClient client = new HoaDonClient(); HoaDon hd = new HoaDon(); hd.MaHoaDon = txt_MaHoaDon.Text; hd.NgayXuat = Convert.ToDateTime(msk_NgayXuat.Text); hd.NhanVien = txt_NhanVien.Text; hd.KhachHang = txt_KhachHang.Text; hd.DonDatHang = txt_DonHang.Text; hd.TongTien = Convert.ToDecimal(txt_TongTien.Text); hd.DaThanhToan = Convert.ToDecimal(txt_DaThanhToan.Text); hd.ConLai = Convert.ToDecimal(txt_ConLai.Text); List <HoaDonCT> dsct = new List <HoaDonCT>(); foreach (DataGridViewRow row in dgv_DanhSachChiTiet.Rows) { HoaDonCT ct = new HoaDonCT(); ct.MaHoaDon = txt_MaHoaDon.Text; ct.MaSanPham = row.Cells["MaSanPham"].Value.ToString(); ct.SoLuong = Convert.ToInt32(row.Cells["SoLuong"].Value); ct.DonGia = Convert.ToDecimal(row.Cells["DonGia"].Value); dsct.Add(ct); } hd.DSChiTiet = dsct.ToArray(); if (IsInsertOrUpdate && !Checknull()) { if (client.HoaDon_Insert(hd)) { MessageBox.Show("Thêm hoá đơn thành công"); DataTable dtb = new DataTable(); dtb.Columns.Add("MaSanPham"); dtb.Columns.Add("SoLuong"); dtb.Columns.Add("DonGia"); txt_MaHoaDon.Text = client.HoaDon_GetNewID(DateTime.Today.Year, DateTime.Today.Month); txt_MaHoaDon.Enabled = false; txt_NhanVien.Text = ""; txt_KhachHang.Text = ""; txt_DonHang.Text = ""; msk_NgayXuat.Text = ""; txt_TongTien.Text = "0"; txt_TongTien.Enabled = false; txt_DaThanhToan.Text = "0"; txt_ConLai.Text = "0"; txt_MaSanPham.Text = ""; txt_TenSanPham.Text = ""; txt_SoLuong.Text = ""; txt_DonGia.Text = ""; LoadMaNhanVien(); LoadMaKhachHang(); LoadSanPham(); LoadDonHang(); dgv_DanhSachChiTiet.DataSource = dtb; } else { MessageBox.Show("Thêm hoá đơn thất bại"); } } else if (!IsInsertOrUpdate && !Checknull()) { if (client.HoaDon_Update(hd)) { MessageBox.Show("Cập nhật hoá đơn thành công"); } else { MessageBox.Show("Cập nhật hoá đơn thất bại"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }