Exemplo n.º 1
0
        public void ThrowsArgumentException_WhenInvalidValueIsPassed(int numberOfFloors)
        {
            // Arrange
            var villa = new Villa(1, 2, 3, 6, 6, false, "Sea", 222);

            // Act & Assert
            Assert.ThrowsException <ArgumentException>(() => villa.NumberOfFloors = numberOfFloors);
        }
Exemplo n.º 2
0
        public void ThrowsArgumentException_WhenInvalidValueIsPassed(int bathrooms)
        {
            // Arrange
            var villa = new Villa(1, 2, 3, 6, 6, false, "Sea", 222);

            // Act & Assert
            Assert.ThrowsException <ArgumentException>(() => villa.Bathrooms = bathrooms);
        }
        public void SetProperBathroom_WhenTheObjectIsConstructed()
        {
            // Arrange & Act
            var villa = new Villa(1, 2, 3, 6, 6, false, "Sea", 222);

            // Assert
            Assert.AreEqual(3, villa.Bathrooms);
        }
        public void ReturnTheProperValue_WhenGetBedroomsMethodIsCalled()
        {
            // Arrange & Act
            var villa = new Villa(1, 2, 3, 6, 6, false, "Sea", 222);

            // Assert
            Assert.AreEqual(2, villa.Bedrooms);
        }
Exemplo n.º 5
0
        public void ReturnTheProperValue_WhenGetNumberOfFloorsMethodIsCalled()
        {
            // Arrange & Act
            var villa = new Villa(1, 2, 3, 6, 6, false, "Sea", 222);

            // Assert
            Assert.AreEqual(1, villa.NumberOfFloors);
        }
Exemplo n.º 6
0
        private void createEstate()
        {
            // Gets all the value from the GUI to create an Estate object
            LegalForms legalForm = (LegalForms)comboBoxLegalForm.SelectedItem;
            Countries  country   = (Countries)comboBoxCountry.SelectedItem;
            string     city      = textBoxCity.Text;
            string     zipCode   = textBoxZipCode.Text;
            string     street    = textBoxStreet.Text;
            Category   category  = (Category)comboBoxCategory.SelectedItem;
            var        type      = comboBoxType.SelectedItem;
            string     text      = textBox6.Text;
            TypeAll    typeAll   = (TypeAll)comboBoxType.SelectedItem;
            string     id        = textId.Text;

            // Id must be unique and in a valid format and all the fields int the GUI must be filled´, else do not create an Estate
            if (!isIdValid(id) || !uniqueId(id) || !estateManager.allFieldsFilled(city, zipCode, street, text))
            {
                return;
            }

            // Creates an address from the given address data
            Address address = new Address(street, zipCode, city, country);
            Estate  estate  = null;

            // Creates an estate in the correct type, depending on what type the user has chosen
            switch (type)
            {
            case TypeCom.Shop:
                estate = new Shop(id, text, legalForm, image, address, category, typeAll);
                break;

            case TypeCom.Warehouse:
                estate = new Warehouse(id, text, legalForm, image, address, category, typeAll);
                break;

            case TypeRes.Apartment:
                estate = new Apartment(id, text, legalForm, image, address, category, typeAll);
                break;

            case TypeRes.House:
                estate = new House(id, text, legalForm, image, address, category, typeAll);
                break;

            case TypeRes.Townhouse:
                estate = new Townhouse(id, text, legalForm, image, address, category, typeAll);
                break;

            case TypeRes.Villa:
                estate = new Villa(id, text, legalForm, image, address, category, typeAll);
                break;

            default:
                break;
            }

            estateManager.Add(indexToChange, estate);
            dictionaryHandler.Add(estate);
        }
        public void SetProperNumberOfFloors_WhenTheObjectIsConstructed()
        {
            // int numberOfFloors, int bedrooms, int bathrooms
            // Arrange & Act
            var villa = new Villa(1, 2, 3, 6, 6, false, "Sea", 222);

            // Assert
            Assert.AreEqual(1, villa.NumberOfFloors);
        }
