示例#1
0
        private void TextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (txtTK.Text == "" || txtTK.Text == null)
            {
                hienthiSP();
                return;
            }

            switch (chosseTimKiem)
            {
            case 0:
                HienTHiTK(txtTK.Text);
                break;

            case 1:
                dgQlsanpham.ItemsSource = CSanPham_BUS.toListTenSanPham(txtTK.Text).Select(x => new
                {
                    maSanPham      = x.maSanPham,
                    tenSanPham     = x.tenSanPham,
                    donViTinh      = x.donViTinh,
                    donGia         = String.Format("{0:#,###,0 VND;(#,###,0 VND);0 VND}", x.donGia),
                    tenLoaiSanPham = x.LoaiSanPham.tenLoai,
                    trangThai      = x.trangThai == 0 ? "Mở" : "Khóa"
                });
                break;

            case 2:
                try
                {
                    int donGia = int.Parse(txtTK.Text);
                    dgQlsanpham.ItemsSource = CSanPham_BUS.toListDonGia(donGia).Select(x => new
                    {
                        maSanPham      = x.maSanPham,
                        tenSanPham     = x.tenSanPham,
                        donViTinh      = x.donViTinh,
                        donGia         = String.Format("{0:#,###,0 VND;(#,###,0 VND);0 VND}", x.donGia),
                        tenLoaiSanPham = x.LoaiSanPham.tenLoai,
                        trangThai      = x.trangThai == 0 ? "Mở" : "Khóa"
                    });
                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show("Đơn giá không được để null");
                }
                catch (FormatException)
                {
                    MessageBox.Show("Đơn giá chỉ được nhập số");
                    txtTK.Text = "";
                }
                catch (OverflowException)
                {
                    MessageBox.Show("Đơn giá có độ dài vượt giá mức cho phép");
                }

                break;

            default:
                break;
            }
        }
示例#2
0
        private void btnChonsanpham_Click(object sender, RoutedEventArgs e)
        {
            if (dgDanhsachsanpham.SelectedItem == null)
            {
                MessageBox.Show("Bạn chưa chọn sản phẩm");
                return;
            }
            SanPham sanPham = CSanPham_BUS.find(dgDanhsachsanpham.SelectedValue.ToString());

            if (sanPham == null)
            {
                MessageBox.Show("khong co san pham");
            }
            else
            {
                ChiTietHoaDon chiTietHoaDon = new ChiTietHoaDon();
                chiTietHoaDon.maSanPham = sanPham.maSanPham;
                chiTietHoaDon.soLuong   = 1;
                chiTietHoaDon.SanPham   = sanPham;
                if (chiTietHoaDons.Where(x => x.maSanPham == chiTietHoaDon.maSanPham).Count() == 0)
                {
                    chiTietHoaDons.Add(chiTietHoaDon);
                    hienThiDSChiTietHD(chiTietHoaDons);
                }
                else
                {
                    ChiTietHoaDon a = new ChiTietHoaDon();
                    a          = chiTietHoaDons.Where(x => x.maSanPham == chiTietHoaDon.maSanPham).FirstOrDefault();
                    a.soLuong += 1;
                    hienThiDSChiTietHD(chiTietHoaDons);
                }
            }
        }
示例#3
0
 public frmQuanLySanPham()
 {
     InitializeComponent();
     hienthiSP();
     hienThiDSNguyenLieu();
     txtMasanpham.Text    = CServices.taoMa <SanPham>(CSanPham_BUS.DsSanPham());
     nguyenLieuThanhPhans = new List <NguyenLieu>();
 }
示例#4
0
 private void dgDanhsachsanpham_Loaded(object sender, RoutedEventArgs e)
 {
     dgDanhsachsanpham.ItemsSource = CSanPham_BUS.toList().Select(x => new
     {
         maSanPham  = x.maSanPham,
         tenSanPham = x.tenSanPham,
         donGia     = String.Format("{0:#,###,0 VND;(#,###,0 VND);0 VND}", x.donGia)
     }).ToList();
 }
示例#5
0
 private void btnBochon_Click(object sender, RoutedEventArgs e)
 {
     txtMasanpham.Text    = CServices.taoMa <SanPham>(CSanPham_BUS.DsSanPham());
     txtDonvitinh.Text    = null;
     cboLoaisanpham.Text  = null;
     txtTensanpham.Text   = "";
     txtDongia.Text       = "";
     sanPhamSelect        = null;
     nguyenLieuThanhPhans = new List <NguyenLieu>();
     hienThiDSNguyenLieuDuocChon();
 }
