/// <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(); }
public bool UpdateEstate(Estate estate) { int index = SearchEstateById(estate.EstateId); if (index < 0) { return(false); } Estate estateCopy = CopyEstate(estate); return(_estateManager.ChangeAt(estateCopy, index)); }
public void UpdateEstate(int id, String estateType, Address address, String legalForm, Image imgEstate) { Estate estate = GetEstate(id); estate.GetAddress().SetCountry((Countries)Enum.Parse(typeof(Countries), address.GetCountry().ToString())); estate.GetAddress().SetCity(address.GetCity()); estate.GetAddress().SetStreet(address.GetStreet()); estate.GetAddress().SetZipCode(address.GetZipCode()); estate.SetLegal((Legal)Enum.Parse(typeof(Legal), legalForm)); estate.SetImage(imgEstate); estates.ChangeAt(estate, GetPosition(id)); ui.CreateMode(true); ui.AddToTable(estate); }
private void AddModBtn_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.ChangeAt(Bobj, listBox1.SelectedIndex); AddModBtn.Enabled = false; AddBtn.Enabled = true; Update(); } if (type == "House") { House Bobj = new House(cat, Aobj, spec, type); Em.ChangeAt(Bobj, listBox1.SelectedIndex); AddModBtn.Enabled = false; AddBtn.Enabled = true; Update(); } if (type == "Villa") { Villa Bobj = new Villa(cat, Aobj, spec, type); Em.ChangeAt(Bobj, listBox1.SelectedIndex); AddModBtn.Enabled = false; AddBtn.Enabled = true; Update(); } if (type == "Townhouse") { Townhouse Bobj = new Townhouse(cat, Aobj, spec, type); Em.ChangeAt(Bobj, listBox1.SelectedIndex); AddModBtn.Enabled = false; AddBtn.Enabled = true; Update(); } if (type == "Shop") { Shop Bobj = new Shop(cat, Aobj, spec, type); Em.ChangeAt(Bobj, listBox1.SelectedIndex); AddModBtn.Enabled = false; AddBtn.Enabled = true; Update(); } if (type == "Warehouse") { Warehouse Bobj = new Warehouse(cat, Aobj, spec, type); Em.ChangeAt(Bobj, listBox1.SelectedIndex); AddModBtn.Enabled = false; AddBtn.Enabled = true; Update(); } } else { MessageBox.Show("Please fill all the forms!!"); } } catch (Exception exc) { throw exc; } }
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(); }