Example #1
0
        //Update the estate list. Triggered when program starts and when information has been updated. Also triggered when search parameters change.
        private void UpdateEstateList()
        {
            String        street = this.SearchBarStreet.Text;
            List <Estate> res    = Estates.ToList();

            string zip         = "";
            int    hiddenCount = 0;

            if (SearchBarZip.Text != null)
            {
                zip = this.SearchBarZip.Text;
            }
            String city    = this.SearchBarCity.Text;
            String country = "";

            if (this.SearchBoxCountry.SelectedIndex > 0)
            {
                country = this.SearchBoxCountry.Text;
                //Console.WriteLine(this.SearchBoxCountry.SelectedIndex);
                Countries c = EstateUtils.parseCountry(country);
                if (Estates.GetCountryDictionary().Contains(c))
                {
                    res = Estates.GetCountryDictionary().Get(c);
                }
            }
            String legal = "";

            if (this.SearchBoxLegal.SelectedIndex > 0)
            {
                legal = this.SearchBoxLegal.Text;
            }
            String type = "";

            if (this.SearchBoxType.SelectedIndex > 0)
            {
                type = this.SearchBoxType.Text;
            }


            EstateList.Items.Clear();
            EstateListItems = new LinkedList <string>();
            //This for-loop goes through every Estate in the list of Estates and checks wether the filter-attributes correspond to the attributes of the estate.
            //If they do they are added to the list, if not they are hidden from view.
            for (int i = 0; i < res.Count; i++)
            {
                Estate e = res[i];
                if (e.Address.Street.ToLower().Contains(street.ToLower()) && e.Address.Zip.ToString().Contains(zip) && e.Address.City.ToLower().Contains(city.ToLower()) && e.Address.country.ToString().Contains(country) && e.type.ToString().Contains(type) && e.GetLegalType().Contains(legal) && e.Sqrft >= EstateSqrftSlider.Value && e.Rent <= EstateRentSlider.Value)
                {
                    //Create a string representation of an Estate as such: ID : Street, City, Country.
                    EstateListItems.AddLast($"{e.Id} : {e.Address.Street} {e.Address.City} {e.Address.country}");
                    EstateList.Items.AddRange(new Object[]
                    {
                        EstateListItems.Last()
                    });
                }
                else
                {
                    hiddenCount++;
                }
            }
            if (Estates.Count == 0)
            {
                DeleteButton.Enabled = false;
            }
            else
            {
                DeleteButton.Enabled = true;
            }
            //Shows the user how many Estates are hidden from the list, so there's no confusion.
            NumberOfHiddenItems.Text = hiddenCount + " hidden items";
            //Resets the selected estate, because the order of estates have been shifted around.
            selectedEstate = -1;
            EnableInfoBoxes(false);
        }
Example #2
0
        //Update Estate text boxes with appropriate values from the selected Estate.
        private void EstateList_SelectedValueChanged(object sender, EventArgs e)
        {
            EnableInfoBoxes(true);
            this.EstateUpdateButton.Text = "Update info";
            this.EditInfo.Text           = "Ready to edit";
            createNew = false;
            try
            {
                ListBox listbox  = (ListBox)sender;
                Estate  building = ListManip.GetEstateFromList(listbox.SelectedIndex, EstateListItems.ToArray(), Estates);
                selectedEstate         = ListManip.GetEstateSearchListPositionByEstateID(building.Id, Estates);
                this.EstateId.Text     = building.Id.ToString();
                this.EstateStreet.Text = building.Address.Street.ToString();
                this.EstateZip.Text    = building.Address.Zip.ToString();
                this.EstateCity.Text   = building.Address.City;

                this.EstateLegalMenu.SelectedItem = building.GetLegalType();
                this.EstateTypeMenu.SelectedItem  = building.type.ToString();

                UpdateImage(building.Image);
                this.EstateRent.Text  = building.Rent.ToString();
                this.EstateSqrft.Text = building.Sqrft.ToString();
                this.EstateCountryMenu.SelectedItem = building.Address.country.ToString();
                changeUniqueValueTextBox();
                switch (building.type)
                {
                case Estate.EstateType.Apartment:
                    Apartment apt = (Apartment)building;
                    UniqueEstateValue.Text = apt.floor.ToString();
                    break;

                case Estate.EstateType.House:
                    House hs = (House)building;
                    UniqueEstateValue.Text = hs.bathrooms.ToString();
                    break;

                case Estate.EstateType.Rowhouse:
                    Rowhouse rh = (Rowhouse)building;
                    UniqueEstateValue.Text = rh.balconies.ToString();
                    break;

                case Estate.EstateType.Shop:
                    Shop sp = (Shop)building;
                    UniqueEstateValue.Text = sp.maxNumberOfShoppers.ToString();
                    break;

                case Estate.EstateType.Villa:
                    Villa vl = (Villa)building;
                    UniqueEstateValue.Text = vl.sqrftGarden.ToString();
                    break;

                case Estate.EstateType.Warehouse:
                    Warehouse wh = (Warehouse)building;
                    UniqueEstateValue.Text = wh.HasDedicatedGuard.ToString();
                    break;
                }
            }
            catch (NullReferenceException exc)
            {
                Console.WriteLine(exc);
            }
        }