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); }
/// <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(); }
/// <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(); }
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); }
static void Main(string[] args) { var cottage = new Cottage ( 300, 320, 7, 2013, 12, 900000 ); var apartment = new Apartment( 100, 30, 3, 1998, 25, 43000 ); var townhouse = new Townhouse (3000, 240, 10, 2016, 3, 1200000 ); var calculator = new InsuranceŠ”alculator(); Console.WriteLine($"{nameof(cottage)} : {calculator.GetInsurance(cottage):F2}"); Console.WriteLine($"{nameof(apartment)} : {calculator.GetInsurance(apartment):F2}"); Console.WriteLine($"{nameof(townhouse)} : {calculator.GetInsurance(townhouse):F2}"); Console.ReadKey(); }
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; } }
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); }