//Phương thức thanh toán void ThanhToan(object sender, EventArgs e) { //Lấy thông tin BanHangThanhToanPresentation wpf = (BanHangThanhToanPresentation)sender; _hoaDon.TienKhachTra_HD = wpf._hoaDon.TienKhachTra_HD; _hoaDon.VouCher_HD = wpf._hoaDon.VouCher_HD; _hoaDon.MaGiamGia = wpf._hoaDon.MaGiamGia; _hoaDon.TienMaGiamGia = wpf._hoaDon.TienMaGiamGia; _hoaDon.TienThuaTraLaiKhach = wpf._hoaDon.TienThuaTraLaiKhach; _hoaDon.DangDung_HD = true; //Tính lại tiền TongTien(); //Lưu lại phiên bán hàng BanHangBusiness.BanHang(_hoaDon, _dsSPMua, true); //In hóa đơn bool _InHoaDon = wpf._InHoaDon; if (_InHoaDon) { //Chuẩn bị dữ liệu Pos_ds _Pos_ds = new Pos_ds(); DataTable _dtHoaDonBanLe = _Pos_ds.tbl_HOADON; DataRow _drHoaDonBanLe; foreach (SanPhamPublic _spHoaDon in _dsSPMua) { _drHoaDonBanLe = _dtHoaDonBanLe.NewRow(); _drHoaDonBanLe["MaSP_SP"] = _spHoaDon.MaSP_SP; _drHoaDonBanLe["TenSP_SP"] = _spHoaDon.TenSP_SP; _drHoaDonBanLe["GiaBan_SP"] = _spHoaDon.GiaBan; _drHoaDonBanLe["DVT_SP"] = _spHoaDon.DVT_SP.TenDVT_DVT; _drHoaDonBanLe["SoLuong_SP"] = _spHoaDon.SoLuong_SP; _drHoaDonBanLe["ChietKhau_SP"] = _spHoaDon.CKTienMat; _drHoaDonBanLe["ThanhTien_SP"] = _spHoaDon.ThanhTien_SP; _dtHoaDonBanLe.Rows.Add(_drHoaDonBanLe); } _hoaDon.TongSoLuongSP = _dsSPMua.Sum(item => item.SoLuong_SP); HoaDonBanLe_UPresentation wpf_HoaDon = new HoaDonBanLe_UPresentation(); wpf_HoaDon._status_para = "Bản gốc"; wpf_HoaDon._dtHoaDon = _dtHoaDonBanLe; wpf_HoaDon._hoaDon = _hoaDon; wpf_HoaDon.ShowDialog(); } //Khởi tạo lại dữ liệu _dsSPMua.Clear(); KhoiTaoDuLieu(); TongTien(); txtMaHang.Focus(); //Xóa thông tin khách hàng vừa mua gdKhachHang.Children.Clear(); }
//wpf loaded private void Window_Loaded(object sender, RoutedEventArgs e) { //Lấy thông tin sp trong hệ thống _dtSPSua = BanHangBusiness.LaySpTheoMa(_sp.MaSP_SP).Tables[0]; if (_dtSPSua.Rows.Count == 0) { MessageBox.Show("Lỗi: Không tìm thấy sp trong hệ thống!"); this.Close(); } //Hiển thị lbTenSP.Content = _sp.TenSP_SP; lbGiaBan.Content = _sp.GiaBan; lbDonVi.Content = _sp.DVT_SP.TenDVT_DVT; txtSoLuong.Text = _sp.SoLuong_SP.ToString(); txtCKTienMat.Text = _sp.CKTienMat; txtSoLuong.Focus(); txtSoLuong.SelectAll(); //Bật tắt chiết khấu sản phẩm ThietLapHeThongPublic _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); txtCKTienMat.IsEnabled = _thietLap.ChietKhauSanPham; TongTien(); }
//Loaded dowork private void Loaded_dowork() { //Lấy thông tin in hóa đơn _report = new ReportDocument(); _report.Load("../../Report/HoaDonBanLe_rpt.rpt"); //Thông tin cửa hàng _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); //Thông tin hàng mua _report.Database.Tables["tbl_HOADON"].SetDataSource(_dtHoaDon); //Thông tin cửa hàng _report.SetParameterValue("TenCuaHang_para", _thietLap.TenCuaHang); _report.SetParameterValue("DiaChi_para", _thietLap.DiaChi); _report.SetParameterValue("SDT_para", _thietLap.SDT); //Thông tin hóa đơn _report.SetParameterValue("SoHD_Para", _hoaDon.SoHD_HD); _report.SetParameterValue("NhanVien_Para", _hoaDon.NguoiLap_HD.MaNV_NV); _report.SetParameterValue("Ngay_Para", _hoaDon.NgayLap_HD.ToString("dd/MM/yyyy [HH:mm tt]")); _report.SetParameterValue("_status_para", _status_para); _report.SetParameterValue("TongSoLuong_para", _hoaDon.TongSoLuongSP); _report.SetParameterValue("TongTien_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TongTien_HD.ToString())); _report.SetParameterValue("TongCKSP_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TongCKSanPham.ToString())); _report.SetParameterValue("TongCKHD_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TongCKHoaDon.ToString())); _report.SetParameterValue("Voucher_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.VouCher_HD.ToString())); _report.SetParameterValue("MaGiamGia_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TienMaGiamGia.ToString())); _report.SetParameterValue("ThanhTien_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TienConLaiPhaiTra.ToString())); _report.SetParameterValue("TienKhachTra_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TienKhachTra_HD.ToString())); _report.SetParameterValue("TienThuaTraKhach_para", UntilitiesBusiness.ThemDauPhay(_hoaDon.TienThuaTraLaiKhach.ToString())); _report.SetParameterValue("TienBangChu_para", UntilitiesBusiness.ChuyenSoThanhChu(_hoaDon.TienConLaiPhaiTra.ToString())); //Thông tin khách hàng int _DiemTichLuyHoaDon = _hoaDon.TongTien_HD / _thietLap.MucQuyDoiDiem; if (String.IsNullOrEmpty(_hoaDon.KhachHang_HD.MaKH_KH)) { _hoaDon.KhachHang_HD.MaKH_KH = ""; _hoaDon.KhachHang_HD.DiemTichLuy_KH = 0; _hoaDon.KhachHang_HD.NHK_KH.TenNKH_NKH = ""; _DiemTichLuyHoaDon = 0; } else { //Lấy tên nhóm khách hàng DataTable _dtKhachHang = BanHangBusiness.LayKhTheoMa(_hoaDon.KhachHang_HD.MaKH_KH).Tables[0]; _hoaDon.KhachHang_HD.DiemTichLuy_KH = (int)_dtKhachHang.Rows[0]["DiemTichLuy_KH"]; _hoaDon.KhachHang_HD.NHK_KH.TenNKH_NKH = _dtKhachHang.Rows[0]["TenNKH_NKH"].ToString(); } _report.SetParameterValue("MaKhachHang_para", _hoaDon.KhachHang_HD.MaKH_KH); _report.SetParameterValue("DiemTichLuy_para", _hoaDon.KhachHang_HD.DiemTichLuy_KH); _report.SetParameterValue("TichLuyDonHang_para", _DiemTichLuyHoaDon.ToString()); _report.SetParameterValue("TenNhomKhachHang_para", _hoaDon.KhachHang_HD.NHK_KH.TenNKH_NKH); }
private void smiComfim_Click(object sender, EventArgs e) { try { ConnectionUtil.Instance.BeginTransaction(); Draft = 0; //cap nhat trang thai don hang goc HuyDonHangGoc(); //cap nhat don hang tra lai UpdateChungTu(); //cap nhat lai diem tich luy the ChinhSachTheTVienDataProvider.Instance.UpdateDiemTichLuyTraHang(Business.ChungTu.IdChungTu); //tinh tien khach phai tra lai do tru diem thuong cac don hang truoc, sau do update lai diem ve 0 int soDiemAm = 0; int idThe = 0; double tienTraLaiThe = ChinhSachTheTVienDataProvider.Instance.CheckSoTienTraLai(Business.ChungTu.IdChungTu, ref soDiemAm, ref idThe); if (tienTraLaiThe > 0) { BanHangBusiness tlaiBus = new BanHangBusiness(Business.ChungTu, tienTraLaiThe, soDiemAm, idThe); tlaiBus.SaveChungTuHoanTien(); MessageBox.Show("Đề nghị khách hàng trả lại tiền quy đổi điểm thưởng"); frmBH_LapPhieuThu frm = new frmBH_LapPhieuThu(tlaiBus.ChungTu); frm.ShowDialog(); } ConnectionUtil.Instance.CommitTransaction(); Updating = false; setEDFunctions(); clsUtils.MsgThongBao(Declare.msgUpdateSucc); } catch (Exception ex) { ConnectionUtil.Instance.RollbackTransaction(); EventLogProvider.Instance.WriteOfflineLog(ex.ToString() + "\nUser: "******"\nMay: " + Declare.TenMay, this.Name); this.Close(); #if DEBUG clsUtils.MsgCanhBao(ex.ToString()); #else clsUtils.MsgCanhBao(ex.Message); #endif } }
//Timfm kiếm sản phẩm private void TimKiemSP(object sender, EventArgs e) { NhapMua_TimKiemSPPresentation wpf_tim = (NhapMua_TimKiemSPPresentation)sender; List <SanPhamPublic> _lstSPTim = wpf_tim._ListSPChon; if (_lstSPTim.Count > 0) { foreach (SanPhamPublic _sp in _lstSPTim) { //Kiểm tra xem trong hệ thống có sản phẩm này không? DataTable _dtSp = BanHangBusiness.LaySpTheoMa(_sp.MaSP_SP).Tables[0];//Chứa toàn bộ sản phẩm của hệ thống if (_dtSp.Rows.Count == 0) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Mã sản phẩm không tồn tại. Vui lòng kiểm tra lại!"; txtMaHang.Focus(); txtMaHang.SelectAll(); return; } //Kiểm tra số lượng hàng có đủ ko? int _SoLuongCon = Convert.ToInt32(_dtSp.Rows[0]["SoLuong_SP"].ToString()); if (_SoLuongCon < 1) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Hết sản phẩm."; txtMaHang.Focus(); txtMaHang.SelectAll(); return; } _dtSp.Dispose(); ThemHangVaoDsHangMua(_sp.MaSP_SP); } //Hiển thị giỏ hàng dgDanhSachSanPham.ItemsSource = _dsSPMua; dgDanhSachSanPham.Items.Refresh(); //Tính tổng tiền hóa đơn TongTien(); //Đặt con trỏ vào ô nhập mã hàng khác txtMaHang.Focus(); txtMaHang.Text = ""; btnThanhToan.IsEnabled = true; btnChietKhau.IsEnabled = true; btnHuy.IsEnabled = true; } }
//Kiểm tra mã hàng nhập vào private bool KiemTraSP(string _MaSp) { //Kiểm tra xem mã có hợp lệ không(Mã chỉ chứa chữ cái, dấu chấm và dấu gạch dưới) string _checkMaSp = @"^([a-zA-Z0-9._]+)$"; if (!Regex.IsMatch(_MaSp, _checkMaSp)) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Mã sản phẩm không hợp lệ!"; txtMaHang.Focus(); txtMaHang.SelectAll(); return(false); } //Kiểm tra xem trong hệ thống có sản phẩm này không? DataTable _dtSp = BanHangBusiness.LaySpTheoMa(_MaSp).Tables[0];//Chứa toàn bộ sản phẩm của hệ thống if (_dtSp.Rows.Count == 0) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Mã sản phẩm không tồn tại. Vui lòng kiểm tra lại!"; txtMaHang.Focus(); txtMaHang.SelectAll(); return(false); } //Kiểm tra số lượng hàng có đủ ko? int _SoLuongCon = Convert.ToInt32(_dtSp.Rows[0]["SoLuong_SP"].ToString()); if (_SoLuongCon < 1) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Hết sản phẩm."; txtMaHang.Focus(); txtMaHang.SelectAll(); return(false); } _dtSp.Dispose(); lbWarning.Visibility = System.Windows.Visibility.Hidden; return(true); }
//THêm khách hàng khi chưa có mã khách hàng đó private void ThemKhachHang(object sender, EventArgs e) { //Lấy thông tin khách hàng KhachHangThemPresentation wpf = (KhachHangThemPresentation)sender; KhachHangPublic _kh = wpf._kh; if (KhachHangBusiness.ThemKhachHang(_kh)) { //Lấy nhóm khách hàng theo mã DataTable _dtNKH = BanHangBusiness.LayNKHTheoMa(_kh.NHK_KH.MaNKH_NKH).Tables[0]; if (_dtNKH.Rows.Count > 0) { _kh.NHK_KH.TenNKH_NKH = _dtNKH.Rows[0]["TenNKH_NKH"].ToString(); _kh.NHK_KH.ChietKhau_NKH = Convert.ToInt32(_dtNKH.Rows[0]["ChietKhau_NKH"].ToString()); _kh.NHK_KH.Diem_NKH = Convert.ToInt32(_dtNKH.Rows[0]["Diem_NKH"].ToString()); _kh.NHK_KH.Anh_NKH = _dtNKH.Rows[0]["Anh_NKH"].ToString(); } //Hiển thị thông tin khách hàng BanHang_KH_UPresentation wpfKhachHang = new BanHang_KH_UPresentation(); wpfKhachHang._kh = _kh; gdKhachHang.Children.Clear(); gdKhachHang.Children.Add(wpfKhachHang); //Lấy chiết khấu hóa đơn _hoaDon.KhachHang_HD = _kh; //Tính tổng TongTien(); } else { MessageBox.Show("Thêm khách hàng thất bại!"); } }
//Phương thức thanh toán - trả sp private void ThanhToanTraSp(object sender, EventArgs e) { #region 1.Lấy thông tin #endregion #region 2. Hủy hóa đơn cũ if (_hoaDon != null) { TraHangBusiness.HuyHoaDon(_hoaDon); } else { MessageBox.Show("Hóa đơn hủy rỗng!"); } #endregion #region 3.Lưu lịch sử bán hàng LichSuBanHangPublic _lsbh = new LichSuBanHangPublic(); _lsbh.MaLSBH_LSBH = UntilitiesBusiness.GetNextID("tbl_LICHSUBANHANG", "MaLSBH_LSBH", "LS.", 10); _lsbh.NhanVienThucHien_LSBH = _NhanVien; _lsbh.SoHD_LSBH.SoHD_HD = _hoaDon.SoHD_HD; _lsbh.MoTa_LSBH = "Khách trả hàng"; _lsbh.ThoiGian_LSBH = DateTime.Now; LichSuBanHangBusiness.ThemLichSuBanHang(_lsbh); #endregion #region 4.Tạo hóa đơn mới nếu còn hàng if (_lstHangMua == null) { goto go; } if (_lstHangMua.Count == 0) { goto go; } //Tạo hóa đơn mới _hoaDonMoi.SoHD_HD = UntilitiesBusiness.GetNextID("tbl_HOADON", "SoHD_HD", "HD.", 10); _hoaDonMoi.NgayLap_HD = DateTime.Now; _hoaDonMoi.KhachHang_HD = _hoaDon.KhachHang_HD; _hoaDonMoi.NguoiLap_HD = _NhanVien; _hoaDonMoi.MaGiamGia.MaThe_MGG = _hoaDon.MaGiamGia.MaThe_MGG; _hoaDonMoi.BanLe_HD = _hoaDon.BanLe_HD; _hoaDonMoi.DangDung_HD = true; ////Tạo danh sách hàng mua cho hóa đơn mới List <SanPhamPublic> _lstSpMua = new List <SanPhamPublic>(); SanPhamPublic _sp; foreach (HangMuaPubLic _hm in _lstHangMua) { _sp = new SanPhamPublic(); _sp.MaSP_SP = _hm.SanPham.MaSP_SP; _sp.TenSP_SP = _hm.SanPham.TenSP_SP; _sp.SoLuong_SP = _hm.SoLuong; _sp.CKPhanTram_SP = _hm.ChietKhauPhanTram; _sp.CKTienMat = _hm.ChietKhauTienMat; _sp.GiaNhap_SP = _hm.GiaNhap_HM; _sp.GiaBan = _hm.GiaBan_HM; _sp.DVT_SP.TenDVT_DVT = _hm.SanPham.DVT_SP.TenDVT_DVT; _sp.ThanhTien_SP = UntilitiesBusiness.ThemDauPhay(_hm.ThanhTien.ToString()); _lstSpMua.Add(_sp); } ////Lưu hóa đơn mới BanHangBusiness.BanHang(_hoaDonMoi, _lstSpMua, false); ////Lưu lịch sử bán hàng //_lsbh = new LichSuBanHangPublic(); //_lsbh.MaLSBH_LSBH = UntilitiesBusiness.GetNextID("tbl_LICHSUBANHANG", "MaLSBH_LSBH", "LS.", 10); //_lsbh.NhanVienThucHien_LSBH = _NhanVien; //_lsbh.SoHD_LSBH.SoHD_HD = _hoaDonMoi.SoHD_HD; //_lsbh.MoTa_LSBH = "Khách mua hàng"; //_lsbh.ThoiGian_LSBH = DateTime.Now; //LichSuBanHangBusiness.ThemLichSuBanHang(_lsbh); //In hóa đơn mới nếu có //Chuẩn bị dữ liệu Pos_ds _Pos_ds = new Pos_ds(); DataTable _dtHoaDonBanLe = _Pos_ds.tbl_HOADON; DataRow _drHoaDonBanLe; foreach (SanPhamPublic _spHoaDon in _lstSpMua) { _drHoaDonBanLe = _dtHoaDonBanLe.NewRow(); _drHoaDonBanLe["MaSP_SP"] = _spHoaDon.MaSP_SP; _drHoaDonBanLe["TenSP_SP"] = _spHoaDon.TenSP_SP; _drHoaDonBanLe["GiaBan_SP"] = _spHoaDon.GiaBan; _drHoaDonBanLe["DVT_SP"] = _spHoaDon.DVT_SP.TenDVT_DVT; _drHoaDonBanLe["SoLuong_SP"] = _spHoaDon.SoLuong_SP; _drHoaDonBanLe["ChietKhau_SP"] = _spHoaDon.CKTienMat; _drHoaDonBanLe["ThanhTien_SP"] = _spHoaDon.ThanhTien_SP; _dtHoaDonBanLe.Rows.Add(_drHoaDonBanLe); } _hoaDonMoi.TongSoLuongSP = _lstSpMua.Sum(item => item.SoLuong_SP); HoaDonBanLe_UPresentation wpf_HoaDon = new HoaDonBanLe_UPresentation(); wpf_HoaDon._dtHoaDon = _dtHoaDonBanLe; wpf_HoaDon._hoaDon = _hoaDonMoi; wpf_HoaDon.ShowDialog(); #endregion go: #region 5.Khởi tạo lại dữ liệu: danh sách hàng trả hàng mua _lstHangMua.Clear(); _lstHangTra.Clear(); _hoaDon = null; _hoaDonMoi = null; //Hiển thị dgHangMua.ItemsSource = _lstHangMua; dgHangMua.Items.Refresh(); libHangTra.ItemsSource = _lstHangTra; libHangTra.Items.Refresh(); lbSoHD.Content = ""; lbNgayLap.Content = ""; lbNhanVien.Content = ""; lbKhachHang.Content = ""; lbTongTien.Content = "0"; lbTongCkSP.Content = "0"; lbTongCKHD.Content = "0"; lbVoucher.Content = "0"; lbMaGiamGia.Content = "0"; lbThanhTien.Content = "0"; btnThanhToan.IsEnabled = false; btnTiepTucMua.IsEnabled = false; btnHoDon.IsEnabled = true; txtSoHD.Focus(); #endregion }
//Nút khách hàng private void btnKhachHang_Click(object sender, RoutedEventArgs e) { //Kiểm tra mã khách hàng nhập vào string _MaKH = txtKhachHang.Text.Trim(); if (String.IsNullOrEmpty(_MaKH)) { MessageBox.Show("Vui lòng nhập vào mã khách hàng!"); txtKhachHang.Focus(); txtKhachHang.SelectAll(); return; } string _checkMaKh = @"^([a-zA-Z0-9._]+)$"; if (!Regex.IsMatch(_MaKH, _checkMaKh)) { MessageBox.Show("Mã khách hàng không hợp lệ!"); txtKhachHang.Focus(); txtKhachHang.SelectAll(); return; } DataTable _dtKhachHang = BanHangBusiness.LayKhTheoMa(_MaKH).Tables[0]; if (_dtKhachHang.Rows.Count == 0)//Chưa có khách hàng này { //Thêm mới khách hàng KhachHangThemPresentation wpf_ThemKh = new KhachHangThemPresentation(); wpf_ThemKh._ThemKhachHang += new EventHandler(ThemKhachHang); wpf_ThemKh.ShowDialog(); } else //Đã có khách hàng { //Lấy thông tin khách hàng KhachHangPublic _kh = new KhachHangPublic(); _kh.MaKH_KH = _dtKhachHang.Rows[0]["MaKH_KH"].ToString(); _kh.HoTen_KH = _dtKhachHang.Rows[0]["HoTen_KH"].ToString(); _kh.GioiTinh_KH = _dtKhachHang.Rows[0]["GioiTinh_KH"].ToString(); _kh.NgaySinh_KH = Convert.ToDateTime(_dtKhachHang.Rows[0]["NgaySinh_KH"].ToString()); _kh.Email_KH = _dtKhachHang.Rows[0]["Email_KH"].ToString(); _kh.NHK_KH.MaNKH_NKH = _dtKhachHang.Rows[0]["Ma_NHK_KH"].ToString(); _kh.NHK_KH.TenNKH_NKH = _dtKhachHang.Rows[0]["TenNKH_NKH"].ToString(); _kh.NHK_KH.Anh_NKH = _dtKhachHang.Rows[0]["Anh_NKH"].ToString(); _kh.NHK_KH.ChietKhau_NKH = Convert.ToInt32(_dtKhachHang.Rows[0]["ChietKhau_NKH"].ToString()); _kh.DiemTichLuy_KH = Convert.ToInt32(_dtKhachHang.Rows[0]["DiemTichLuy_KH"].ToString()); _kh.SoLanMuaHang_KH = Convert.ToInt32(_dtKhachHang.Rows[0]["SoLanMuaHang_KH"].ToString()); _kh.LanMuaHangGanNhat_KH = Convert.ToDateTime(_dtKhachHang.Rows[0]["LanMuaHangGanNhat_KH"].ToString()); _kh.SDT_KH = _dtKhachHang.Rows[0]["SDT_KH"].ToString(); _kh.GhiChu = _dtKhachHang.Rows[0]["GhiChu_KH"].ToString(); _kh.NgayTao_KH = Convert.ToDateTime(_dtKhachHang.Rows[0]["NgayTao_KH"].ToString()); _kh.TuDongLenNhom_KH = _dtKhachHang.Rows[0]["TuDongLenNhom_KH"].ToString() == "True" ? true : false; //Hiển thị thông tin khách hàng BanHang_KH_UPresentation wpf = new BanHang_KH_UPresentation(); wpf._XoaKH += new EventHandler(HuyKhahHang); wpf._kh = _kh; gdKhachHang.Children.Clear(); gdKhachHang.Children.Add(wpf); //Lấy chiết khấu hóa đơn _hoaDon.KhachHang_HD = _kh; //Tính tổng tiền TongTien(); } }
//Thêm hàng vào danh sách hàng mua private void ThemHangVaoDsHangMua(string _MaSP) { //Lấy thông tin sp SanPhamPublic _sp = new SanPhamPublic(); DataTable _dtSp = BanHangBusiness.LaySpTheoMa(_MaSP).Tables[0]; DataView _dvSP = new DataView(_dtSp); _dvSP.Sort = "MaSP_SP"; int _index = _dvSP.Find(_MaSP); if (_index == -1) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Mã sản phẩm không tồn tại. Vui lòng kiểm tra lại!"; txtMaHang.Focus(); txtMaHang.SelectAll(); return; } int _soLuongConTrongKho = Convert.ToInt32(_dvSP[_index]["SoLuong_SP"].ToString()); _sp.STT = _dsSPMua.Count + 1; _sp.MaSP_SP = _dvSP[_index]["MaSP_SP"].ToString(); _sp.TenSP_SP = _dvSP[_index]["TenSP_SP"].ToString(); _sp.GiaNhap_SP = _dvSP[_index]["GiaNhap_SP"].ToString(); _sp.GiaBanLe_SP = _dvSP[_index]["GiaBanLe_SP"].ToString(); _sp.GiaBanSi_SP = _dvSP[_index]["GiaBanSi_SP"].ToString(); _sp.NCC_SP.MaNCC_NCC = _dvSP[_index]["MaNCC_SP"].ToString(); _sp.NSP_SP.MaNSP_NSP = _dvSP[_index]["MaNSP_SP"].ToString(); _sp.DVT_SP.MaDVT_DVT = _dvSP[_index]["MaDVT_SP"].ToString(); _sp.DVT_SP.TenDVT_DVT = _dvSP[_index]["TenDVT_DVT"].ToString(); _sp.GhiChu_SP = _dvSP[_index]["GhiChu_SP"].ToString(); _sp.SoLuong_SP = 1; _sp.CKPhanTram_SP = Convert.ToInt32(_dvSP[_index]["CKPhanTram_SP"].ToString()); _sp.Anh_SP = _dvSP[_index]["Anh_SP"].ToString(); _sp.NgayTao_SP = Convert.ToDateTime(_dvSP[_index]["NgayTao_SP"].ToString()); //Thêm hàng vào giỏ hàng if (_dsSPMua.Count == 0)//trong giỏ chưa có sp nào { //Tắt kiểu bán - 1 hóa đơn chỉ 1 kiểu bán rdBanLe.IsEnabled = false; rdBanBuon.IsEnabled = false; _hoaDon.BanLe_HD = rdBanLe.IsChecked == true ? true : false; //Tính thành tiền sp _sp.GiaBan = UntilitiesBusiness.ThemDauPhay(_hoaDon.BanLe_HD == true ? _sp.GiaBanLe_SP : _sp.GiaBanSi_SP); int _giaBan = Convert.ToInt32(UntilitiesBusiness.BoDauPhay(_sp.GiaBan)); int _soLuong = _sp.SoLuong_SP; float _chietKhau = _sp.CKPhanTram_SP; int _chietKhauTienMat = (int)(_giaBan * _chietKhau) / 100; _sp.CKTienMat = UntilitiesBusiness.ThemDauPhay(_chietKhauTienMat.ToString()); _sp.ThanhTien_SP = UntilitiesBusiness.ThemDauPhay(ThanhTien1Sp(_giaBan, _soLuong, _chietKhau).ToString()); _dsSPMua.Add(_sp); } else { //Kiểm tra trong giỏ hàng có sp này chưa: có thì công số lượng, chưa thì thêm vào giỏ hàng SanPhamPublic _result = _dsSPMua.Find(item => item.MaSP_SP == _sp.MaSP_SP); if (_result != null)//Đã có trong giỏ hàng => cộng thêm số lượng { //Kiểm tra số lượng sp trong kho if (_result.SoLuong_SP == _soLuongConTrongKho) { lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Text = "Chỉ còn " + _result.SoLuong_SP + " " + _result.TenSP_SP + "trong kho."; txtMaHang.Focus(); txtMaHang.SelectAll(); return; } //Cộng số lượng _result.SoLuong_SP = _result.SoLuong_SP + _sp.SoLuong_SP; //Tính lại ck tiền mặt và thành tiền int _giaBan = Convert.ToInt32(UntilitiesBusiness.BoDauPhay(_result.GiaBan)); int _soLuong = _dsSPMua.Where(item => item.MaSP_SP == _sp.MaSP_SP).First().SoLuong_SP; float _chietKhau = _result.CKPhanTram_SP; int _chietKhauTienMat = (int)(_soLuong * (_giaBan * _chietKhau) / 100); _result.CKTienMat = UntilitiesBusiness.ThemDauPhay(_chietKhauTienMat.ToString()); _result.ThanhTien_SP = UntilitiesBusiness.ThemDauPhay(ThanhTien1Sp(_giaBan, _soLuong, _chietKhau).ToString()); } else//Chưa có trong giỏ hàng { //Tính thành tiền sp _sp.GiaBan = UntilitiesBusiness.ThemDauPhay(_hoaDon.BanLe_HD == true ? _sp.GiaBanLe_SP : _sp.GiaBanSi_SP); int _giaBan = Convert.ToInt32(UntilitiesBusiness.BoDauPhay(_sp.GiaBan)); int _soLuong = _sp.SoLuong_SP; float _chietKhau = _sp.CKPhanTram_SP; int _chietKhauTienMat = (int)(_giaBan * _chietKhau) / 100; _sp.CKTienMat = UntilitiesBusiness.ThemDauPhay(_chietKhauTienMat.ToString()); _sp.ThanhTien_SP = UntilitiesBusiness.ThemDauPhay(ThanhTien1Sp(_giaBan, _soLuong, _chietKhau).ToString()); _dsSPMua.Add(_sp); } } }
//txt mã giảm giá textchange private void txtCode_TextChanged(object sender, TextChangedEventArgs e) { try { if (KiemTraMaGiamGia()) { //Lấy mã giảm giá nhập vào DataTable _dtMaGG = BanHangBusiness.LayMaGiamGiaTheoMa(txtCode.Text.Trim()).Tables[0]; if (_dtMaGG.Rows.Count > 0) { //Lấy thông tin mã giảm giá _maGiamGia = new MaGiamGiaPublic(); _maGiamGia.MaThe_MGG = _dtMaGG.Rows[0]["MaGG_MGG"].ToString(); _maGiamGia.ChietKhau_MGG = Convert.ToInt32(_dtMaGG.Rows[0]["ChietKhau_MGG"].ToString()); _maGiamGia.NgayHetHan_MGG = Convert.ToDateTime(_dtMaGG.Rows[0]["NgayHetHan_MGG"].ToString()); _maGiamGia.TrangThai_MGG = _dtMaGG.Rows[0]["TrangThai_MGG"].ToString() == "True" ? true : false; _maGiamGia.GhiChu_MGG = _dtMaGG.Rows[0]["GhiChu_MGG"].ToString(); //Kiểm tra trạng thái của mã if (_maGiamGia.TrangThai_MGG) { TimeSpan _timespan = _maGiamGia.NgayHetHan_MGG - DateTime.Now; if (_timespan.Seconds > 0) { //Hiển thị giá tiền int _TienMaGiamGia = _maGiamGia.ChietKhau_MGG * _hoaDon.TongTien_HD / 100; lbMaGiamGia.Visibility = System.Windows.Visibility.Visible; lbMaGiamGia.Content = UntilitiesBusiness.ThemDauPhay(_TienMaGiamGia.ToString()); TinhTien(); } else { //thông báo code đã hết hạn lbMaGiamGia.Visibility = System.Windows.Visibility.Collapsed; lbMaGiamGia.Content = "0"; lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Content = "Mã đã hết hạn dùng! (" + _maGiamGia.NgayHetHan_MGG.ToString("dd-MM-yyyy") + ")"; TinhTien(); _maGiamGia = null; } } else { //Thông báo mã ko sử dụng dc lbMaGiamGia.Visibility = System.Windows.Visibility.Collapsed; lbMaGiamGia.Content = "0"; lbWarning.Visibility = System.Windows.Visibility.Visible; lbWarning.Content = _maGiamGia.GhiChu_MGG; TinhTien(); _maGiamGia = null; } } else { lbMaGiamGia.Visibility = System.Windows.Visibility.Collapsed; lbMaGiamGia.Content = "0"; lbWarning.Visibility = System.Windows.Visibility.Hidden; TinhTien(); _maGiamGia = null; } } } catch (Exception ex) { return; } }