Exemplo n.º 1
0
 public RentRoom getRentRoomFromData(int id)
 {
     using (var db = new RoomManagerEntities2())
     {
         return(db.RentRooms.SingleOrDefault(b => b.id == rentRoom.id));
     }
 }
Exemplo n.º 2
0
        private void btnDeleteRentRoom_Click(object sender, RoutedEventArgs e)

        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa Rent Room {rentRoom.id}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new RentRoom()
                        {
                            id = rentRoom.id
                        };
                        db.RentRooms.Attach(deleteItem);
                        db.RentRooms.Remove(deleteItem);
                        db.SaveChanges();
                        var oldRoom = db.Rooms.SingleOrDefault(b => b.Id == this.rentRoom.roomID);
                        oldRoom.Status = 1;

                        db.SaveChanges();
                        this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
 public USDDetail getUSDDetailFromData(int usID, int sID, int times)
 {
     using (var db = new RoomManagerEntities2())
     {
         return(db.USDDetails.SingleOrDefault(b => (b.usID == usID && b.sID == sID && b.times == times)));
     }
 }
 public UsedService getUsedServicesFromData(int id)
 {
     using (var db = new RoomManagerEntities2())
     {
         return(db.UsedServices.SingleOrDefault(b => b.id == UsedServices.id));
     }
 }
        private void btnDeleteServices_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa Service {Services.id}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new Service()
                        {
                            id = Services.id
                        };
                        db.Services.Attach(deleteItem);
                        db.Services.Remove(deleteItem);
                        db.SaveChanges();

                        this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
