private void btedit_Click(object sender, RoutedEventArgs e) { if (btedit.Content.ToString() == "Edit") { //Load Du Lieu Cho edit it.OperEqual(item); LoadListImageEdit(); lsviewedit.ItemsSource = imgs.ToList(); idimgsdelete.Clear(); insert.Clear(); stackpennaledit.Height = stackpennalshow.Height; stackpennalshow.Height = 0; btedit.Content = "Show"; btapply.IsEnabled = true; } else { stackpennalshow.Height = stackpennaledit.Height; stackpennaledit.Height = 0; btedit.Content = "Edit"; btapply.IsEnabled = false; } }
private async void btinsert_Click(object sender, RoutedEventArgs e) { if (item.Name != "" && item.Price != 0 && item.Description != "") { using (var db = new RoomManagerEntities2()) { try { RoomCategory newitem = new RoomCategory(); newitem.OperEqual(item); db.RoomCategories.Add(newitem); await db.SaveChangesAsync(); foreach (var img in imgs) { ////Đường Dẫn File Ảnh Gốc //var sourceImageFileInfo = new FileInfo(img); ////Tao ten duy nhat //var uniqueName = $"{Guid.NewGuid()}{sourceImageFileInfo.Extension}"; ////Đường dẫn tập tin exe //var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; ////Đường dẫn folder Image trong file exe //var destinationPath = $"{baseDirectory}Image_RoomCategory\\{uniqueName}"; ////Copy Ảnh từ File Ảnh Gốc Sang Folder Ảnh Trong File Exe //if (!File.Exists(destinationPath)) //{ // File.Copy(img, destinationPath); //} var newsource = ImageUniqueName.UniqueName(img); var newimg = new ImagesRoomCategory() { IdCategory = newitem.Id, Source = newsource, }; newitem.ImagesRoomCategories.Add(newimg); await db.SaveChangesAsync(); } MessageBox.Show("Them Loai Phong Thanh Cong"); item.ResetValue(); tbname.Text = ""; tbgia.Text = ""; tbdes.Text = ""; imgs.Clear(); lsviewinsert.ItemsSource = imgs.ToList(); data.ItemsSource = db.RoomCategories.ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("Vui Long Nhap Du Thong Tin Loai Phong"); } }