示例#6
0
 public void HienTHiTK(string maSP)
 {
     try
     {
         dgQlsanpham.ItemsSource = CSanPham_BUS.toListTK(maSP);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Có lỗi: " + ex.Message);
     }
 }
示例#7
0
 public void load()
 {
     txtMasanpham.Text    = CServices.taoMa <SanPham>(CSanPham_BUS.DsSanPham());
     txtDonvitinh.Text    = null;
     cboLoaisanpham.Text  = null;
     txtTensanpham.Text   = "";
     txtDongia.Text       = "";
     sanPhamSelect        = null;
     nguyenLieuThanhPhans = new List <NguyenLieu>();
     hienThiDSNguyenLieuDuocChon();
 }
示例#8
0
        public void hienthitheoListBOX(string maloai)
        {
            List <SanPham> listLoaiSP = CSanPham_BUS.hienthiTheoMa(maloai);

            if (listLoaiSP.Count() > 0)
            {
                dgDanhsachsanpham.ItemsSource = listLoaiSP;
            }
            else
            {
                MessageBox.Show("Không có loại sản phẩm nào");
            }
        }
示例#9
0
        private void btnTreoHoaDon_Click(object sender, RoutedEventArgs e)
        {
            if (CHoaDon_BUS.hoaDonTreo == null)
            {
                try
                {
                    CHoaDon_BUS.hoaDonTreo               = new HoaDon();
                    CHoaDon_BUS.hoaDonTreo.maNhanVien    = nhanVienSelect.maNhanVien;
                    CHoaDon_BUS.hoaDonTreo.ngayLap       = DateTime.Now;
                    CHoaDon_BUS.hoaDonTreo.tongThanhTien = tongThanhTien;

                    CHoaDon_BUS.hoaDonTreo.trangThai = 0;

                    foreach (var item in chiTietHoaDons)
                    {
                        ChiTietHoaDon a = new ChiTietHoaDon();
                        a.maHoaDon  = CHoaDon_BUS.hoaDonTreo.maHoaDon;
                        a.maSanPham = item.maSanPham;
                        a.SanPham   = CSanPham_BUS.find(item.maSanPham);
                        if (a.SanPham == null)
                        {
                            MessageBox.Show("Lỗi, không thể treo hóa đơn");
                            return;
                        }
                        a.soLuong   = item.soLuong;
                        a.thanhTien = CChiTietHoaDon_BUS.tinhThanhTien(item);
                        CHoaDon_BUS.hoaDonTreo.ChiTietHoaDons.Add(a);
                    }
                    chiTietHoaDons.Clear();
                    hienThiDSChiTietHD(chiTietHoaDons);
                    btnHoanTac.IsEnabled    = true;
                    btnTreoHoaDon.IsEnabled = false;
                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show("Tổng tiền null");
                }
                catch (FormatException)
                {
                    MessageBox.Show("Tổng tiền không thể format");
                }
                catch (OverflowException)
                {
                    MessageBox.Show("Tổng tiền vượt quá giới hạn cho phép");
                }
            }
            else
            {
                MessageBox.Show("Chỉ có thể treo 1 hóa đơn, vui lòng hoàn tác hóa đơn trước");
            }
        }
示例#10
0
 private void cboLoaisanpham_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         if (CSanPham_BUS.toListByMaSP().Count() <= 0)
         {
             MessageBox.Show("Bạn chưa có loại sản phẩm nào, cần thêm loại sản phẩm trước");
         }
         else
         {
             cboLoaisanpham.ItemsSource = CSanPham_BUS.toListByMaTenLoaiSP();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Có lỗi: " + ex.Message);
     }
 }