Exemplo n.º 6
0
 private void btinsert_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new RoomManagerEntities2())
     {
         try
         {
             var newitem = new Room()
             {
                 Name       = tbsophong.Text,
                 IdCategory = GetMaLoaiComBoBox(),
                 Status     = Classify_Status(),
             };
             db.Rooms.Add(newitem);
             db.SaveChanges();
             data.ItemsSource = db.Rooms.ToList();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     tbsophong.Text     = "";
     rbttrong.IsChecked = true;
     MessageBox.Show("Them Phong Thanh Cong");
 }
        private void btnDeleteUSDDetails_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa USDetail {USDetail.usID} {USDetail.sID} {USDetail.times}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new USDDetail {
                            usID = USDetail.usID, sID = USDetail.sID, times = USDetail.times
                        };
                        db.USDDetails.Attach(deleteItem);
                        db.USDDetails.Remove(deleteItem);
                        db.SaveChanges();
                        //var oldRoom = db.Rooms.SingleOrDefault(b => b.Id == this.USDDetails.roomID);
                        //oldRoom.Status = 1;

                        //db.SaveChanges();
                        this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
        private void btnAddUsedServices_Click(object sender, RoutedEventArgs e)
        {
            var errorMessage = catchErrorValidate();

            if (errorMessage != "")
            {
                tbErrorMessage.Text = errorMessage;
                return;
            }
            var addItem = getDataFromForm();

            using (var db = new RoomManagerEntities2())
            {
                try
                {
                    db.UsedServices.Add(addItem);

                    db.SaveChanges();

                    //MessageBox.Show("Thêm Sản Phẩm Thành Công");
                    //var rentedRoom = db.Rooms.SingleOrDefault(b => b.Id == addItem.rentRoomID);
                    //rentedRoom.Status = 2;
                    //db.SaveChanges();
                    this.DialogResult = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            //complete action
            Close();
        }
Exemplo n.º 9
0
        private void LoadServicesData(int page = 1)
        {
            var db = new RoomManagerEntities2();

            ServiceList = db.Services.ToList();
            //Load Datagrid
            dgServices.ItemsSource      = ServiceList.Skip((page - 1) * 10).Take(10);
            tbTotalPageServices.Text    = (ServiceList.Count() % 10 != 0 ? ServiceList.Count() / 10 + 1 : ServiceList.Count() / 10).ToString();
            tbxCurrentPageServices.Text = currentServicesPage.ToString();
        }
Exemplo n.º 10
0
        private void LoadRentRoomData(int page = 1)
        {
            var db = new RoomManagerEntities2();

            RentRoomList = db.RentRooms.ToList();
            //Load Datagrid
            dgRentRoom.ItemsSource = RentRoomList.Skip((page - 1) * 10).Take(10);

            tbTotalPageRentRoom.Text    = (RentRoomList.Count() % 10 != 0?RentRoomList.Count() / 10 + 1: RentRoomList.Count() / 10).ToString();
            tbxCurrentPageRentRoom.Text = currentRentRoomPage.ToString();
        }
Exemplo n.º 11
0
        private void btnSaveRentRoom_Click(object sender, RoutedEventArgs e)
        {
            var errorMessage = catchErrorValidate();

            if (errorMessage != "")
            {
                tbErrorMessage.Text = errorMessage;
                return;
            }
            var editedItem = getDataFromForm();

            editedItem.id = rentRoom.id;
            using (var db = new RoomManagerEntities2())
            {
                this.IsEnabled = false;
                var creen = new ConfirmWindow($"Ban Co Chac Muon Edit Rent Room {editedItem.id}");
                creen.ShowDialog();
                if (creen.DialogResult == true)
                {
                    var result = db.RentRooms.SingleOrDefault(b => b.id == editedItem.id);
                    if (result != null)
                    {
                        try
                        {
                            result.roomID     = editedItem.roomID;
                            result.renterName = editedItem.renterName;
                            result.tel        = editedItem.tel;
                            result.price      = editedItem.price;
                            result.date       = editedItem.date;
                            db.SaveChanges();
                            // save ok
                            if (editedItem.roomID != this.rentRoom.roomID)
                            {
                                var editedRoom = db.Rooms.SingleOrDefault(b => b.Id == editedItem.roomID);
                                editedRoom.Status = 2;
                                var oldRoom = db.Rooms.SingleOrDefault(b => b.Id == this.rentRoom.roomID);
                                oldRoom.Status = 1;

                                db.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                this.IsEnabled = true;
            }
            //complete action
            switchToInfoAction();
        }
Exemplo n.º 12
0
        private void LoadDuLieu()
        {
            var db = new RoomManagerEntities2();

            lsctgry         = db.RoomCategories.ToList();
            lsr             = db.Rooms.ToList();
            listimgcategory = db.ImagesRoomCategories.ToList();
            loaiphongdatagrid.ItemsSource = lsctgry.ToList();
            phongdatagrid.ItemsSource     = lsr.ToList();
            LoadRentRoomData(currentRentRoomPage);
            LoadServicesData(currentServicesPage);
            LoadUsedServicesData(currentUsedServicesPage);
        }
        public void LoadUSDDetailsData(int page = 1)
        {
            using (var db = new RoomManagerEntities2()) {
                db.UsedServices.Attach(UsedServices);

                db.Entry(UsedServices).Collection(s => s.USDDetails).Load();
                USDDetailList = UsedServices.USDDetails.ToList();

                //Load Datagrid
                dgUSDDetails.ItemsSource      = USDDetailList.Skip((page - 1) * 10).Take(10);
                tbTotalPageUSDDetails.Text    = (USDDetailList.Count() % 10 != 0 ? USDDetailList.Count() / 10 + 1 : USDDetailList.Count() / 10).ToString();
                tbxCurrentPageUSDDetails.Text = currentUSDDetailsPage.ToString();
            }
        }
Exemplo n.º 14
0
        public List <USDDetail> getUSDDetailFromData()
        {
            using (var db = new RoomManagerEntities2())
            {
                db.RentRooms.Attach(rentRoom);

                db.Entry(rentRoom).Collection(s => s.UsedServices).Load();
                var us = rentRoom.UsedServices.Where(i => i.status == 0).ToList();
                if (us.Count > 0)
                {
                    return(us[0].USDDetails.ToList());
                }
                return(null);
            }
        }
Exemplo n.º 15
0
        private void btnImportRentRoom_Click(object sender, RoutedEventArgs e)
        {
            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 == "RentRoom")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var newRent = new RentRoom()
                                    {
                                        roomID     = tab.Cells[$"B{row}"].IntValue,
                                        renterName = tab.Cells[$"C{row}"].StringValue,
                                        tel        = tab.Cells[$"D{row}"].StringValue,
                                        price      = tab.Cells[$"E{row}"].DoubleValue,
                                        date       = tab.Cells[$"F{row}"].DateTimeValue,
                                    };
                                    db.RentRooms.Add(newRent);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                                LoadRentRoomData();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        private void btdelete_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            var creen = new ConfirmWindow($"Ban Co Chac Muon Delete Room");

            creen.ShowDialog();
            if (creen.DialogResult == true)
            {
                using (var db = new RoomManagerEntities2())
                {
                    var victim = db.Rooms.Find(item.Id);
                    db.Rooms.Remove(victim);
                    db.SaveChanges();
                }
                this.Close();
            }
            this.IsEnabled = true;
        }
        private void btnAddUSDDetails_Click(object sender, RoutedEventArgs e)
        {
            var errorMessage = catchErrorValidate();

            if (errorMessage != "")
            {
                tbErrorMessage.Text = errorMessage;
                return;
            }
            var addItem = getDataFromForm();

            using (var db = new RoomManagerEntities2())
            {
                // var a = db.USDDetails.Where(i => i.usID == USDetail.usID && i.sID == USDetail.sID);
                //var b = a.Select(p => p.times);
                //var c = b.DefaultIfEmpty(0);
                //var times = c.Max().FirstOrDefault();
                //MessageBox.Show(record.ToString());
                var lastTimes = db.USDDetails.Where(i => i.usID == addItem.usID && i.sID == addItem.sID).Select(x => x.times)
                                .DefaultIfEmpty(0)
                                .Max();
                var times = lastTimes + 1;

                addItem.times = times;

                try
                {
                    db.USDDetails.Add(addItem);

                    db.SaveChanges();

                    //MessageBox.Show("Thêm Sản Phẩm Thành Công");
                    this.DialogResult = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            //complete action
            Close();
        }
        private void btnSaveServices_Click(object sender, RoutedEventArgs e)
        {
            var errorMessage = catchErrorValidate();

            if (errorMessage != "")
            {
                tbErrorMessage.Text = errorMessage;
                return;
            }
            var editedItem = getDataFromForm();

            editedItem.id = Services.id;
            using (var db = new RoomManagerEntities2())
            {
                this.IsEnabled = false;
                var creen = new ConfirmWindow($"Ban Co Chac Muon Edit Service {editedItem.id}");
                creen.ShowDialog();
                if (creen.DialogResult == true)
                {
                    var result = db.Services.SingleOrDefault(b => b.id == editedItem.id);
                    if (result != null)
                    {
                        try
                        {
                            result.name = editedItem.name;

                            result.price = editedItem.price;

                            db.SaveChanges();
                            // save ok
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                this.IsEnabled = true;
            }
            //complete action
            switchToInfoAction();
        }
Exemplo n.º 19
0
 private void btnCheckOutRentRoom_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (var db = new RoomManagerEntities2())
         {
             var us = db.UsedServices.SingleOrDefault(i => i.rentRoomID == rentRoom.id && i.status == 0);
             us.status = 1;
             db.SaveChanges();
             var rr = db.Rooms.SingleOrDefault(i => i.Id == rentRoom.roomID);
             rr.Status = 1;
             db.SaveChanges();
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 20
0
        private void btdelete_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            var creen = new ConfirmWindow($"Ban Co Chac Muon Delete Loai Phong");

            creen.ShowDialog();
            if (creen.DialogResult == true)
            {
                if (item.Rooms.Count == 0)
                {
                    using (var db = new RoomManagerEntities2())
                    {
                        try
                        {
                            //Xoa Ảnh Trước
                            foreach (var img in item.ImagesRoomCategories)
                            {
                                var dele = db.ImagesRoomCategories.Find(img.Id);
                                db.ImagesRoomCategories.Remove(dele);
                                db.SaveChanges();
                            }
                            // Xóa Loại Room
                            var itemdelete = db.RoomCategories.Find(item.Id);
                            db.RoomCategories.Remove(itemdelete);
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    MessageBox.Show("Xoa Loai Phong Thanh Cong");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Xoa That Bai Loai Phong Nay Dang Ton Tai Trong Mot Phong Nao Do");
                }
            }
            this.IsEnabled = true;
        }
        private void btnDeleteUsedServices_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa Used Services {UsedServices.id}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new UsedService()
                        {
                            id = UsedServices.id
                        };
                        var deleteDetailItem = new USDDetail()
                        {
                            usID = UsedServices.id
                        };
                        db.Entry(deleteDetailItem).State = EntityState.Modified;
                        db.USDDetails.Attach(deleteDetailItem);
                        db.USDDetails.Remove(deleteDetailItem);
                        db.SaveChanges();
                        switchToInfoAction();
                        //db.UsedServices.Attach(deleteItem);
                        //db.UsedServices.Remove(deleteItem);


                        //db.SaveChanges();
                        //this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
Exemplo n.º 22
0
        private 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 database = new RoomManagerEntities2())
                {
                    var victim = database.Rooms.Find(item.Id);
                    victim.Name       = tbsophong.Text;
                    victim.IdCategory = GetMaLoaiComBoBox();
                    victim.Status     = Classify_Status();
                    database.SaveChanges();
                }
                stackpennalshow.Height = stackpennaledit.Height;
                stackpennaledit.Height = 0;
                btedit.Content         = "Edit";
                btapply.IsEnabled      = false;
            }
            this.IsEnabled = true;
        }
Exemplo n.º 23
0
 private void btnCheckOutRentRoom_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (var db = new RoomManagerEntities2())
         {
             this.IsEnabled = false;
             var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa Rent Room {rentRoom.id}");
             screen.ShowDialog();
             if (screen.DialogResult == true)
             {
                 var checkOutWindow = new CheckOutWindow(rentRoom);
                 checkOutWindow.ShowDialog();
             }
             this.IsEnabled = true;
         }
     }
     catch (Exception ex)
     {
         this.IsEnabled = true;
         //MessageBox.Show("delete failure");
         switchToInfoAction();
     }
 }
Exemplo n.º 24
0
        private void btnRent_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new RoomManagerEntities2())
            {
                this.IsEnabled = false;
                var creen = new ConfirmWindow($"Ban Co Chac Muon  Rent Room {item.Id}");
                creen.ShowDialog();
                if (creen.DialogResult == true)
                {
                    var result = db.Rooms.FirstOrDefault(b => b.IdCategory == item.Id && b.Status == 1);
                    if (result != null)
                    {
                        this.IsEnabled = false;

                        var Rentscreen = new RentRoomInfoWindow(RentRoomInfoWindow.ADDACTION, null, result.Id);
                        this.IsEnabled = false;


                        if (Rentscreen.ShowDialog() == true)
                        {
                            MessageBox.Show(" Rent Room Successfull");
                        }
                        else
                        {
                            MessageBox.Show(" Rent Room Fail");
                        }
                        this.IsEnabled = true;
                    }
                    else
                    {
                        MessageBox.Show(" not room available");
                    }
                }
                this.IsEnabled = true;
            }
        }
Exemplo n.º 25
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;
        }
Exemplo n.º 26
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 27
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");
            }
        }
Exemplo n.º 28
0
        private void btnImportUsedServices_Click(object sender, RoutedEventArgs e)
        {
            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 == "Services")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var newUService = new UsedService()
                                    {
                                        rentRoomID = tab.Cells[$"B{row}"].IntValue,

                                        date   = tab.Cells[$"C{row}"].DateTimeValue,
                                        status = tab.Cells[$"D{row}"].IntValue,
                                    };
                                    db.UsedServices.Add(newUService);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                                LoadServicesData();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    foreach (var tab in tabs)
                    {
                        try
                        {
                            if (tab.Name == "USDDetails")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var newUSDDetail = new USDDetail()
                                    {
                                        usID  = tab.Cells[$"B{row}"].IntValue,
                                        sID   = tab.Cells[$"C{row}"].IntValue,
                                        times = tab.Cells[$"D{row}"].IntValue,
                                        price = tab.Cells[$"E{row}"].DoubleValue,
                                        date  = tab.Cells[$"F{row}"].DateTimeValue,
                                    };
                                    db.USDDetails
                                    .Add(newUSDDetail);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                                LoadServicesData();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }