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(); } }
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 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(); } }
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(); }
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 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(); }
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(); } }
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; }
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; } }
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(); } }
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; }