示例#11
0
        private void dgQlsanpham_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (dgQlsanpham.SelectedItem != null)
                {
                    nguyenLieuThanhPhans = new List <NguyenLieu>();
                    sanPhamSelect        = CSanPham_BUS.find(dgQlsanpham.SelectedValue.ToString());
                    if (sanPhamSelect != null)
                    {
                        txtTensanpham.Text  = sanPhamSelect.tenSanPham;
                        txtMasanpham.Text   = sanPhamSelect.maSanPham;
                        txtDonvitinh.Text   = sanPhamSelect.donViTinh;
                        txtDongia.Text      = sanPhamSelect.donGia.ToString();
                        cboLoaisanpham.Text = sanPhamSelect.LoaiSanPham.tenLoai;

                        foreach (ThanhPhan thanhPhan in sanPhamSelect.ThanhPhans)
                        {
                            NguyenLieu nguyenLieu = new NguyenLieu();
                            nguyenLieu = CNguyenLieu_BUS.find(thanhPhan.maNguyenLieu);
                            nguyenLieuThanhPhans.Add(nguyenLieu);
                        }

                        hienThiDSNguyenLieuDuocChon();
                    }
                }
                else
                {
                    txtMasanpham.Text    = "";
                    txtTensanpham.Text   = "";
                    txtDonvitinh.Text    = "";
                    txtDongia.Text       = "";
                    cboLoaisanpham.Text  = "";
                    nguyenLieuThanhPhans = new List <NguyenLieu>();
                    hienThiDSNguyenLieuDuocChon();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi: " + ex.Message);
            }
        }
示例#12
0
        private List <CBangXepHangSanPham> getDSSanPham(int month)
        {
            List <CBangXepHangSanPham> dsSanPham = new List <CBangXepHangSanPham>();
            List <SanPham>             sanPhams  = CSanPham_BUS.toList();

            if (sanPhams.Count() > 0)
            {
                foreach (var sanPham in sanPhams)
                {
                    int soLuongBan = CHoaDon_BUS.demSoLuongSanPham(sanPham.maSanPham, month);

                    dsSanPham.Add(new CBangXepHangSanPham(
                                      sanPham.maSanPham,
                                      sanPham.tenSanPham.ToString(),
                                      soLuongBan,
                                      sanPham.donGia.Value));
                }
            }
            return(dsSanPham);
        }