Exemplo n.º 8
0
        /// <summary>
        /// method for changing an objects values, and refresh the list and viewlist with the new values.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnChange_Click(object sender, EventArgs e)
        {
            Property property;
            string   typeOfProperty   = cbType.Text;
            int      selectedObjectId = Int32.Parse(lvProperties.SelectedItems[0].SubItems[0].Text);

            switch (typeOfProperty)
            {
            case "Apartment":
                property = new Apartment();
                break;

            case "House":
                property = new House();

                break;

            case "Shop":
                property = new Shop();

                break;

            case "TownHouse":
                property = new Townhouse();

                break;

            case "Warehouse":
                property = new Warehouse();

                break;

            case "Villa":
                property    = new Villa();
                property.Id = id;
                break;

            default:
                typeOfProperty = cbType.Text;
                return;
            }
            property.Id = selectedObjectId;
            AddProperty(property);

            test();
            btnChange.Enabled = false;
            btnDelete.Enabled = false;
            for (int i = 0; i < estateManager.Count; i++)
            {
                if (estateManager.GetAt(i).Id == selectedObjectId)
                {
                    estateManager.ChangeAt(property, i);
                }
            }
            fillList();
        }
Exemplo n.º 9
0
        /*
         *      G52: Aufgabe 2
         */
        public void Uebung2()
        {
            Gebaeude gebaeude1 = new Gebaeude();
            Gebaeude gebaeude2 = new Gebaeude("Musterstraße 1");
            Villa    villa1    = new Villa();
            Villa    villa2    = new Villa("Musterstraße 2");
            Villa    villa3    = new Villa("Musterstraße 3", 1200000);

            Gebaeude.ZeigeGebaeudeListe();
            Villa.ZeigeVillaListe();
        }
Exemplo n.º 10
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Villa v1;
            int   c    = int.Parse(tbxCodiceVilla.Text);
            int   nump = int.Parse(tbxPersoneVilla.Text);
            int   mq   = int.Parse(tbxMetriVilla.Text);
            int   g    = int.Parse(tbxMetriGiardinoVilla.Text);

            v1 = new Villa(c, nump, mq, g);
            lblDatiVilla.Text    = "Codice: " + v1.getCodice() + " " + " Numero persone : " + v1.getNumPersone() + " " + "Metri quadri : " + v1.getMetriQuadri() + " " + "Giardino : " + v1.getGiardino();
            lblAcquaVilla.Text   = "Costo totale acqua = " + v1.costoAcqua(costo);
            lblDensitaVilla.Text = "Densità in villa = " + v1.densità();
            lblValoreVilla.Text  = "Valore = " + v1.valore(val1, val2);
        }
    protected override RealEstate createRealEstate(RealEstateType type, double sqmeters, int rooms, double garden_sqmeters, int num_of_parkingslots)
    {
        double price = 0;

        price += sqmeters * price_per_m2;
        price += garden_sqmeters * price_per_m2;
        price += num_of_parkingslots * price_per_parkinglot;

        if (type == RealEstateType.Apartment)
        {
            Apartment apartment = new Apartment();

            apartment.setGarden_squaremeter(garden_sqmeters);
            apartment.setLocation(location);
            apartment.setNum_of_parkinglots(num_of_parkingslots);
            apartment.setRooms(rooms);
            apartment.setSquaremeter(sqmeters);
            apartment.setPrice(price);

            return(apartment);
        }
        else if (type == RealEstateType.House)
        {
            House house = new House();

            house.setGarden_squaremeter(garden_sqmeters);
            house.setLocation(location);
            house.setNum_of_parkinglots(num_of_parkingslots);
            house.setRooms(rooms);
            house.setSquaremeter(sqmeters);
            house.setPrice(price);

            return(house);
        }
        else if (type == RealEstateType.Villa)
        {
            Villa villa = new Villa();

            villa.setGarden_squaremeter(garden_sqmeters);
            villa.setLocation(location);
            villa.setNum_of_parkinglots(num_of_parkingslots);
            villa.setRooms(rooms);
            villa.setSquaremeter(sqmeters);
            villa.setPrice(price);

            return(villa);
        }
        return(null);
    }
