Beispiel #1
0
 //set a selected resident as the owner of a selected property
 private void BuyProperty_Click(object sender, EventArgs e) //good
 {
     //check to make sure a community has been selected first
     if (selectedCommunity.Id == 0)
     {
         Output_rtbox.Text += "Please select a community first.\n";
         return;
     }
     //check to make sure a resident and a property have been selected otherwise, "Must select a resident and a for-sale property"
     if ((Residence_listbox.SelectedIndex == -1) || (Person_listbox.SelectedIndex == -1))
     {
         Output_rtbox.Text += "Please select a for-sale property and the person who is purchasing the property.\n";
         return;
     }
     //check to make sure the property is for sale otherwise, "Sorry, that property is not for-sale"
     if (selectedProperty.ForSale == false)
     {
         Output_rtbox.Text += "Sorry, that property is not for-sale at this time.\n";
         return;
     }
     //check to make sure that the selected resident does not live at the selected property already otherwise, "Sorry, you already live here"
     if (selectedPerson.Id == selectedProperty.OwnerID)
     {
         Output_rtbox.Text += "You already own that property.\n";
         return;
     }
     //set the selected resident as the owner of the selected property
     Output_rtbox.Clear();
     selectedProperty.OwnerID = selectedPerson.Id; //set selected person as the owner for selected property
     selectedProperty.ForSale = false;             //property is no longer for-sale
     Refresh(selectedCommunity.Id);
     Output_rtbox.Text += selectedPerson.FirstName + " " + selectedPerson.LastName + " is now the owner of " +
                          selectedProperty.StreetAddr + ".\n";
 }
Beispiel #2
0
 //when the user selects a resident in the person listbox
 private void Person_listbox_MouseClick(object sender, MouseEventArgs e)
 {
     Output_rtbox.Clear();                                                  //clear output box
     selectedPerson     = Person_listbox.SelectedItem as Person;            //set selected person
     Output_rtbox.Text += selectedPerson.ToString() + " who resides at:\n"; //ouput person's info
     for (int i = 0; i < selectedPerson.ResidenceIds.Length; i++)
     {
         foreach (Property property in selectedCommunity.props)
         {
             if (selectedPerson.ResidenceIds[i] == property.Id)
             {
                 Output_rtbox.Text += "     " + property.StreetAddr + "\n"; //display where person lives
                 break;
             }
         }
     }
     Output_rtbox.Text += "###END OUTPUT###\n";
 }
Beispiel #3
0
 //check which community was selected
 private void Community_button_CheckedChanged(object sender, EventArgs e) //good :)
 {
     Output_rtbox.Clear();                                                //clear anything in the output box
     // set the selected community to whichever is checked
     foreach (Community comm in allCommunities)
     {
         if (DeKalb_button.Checked == true && DeKalb_button.Text == comm.Name)          //if dekalb is selected and dekalb community is found
         {
             selectedCommunity = comm;                                                  //set selected community
             communityID       = comm.Id;                                               //set community id
         }
         else if (Sycamore_button.Checked == true && Sycamore_button.Text == comm.Name) //if sycamore is selected and sycamore community is found
         {
             selectedCommunity = comm;                                                  //set selected community
             communityID       = comm.Id;                                               //set community id
         }
     }
     Output_rtbox.Text += selectedCommunity.Name + " displayed.\n" +
                          "Population: " + selectedCommunity.Poplation + "\n"; //tell user which town is being displayed
     Refresh(communityID);
 }
Beispiel #4
0
        //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;
            }
        }
Beispiel #5
0
        // residence mouse click action event
        private void Residence_listbox_MouseClick(object sender, MouseEventArgs e)
        {
            // clear output box
            Output_rtbox.Clear();
            // output which residence it is
            selectedProperty = Residence_listbox.SelectedItem as Property;

            Output_rtbox.Text += "Residents Living at ";
            if (Residence_listbox.SelectedItem is House) //if the selected property is a house
            {
                // who is owned by
                selectedHouse      = Residence_listbox.SelectedItem as House;
                Output_rtbox.Text += selectedHouse.StreetAddr + " ";
                Output_rtbox.Text += "Owned by ";
                foreach (Person person in selectedCommunity.residents)
                {
                    if (person.Id == selectedHouse.OwnerID)
                    {
                        Output_rtbox.Text += person.FullName() + ":\n";
                        Output_rtbox.Text += "------------------------------------\n";
                        break;
                    }
                }
                // list people living there
                foreach (Person person in selectedCommunity.residents) //go through all residents in selected community
                {
                    for (int i = 0; i < person.ResidenceIds.Length; i++)
                    {
                        if (person.ResidenceIds[i] == selectedHouse.Id)
                        {
                            Output_rtbox.Text += person.FullName() + "\n";
                            break;
                        }
                    }
                }
            }
            else if (Residence_listbox.SelectedItem is Apartment) //if selected property is an apartment
            {
                // who owns the apartment
                selectedApartment  = Residence_listbox.SelectedItem as Apartment;
                Output_rtbox.Text += selectedApartment.StreetAddr + " # " + selectedApartment.Unit + " ";
                Output_rtbox.Text += "Owned by ";
                foreach (Person person in selectedCommunity.residents) //go through all the people in the selected community
                {
                    if (person.Id == selectedApartment.OwnerID)        //if person owns the property
                    {
                        Output_rtbox.Text += person.FullName() + ":\n";
                        Output_rtbox.Text += "------------------------------------\n";
                        break;
                    }
                }
                // output residents
                foreach (Person person in selectedCommunity.residents) //go through all the people in the selected community
                {
                    for (int i = 0; i < person.ResidenceIds.Length; i++)
                    {
                        if (person.ResidenceIds[i] == selectedApartment.Id)
                        {
                            Output_rtbox.Text += person.FullName() + "\n";
                            break;
                        }
                    }
                }
            }
            Output_rtbox.Text += "###End Output###\n\n";
            return;
        }