private void btnAdd_Click(object sender, EventArgs e) { // error check to make sure only ints or doubles were entered into the bedroom and rental boxes if (CheckForNumberEntered(txtBedrooms.Text) == false) { ErrorMessageBeds(); return; } if (CheckForNumberEntered(txtPrice.Text) == false) { ErrorMessageRent(); return; } // check to make sure something has been selected from the combo box and error message if not if (cmbStatus.SelectedIndex < 0) { MessageBox.Show("Please select the property condition"); return; } else { //extract the info from the boxes and load them into variables to add the property array propNumber = txtPropertyNumber.Text.ToUpper(); suburb = txtSuburb.Text; bedrooms = int.Parse(txtBedrooms.Text); rental = double.Parse(txtPrice.Text); status = cmbStatus.SelectedItem.ToString(); // error check to ensure all forms had been entered correctly and error message if not if (propNumber == "" || suburb == "" || bedrooms < 0 || rental < 0) { ErrorMessageValues(); return; } // loop to check for the next empty space in the array and to add the property to that space for (int i = 0; i < propertyArray.Length; i++) { if (propertyArray[i] == null) { propertyArray[i] = new MyProperty_(propNumber, suburb, bedrooms, rental, status); break; } if (i == propertyArray.Length - 1) { MessageBox.Show("Array Full!"); return; } } MessageBox.Show("Property Added"); ClearTextBoxes(); } }
private void Form1_Load(object sender, EventArgs e) { txtPropertyNumber.Focus(); // load the array with the 4 initial values propertyArray[0] = new MyProperty_ { PropertyNumber = "PET1", Suburb = "Petersham", Bedrooms = 1, RentalPrice = 160, Status = "New" }; propertyArray[1] = new MyProperty_ { PropertyNumber = "STA1", Suburb = "Stanmore", Bedrooms = 3, RentalPrice = 240, Status = "Renovated" }; propertyArray[2] = new MyProperty_ { PropertyNumber = "STA2", Suburb = "Stanmore", Bedrooms = 2, RentalPrice = 70, Status = "Old" }; propertyArray[3] = new MyProperty_ { PropertyNumber = "PET2", Suburb = "Petersham", Bedrooms = 2, RentalPrice = 190, Status = "Renovated" }; }