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