private void ShowTextBoxes(string str) { HideTextBoxes(); // show global atributts Name_textBox.Show(); Name_input_textBox.Show(); Mobile_textBox.Show(); Mobile_input_textBox.Show(); Email_OR_Address_textBox.Show(); Email_OR_Address_input_textBox.Show(); Tax_Number_textBox.Show(); Tax_Number_input_textBox.Show(); if (str.Equals("tenant")) { // Show Tenant only attributs Email_OR_Address_textBox.Text = "Email:"; Apartment_textBox.Show(); if (AddTenant || edit) { EnableAllWriteTextboxes(); apart_comboBox.Show(); } else { DisableAllWriteTextboxes(); apart_input_textBox.Show(); } } else if (str.Equals("sp")) { // Show Service Provider only attributs Email_OR_Address_textBox.Text = "Address:"; Type_textBox.Show(); if (AddSP || edit) { EnableAllWriteTextboxes(); type_comboBox.Show(); //TODO fill dropdown } else { DisableAllWriteTextboxes(); Type_input_textBox.Show(); } } }
//when "Garage?" is checked, reveals "Attached" checkbox and vice versa private void Garage_exists(object sender, EventArgs e) //good :) { if (Garage_checkbox.Checked == true) //if the property has a garage { Attached_checkbox.Show(); //reveal "Attached?" checkbox Apartment_textBox.Hide(); //hide the "Apt. #" textbox Apt_label.Hide(); //hide the label for the "Apt. #" textbox Floors_NUD.Maximum = 10; //set max floors to 10 } else if (Garage_checkbox.Checked == false) //if the property does not have a garage { Attached_checkbox.Checked = false; //for when "Garage?" is unchecked, "Attached?" also becomes unchecked Attached_checkbox.Hide(); //hide "Attached?" checkbox Apartment_textBox.Show(); //show the "Apt. #" textbox Apt_label.Show(); //show the label for the "Apt. #" textbox Floors_NUD.Maximum = 10; //set max floors to 10 } }
private void HideTextBoxes() { // Hide Contact Info Name_textBox.Hide(); Name_input_textBox.Hide(); Mobile_textBox.Hide(); Mobile_input_textBox.Hide(); Email_OR_Address_textBox.Hide(); Email_OR_Address_input_textBox.Hide(); Type_textBox.Hide(); Apartment_textBox.Hide(); Type_input_textBox.Hide(); apart_input_textBox.Hide(); apart_comboBox.Hide(); type_comboBox.Hide(); Tax_Number_textBox.Hide(); Tax_Number_input_textBox.Hide(); }
//adds a new property to the list of properties private void AddProperty_Click(object sender, EventArgs e) //good :) { //make sure community is selected and street address is entered (others have default values) if (selectedCommunity.Name == "") //no community was selected { Output_rtbox.Text = "Please select a community first.\n"; return; //go back to form1` 7 } else if (StreetAddr_textBox.Text == "") //no street address was entered { Output_rtbox.Text = "Please enter the street address for the new property.\n"; return; //go back to form } Output_rtbox.Clear(); // ensure that the property that user wants to add doesn't already exist foreach (Property prop in selectedCommunity.props) //go through all properties in selected community { // check street # if (StreetAddr_textBox.Text.ToLower() == prop.StreetAddr.ToLower()) //if property at the address user entered is found { // street # and unit number for apartment if (prop is Apartment) //check if property is an apartment { Apartment apartment = prop as Apartment; if (Apartment_textBox.Text == "") //if user doesn't enter anything for the unit # { Output_rtbox.Text = "Please enter a unit number for " + apartment.StreetAddr + ".\n"; return; //go back to form } if (Apartment_textBox.Text.ToLower() == apartment.Unit.ToLower()) //apartment with same unit entered already exists { Output_rtbox.Text = "Sorry, " + apartment.StreetAddr + " apt# " + apartment.Unit + " already exists in " + selectedCommunity + ".\n"; return; //go back to form } //string message = StreetAddr_textBox.Text + Apartment_textBox.Text + "\n\nIs this correct?"; } //same street address, not an apartment = duplicate property else { Output_rtbox.Text = "Sorry, " + prop.StreetAddr + " already exists in " + selectedCommunity + ".\n"; return; //go back to form } } //ask user to confirm their input string message = StreetAddr_textBox.Text + Apartment_textBox.Text + "\nSquare Footage: " + Squarefootage_NUD.Value + "\nBedrooms: " + Bedrooms_NUD.Value + "\nBaths: " + Baths_NUD.Value + "\nFloors: " + Floors_NUD.Value + "\nGarage: " + Garage_checkbox.Checked + " Attached: " + Attached_checkbox.Checked + "\n\nIs this correct?"; //display user's input for them to confirm string caption = "Add Property"; //title of message box MessageBoxButtons buttons = MessageBoxButtons.YesNo; //yes and no buttons DialogResult result; result = MessageBox.Show(message, caption, buttons); //display message box if (result == DialogResult.No) //if user says information is not correct { return; //go back so user can correct it } else if (result == DialogResult.Yes) //if user says the information is correct { break; //continue to adding the property } } string[] argIn = new string[15]; // argument list for adding the property string zip = ""; // zip string state = ""; // state uint i = 1; // for unique id bool found = false; // found unique id // find uniqe id for new property & fill in state and zip attributes foreach (Property property in selectedCommunity.props) { // not sure if theres another way to do this because we need the state and zip from the community selected // we could hard code it to be only illiniois and a default zip state = property.State; // state attribute zip = property.Zip; // zip attribute // fine unique id if (property.Id != i) { found = true; break; } i++; } // if we went through all properties and did not find a unique id we can just add 1 to get a id if (!found) { i++; } //add property to selected community try //try-catch in case anything goes wrong with adding the property { // append values to argument list argIn[0] = i.ToString(); // id argIn[1] = "0"; // owner id argIn[2] = "0"; // x argIn[3] = "0"; // y argIn[4] = StreetAddr_textBox.Text; // street addr argIn[5] = selectedCommunity.Name; // city argIn[6] = state; // state argIn[7] = zip; // zip argIn[8] = "true"; // for sale argIn[9] = Bedrooms_NUD.Value.ToString(); // bedrooms argIn[10] = Baths_NUD.Value.ToString(); // baths argIn[11] = Squarefootage_NUD.Value.ToString(); // sqft // if property is an house if (Apartment_textBox.Text == "")// is a house { // is garage there and if so, is it attached? if (Garage_checkbox.Checked) // checked garage { argIn[12] = "T"; // value must be t or f (cannot be true or false) if (Attached_checkbox.Checked) { argIn[13] = "T"; // attached garage } else { argIn[13] = "F"; //unattached garage } } else { argIn[12] = "F"; //no garage } argIn[14] = Floors_NUD.Value.ToString(); // floors selectedCommunity.props.Add(new House(argIn)); //add the house foreach (Property property in selectedCommunity.props) //check that the house has been added { if (property.Id == i) { Output_rtbox.Text += property.StreetAddr + " has been successfully added to " + selectedCommunity.Name + ".\n"; break; //break out so refresh happens at the end } } } // if it is an apartment else { argIn[12] = Apartment_textBox.Text; // unit value selectedCommunity.props.Add(new Apartment(argIn)); //add apartment foreach (Property property in selectedCommunity.props) //check that apartment has been added { if (property.Id == i) { Output_rtbox.Text += property.StreetAddr + " has been successfully added to " + selectedCommunity.Name + ".\n"; break; //break out so refresh happens at the end } } } Refresh(communityID); //refresh list to show new property //clear input StreetAddr_textBox.Clear(); //clear street address input box Apartment_textBox.Clear(); //clear apt # input box Squarefootage_NUD.Value = 500; //reset the sqare footage value Bedrooms_NUD.Value = 1; //reset the bedrooms value Baths_NUD.Value = 1; //reset the baths value Floors_NUD.Value = 1; //reset the floors value Garage_checkbox.Checked = false; //reset the garage checkbox Attached_checkbox.Checked = false; //reset the attached checkbox } // catch all errors so program doesnt crash catch { Output_rtbox.Text += "There was an error adding the property.\n"; //error message return; } }