示例#1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            double    footage;
            int       amountOfRooms;
            int       year;
            string    material;
            int       floor;
            string    country;
            string    district;
            string    street;
            string    houseNumber;
            string    flatNumber;
            string    index;
            bool      balcony    = false;
            bool      basement   = false;
            bool      bathroom   = false;
            bool      kitchen    = false;
            bool      livingRoom = false;
            string    property   = null;
            FlatState state      = FlatState.repairing;

            try
            {
                street        = textBoxStreet.Text;
                footage       = trackBarFootage.Value;
                amountOfRooms = (int)numericUpDownRooms.Value;
                year          = dateTimePickerYear.Value.Year;
                material      = comboBoxMaterial.Text;
                floor         = (int)numericUpDownFloor.Value;
                if (treeViewCountry.SelectedNode == null)
                {
                    throw new Exception("Выберите страну или город квартиры!");
                }
                else
                {
                    country = treeViewCountry.SelectedNode.Text;
                }
                district    = comboBoxDistrict.Text;
                street      = textBoxStreet.Text;
                houseNumber = textBoxNumberHouse.Text;
                flatNumber  = textBoxNumberFlat.Text;
                index       = textBoxIndex.Text;
                if (checkBoxBalcony.Checked)
                {
                    balcony = true;
                }
                if (checkBoxBasement.Checked)
                {
                    basement = true;
                }
                if (checkBoxBathroom.Checked)
                {
                    bathroom = true;
                }
                if (checkBoxKitchen.Checked)
                {
                    kitchen = true;
                }
                if (checkBoxLivingRoom.Checked)
                {
                    livingRoom = true;
                }
                if (tempFlat.Property == string.Empty)
                {
                    MessageBox.Show("Выберите, продается ли квартира!");
                }
                else
                {
                    property = tempFlat.Property;
                }
                if (radioButtonNotSalling.Checked)
                {
                    state = FlatState.notsalling;
                }
                if (radioButtonSalling.Checked)
                {
                    state = FlatState.salling;
                }
                if (radioButton1.Checked)
                {
                    state = FlatState.repairing;
                }

                Address address = new Address(country, district, street, houseNumber, flatNumber, index);
                Flat    flat    = new Flat(footage, amountOfRooms, year, material, floor, kitchen, balcony, basement, livingRoom, bathroom, property, state, address);
                flat.Cost        = flat.CountCost();
                textBoxCost.Text = flat.Cost.ToString();
                flats.Add(flat);
                XmlSerializeWrapper.Serialize(flats, "flat.xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{ex.Message}");
            }
            finally
            {
                MessageBox.Show($"Данные успешно записаны в файл \"flat.xml\"");
            }
            amountObjects++;
            toolStripStatusLabelAmount.Text = amountObjects.ToString();
            toolStripStatusLabelAction.Text = "Данные были записаны в файл";
        }
示例#2
0
 public Flat(double footage, int amounOfRooms, int year, string material, int floor, bool kitchen,
             bool balcony, bool basement, bool livingRoom, bool bathroom, string property, FlatState flatState, Address address)
 {
     Footage        = footage;
     AmountOfRooms  = amounOfRooms;
     Year           = year;
     Material       = material;
     Floor          = floor;
     Kitchen        = kitchen;
     Balcony        = balcony;
     Basement       = basement;
     LivingRoom     = livingRoom;
     Bathroom       = bathroom;
     Property       = property;
     this.address   = address;
     this.flatState = flatState;
 }