public void EditHouse(NHA Nha)
        {
            if (Nha is null)
            {
                throw new System.ArgumentNullException(nameof(Nha));
            }

            using (var db = new QUANLYNHADATEntities())
            {
                var house = db.NHAs.Find(Nha.MANHA, Nha.MACN);
                if (house != null)
                {
                    house.MACN   = Nha.MACN;
                    house.MACNHA = Nha.MACNHA;
                    house.MANV   = Nha.MANV;
                    //house.MALOAI = Nha.MALOAI;
                    if (house.MALOAI != Nha.MALOAI)
                    {
                        this.UpdateHouseCategory(Nha);
                    }
                    house.SOLUONGPHONGO = Nha.SOLUONGPHONGO;
                    house.NGAYHETHAN    = Nha.NGAYHETHAN;
                    house.NGAYDANG      = Nha.NGAYDANG;
                    house.DUONG         = Nha.DUONG;
                    house.QUAN          = Nha.QUAN;
                    house.KHUVUC        = Nha.KHUVUC;
                    house.THANHPHO      = Nha.THANHPHO;
                    house.TINHTRANG     = Nha.TINHTRANG;
                    house.SOLUOTXEM     = Nha.SOLUOTXEM;
                    db.SaveChanges();
                }
            }

            this.Reset();
        }
예제 #2
0
        internal void SetSelectedHouse(NHA selectedNha)
        {
            SelectedHouse = selectedNha;
            if (selectedNha != null)
            {
                using (QUANLYNHADATEntities db = new QUANLYNHADATEntities())
                {
                    SelectedHouseForRent = db.CHITIETNHATHUEs.FirstOrDefault(item => item.MANHA == selectedNha.MANHA);
                    SelectedHouseForSale = db.CHITIETNHABANs.FirstOrDefault(item => item.MANHA == selectedNha.MANHA);
                }
            }
            else
            {
                SelectedHouseForRent = new CHITIETNHATHUE();
                SelectedHouseForSale = new CHITIETNHABAN();
            }

            if (SelectedHouseForRent != null)
            {
                HouseType = 0;
            }
            else if (SelectedHouseForSale != null)
            {
                HouseType = 1;
            }
        }
예제 #3
0
        private void ClearSelectedHouseButton_Click(object sender, RoutedEventArgs e)
        {
            NHA selectedNha = new NHA();

            HomeScreenViewModel.Instance.SetSelectedHouse(selectedNha);
            HouseListComboBox.SelectedItem = null;
        }
예제 #4
0
        private void HouseListComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*get selectedHouse trong thêm /xóa/ sửa nhà */
            NHA selectedNha = HouseListComboBox.SelectedItem as NHA;

            HomeScreenViewModel.Instance.SetSelectedHouse(selectedNha);
        }
예제 #5
0
        private async void ExecuteEditHouseCommand(object key)
        {
            var values = (object[])key;

            this.ModifiedHouse             = NhaDAO.GetInstance().GetHouseById(values);
            this.ModifiedRentalHouseDetail = ChiTietNhaThueDAO.GetInstance().GetRentalhouseDetailById(values);
            var selectedhHouseCate = this.allHouseCategories.FirstOrDefault(c => c.MALOAI == this.ModifiedHouse.MALOAI);
            var cateIndex          = this.allHouseCategories.IndexOf(selectedhHouseCate);

            this.HouseDetailViewModel = new HouseDetailViewModel
            {
                HouseCateSelectedIndex    = cateIndex,
                SelectedHouse             = this.ModifiedHouse,
                SelectedRentalHouseDetail = this.ModifiedRentalHouseDetail,
                AgenciesCollection        = this.allAgencies,
                HouseOwnersCollection     = this.allHouseOwners,
                StaffsCollection          = this.allStaffs,
                HouseCatesCollection      = this.allHouseCategories
            };

            var view = new HouseDetailDialog
            {
                DataContext = this.HouseDetailViewModel
            };

            //show the dialog
            var result = await DialogHost.Show(view, BaseMainWindowViewModel.Instance.Identifier, ExtendedOpenedEventHandler, EditHouseClosingEventHandler).ConfigureAwait(false);

            //check the result...
            Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL"));
        }
 private HomeScreenViewModel()
 {
     using (QUANLYNHADATEntities db = new QUANLYNHADATEntities())
     {
         Houses        = new ObservableCollection <NHA>(db.NHAs.Where(item => item.MACNHA == MACNHA).ToList());
         AllHouseTypes = new ObservableCollection <LOAINHA>(db.LOAINHAs);
     }
     SelectedHouse        = new NHA();
     SelectedHouseForRent = new CHITIETNHATHUE();
     SelectedHouseForSale = new CHITIETNHABAN();
 }
