private void Window_Loaded(object sender, RoutedEventArgs e) { Detail.DataContext = _myproduct; DetailSP sp = new DetailSP(); sp.Find(_myproduct.MaSP); CarouselItemCount = sp.hinhanh.Count; ImageCarousel.ItemsSource = sp.hinhanh; Ingredients.ItemsSource = GetIngredients(); Steps.ItemsSource = sp.stepdo; }
private void Add_Click(object sender, RoutedEventArgs e) { List <TextBox> childrenOfIngredients = AllChildren(Ingredients); List <TextBox> childrenOfSteps = AllChildren(Steps); FileInfo info = null; var folderfile = AppDomain.CurrentDomain.BaseDirectory; var newname = ""; // Ảnh đại diện: _fileAvatar // Tên món ăn: ProductName.Text // Mô tả: ProductIntro.Text // Danh mục: Categories.SelectedItem; (xem lại) // Thời gian nấu: Time.Text // Nguyên liệu được thêm vào childrenOfIngredients // Kiểm tra dữ liệu if (ConditionCheck(childrenOfIngredients, childrenOfSteps)) { info = new FileInfo(_fileAvatar); newname = $"{Guid.NewGuid()}{info.Extension}"; //copy vào file info.CopyTo($"{folderfile}Resource\\Images\\Product\\{newname}"); //them vao chổ sp SanPham sp = new SanPham(); sp.AnhDaiDien = "Resource/Images/Product/" + newname; if (ProductName.Text.Trim() != "") { sp.TenSP = ProductName.Text.Trim(); } if (ProductIntro.Text.Trim() != "") { sp.MoTa = ProductIntro.Text.Trim(); } sp.Video = ProductVideo.Text; sp.MaDM = (Categories.SelectedIndex + 1).ToString(); sp.ThoiGian = Time.Text.Trim(); foreach (var element in childrenOfIngredients) { if (element.Text.Trim() != "") { sp.NguyenLieu += element.Text + "\\n"; } } sp.SoThanhPhan = childrenOfIngredients.Count; ///thêm đối tượng sp vào database sp.Add(); DetailSP ctsp = new DetailSP(); for (int i = 1; i <= childrenOfSteps.Count; i++) { StepDo stp = new StepDo(); stp.step = (i.ToString()); stp.Do = (childrenOfSteps[i - 1].Text); ctsp.stepdo.Add(stp); } //// List ảnh các bước làm _stepImageList foreach (var av in _stepImageList) { if (av.Name != null) { newname = $"{Guid.NewGuid()}{av.Extension}"; av.CopyTo($"{folderfile}Resource\\Images\\Product\\{newname}"); string path = $"Resource/Images/Product/{newname}"; ctsp.hinhanh.Add(path); } } ////thêm ctsp vào database ctsp.Add(); DialogResult = true; } }