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); } } }
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"); } }
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); } }
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"); } }