public HoaDonBaoHanh() { this.hoaDon = new HoaDon(); this.hoaDonBan = new HoaDonBan(); this.khachHang = new KhachHang(); this.ctHoaDonBH = new CTHoaDonBaoHanh(); }
public bool ThemhoaDon(HoaDonBan hoaDon, XElement xml) { try { return this.hoaDonDAL.ThemHoaDon(hoaDon, xml); } catch (System.Exception ex) { Console.WriteLine("Message= {1}", ex.Message); } return false; }
public bool CapNhatHoaDon(HoaDonBan hd, XElement xml) { try { SqlParameter[] para = new SqlParameter[13]; para[0] = new SqlParameter("@p_MaHoaDon", hd.HoaDon.MaHoaDon == null ? "" : hd.HoaDon.MaHoaDon); para[1] = new SqlParameter("@p_MaNhanVien", hd.HoaDon.NhanVien.MaNhanVien == null ? "" : hd.HoaDon.NhanVien.MaNhanVien); para[2] = new SqlParameter("@p_MaTrangThai", hd.HoaDon.TrangThai.MaTrangThai == null ? "" : hd.HoaDon.TrangThai.MaTrangThai); para[3] = new SqlParameter("@p_TongTien", hd.HoaDon.TongTien == null ? Decimal.Zero : hd.HoaDon.TongTien); para[4] = new SqlParameter("@p_TienDaTT", hd.HoaDon.TienDaTT == null ? Decimal.Zero : hd.HoaDon.TienDaTT); para[5] = new SqlParameter("@p_NgayLap", hd.HoaDon.NgayLap == null ? "" : hd.HoaDon.NgayLap); para[6] = new SqlParameter("@p_GhiChu", hd.HoaDon.GhiChu == null ? "" : hd.HoaDon.GhiChu); para[7] = new SqlParameter("@p_MaKhachHang", hd.KhachHang.MaKhachHang == null ? "" : hd.KhachHang.MaKhachHang); para[8] = new SqlParameter("@p_DiaChiGiaoHang", hd.DiaChiGH == null ? "" : hd.DiaChiGH); para[9] = new SqlParameter("@p_MaKhuVuc", hd.LePhiGiaoHang.MaKhuVuc == null ? "" : hd.LePhiGiaoHang.MaKhuVuc); para[10] = new SqlParameter("@p_NgayGiaoHang", hd.NgayGiaoHang == null ? "" : hd.NgayGiaoHang); para[11] = new SqlParameter("@p_NgayTT", hd.NgayTT == null ? "" : hd.NgayTT); para[12] = new SqlParameter(); para[12].ParameterName = "@p_XML_TEMP"; para[12].DbType = DbType.Xml; para[12].Direction = ParameterDirection.Input; para[12].Value = xml.ToString(); int result = this.ExecuteNonQuery("HOADONBAN_Upd", para); if (result != 0) { return true; } } catch (System.Exception ex) { Console.WriteLine("Message= {1}", ex.Message); } return false; }
private void ConvertDataToXML(out XElement XML) { List<HoaDonBan> lstHoaDonBan = new List<HoaDonBan>(); XML = new XElement(new XElement("Root")); for (int i = 0; i < gridSpMua.RowCount; i++) { HoaDonBan temp = new HoaDonBan(); temp.CtHoaDon.MatHang.MaMatHang = gridSpMua.GetRowCellValue(i, "Mã sản phẩm").ToString(); temp.CtHoaDon.SoLuong = Convert.ToInt32(gridSpMua.GetRowCellValue(i, "Số lượng")); temp.CtHoaDon.GiaBan = Convert.ToDecimal(gridSpMua.GetRowCellValue(i, "Giá bán")); if (temp.CtHoaDon.SoLuong == 0) { MessageBox.Show("Số lượng mua phải khác 0. ", "Thông báo", MessageBoxButtons.OK); XML = null; return; } lstHoaDonBan.Add(temp); } foreach (HoaDonBan item in lstHoaDonBan) { XElement xml = new XElement("XmlData", new XElement("MaCTHoaDon", item.CtHoaDon.MaCTHoaDonBan == null ? "" : item.CtHoaDon.MaCTHoaDonBan), new XElement("MaMatHang", item.CtHoaDon.MatHang.MaMatHang == null ? "" : item.CtHoaDon.MatHang.MaMatHang), new XElement("SoLuong", item.CtHoaDon.SoLuong == null ? Decimal.Zero : item.CtHoaDon.SoLuong), new XElement("GiaBan", item.CtHoaDon.GiaBan == null ? Decimal.Zero : item.CtHoaDon.GiaBan) ); XML.Add(xml); } }
private void sbLuu_Click_1(object sender, EventArgs e) { HoaDonBan hd = new HoaDonBan(); hd.HoaDon.MaHoaDon = this.maHD; hd.KhachHang.MaKhachHang = this.lueKhachHang.EditValue == null ? "" : this.lueKhachHang.EditValue.ToString(); hd.HoaDon.TrangThai.MaTrangThai = this.lueTrangThai.EditValue == null ? "" : this.lueTrangThai.EditValue.ToString(); if (!hd.HoaDon.TrangThai.MaTrangThai.Equals("") && hd.HoaDon.TrangThai.MaTrangThai.Contains("Đã Thanh toán")) hd.NgayTT = DateTime.Now.ToString("dd/MM/yyyy"); else hd.NgayTT = ""; hd.KhachHang.TenKhachHang = this.teTenKhachHang.Text; hd.HoaDon.NhanVien.TenNhanVien = this.teTenNhanVien.Text; hd.HoaDon.NhanVien.MaNhanVien = this.teMaNhanVien.Text; hd.HoaDon.TongTien = (this.teTongTien.Text == "" ? Decimal.Zero : Convert.ToDecimal(this.teTongTien.Text)); hd.HoaDon.TienDaTT = (this.teTienDTT.Text == "" ? Decimal.Zero : Convert.ToDecimal(this.teTienDTT.Text)); hd.HoaDon.NgayLap = this.deThoiGianLap.DateTime.ToString("dd/MM/yyyy"); if (hd.KhachHang.TenKhachHang.Equals("")) { MessageBox.Show("Tên Khách hàng không được bỏ trống. ", "Thông báo", MessageBoxButtons.OK); return; } if (this.gridSpMua.RowCount == 0) { MessageBox.Show("Danh sách sản phẩm mua không được để trống. ", "Thông báo", MessageBoxButtons.OK); return; } hd.LePhiGiaoHang.MaKhuVuc = this.lueKhuVu.EditValue == null ? null : this.lueKhuVu.EditValue.ToString(); hd.NgayGiaoHang = this.dateGiaoHang.DateTime.ToString("dd/MM/yyyy"); if (hd.NgayGiaoHang.Equals("01-01-0001")) { hd.NgayGiaoHang = ""; } hd.DiaChiGH = this.txtDiaChiGH.Text; if(hd.DiaChiGH.Equals("")) { MessageBox.Show("Địa chỉ giao hàng không được để trống ", "Thông báo", MessageBoxButtons.OK); return; } if (hd.HoaDon.TongTien < (hd.HoaDon.TienDaTT)) { MessageBox.Show("Số tiền trả không được lớn hơn tổng tiền", "Thông báo", MessageBoxButtons.OK); return; } if (hd.KhachHang.TenKhachHang.Equals("")) { MessageBox.Show("Yêu cầu nhập tên khách hàng", "Thông báo", MessageBoxButtons.OK); return; } XElement xlmData; this.ConvertDataToXML(out xlmData); if (StaticVariables.gHoaDonBan == null) { if (xlmData != null) { // Kiểm tra xem sp đó có phải sp khuyến mãi không if (this.rdbDSKhuyenMai.Checked && gridSpMua.RowCount != 0) { //ct.SoLuong = for (int j = 0; j < this.gridSpMua.RowCount; j++) { CTKHuyenMai ct = new CTKHuyenMai(); ct.KhuyenMai.MaKhuyenMai = this.maKhuyenMai; ct.MatHang.MaMatHang = gridSpMua.GetRowCellValue(j, "Mã sản phẩm").ToString(); ct.SoLuong += Convert.ToInt32(gridSpMua.GetRowCellValue(j, "Số lượng")); bool result = (new KhuyenMaiBUS()).CapNhatCTSoLuongKhuyenMai(ct); } } if (new HoaDonBanBUS().ThemhoaDon(hd, xlmData)) { MessageBox.Show("Thêm hóa đơn thành công", "Thông báo", MessageBoxButtons.OK); this.LoadData(); } else { MessageBox.Show("Thêm hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK); } } } else { if (xlmData != null) { if (new HoaDonBanBUS().CapNhathoaDon(hd, xlmData)) { MessageBox.Show("Cập nhật hóa đơn thành công", "Thông báo", MessageBoxButtons.OK); this.LoadData(); } else { MessageBox.Show("Cập nhật đơn thất bại", "Thông báo", MessageBoxButtons.OK); } } } }
private void groupControl1_Enter(object sender, EventArgs e) { if (StaticVariables.gHoaDonBan != null) { this.maHD = StaticVariables.gHoaDonBan.HoaDon.MaHoaDon; this.lueKhachHang.EditValue = StaticVariables.gHoaDonBan.KhachHang.MaKhachHang; this.lueTrangThai.Text = StaticVariables.gHoaDonBan.HoaDon.TrangThai.TenTrangThai; this.teTenKhachHang.Text = StaticVariables.gHoaDonBan.KhachHang.TenKhachHang; this.teMaNhanVien.Text = StaticVariables.gHoaDonBan.HoaDon.NhanVien.MaNhanVien; this.teTenNhanVien.Text = StaticVariables.gHoaDonBan.HoaDon.NhanVien.TenNhanVien; this.teTongTien.Text = StaticVariables.gHoaDonBan.HoaDon.TongTien.ToString(); this.tienTongSp = Convert.ToDecimal(this.teTongTien.Text); this.teTienDTT.Text = StaticVariables.gHoaDonBan.HoaDon.TienDaTT.ToString(); this.teTienConLai.Text = (StaticVariables.gHoaDonBan.HoaDon.TongTien - StaticVariables.gHoaDonBan.HoaDon.TienDaTT + StaticVariables.gHoaDonBan.LePhiGiaoHang.Dongia).ToString(); this.deThoiGianLap.Text = StaticVariables.gHoaDonBan.HoaDon.NgayLap; this.txtDiaChiGH.Text = StaticVariables.gHoaDonBan.DiaChiGH; this.lueKhuVu.Text = StaticVariables.gHoaDonBan.LePhiGiaoHang.TenKhuVuc; this.dateGiaoHang.Text = StaticVariables.gHoaDonBan.NgayGiaoHang; HoaDonBan hd = new HoaDonBan(); hd.HoaDon.MaHoaDon = this.maHD; this.gridSanPhamMua.DataSource = (new HoaDonBanBUS().TimKiemCThoaDon(hd)); for (int j = 0; j < this.gridSpMua.RowCount; j++) { Decimal giaBan = Convert.ToDecimal(gridSpMua.GetRowCellValue(j, "Giá bán")); int slTemp = Convert.ToInt32(gridSpMua.GetRowCellValue(j, "Số lượng")); gridSpMua.SetRowCellValue(j, "Giá bán", (slTemp) * giaBan); } this.dateGiaoHang.EditValue = DateTime.Now; if (this.lueTrangThai.Text.Equals("Đã Thanh toán")) { this.sbLuu.Enabled = false; } else { this.sbLuu.Enabled = true; } } else { // nó vao day this.btnLamMoi_Click(null, null); } }
private void sbTimKiemHoaDon_Click(object sender, EventArgs e) { HoaDonBan hd = new HoaDonBan(); hd.KhachHang.TenKhachHang = this.teTenKhachHang.Text; hd.HoaDon.MaHoaDon = this.teMaHoaDon.Text; hd.LePhiGiaoHang.MaKhuVuc = this.lueKhuVu.EditValue == null ? "" : this.lueKhuVu.EditValue.ToString(); hd.HoaDon.TrangThai.MaTrangThai = this.lueTrangThai.EditValue == null ? "" : this.lueTrangThai.EditValue.ToString(); hd.NgayTT = this.deThoiGianLap.DateTime.ToString("dd/MM/yyyy"); if (hd.NgayTT.Equals("01/01/0001")) { hd.NgayTT = ""; } hd.HoaDon.NhanVien.TenNhanVien = this.teTenNhanVien.Text; this.gcKetQua.DataSource = this.hoaDonBUS.TimKiemhoaDon(hd); }
private void teMaHoaDon_EditValueChanged(object sender, EventArgs e) { try { if (teMaHoaDon.Text.Length == 15) { HoaDonBan hd = new HoaDonBan(); hd.HoaDon.MaHoaDon = teMaHoaDon.Text; this.gridSanPham.DataSource = (new HoaDonBanBUS().TimKiemCThoaDon(hd)); } else this.gridSanPham.DataSource = null; } catch { this.gridSanPham.DataSource = null; } }
public DataTable TimKiemCThoaDon(HoaDonBan hoaDon) { try { return this.hoaDonDAL.TimKiemCTHoaDon(hoaDon); } catch (System.Exception ex) { Console.WriteLine("Message= {1}", ex.Message); } return null; }
public DataTable TimKiemHoaDon(HoaDonBan hd) { try { SqlParameter[] para = new SqlParameter[10]; para[0] = new SqlParameter("@p_TenNhanVien", hd.HoaDon.NhanVien.TenNhanVien == null ? "" : hd.HoaDon.NhanVien.TenNhanVien); para[1] = new SqlParameter("@p_MaTrangThai", hd.HoaDon.TrangThai.MaTrangThai == null ? "" : hd.HoaDon.TrangThai.MaTrangThai); para[2] = new SqlParameter("@p_NgayLap", hd.HoaDon.NgayLap == null ? "" : hd.HoaDon.NgayLap); para[3] = new SqlParameter("@p_MaHoaDonBan", hd.HoaDon.MaHoaDon == null ? "" : hd.HoaDon.MaHoaDon); para[4] = new SqlParameter("@p_TenKhachHang", hd.KhachHang.TenKhachHang == null ? "" : hd.KhachHang.TenKhachHang); para[5] = new SqlParameter("@p_DiaChiGiaoHang", hd.DiaChiGH == null ? "" : hd.DiaChiGH); para[6] = new SqlParameter("@p_MaKhuVuc", hd.LePhiGiaoHang.MaKhuVuc == null ? "" : hd.LePhiGiaoHang.MaKhuVuc); para[7] = new SqlParameter("@p_NgayGiaoHang", hd.NgayGiaoHang == null ? "" : hd.NgayGiaoHang); para[8] = new SqlParameter("@p_NgayTT", hd.NgayTT == null ? "" : hd.NgayTT); para[9] = new SqlParameter("@p_TOP", 100); DataTable lstHoaDon = this.LoadDataTable("HOADONBAN_Search", para); return lstHoaDon; } catch (System.Exception ex) { Console.WriteLine("Message= {1}", ex.Message); } return null; }
public DataTable TimKiemCTHoaDonBH(HoaDonBan hd) { try { SqlParameter[] para = new SqlParameter[5]; para[0] = new SqlParameter("@p_MaCTHoaDon", hd.CtHoaDon.MaCTHoaDonBan == null ? "" : hd.CtHoaDon.MaCTHoaDonBan); para[1] = new SqlParameter("@p_MaHoaDonBan", hd.HoaDon.MaHoaDon == null ? "" : hd.HoaDon.MaHoaDon); para[2] = new SqlParameter("@p_MaMatHang", hd.CtHoaDon.MatHang == null ? "" : hd.CtHoaDon.MatHang.MaMatHang); para[3] = new SqlParameter("@p_SoLuong", hd.CtHoaDon.SoLuong == null ? 0 : hd.CtHoaDon.SoLuong); para[4] = new SqlParameter("@p_TOP", 100); DataTable lstCTHoaDon = this.LoadDataTable("CT_HOADONBANBH_Search", para); return lstCTHoaDon; } catch (System.Exception ex) { Console.WriteLine("Message= {1}", ex.Message); } return null; }