Beispiel #1
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);
            }
        }
Beispiel #2
0
        //Update an Estate within the Estate list by creating a new one and replacing it, creates a new estate by adding it to the lists.
        private void EstateUpdateButtonClick(object sender, EventArgs e)
        {
            try
            {
                Estate  res   = null;
                int     id    = -1;
                int     zip   = -1;
                int     rent  = -1;
                int     sqrft = -1;
                Address a     = null;

                try
                {
                    //Checks wether the ID is unique, or the currently selected estate has the same ID. If not it throws an InvalidIDException.
                    id = VariablesCheck.AddNewId(this.EstateId.Text, ListManip.GetEstateFromList(EstateList.SelectedIndex, EstateListItems.ToArray(), Estates), Estates);
                }
                catch (DuplicateIDException)
                {
                    //Informs the user of the issue.
                    this.EditInfo.Text = "ID cannot be a duplicate. Changes not saved.";
                    throw new DuplicateIDException();
                }
                catch (StringNotIntException)
                {
                    //Informs the user that an ID must only contain numbers.
                    this.EditInfo.Text = "ID must only contain numbers 0 to 9";
                    throw new StringNotIntException();
                }

                try
                {
                    //Checks wether the ZIP contains only numbers.
                    zip = VariablesCheck.CheckIfNumberFieldHasLetters(this.EstateZip.Text);
                }
                catch (StringNotIntException)
                {
                    //Informs the user that a ZIP must only contain numbers.
                    this.EditInfo.Text = "Zip must only contain numbers 0 to 9";
                    throw new StringNotIntException();
                }

                try
                {
                    //Checks wether the rent contains only numbers.
                    rent = VariablesCheck.CheckIfNumberFieldHasLetters(this.EstateRent.Text);
                }
                catch (StringNotIntException)
                {
                    //Informs the user that rent must only contain numbers.
                    this.EditInfo.Text = "Rent must only contain numbers 0 to 9";
                    throw new StringNotIntException();
                }
                try
                {
                    //Checks wether the Square Feet attribute only contains numbers.
                    sqrft = VariablesCheck.CheckIfNumberFieldHasLetters(this.EstateSqrft.Text);
                }
                catch (StringNotIntException)
                {
                    //INforms the user that Square Feet must only contain numbers.
                    this.EditInfo.Text = "Square Feet must only contain numbers 0 to 9";
                    throw new StringNotIntException();
                }
                try
                {
                    //Attempts to create a new Address attribute. If Street address contains any special characters the constructor throws a SpecialCharException.
                    //If the City contains anything other than letters the constructor throws a SpecialCharException.
                    a = new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text));
                }
                catch (SpecialCharException)
                {
                    //Informs the user that Street can only contain numbers and letters, and City can only contain letters.
                    this.EditInfo.Text = "Street address must only contain letters A-Ö and numbers 0 to 9. And City can only contain letters A-Ö.";
                }
                //Saves the path and name of the selected image to a new variable.
                string imageLocation = this.DisplayImage.ImageLocation;

                //Checks wether the estate type is either Shop or Warehouse.
                if (EstateTypeMenu.Text == Estate.EstateType.Shop.ToString() || EstateTypeMenu.Text == Estate.EstateType.Warehouse.ToString())
                {
                    //Shop and Warehouse can't be of the legal type Tenement.
                    if (EstateLegalMenu.Text == Estate.Legal.Tenement.ToString())
                    {
                        //Informs the user of the issue mentioned above.
                        this.EditInfo.Text = "Shops and Warehouses can't have Tenement as legal type.";
                        throw new Exception();
                    }
                }

                //Depending on the type of estate the program creates different estates.
                if (this.EstateTypeMenu.Text == Estate.EstateType.House.ToString())
                {
                    int val = VariablesCheck.CheckIfNumberFieldHasLetters(UniqueEstateValue.Text);
                    res = new House(id, sqrft, rent, new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text)), (Residential.Legal)Enum.Parse(typeof(Residential.Legal), this.EstateLegalMenu.Text), imageLocation, val);
                }
                else if (EstateTypeMenu.Text == Estate.EstateType.Apartment.ToString())
                {
                    int val = VariablesCheck.CheckIfNumberFieldHasLetters(UniqueEstateValue.Text);
                    res = new Apartment(id, sqrft, rent, new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text)), (Residential.Legal)Enum.Parse(typeof(Residential.Legal), this.EstateLegalMenu.Text), imageLocation, val);
                }
                else if (EstateTypeMenu.Text == Estate.EstateType.Villa.ToString())
                {
                    int val = VariablesCheck.CheckIfNumberFieldHasLetters(UniqueEstateValue.Text);
                    res = new Villa(id, sqrft, rent, new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text)), (Residential.Legal)Enum.Parse(typeof(Residential.Legal), this.EstateLegalMenu.Text), imageLocation, val);
                }
                else if (EstateTypeMenu.Text == Estate.EstateType.Rowhouse.ToString())
                {
                    int val = VariablesCheck.CheckIfNumberFieldHasLetters(UniqueEstateValue.Text);
                    res = new Rowhouse(id, sqrft, rent, new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text)), (Residential.Legal)Enum.Parse(typeof(Residential.Legal), this.EstateLegalMenu.Text), imageLocation, val);
                }
                else if (EstateTypeMenu.Text == Estate.EstateType.Shop.ToString())
                {
                    int val = VariablesCheck.CheckIfNumberFieldHasLetters(UniqueEstateValue.Text);
                    res = new Shop(id, sqrft, rent, new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text)), (Commercial.Legal)Enum.Parse(typeof(Commercial.Legal), this.EstateLegalMenu.Text), imageLocation, val);
                }
                else if (EstateTypeMenu.Text == Estate.EstateType.Warehouse.ToString())
                {
                    bool val = VariablesCheck.checkTrueFalse(UniqueEstateValue.Text);
                    res = new Warehouse(id, sqrft, rent, new Address(this.EstateStreet.Text, zip, this.EstateCity.Text, EstateUtils.parseCountry(this.EstateCountryMenu.Text)), (Commercial.Legal)Enum.Parse(typeof(Commercial.Legal), this.EstateLegalMenu.Text), imageLocation, val);
                }

                //If the boolean createnew is set to false then the new estate replaces the selected item in the list.
                //If not, then it creates a new estate and adds it to the top of the list.
                if (!createNew)
                {
                    Estates.ChangeAt(res, selectedEstate);
                    EditInfo.Text = "Estate edited succesfully!";
                }
                else
                {
                    Estates.Add(res);
                    selectedEstate = 0;

                    EditInfo.Text = "Estate created succesfully!";
                    this.EstateUpdateButton.Text = "Update info";
                    createNew = false;
                }
                UpdateEstateList();
            }
            catch (Exception _e)
            {
                Console.WriteLine(_e);
            }
        }