예제 #1
0
        //CompareTo
        public int CompareTo(Property beta)
        {
            // Always check for null
            if (beta == null)
            {
                throw new Exception("ERROR: CompareTo argument is null.");
            }

            Apartment rightOp = beta as Apartment;

            // Next, check if the typecast was successful or not
            if (rightOp != null)
            {
                return(Unit.CompareTo(rightOp.Unit));
            }
            // else they are not a Property object
            else
            {
                throw new Exception("ERROR: Apartment object compared to non-Apartment object.");
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: cstojan/CSCI-473
        //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;
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: cstojan/CSCI-473
        // 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;
        }