예제 #7
0
        public bool IsContainsHouse(NHA Nha)
        {
            if (Nha is null)
            {
                throw new System.ArgumentNullException(nameof(Nha));
            }

            using (var db = new QUANLYNHADATEntities())
            {
                return(db.CHITIETNHATHUEs.Any(c => c.MANHA == Nha.MANHA && c.MACN == Nha.MACN));
            }
        }
        public void AddNewHouse(NHA Nha)
        {
            if (Nha is null)
            {
                throw new System.ArgumentNullException(nameof(Nha));
            }

            using (var db = new QUANLYNHADATEntities())
            {
                db.NHAs.Add(Nha);
                db.SaveChanges();
            }

            this.Reset();
        }
        private void UpdateHouseCategory(NHA Nha)
        {
            if (Nha is null)
            {
                throw new System.ArgumentNullException(nameof(Nha));
            }

            using (var db = new QUANLYNHADATEntities())
            {
                try
                {
                    db.USP_UpdateHouseTypeInHouse(Nha.MANHA, Nha.MALOAI);
                    db.SaveChanges();
                    this.Reset();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #10
0
        private HomeScreenViewModel()
        {
            using (QUANLYNHADATEntities db = new QUANLYNHADATEntities())
            {
                Houses         = new ObservableCollection <NHA>(db.NHAs.Where(item => item.MACN == MACN));
                AllHouses      = new ObservableCollection <NHA>(db.NHAs.Where(item => item.MACN == MACN));
                AllHouseTypes  = new ObservableCollection <LOAINHA>(db.LOAINHAs);
                AllHouseOwners = new ObservableCollection <CHUNHA>(db.CHUNHAs);

                Staffs = new ObservableCollection <NHANVIEN>(db.NHANVIENs.Where(item => item.MACN == MACN));

                Customers = new ObservableCollection <KHACHHANG>(db.KHACHHANGs.Where(item => item.CNQUANLY == MACN));
            }
            SelectedHouse        = new NHA();
            SelectedHouseForRent = new CHITIETNHATHUE();
            SelectedHouseForSale = new CHITIETNHABAN();

            SelectedStaff = new NHANVIEN();

            SelectedCustomer       = new KHACHHANG();
            OldNewHousetypeRequest = new Dictionary <int, int>();
        }
예제 #11
0
        private async void ExecuteDeleteHouseCommand(object key)
        {
            var values = (object[])key;

            this.ModifiedHouse             = NhaDAO.GetInstance().GetHouseById(values);
            this.ModifiedRentalHouseDetail = ChiTietNhaThueDAO.GetInstance().GetRentalhouseDetailById(values);

            var okeCancelDialogViewModel = new OkCancelDialogViewModel
            {
                Message = "Xóa nhà này?"
            };

            var view = new OkCancelDialogControl
            {
                DataContext = okeCancelDialogViewModel
            };

            //show the dialog
            var result = await DialogHost.Show(view, BaseMainWindowViewModel.Instance.Identifier, ExtendedOpenedEventHandler, DeleteExtendedClosingEventHandler).ConfigureAwait(false);

            //check the result...
            Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL"));
        }