Esempio n. 1
0
 //Delete the selected estate
 private void DeleteButton_Click(object sender, EventArgs e)
 {
     Estates.DeleteEstate(ListManip.GetEstateByID(ListManip.GetEstateIdFromEstateSearchList(EstateListItems.ElementAt(selectedEstate)), Estates));
     selectedEstate = -1;
     UpdateEstateList();
     EnableInfoBoxes(false);
 }
Esempio n. 2
0
    public void Cancel(int kw, int ile)
    {
        List <int> cancelTable = new List <int>();
        List <int> posTable    = new List <int>();

        for (int i = 0; i < 9; i++)
        {
            posTable.Add(i);
        }
        cancelTable = ListManip.Choice <int>(posTable, ile);
        for (int i = 0; i < ile; i++)
        {
            this.InputInMatrix(kw, cancelTable[i], 0);
        }
    }
Esempio n. 3
0
    public static Sudoku Create()
    {
        Sudoku sudoku = new Sudoku();

        int[]      helpTab = new int[] { 0, 3, 6, 1, 4, 7, 2, 5, 8 };
        List <int> row     = new List <int>();

        for (int i = 1; i < 10; i++)
        {
            row.Add(i);
        }
        ListManip.Shuffle <int>(row);

        /*
         * for (int i =0 ; i < 9; i++)
         * {
         *  Console.Write(row[i]);
         * }
         * Console.WriteLine();
         * for(int i=0;i<15;i++)
         * {
         *  ListManip.RollLeft<int>(row);
         *  for (int j = 0; j < 9; j++)
         *  {
         *      Console.Write(row[j]);
         *  }
         *  Console.WriteLine();
         *  Console.WriteLine();
         * }
         */
        for (int i = 0; i < 9; i++)
        {
            sudoku.inputRow(row, helpTab[i]);
            ListManip.RollLeft <int>(row);
        }
        return(sudoku);
    }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }