public frmQuanLySanPham() { InitializeComponent(); hienthiSP(); hienThiDSNguyenLieu(); txtMasanpham.Text = CServices.taoMa <SanPham>(CSanPham_BUS.DsSanPham()); nguyenLieuThanhPhans = new List <NguyenLieu>(); }
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(); }
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(); }
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"); } }