private void Luu_Button_Click(object sender, RoutedEventArgs e) { var sanPham = new SanPham(); var loaiSp = new LoaiSanPham(); SanPham_Bus sanPham_Bus = new SanPham_Bus(); LoaiSanPham_Bus loaiSanPham_Bus = new LoaiSanPham_Bus(); sanPham.MaSanPham = int.Parse(MaSP_textbox.Text); var sp = sanPham_Bus.FindByID(sanPham.MaSanPham); try { sanPham.TenSanPham = TenSP_Textbox.Text; sanPham.GiaGoc = int.Parse(GiaGoc_Textbox.Text); sanPham.GiaBan = int.Parse(GiaBan_TextBox.Text); if (sp.HinhAnh != null) { sanPham.HinhAnh = sp.HinhAnh; } if (LoaiSP_ComboBox.SelectedIndex == -1) { sanPham.MaLoaiSanPham = sp.MaLoaiSanPham; } else if (LoaiSP_ComboBox.SelectedIndex < dsLoaiSp.Count()) { var lsp = loaiSanPham_Bus.LoadAll(); sanPham.MaLoaiSanPham = lsp[LoaiSP_ComboBox.SelectedIndex].MaLoaiSanPham; } else { loaiSp.TenLoaiSanPham = LoaiSP_Textbox.Text; loaiSanPham_Bus.AddLoaiSanPham(loaiSp); sanPham.MaLoaiSanPham = loaiSp.MaLoaiSanPham; } sanPham.SoLuongConLai = int.Parse(Soluong_Textbox.Text); if (sanPham_Bus.EditSanPham(sanPham)) { MessageBox.Show("Lưu thành công"); } } catch (Exception) { MessageBox.Show("Lưu k thành công"); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { LoaiSanPham_Bus loaiSanPham_Bus = new LoaiSanPham_Bus(); dsLoaiSp = loaiSanPham_Bus.LoadAll(); List <string> ten = new List <string>(); for (int i = 0; i < dsLoaiSp.Count(); i++) { ten.Add(dsLoaiSp[i].TenLoaiSanPham); } ten.Add("Khác"); LoaiSP_ComboBox.ItemsSource = ten; }
private void LoaiSP_ComboBox_Loaded(object sender, RoutedEventArgs e) { LoaiSanPham_Bus loaiSanPham_Bus = new LoaiSanPham_Bus(); dsLoaiSp = loaiSanPham_Bus.LoadAll(); List <string> ten = new List <string> { "Tất cả" }; for (int i = 0; i < dsLoaiSp.Count(); i++) { ten.Add(dsLoaiSp[i].TenLoaiSanPham); } LoaiSP_ComboBox.ItemsSource = ten; LoaiSP_ComboBox.SelectedIndex = 0; }
private void Luu_Button_Click(object sender, RoutedEventArgs e) { var sanPham = new SanPham(); var DsSp = new List <SanPham>(); var loaiSp = new LoaiSanPham(); SanPham_Bus sanPham_Bus = new SanPham_Bus(); DsSp = sanPham_Bus.LoadAll(); try { sanPham.TenSanPham = TenSP_Textbox.Text; sanPham.GiaGoc = int.Parse(GiaGoc_Textbox.Text); sanPham.GiaBan = int.Parse(GiaBan_TextBox.Text); if (LoaiSP_ComboBox.SelectedIndex < dsLoaiSp.Count()) { sanPham.MaLoaiSanPham = dsLoaiSp[LoaiSP_ComboBox.SelectedIndex].MaLoaiSanPham; } else { loaiSp.TenLoaiSanPham = LoaiSP_Textbox.Text; LoaiSanPham_Bus loaiSanPham_Bus = new LoaiSanPham_Bus(); loaiSanPham_Bus.AddLoaiSanPham(loaiSp); sanPham.MaLoaiSanPham = loaiSp.MaLoaiSanPham; } sanPham.HinhAnh = strfileName; sanPham.isDelete = 0; sanPham.SoLuongConLai = int.Parse(Soluong_Textbox.Text); if (sanPham_Bus.AddSanPham(sanPham)) { MessageBox.Show("Thêm thành công"); Close(); } } catch (Exception) { MessageBox.Show("Lol"); } }