예제 #1
0
        private async void btapply_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            var creen = new ConfirmWindow($"Ban Co Chac Muon Edit Loai Phong");

            creen.ShowDialog();
            if (creen.DialogResult == true)
            {
                using (var db = new RoomManagerEntities2())
                {
                    try
                    {
                        var result = db.RoomCategories.SingleOrDefault(b => b.Id == item.Id);
                        if (result != null)
                        {
                            try
                            {
                                result.Name        = it.Name;
                                result.Price       = it.Price;
                                result.Description = it.Description;

                                await db.SaveChangesAsync();

                                foreach (var insr in insert)
                                {
                                    var newsource = ImageUniqueName.UniqueName(insr.Source);
                                    insr.Source = newsource;
                                    ImagesRoomCategory newimg = new ImagesRoomCategory()
                                    {
                                        IdCategory = insr.IdCategory,
                                        Source     = insr.Source,
                                    };

                                    db.ImagesRoomCategories.Add(insr);
                                    await db.SaveChangesAsync();
                                }
                                foreach (var dele in idimgsdelete)
                                {
                                    var img = db.ImagesRoomCategories.Find(dele);
                                    db.ImagesRoomCategories.Remove(img);

                                    await db.SaveChangesAsync();
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                stackpennalshow.Height = stackpennaledit.Height;
                stackpennaledit.Height = 0;
                btedit.Content         = "Edit";

                var dba = new RoomManagerEntities2();
                item = dba.RoomCategories.Find(item.Id);
                stackpennalshow.DataContext = item;

                btapply.IsEnabled = false;
            }
            this.IsEnabled = true;
        }
예제 #2
0
        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");
            }
        }