Exemplo n.º 1
0
        public Community Active_Files(string personFile, string houseFile, string apartmentFile, string commName)
        {
            //Dekalb and Sycamore Community
            Community Community = new Community(99999, commName, 0);

            // if PersonFile exists
            if (File.Exists(personFile))
            {
                // PersonFile declares here
                using (StreamReader sr = File.OpenText(personFile))
                {
                    // Split the data by '\n' and save them as 1d array
                    string[] input = sr.ReadToEnd().Split('\n');
                    int      i     = 0;

                    do
                    {
                        // Split the data from input[] and save them in iInput[]
                        string[] iInput = input[i].Split('\t');

                        var id    = UInt32.Parse(iInput[0]);
                        var lName = iInput[1];
                        var fName = iInput[2];
                        var occ   = iInput[3];
                        var year  = Int32.Parse(iInput[4]);
                        var month = Int32.Parse(iInput[5]);
                        var day   = Int32.Parse(iInput[6]);
                        var dt    = new DateTime(year, month, day);
                        var resId = iInput[7];

                        Community.Residents.Add(new Person(id, dt, lName, fName, occ, resId));
                        i++;
                    } while (i < input.Length); // if i less than input[]'s length

                    sr.Close();
                }
            }

            // if HouseFile exists
            if (File.Exists(houseFile))
            {
                using (StreamReader sr = File.OpenText(houseFile))
                {
                    // split data by '\n' and save them in input array
                    string[] input = sr.ReadToEnd().Split('\n');
                    int      i     = 0;

                    do
                    {
                        // split data by '\t' and save them in iInput array
                        string[] iInput  = input[i].Split('\t');
                        var      id      = UInt32.Parse(iInput[0]);
                        var      oId     = UInt32.Parse(iInput[1]);
                        var      x       = UInt32.Parse(iInput[2]);
                        var      y       = UInt32.Parse(iInput[3]);
                        var      stAddr  = iInput[4];
                        var      city    = iInput[5];
                        var      state   = iInput[6];
                        var      zip     = iInput[7];
                        var      forSale = iInput[8].Equals("T");
                        var      bedRoom = UInt32.Parse(iInput[9]);
                        var      bath    = UInt32.Parse(iInput[10]);
                        var      sqft    = UInt32.Parse(iInput[11]);
                        var      garage  = iInput[12].Equals("T");
                        var      aGarage = iInput[13].Equals("T");
                        var      floor   = UInt32.Parse(iInput[14]);

                        House house = new House(id, x, y, oId, stAddr, city, state,
                                                zip, forSale, bedRoom, bath, sqft, garage, aGarage, floor);
                        Community.Props.Add(house);
                        i++;
                    } while (i < input.Length); // if i less than input array's length

                    sr.Close();
                }
            }

            // if ApartmentFile exists
            if (File.Exists(apartmentFile))
            {
                using (StreamReader sr = File.OpenText(apartmentFile))
                {
                    // split data by '\n' and save them in input array
                    string[] input = sr.ReadToEnd().Split('\n');
                    int      i     = 0;

                    do
                    {
                        // split data by '\t' and save them in input array
                        string[] iInput  = input[i].Split('\t');
                        var      id      = UInt32.Parse(iInput[0]);
                        var      oId     = UInt32.Parse(iInput[1]);
                        var      x       = UInt32.Parse(iInput[2]);
                        var      y       = UInt32.Parse(iInput[3]);
                        var      stAddr  = iInput[4];
                        var      city    = iInput[5];
                        var      state   = iInput[6];
                        var      zip     = iInput[7];
                        var      forSale = iInput[8].Equals("T");
                        var      bedRoom = UInt32.Parse(iInput[9]);
                        var      bath    = UInt32.Parse(iInput[10]);
                        var      sqft    = UInt32.Parse(iInput[11]);
                        var      unit    = iInput[12];

                        Apartment apartment = new Apartment(id, x, y, oId, stAddr, city, state, zip, forSale, bedRoom,
                                                            bath, sqft, unit);
                        Community.Props.Add(apartment);
                        i++;
                    } while (i < input.Length); // do if i less than input array's length

                    sr.Close();
                }
            }

            return(Community);
        }
