//Nút Lưu private void btnLuu_Click(object sender, RoutedEventArgs e) { //Kiểm tra dữ liệu if (!KiemTraDuLieu()) { return; } //Cập nhật ThietLapHeThongPublic _SuaThietLap = new ThietLapHeThongPublic(); _SuaThietLap.TenCuaHang = txtTenCuaHang.Text.Trim(); _SuaThietLap.SDT = txtSDT.Text.Trim(); _SuaThietLap.DiaChi = txtDiaChi.Text.Trim(); _SuaThietLap.Voucher = btnVoucher.IsChecked.Value; _SuaThietLap.MaGiamGia = btnMaGiaGia.IsChecked.Value; _SuaThietLap.MucQuyDoiDiem = Convert.ToInt32(txtMucQuyDoi.Text.Trim()); _SuaThietLap.CongDiemKhachHang = btnTichDiem.IsChecked.Value; _SuaThietLap.ChietKhauHoaDon = btnCkHoaDon.IsChecked.Value; _SuaThietLap.ChietKhauSanPham = btnCkSanPham.IsChecked.Value; _SuaThietLap.KiemTraGiaNhap = btnKiemTraGiaNhap.IsChecked.Value; ThietLapHeThongBusiness.CapNhatThietLapHeThong(_SuaThietLap); _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); HienThi(); MessageBox.Show("Lưu thiết lập thành công."); EventHandler _eh = _CapNhatHienThi; if (_eh != null) { _eh(this, e); } }
//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); }
//Loaded private void Window_Loaded(object sender, RoutedEventArgs e) { _hoaDon.TienKhachTra_HD = 0; _hoaDon.VouCher_HD = 0; _hoaDon.TienMaGiamGia = 0; //Hiển thị (Tiền phải trả) lbTienPhaiTra.Content = UntilitiesBusiness.ThemDauPhay(_hoaDon.TienConLaiPhaiTra.ToString()); txtTienMat.Text = "0"; txtVoucher.Text = "0"; txtCode.Text = ""; lbTraLaiKhach.Content = "0"; lbMaGiamGia.Content = "0"; txtTienMat.Focus(); txtTienMat.SelectAll(); //Hiển thị Voucher ThietLapHeThongPublic _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); if (_thietLap.Voucher) { txtVoucher.IsEnabled = true; } //Hiển thị Mã giảm giá if (_thietLap.MaGiamGia) { txtCode.IsEnabled = true; } TinhTien(); }
//Khởi tạo bán hàng - dowork private void KhoiTao_dowork() { //Khởi tạo hóa đơn mới _hoaDon = new HoaDonPublic(); _hoaDon.SoHD_HD = UntilitiesBusiness.GetNextID("tbl_HOADON", "SoHD_HD", "HD.", 10); _hoaDon.NgayLap_HD = DateTime.Now; _hoaDon.NguoiLap_HD = _NhanVien; _khachHang = new KhachHangPublic(); _khachHang.MaKH_KH = null; _hoaDon.KhachHang_HD = _khachHang; _hoaDon.KhachHang_HD.NHK_KH.ChietKhau_NKH = 0; _hoaDon.BanLe_HD = true; // Chú ý: đặt lại giá trị khi thêm hàng vào giỏ _hoaDon.TongCKHoaDon = 0; _hoaDon.TongCKSanPham = 0; _hoaDon.TongTien_HD = 0; _hoaDon.TongTienNhap = 0; _hoaDon.TienKhachTra_HD = 0; _hoaDon.TienConLaiPhaiTra = 0; _hoaDon.VouCher_HD = 0; //Nếu có hóa đơn cũ truyền vào thì lấy thông tin từ hóa đơn cũ if (_hoaDonCu != null && _lstSpTiepTucMua != null) { _hoaDon.KhachHang_HD = _hoaDonCu.KhachHang_HD; _hoaDon.TongCKHoaDon = _hoaDonCu.TongCKHoaDon; _hoaDon.TongCKSanPham = _hoaDonCu.TongCKSanPham; _hoaDon.TongTien_HD = _hoaDonCu.TongTien_HD; _hoaDon.TongTienNhap = _hoaDonCu.TongTienNhap; _hoaDon.TienKhachTraTruoc = _hoaDonCu.TienKhachTraTruoc; _hoaDon.TienKhachTra_HD = 0; _hoaDon.TienConLaiPhaiTra = 0; _dsSPMua = new List <SanPhamPublic>(); _dsSPMua = _lstSpTiepTucMua; ////Hủy dữ liệu cũ truyền sang _hoaDonCu = null; _lstSpTiepTucMua = null; } else { //Khởi tạo giỏ hàng- truwnowngf hợp ko có hóa đơn cũ tiếp tục mua hàng _dsSPMua = new List <SanPhamPublic>(); _dsSPMua.Clear(); } //Lấy thiết lập _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); }
//Update thông tin thiết lập, thông tin nhân viên hiển thị trên giao diện main private void UpdateThongTin() { //Update thông tin nhân viên _NhanVien = NhanVienBusiness.Lay1NhanVien(_NhanVien.MaNV_NV); HienThiNhanVien(); //Update thông tin thiết lập hiển thị _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); HienThiCuaHang(); }
//Hủy hóa đơn public static void HuyHoaDon(HoaDonPublic _hoaDon) { //Đổi trạng thái hóa đơn SqlCommand _cmd = new SqlCommand(); _cmd.CommandType = CommandType.StoredProcedure; _cmd.CommandText = "[Hủy hóa đơn]"; _cmd.Parameters.AddWithValue("@SoHD_HD", _hoaDon.SoHD_HD); conn.Execute(_cmd); _cmd.Dispose(); if (_hoaDon.KhachHang_HD.MaKH_KH != null) { //Trừ điểm khách hàng ThietLapHeThongPublic _thietLap = ThietLapHeThongDataAccess.LayThietLapHeThong(); int _diemTru = _hoaDon.TongTien_HD / _thietLap.MucQuyDoiDiem; TruDiemKhachHang(_hoaDon.KhachHang_HD.MaKH_KH, _diemTru); //Chỉnh nhóm khách hàng XetNhomKhacHang(_hoaDon.KhachHang_HD); } }
//Lấy thiết lập hệ thống public static ThietLapHeThongPublic LayThietLapHeThong() { DataTable _dtThietLap = conn.GetDataSet("[Lấy thiết lập]").Tables[0]; ThietLapHeThongPublic _thietLapHT = new ThietLapHeThongPublic(); //Voucher _thietLapHT.Voucher = _dtThietLap.Rows[0][2].ToString().Trim() == "1" ? true : false; //Mã giảm giá _thietLapHT.MaGiamGia = _dtThietLap.Rows[1][2].ToString().Trim() == "1" ? true : false; //Tên cửa hàng _thietLapHT.TenCuaHang = _dtThietLap.Rows[2][2].ToString().Trim(); //Địa chỉ _thietLapHT.DiaChi = _dtThietLap.Rows[3][2].ToString().Trim(); //SĐT _thietLapHT.SDT = _dtThietLap.Rows[4][2].ToString().Trim(); //Mức đổi điểm _thietLapHT.MucQuyDoiDiem = Convert.ToInt32(_dtThietLap.Rows[5][2].ToString()); //Bật tắt cộng điểm cho khách hàng khi mua hàng _thietLapHT.CongDiemKhachHang = _dtThietLap.Rows[6][2].ToString().Trim() == "1" ? true : false; //Bật tắt chiết khấu hóa đơn _thietLapHT.ChietKhauHoaDon = _dtThietLap.Rows[7][2].ToString() == "1" ? true : false; //Bật tắ chiết khấu sản phẩm _thietLapHT.ChietKhauSanPham = _dtThietLap.Rows[8][2].ToString() == "1" ? true : false; //Bật tắt kiểm tra giá nhập _thietLapHT.KiemTraGiaNhap = _dtThietLap.Rows[9][2].ToString() == "1" ? true : false; return(_thietLapHT); }
//Cập nhật thiết lập hệ thống public static void CapNhatThietLapHeThong(ThietLapHeThongPublic _thietLap) { SqlCommand _cmd = new SqlCommand(); _cmd.CommandType = CommandType.StoredProcedure; _cmd.CommandText = "[Sửa thiết lập hệ thống]"; //Cập nhật Tên cửa hàng _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00002"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.TenCuaHang); conn.Execute(_cmd); //Cập nhật địa chỉ _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00003"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.DiaChi); conn.Execute(_cmd); //cập nhật số điện thoại _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00004"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.SDT); conn.Execute(_cmd); //Mức quy đổi điểm _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00005"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.MucQuyDoiDiem); conn.Execute(_cmd); //Voucher _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00000"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.Voucher == true ? "1" : "0"); conn.Execute(_cmd); //Mã giảm giá _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00001"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.MaGiamGia == true ? "1" : "0"); conn.Execute(_cmd); ////Cộng điểm tích lũy //_cmd.Parameters.Clear(); //_cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00006"); //_cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.CongDiemKhachHang == true ? "1" : "0"); //conn.Execute(_cmd); //Chiết khấu hóa đơn _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00007"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.ChietKhauHoaDon == true ? "1" : "0"); conn.Execute(_cmd); //Chiết khấu sản phẩm _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00008"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.ChietKhauSanPham == true ? "1" : "0"); conn.Execute(_cmd); //Kiểm tra giá nhập _cmd.Parameters.Clear(); _cmd.Parameters.AddWithValue("@MaThietLap_TL", "TL.00009"); _cmd.Parameters.AddWithValue("@GiaTri_TL", _thietLap.ChietKhauSanPham == true ? "1" : "0"); conn.Execute(_cmd); }
//Cập nhật thiết lập hệ thống public static void CapNhatThietLapHeThong(ThietLapHeThongPublic _thietLap) { ThietLapHeThongDataAccess.CapNhatThietLapHeThong(_thietLap); }
private void HienThi_dowor() { _thietLap = ThietLapHeThongBusiness.LayThietLapHeThong(); }