示例#1
0
        private void LoadListImageEdit()
        {
            imgs.Clear();
            foreach (var img in item.ImagesRoomCategories)
            {
                var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

                //Đường dẫn folder Image trong file exe
                var destinationPath = $"{baseDirectory}Image_RoomCategory\\{img.Source}";

                ImagesRoomCategory newimg = new ImagesRoomCategory()
                {
                    Id         = img.Id,
                    IdCategory = img.IdCategory,
                    Source     = destinationPath,
                };
                imgs.Add(newimg);
            }
        }
示例#2
0
        private void btchooseimage_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Multiselect = true;
            if (openFileDialog.ShowDialog() == true)
            {
                var images = openFileDialog.FileNames;
                foreach (var img in images)
                {
                    ImagesRoomCategory newimg = new ImagesRoomCategory
                    {
                        IdCategory = item.Id,
                        Source     = img,
                    };
                    insert.Add(newimg);
                    imgs.Add(newimg);
                }
            }
            lsviewedit.ItemsSource = imgs.ToList();
        }
示例#3
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;
        }
示例#4
0
        private void InprotExcel()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                var wookbook = new Workbook(openFileDialog.FileName);
                var tabs     = wookbook.Worksheets;
                using (var db = new RoomManagerEntities2())
                {
                    foreach (var tab in tabs)
                    {
                        try
                        {
                            if (tab.Name == "Category")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var name  = tab.Cells[$"C{row}"].StringValue;
                                    var price = tab.Cells[$"D{row}"].FloatValue;
                                    var des   = tab.Cells[$"E{row}"].StringValue;

                                    var newCategory = new RoomCategory()
                                    {
                                        Name        = name,
                                        Price       = price,
                                        Description = des
                                    };
                                    db.RoomCategories.Add(newCategory);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                            }
                            else if (tab.Name == "Image")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var idcategory = tab.Cells[$"B{row}"].IntValue;
                                    var src        = tab.Cells[$"C{row}"].StringValue;

                                    //lay duong dan cu Foder anh
                                    var srcImageInfo    = new FileInfo(openFileDialog.FileName);
                                    var srcPath         = $"{srcImageInfo.DirectoryName}\\Images\\{src}";
                                    var sourceImageInfo = new FileInfo(srcPath);

                                    //Tao ten duy nhat
                                    var uniqueName = $"{Guid.NewGuid()}{sourceImageInfo.Extension}";

                                    var basePath = AppDomain.CurrentDomain.BaseDirectory;
                                    var desPath  = $"{basePath}Image_RoomCategory\\{uniqueName}";
                                    if (!File.Exists(desPath))
                                    {
                                        File.Copy(srcPath, desPath);
                                    }

                                    var newimg = new ImagesRoomCategory()
                                    {
                                        IdCategory = idcategory,
                                        Source     = uniqueName,
                                    };

                                    db.ImagesRoomCategories.Add(newimg);

                                    db.SaveChanges();
                                    //await db.SaveChangesAsync();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                            }
                            else if (tab.Name == "Room")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var    idcategory = tab.Cells[$"B{row}"].IntValue;
                                    var    name       = tab.Cells[$"C{row}"].StringValue;
                                    string str_status = tab.Cells[$"D{row}"].StringValue;
                                    int    status;
                                    if (str_status == "Trống")
                                    {
                                        status = 1;
                                    }
                                    else if (str_status == "Đã Có Người Thuê")
                                    {
                                        status = 2;
                                    }
                                    else
                                    {
                                        status = 3;
                                    }

                                    var newimg = new Room()
                                    {
                                        IdCategory = idcategory,
                                        Name       = name,
                                        Status     = status
                                    };
                                    db.Rooms.Add(newimg);
                                    db.SaveChanges();
                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
示例#5
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");
            }
        }