Exemplo n.º 12
0
        /// <summary>
        ///method to add a object to the list in listmanager and add to the view.
        ///creates a Property and uses the switch case to give the property a value.
        /// </summary>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Property property;
            string   typeOfProperty = cbType.Text;

            switch (typeOfProperty)
            {
            case "Apartment":
                property = new Apartment();
                break;

            case "House":
                property = new House();
                break;

            case "Shop":
                property = new Shop();
                break;

            case "Townhouse":
                property = new Townhouse();
                break;

            case "Warehouse":
                property = new Warehouse();
                break;

            case "Villa":
                property = new Villa();
                break;

            default:
                typeOfProperty = cbType.Text;
                return;
            }
            property.Id = id;
            AddProperty(property);
            estateManager.Add(property);
            id++;
            test(); // check how many objects in listmanager.
            fillList();
        }
Exemplo n.º 13
0
        public void CreateEstate(int id, String estateType, Address address, String legalForm, Image imgEstate)
        {
            Estate estate = null;

            if (id < 0)
            {
                id = GetNewID();
            }

            switch (estateType)
            {
            case "Villa":
                estate = new Villa(id, address, (Legal)Enum.Parse(typeof(Legal), legalForm), imgEstate);
                break;

            case "House":
                estate = new House(id, address, (Legal)Enum.Parse(typeof(Legal), legalForm), imgEstate);
                break;

            case "Townhouse":
                estate = new Townhouse(id, address, (Legal)Enum.Parse(typeof(Legal), legalForm), imgEstate);
                break;

            case "Apartment":
                estate = new Apartment(id, address, (Legal)Enum.Parse(typeof(Legal), legalForm), imgEstate);
                break;

            case "Shop":
                estate = new Shop(id, address, (Legal)Enum.Parse(typeof(Legal), legalForm), imgEstate);
                break;

            case "Warehouse":
                estate = new Warehouse(id, address, (Legal)Enum.Parse(typeof(Legal), legalForm), imgEstate);
                break;
            }
            estates.Add(estate);
            ui.AddToTable(estate);
        }