Exemplo n.º 2
0
        private void AddAProperty(Community comm)
        {
            //temp variables
            bool IsGood = false;

            //keep checking and regenerating till a good number is found
            while (IsGood == false)
            {
                //make new random number
                int rnd = GenerateRandomNo();

                foreach (var res in comm.Props)
                {
                    if (res.Id == rnd)
                    {
                        break;
                    }
                    else
                    {
                        IsGood = true;
                    }
                }
                if (IsGood == true)
                {
                    //Start assigning values to the data for merging to new property
                    uint   id     = (uint)(int)rnd; //convert int to uint
                    uint   x      = 9999;           //we dont plan to use these for this assignment according to rogness
                    uint   y      = 9999;           //we dont plan to use these for this assignment according to rogness
                    uint   oId    = default(uint);  //0 or default value
                    string stAddr = StreetAddressTextbox.Text.ToString();
                    string city   = null;
                    string zip    = null;
                    if (DekalbRadioButton.Checked)
                    {
                        city = "DeKalb";
                        zip  = "60115";
                    }
                    else if (SycamoreRadioButton.Checked)
                    {
                        city = "Sycamore";
                        zip  = "60178";
                    }
                    string  state    = "Illinois";
                    bool    forSale  = true;
                    decimal tempbr   = BedroomsUpDown.Value;
                    uint    bedRoom  = (uint)(decimal)tempbr;
                    decimal tempb    = BathsUpDown.Value;
                    uint    bath     = (uint)(decimal)tempb;
                    decimal tempsqft = SquareFtUpDown.Value;
                    uint    sqft     = (uint)(decimal)tempsqft;
                    decimal tempf    = FloorsUpDown.Value;
                    uint    floor    = (uint)(decimal)tempf;



                    //check wether were adding a apartment or a house
                    if (String.IsNullOrEmpty(AptNumTextbox.Text))
                    {
                        bool garage  = false;
                        bool aGarage = false;
                        //check if it has a garage
                        if (GarageCheckbox.Checked == true)
                        {
                            garage = true;
                        }
                        if (AttachedCheckbox.Checked == true)
                        {
                            aGarage = true;
                        }

                        House house = new House(id, x, y, oId, stAddr, city, state, zip, forSale, bedRoom, bath, sqft, garage, aGarage, floor);
                        comm.Props.Add(house);
                        OutputTextbox.AppendText("Success! A new property at " + stAddr + " has been added to " + comm.Name + "!" + Environment.NewLine);
                        CommunityListShowingRefresh(currentCommunity);
                        //clear everything
                        SnapProperty();
                    }
                    else
                    {
                        //set the properties unit value
                        var unit = AptNumTextbox.Text;

                        Apartment apartment = new Apartment(id, x, y, oId, stAddr, city, state, zip, forSale, bedRoom, bath, sqft, unit);
                        comm.Props.Add(apartment);
                        OutputTextbox.AppendText("Success! A new property at " + stAddr + " has been added to " + comm.Name + "!" + Environment.NewLine);
                        CommunityListShowingRefresh(currentCommunity);
                        //clear everything
                        SnapProperty();
                    }
                }
            }
        }
Exemplo n.º 3
0
 //output the amount of residents
 private void DisplayResidentAmounts(Community comm)
 {
     OutputTextbox.AppendText("There are " + comm.Population + " people living in " + comm.Name + "." + Environment.NewLine);
 }
Exemplo n.º 4
0
        private void AddToProperty(Community comm)
        {
            //temp variables
            bool IsGood = false;

            //keep checking and regenerating till a good number is found
            while (IsGood == false)
            {
                //make new random number
                int rnd = GenerateRandomNo();

                foreach (var res in comm.Residents)
                {
                    if (res.Id == rnd)
                    {
                        break;
                    }
                    else
                    {
                        IsGood = true;
                    }
                }

                //double chacking to make sure it was good
                if (IsGood == true)
                {
                    //take in the infroamtion
                    string[] splitstring = NameTextbox.Text.ToString().Split(' ');
                    string   fName       = splitstring[0];
                    string   lName       = splitstring[1];
                    string   occ         = OccupationTextbox.Text.ToString();
                    DateTime dt          = BirthdayPicker.Value;
                    //convert int to uint
                    uint id = (uint)(int)rnd;

                    //find the resident id and from address and add it
                    string lookup = ResidenceCombobox.Text;

                    //search for the property and find its id
                    foreach (var property in comm.Props)
                    {
                        bool added = false;
                        //start going through each property listed
                        if (property.StreetAddr == lookup)
                        {
                            bool isFound = false;
                            foreach (var r in comm.Residents)
                            {
                                foreach (var e in r.Residencelds)
                                {
                                    if (e == property.Id)
                                    {
                                        //output
                                        OutputTextbox.AppendText("You are already a resident here" + Environment.NewLine);
                                        isFound = true;
                                        break;
                                    }
                                }

                                //if not found then its good
                                if (!isFound)
                                {
                                    //Add the property ID to the residnce list
                                    var resId = property.Id.ToString();

                                    comm.Residents.Add(new Person(id, dt, lName, fName, occ, resId));
                                    OutputTextbox.AppendText("Success! " + fName + " has been added as a resident to " + comm.Name + Environment.NewLine);
                                    CommunityListShowingRefresh(currentCommunity);
                                    added = true;
                                    SnapPerson();
                                    break;
                                }
                            }
                        }
                        if (added)
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 //update the communtiy to current
 private void UpdateCommunity(Community comm)
 {
     //current community
     currentCommunity = comm;
     CommunityListShowing(comm);
 }