示例#13
0
 private void btnXoaLoaiSP_Click(object sender, RoutedEventArgs e)
 {
     if (a != null)
     {
         try
         {
             //string maloai = dgLoaisanpham.SelectedValue.ToString();
             string maloai = a.maLoaiSanPham.ToString();
             if (maloai == null)
             {
                 MessageBox.Show("Không tìm thấy");
             }
             else
             {
                 a = CLoaiSanPham_BUS.find(maloai);
                 if (CLoaiSanPham_BUS.remove(a))
                 {
                     if (CSanPham_BUS.thaydoiLoai(a))
                     {
                         MessageBox.Show("Đã thay đổi trạng thái " + maloai + " thành công.");
                         HienThiDSLoaiSanPham();
                         load();
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Có lỗi: " + ex.Message);
         }
         HienThiDSLoaiSanPham();
         load();
     }
     else
     {
         MessageBox.Show("Vui lòng chọn sản phẩm cần thay đổi trạng thái");
     }
     HienThiDSLoaiSanPham();
     load();
 }
示例#14
0
 private void btnXoa_Click(object sender, RoutedEventArgs e)
 {
     if (sanPhamSelect != null)
     {
         if (CSanPham_BUS.remove(sanPhamSelect))
         {
             MessageBox.Show("Thay đổi trạng thái thành công");
             hienthiSP();
             load();
             nguyenLieuThanhPhans = new List <NguyenLieu>();
             hienThiDSNguyenLieuDuocChon();
         }
         else
         {
             MessageBox.Show("Không thể thay đổi, có lỗi");
         }
     }
     else
     {
         MessageBox.Show("Vui lòng chọn sản phẩm");
     }
 }
示例#15
0
 public void hienthiSP()
 {
     try
     {
         List <SanPham> list = CSanPham_BUS.toListall();
         if (list.Count > 0)
         {
             dgQlsanpham.ItemsSource = list.Select(x => new
             {
                 maSanPham      = x.maSanPham,
                 tenSanPham     = x.tenSanPham,
                 donViTinh      = x.donViTinh,
                 donGia         = String.Format("{0:#,###,0 VND;(#,###,0 VND);0 VND}", x.donGia),
                 tenLoaiSanPham = x.LoaiSanPham.tenLoai,
                 trangThai      = x.trangThai == 0 ? "Mở" : "Khóa"
             });
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Có lỗi: " + ex.Message);
     }
 }
示例#16
0
 private void cmbLocSanPham_Loaded(object sender, RoutedEventArgs e)
 {
     cmbLocSanPham.ItemsSource = CSanPham_BUS.toListTenSanPham();
 }
示例#17
0
        private void btnThem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SanPham sp1 = new SanPham();
                sp1.maSanPham  = txtMasanpham.Text;
                sp1.tenSanPham = txtTensanpham.Text;
                sp1.donViTinh  = txtDonvitinh.Text;
                if (cboLoaisanpham.SelectedItem != null)
                {
                    loaisanpham       = CSanPham_BUS.findTen(cboLoaisanpham.SelectedItem.ToString());
                    sp1.maLoaiSanPham = loaisanpham.maLoaiSanPham;
                }
                else
                {
                    MessageBox.Show("Loại sản phẩm không được để trống");
                    return;
                }

                sp1.donGia    = int.Parse(txtDongia.Text);
                sp1.trangThai = 0;

                if (nguyenLieuThanhPhans.Count() > 0)
                {
                    List <ThanhPhan> thanhPhans = new List <ThanhPhan>();
                    foreach (NguyenLieu nguyenLieu in nguyenLieuThanhPhans)
                    {
                        ThanhPhan thanhPhan = new ThanhPhan();
                        thanhPhan.maNguyenLieu = nguyenLieu.maNguyenLieu;
                        thanhPhan.maSanPham    = sp1.maSanPham;
                        thanhPhan.trangThai    = 0;
                    }
                    sp1.ThanhPhans = thanhPhans;
                }
                else
                {
                    MessageBox.Show("Vui lòng chọn thành phần nguyên liệu có trong sản phẩm");
                    return;
                }

                if (CSanPham_BUS.KTRong(sp1))
                {
                    if (CServices.kiemTraThongTin(sp1))
                    {
                        if (CSanPham_BUS.find(txtMasanpham.Text) == null)
                        {
                            if (CSanPham_BUS.add(sp1))
                            {
                                MessageBox.Show("Thêm thành công");
                                txtMasanpham.Text = CServices.taoMa <SanPham>(CSanPham_BUS.DsSanPham());
                                hienthiSP();
                                load();
                                nguyenLieuThanhPhans = new List <NguyenLieu>();
                                hienThiDSNguyenLieuDuocChon();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Mã sản phẩm bị trùng");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Xem lại đơn giá");
                    }
                }
                else
                {
                    MessageBox.Show("Yêu cầu nhập đầy đủ thông tin sản phẩm");
                }
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Không được để rỗng đơn giá");
            }
            catch (FormatException)
            {
                MessageBox.Show("Đơn giá phải là số");
            }
            catch (OverflowException)
            {
                MessageBox.Show("Đơn giá vượt quá giới hạn lưu trữ");
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Dữ liệu không được bỏ trống");
            }
        }
示例#18
0
        private void cmbLocSanPham_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbLocSanPham.SelectedItem != null)
            {
                string tenSanPham = cmbLocSanPham.SelectedItem.ToString();
                if (tenSanPham != null && tenSanPham != "")
                {
                    // Hiển thị bảng thống kê sản phẩm
                    SanPham sanPham = CSanPham_BUS.findSPbyTen(tenSanPham);
                    if (sanPham.tenSanPham != null)
                    {
                        List <CBangXepHangSanPham> list = new List <CBangXepHangSanPham>();
                        int soLuongBan = CHoaDon_BUS.demSoLuongSanPham(sanPham.maSanPham, monthSelect);
                        list.Add(new CBangXepHangSanPham(
                                     sanPham.maSanPham,
                                     sanPham.tenSanPham.ToString(),
                                     soLuongBan,
                                     sanPham.donGia.Value));

                        showListSanPham(list);
                    }

                    // Hiển thị bảng thống kê phiếu nhập nguyên liệu
                    List <CBangXepHangNguyenLieuNhap> dsNguyenLieuNhap     = new List <CBangXepHangNguyenLieuNhap>();
                    List <PhieuNhapNguyenLieu>        phieuNhapNguyenLieus = new List <PhieuNhapNguyenLieu>();

                    phieuNhapNguyenLieus = CPhieuNhapNguyenLieu_BUS.toListInMonth(monthSelect);
                    if (phieuNhapNguyenLieus.Count() > 0)
                    {
                        foreach (ThanhPhan thanhPhan in sanPham.ThanhPhans.Where(x => x.trangThai == 0).ToList())
                        {
                            foreach (PhieuNhapNguyenLieu phieuNhap in phieuNhapNguyenLieus)
                            {
                                foreach (ChiTietPhieuNhap chiTiet in phieuNhap.ChiTietPhieuNhaps.ToList())
                                {
                                    if (chiTiet.ChiTietNguyenLieu.maNguyenLieu == thanhPhan.maNguyenLieu)
                                    {
                                        int    soLuong = chiTiet.soLuong.Value;
                                        double donGia  = chiTiet.donGia.Value;
                                        dsNguyenLieuNhap.Add(new CBangXepHangNguyenLieuNhap(
                                                                 thanhPhan.maNguyenLieu,
                                                                 thanhPhan.NguyenLieu.tenNguyenLieu,
                                                                 soLuong,
                                                                 donGia));
                                    }
                                }
                            }
                        }
                        showListNguyenLieuNhap(dsNguyenLieuNhap);
                    }

                    // Hiển thị bảng thống kê phiếu xuất nguyên liệu
                    List <CBangXepHangNguyenLieuNhap> dsNguyenLieuXuat     = new List <CBangXepHangNguyenLieuNhap>();
                    List <PhieuXuatNguyenLieu>        phieuXuatNguyenLieus = new List <PhieuXuatNguyenLieu>();

                    phieuXuatNguyenLieus = CPhieuXuatNguyenLieu_BUS.toListInMonth(monthSelect);
                    if (phieuXuatNguyenLieus.Count() > 0)
                    {
                        foreach (ThanhPhan thanhPhan in sanPham.ThanhPhans.Where(x => x.trangThai == 0).ToList())
                        {
                            foreach (PhieuXuatNguyenLieu phieuXuat in phieuXuatNguyenLieus)
                            {
                                foreach (ChiTietPhieuXuat chiTiet in phieuXuat.ChiTietPhieuXuats.ToList())
                                {
                                    if (chiTiet.ChiTietNguyenLieu.maNguyenLieu == thanhPhan.maNguyenLieu)
                                    {
                                        int    soLuong = chiTiet.soLuong.Value;
                                        double donGia  = chiTiet.donGia.Value;

                                        dsNguyenLieuXuat.Add(new CBangXepHangNguyenLieuNhap(
                                                                 thanhPhan.maNguyenLieu,
                                                                 thanhPhan.NguyenLieu.tenNguyenLieu,
                                                                 soLuong,
                                                                 donGia));
                                    }
                                }
                            }
                        }
                        showListNguyenLieuXuat(dsNguyenLieuXuat);
                    }
                }
                else
                {
                    MessageBox.Show("Không lấy được nguyên liệu đã chọn");
                    return;
                }
            }
        }
示例#19
0
        private void btnSua_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (sanPhamSelect == null)
                {
                    MessageBox.Show("Vui lòng chọn sản phẩm");
                }
                else
                {
                    loaisanpham = CSanPham_BUS.findTen(cboLoaisanpham.Text);
                    SanPham a = new SanPham();
                    a.maSanPham     = txtMasanpham.Text;
                    a.tenSanPham    = txtTensanpham.Text;
                    a.donViTinh     = txtDonvitinh.Text;
                    a.maLoaiSanPham = loaisanpham.maLoaiSanPham;
                    a.donGia        = int.Parse(txtDongia.Text);
                    a.trangThai     = 0;

                    if (nguyenLieuThanhPhans.Count() > 0)
                    {
                        List <ThanhPhan> thanhPhans = new List <ThanhPhan>();
                        foreach (NguyenLieu nguyenLieu in nguyenLieuThanhPhans)
                        {
                            ThanhPhan thanhPhan = new ThanhPhan();
                            thanhPhan.maNguyenLieu = nguyenLieu.maNguyenLieu;
                            thanhPhan.maSanPham    = a.maSanPham;
                            thanhPhan.trangThai    = 0;
                            thanhPhans.Add(thanhPhan);
                        }
                        a.ThanhPhans = thanhPhans;
                    }
                    else
                    {
                        MessageBox.Show("Vui lòng chọn thành phần nguyên liệu có trong sản phẩm");
                        return;
                    }

                    if (CSanPham_BUS.KTRong(a))
                    {
                        if (CSanPham_BUS.edit(a))
                        {
                            MessageBox.Show("Sửa thành công");
                            hienthiSP();
                            load();
                            nguyenLieuThanhPhans = new List <NguyenLieu>();
                            hienThiDSNguyenLieuDuocChon();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Yêu cầu nhập đầy đủ thông tin sản phẩm");
                    }
                }
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Không được để rỗng đơn giá");
            }
            catch (FormatException)
            {
                MessageBox.Show("Đơn giá phải là số");
            }
            catch (OverflowException)
            {
                MessageBox.Show("Đơn giá vượt quá giới hạn lưu trữ");
            }

            hienthiSP();
            load();
        }