Exemplo n.º 14
0
        private void ChangeBtn_Click(object sender, EventArgs e)
        {
            //If no object is chosen
            if (objectsLView.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please choose an object in the list to change");
                return;
            }

            //Get the ID of the selected object so we can change the corresponding object
            //in the list
            int idOfSelected = Int32.Parse(objectsLView.SelectedItems[0].SubItems[0].Text);
            RealEstateObject objectToAdd;

            //Create the type of object according to what type of estate it is
            string typeOfEstate = typeOfEstateCBox.GetItemText(typeOfEstateCBox.SelectedItem);

            switch (typeOfEstate)
            {
            case "WareHouse":
                objectToAdd = new Warehouse();
                if (landSizeTBox.Text.ToString() != "")
                {
                    Warehouse warehouse = (Warehouse)objectToAdd;
                    warehouse.LandSizeInSquareMeters = Int32.Parse(landSizeTBox.Text);
                }
                else
                {
                    MessageBox.Show("Please enter land size", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;

            case "Store":
                objectToAdd = new Store();
                break;

            case "Apartment":
                objectToAdd = new Apartment();
                if (floorTBox.Text.ToString() != "")
                {
                    Apartment apartment = (Apartment)objectToAdd;
                    apartment.Floor = floorTBox.Text;
                }
                else
                {
                    MessageBox.Show("Please enter floor", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;

            case "Villa":
                objectToAdd = new Villa();
                break;

            case "RowHouse":
                objectToAdd = new RowHouse();
                break;

            default:
                MessageBox.Show("Please choose type of estate", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            SetLegalForm(objectToAdd);

            //Check so the correct fields are filled in,
            //then add/ replace with the new edited object to the list
            if (CheckFields())
            {
                MakeObjectToAdd(objectToAdd);
            }
            else
            {
                MessageBox.Show("Please enter text in all fields", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            objectToAdd.Id = idOfSelected;

            for (int i = 0; i < estateManager.Count; i++)
            {
                if (estateManager.GetAt(i).Id == idOfSelected)
                {
                    estateManager.ChangeAt(objectToAdd, i);
                }
            }

            ShowAllObjectsInListBox();
        }
Exemplo n.º 15
0
        //När användaren trycker på knappen Lägg till
        //Läs all indata från GUI i ett lokalt objekt av fastighet
        //Gör indata kontroll
        //Spara objektet i fastighetMngr
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Estate estate;  //holder for input - create in ReadInput

            //Send this object to ReadInput
            //for filling in values (input)
            //out tells ReadInput that the variable
            //is data out. All changes to this object
            //comes back here.
            //ReadInput creates all data used for the common fields of all estates.
            //The special for each are filled in later in the switch case.
            bool ok = ReadInput(out estate);

            if (ok)  //If all common data (in variable estate) is OK
            {
              // Now create a correct estate according to the type combo
              switch ((EstateType)cmbTyp.SelectedIndex)
              {
                case EstateType.WareHouse:
                  {
                    // Use a copy constructor to set a warehouse with common data
                    WareHouse  wHouse = new WareHouse(estate);
                    // If more data in GUI to fill in for this estate, do it here
                    //Then send it to the manager for adding to the list
                    estateMngr.Add(wHouse);
                    break;
                  }
                case EstateType.Villa:
                  {
                    // Same procedure all different types of estates
                    Villa vHouse = new Villa(estate);
                    // But here we need to add landSize size
                    bool landSizeOk = false;
                    vHouse.LandSize = ReadLandSize(out landSizeOk);
                    if (!landSizeOk)
                      return;
                    estateMngr.Add(vHouse);
                    break;
                  }
                case EstateType.Store:
                  {
                    Store store = new Store(estate);
                    estateMngr.Add(store);
                    break;
                  }
                case EstateType.RowHouse:
                  {
                    RowHouse rHouse = new RowHouse(estate);
                    // Here we need to add landSize size
                    bool gardenok = false;
                    rHouse.LandSize = ReadLandSize(out gardenok);
                    if (!gardenok)
                      return;
                    estateMngr.Add(rHouse);
                    break;
                  }
                case EstateType.Apartment:
                  {
                    Apartment apart = new Apartment(estate);
                    // We need to add floor
                    bool floorok = false;
                    apart.Floor = ReadFloor(out floorok);
                    if (!floorok)
                      return;
                    estateMngr.Add(apart);
                    break;
                  }
              }

              //Then Update the GUI
              UpdateResults();
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            // Version
            string strVersion = "Alpha 0.7";

            // Variablen
            string strEingabe;

            // Hauptmenü Überschrift
            HauptUeberschrift(strVersion);

            // Schleifen Beginn für das Spiel
            do
            {
                // Hauptmenü Benutzereingabe
                HauptBenutzereingaben();

                // Eingabe abfragen
                strEingabe = EingabeAbfragen();


                // Menüpunkte
                Console.Clear();
                switch (strEingabe)
                {
                // LEICHTES LEVEL
                case "l":
                {
                    if (neuesLevel == 3 || neuesLevel == 4)
                    {
                        strEingabe = BeginneNeuesLevel();
                        if (strEingabe == "y")
                        {
                            neuesLevel = 1;
                        }
                        else if (strEingabe == "n")
                        {
                            break;
                        }
                        else
                        {
                            FalscheEingabe();
                            break;
                        }
                    }

                    if (neuesLevel == 1)
                    {
                        // Ressourcen nicht noch einmal neu setzen
                        neuesLevel = 2;

                        // Ressourcen festlegen
                        holz     = 100;
                        getHolz  = 50;
                        eisen    = 100;
                        getEisen = 25;
                        gold     = 1000;
                        getGold  = 100;
                        haus     = 0;
                        villa    = 0;
                        // Gebäude kosten und Rohstoffe addition
                        kostenHausHolz   = 300;
                        kostenHausGold   = 1500;
                        addHausEisen     = 25;
                        addHausGold      = 50;
                        kostenVillaEisen = 200;
                        kostenVillaGold  = 2000;
                        addVillaHolz     = 20;
                        addVillaGold     = 150;
                    }
                    do
                    {
                        Console.WriteLine("Level Leicht");
                        ResMenue(holz, getHolz, eisen, getEisen, gold, getGold, haus, villa);
                        strEingabe = SpielerBenutzereingabeMenü();
                        Console.Clear();

                        switch (strEingabe)
                        {
                        case "h":
                        {
                            holz += getHolz;
                            Console.WriteLine($"Du hast {getHolz} Holz abgebaut");
                        }
                        break;

                        case "e":
                        {
                            eisen += getEisen;
                            Console.WriteLine($"Du hast {getEisen} Eisen abgebaut");
                        }
                        break;

                        case "g":
                        {
                            gold += getGold;
                            Console.WriteLine($"Du hast {getGold} Gold abgebaut");
                        }
                        break;

                        case "a":
                        {
                            Haus.HausKaufenMenue(kostenHausHolz, kostenHausGold, addHausEisen, addHausGold);
                        }
                        break;

                        case "v":
                        {
                            Villa.VillaKaufenMenue(kostenVillaEisen, kostenVillaGold, addVillaHolz, addVillaGold);
                        }
                        break;

                        case "b":
                        {
                            Environment.Exit(0);
                        }
                        break;

                        default:
                        {
                            if (strEingabe != "z")
                            {
                                FalscheEingabe();
                            }
                        }
                        break;
                        }
                    } while (strEingabe != "z");
                }
                break;

                // NORMALES LEVEL
                case "n":
                {
                    if (neuesLevel == 2 || neuesLevel == 4)
                    {
                        strEingabe = BeginneNeuesLevel();
                        if (strEingabe == "y")
                        {
                            neuesLevel = 1;
                        }
                        else if (strEingabe == "n")
                        {
                            break;
                        }
                        else
                        {
                            FalscheEingabe();
                            break;
                        }
                    }
                    if (neuesLevel == 1)
                    {
                        // Ressourcen nicht noch einmal neu setzen
                        neuesLevel = 3;

                        // Ressourcen festlegen
                        holz     = 100;
                        getHolz  = 50;
                        eisen    = 100;
                        getEisen = 25;
                        gold     = 1000;
                        getGold  = 100;
                        haus     = 0;
                        villa    = 0;
                        // Gebäude kosten und Rohstoffe addition
                        kostenHausHolz   = 600;
                        kostenHausGold   = 3000;
                        addHausEisen     = 25;
                        addHausGold      = 50;
                        kostenVillaEisen = 400;
                        kostenVillaGold  = 4000;
                        addVillaHolz     = 20;
                        addVillaGold     = 150;
                    }
                    do
                    {
                        Console.WriteLine("Level Normal");
                        ResMenue(holz, getHolz, eisen, getEisen, gold, getGold, haus, villa);
                        strEingabe = SpielerBenutzereingabeMenü();
                        Console.Clear();

                        switch (strEingabe)
                        {
                        case "h":
                        {
                            holz += getHolz;
                            Console.WriteLine($"Du hast {getHolz} Holz abgebaut");
                        }
                        break;

                        case "e":
                        {
                            eisen += getEisen;
                            Console.WriteLine($"Du hast {getEisen} Eisen abgebaut");
                        }
                        break;

                        case "g":
                        {
                            gold += getGold;
                            Console.WriteLine($"Du hast {getGold} Gold abgebaut");
                        }
                        break;

                        case "a":
                        {
                            Haus.HausKaufenMenue(kostenHausHolz, kostenHausGold, addHausEisen, addHausGold);
                        }
                        break;

                        case "v":
                        {
                            Villa.VillaKaufenMenue(kostenVillaEisen, kostenVillaGold, addVillaHolz, addVillaGold);
                        }
                        break;

                        case "b":
                        {
                            Environment.Exit(0);
                        }
                        break;

                        default:
                        {
                            if (strEingabe != "z")
                            {
                                FalscheEingabe();
                            }
                        }
                        break;
                        }
                    } while (strEingabe != "z");
                }
                break;

                // SCHWERES LEVEL
                case "s":
                {
                    if (neuesLevel == 2 || neuesLevel == 3)
                    {
                        strEingabe = BeginneNeuesLevel();
                        if (strEingabe == "y")
                        {
                            neuesLevel = 1;
                        }
                        else if (strEingabe == "n")
                        {
                            break;
                        }
                        else
                        {
                            FalscheEingabe();
                            break;
                        }
                    }

                    if (neuesLevel == 1)
                    {
                        // Ressourcen nicht noch einmal neu setzen
                        neuesLevel = 4;

                        // Ressourcen festlegen
                        holz     = 100;
                        getHolz  = 20;
                        eisen    = 100;
                        getEisen = 15;
                        gold     = 1000;
                        getGold  = 50;
                        haus     = 0;
                        villa    = 0;
                        // Gebäude kosten und Rohstoffe addition
                        kostenHausHolz   = 900;
                        kostenHausGold   = 4500;
                        addHausEisen     = 10;
                        addHausGold      = 20;
                        kostenVillaEisen = 600;
                        kostenVillaGold  = 6000;
                        addVillaHolz     = 10;
                        addVillaGold     = 30;
                    }
                    do
                    {
                        Console.WriteLine("Level Schwer");
                        ResMenue(holz, getHolz, eisen, getEisen, gold, getGold, haus, villa);
                        strEingabe = SpielerBenutzereingabeMenü();
                        Console.Clear();

                        switch (strEingabe)
                        {
                        case "h":
                        {
                            holz += getHolz;
                            Console.WriteLine($"Du hast {getHolz} Holz abgebaut");
                        }
                        break;

                        case "e":
                        {
                            eisen += getEisen;
                            Console.WriteLine($"Du hast {getEisen} Eisen abgebaut");
                        }
                        break;

                        case "g":
                        {
                            gold += getGold;
                            Console.WriteLine($"Du hast {getGold} Gold abgebaut");
                        }
                        break;

                        case "a":
                        {
                            Haus.HausKaufenMenue(kostenHausHolz, kostenHausGold, addHausEisen, addHausGold);
                        }
                        break;

                        case "v":
                        {
                            Villa.VillaKaufenMenue(kostenVillaEisen, kostenVillaGold, addVillaHolz, addVillaGold);
                        }
                        break;

                        case "b":
                        {
                            Environment.Exit(0);
                        }
                        break;

                        default:
                        {
                            if (strEingabe != "z")
                            {
                                FalscheEingabe();
                            }
                        }
                        break;
                        }
                    } while (strEingabe != "z");
                }
                break;

                // CREDITS
                case "c":
                {
                    Credits(strVersion);
                    Benutzereingabe();
                }
                break;

                // LEVEL INFO
                case "i":
                {
                    LevelInfo();
                    Benutzereingabe();
                }
                break;

                // HI I BIMS DER BEENDER
                case "b":
                {
                    Environment.Exit(0);
                }
                break;

                // FALSCHE EINGABE?
                default:
                {
                    FalscheEingabe();
                }
                break;
                }
            } while (strEingabe != "b");
        }
Exemplo n.º 17
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            string cat     = CategoryCB.Text;
            string type    = TypeCB.Text;
            string country = CountryCB.Text;
            string city    = CityTB.Text;
            string street  = StreetTB.Text;
            string zip     = ZipTB.Text;
            string spec    = SpecTB.Text;

            Adress Aobj = new Adress(city, street, zip, country);

            try
            {
                if (!string.IsNullOrEmpty(cat) && !string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(street) && !string.IsNullOrEmpty(zip))
                {
                    if (type == "Appartment")
                    {
                        Appartment Bobj = new Appartment(cat, Aobj, spec, type);
                        Em.Add(Bobj);
                        MessageBox.Show("Added");
                        Update();
                    }
                    if (type == "House")
                    {
                        House Bobj = new House(cat, Aobj, spec, type);
                        Em.Add(Bobj);

                        MessageBox.Show("Added");

                        Update();
                    }
                    if (type == "Villa")
                    {
                        Villa Bobj = new Villa(cat, Aobj, spec, type);
                        Em.Add(Bobj);

                        MessageBox.Show("Added");

                        Update();
                    }
                    if (type == "Townhouse")
                    {
                        Townhouse Bobj = new Townhouse(cat, Aobj, spec, type);
                        Em.Add(Bobj);

                        MessageBox.Show("Added");

                        Update();
                    }
                    if (type == "Shop")
                    {
                        Shop Bobj = new Shop(cat, Aobj, spec, type);
                        Em.Add(Bobj);

                        MessageBox.Show("Added");

                        Update();
                    }
                    if (type == "Warehouse")
                    {
                        Warehouse Bobj = new Warehouse(cat, Aobj, spec, type);
                        Em.Add(Bobj);

                        MessageBox.Show("Added");

                        Update();
                    }
                }
                else
                {
                    MessageBox.Show("Please fill all the forms!!");
                }
            }

            catch (Exception exc)
            {
                throw exc;
            }
        }
Exemplo n.º 18
0
        private Estate CopyEstate(Estate estate)
        {
            Estate estateCopy;

            switch (estate.GetType().Name)
            {
            case "House":
                estateCopy = new House()
                {
                    EstateId  = estate.EstateId,
                    LegalForm = estate.LegalForm,
                    Address   = estate.Address
                };
                break;

            case "Apartment":
                estateCopy = new Apartment()
                {
                    EstateId  = estate.EstateId,
                    LegalForm = estate.LegalForm,
                    Address   = estate.Address
                };
                break;

            case "Shop":
                estateCopy = new Shop()
                {
                    EstateId  = estate.EstateId,
                    LegalForm = estate.LegalForm,
                    Address   = estate.Address
                };
                break;

            case "Townhouse":
                estateCopy = new Townhouse()
                {
                    EstateId  = estate.EstateId,
                    LegalForm = estate.LegalForm,
                    Address   = estate.Address
                };
                break;

            case "Villa":
                estateCopy = new Villa()
                {
                    EstateId  = estate.EstateId,
                    LegalForm = estate.LegalForm,
                    Address   = estate.Address
                };
                break;

            case "Warehouse":
                estateCopy = new Warehouse()
                {
                    EstateId  = estate.EstateId,
                    LegalForm = estate.LegalForm,
                    Address   = estate.Address
                };
                break;

            default:
                estateCopy = null;
                break;
            }
            return(estateCopy);
        }
Exemplo n.º 19
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            RealEstateObject objectToAdd;

            //Create the type of object according to what type of estate it is
            string typeOfEstate = typeOfEstateCBox.GetItemText(typeOfEstateCBox.SelectedItem);

            switch (typeOfEstate)
            {
            case "WareHouse":
                objectToAdd = new Warehouse();
                if (landSizeTBox.Text.ToString() != "")
                {
                    Warehouse warehouse = (Warehouse)objectToAdd;
                    warehouse.LandSizeInSquareMeters = Int32.Parse(landSizeTBox.Text);
                }
                else
                {
                    MessageBox.Show("Please enter land size", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;

            case "Store":
                objectToAdd = new Store();
                break;

            case "Apartment":
                objectToAdd = new Apartment();
                if (floorTBox.Text.ToString() != "")
                {
                    Apartment apartment = (Apartment)objectToAdd;
                    apartment.Floor = floorTBox.Text;
                }
                else
                {
                    MessageBox.Show("Please enter floor", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;

            case "Villa":
                objectToAdd = new Villa();
                break;

            case "RowHouse":
                objectToAdd = new RowHouse();
                break;

            default:
                MessageBox.Show("Please choose type of estate", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            SetLegalForm(objectToAdd);

            //Check so the correct fields are filled in,
            //then add the object to the list
            if (CheckFields())
            {
                MakeObjectToAdd(objectToAdd);
            }
            else
            {
                MessageBox.Show("Please enter text in all fields", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            objectToAdd.Id = id;

            estateManager.Add(objectToAdd);
            ShowAllObjectsInListBox();
            ClearFields();
            id++;
        }