Exemplo n.º 1
0
        public void Serialize(Flat flat, Address address)
        {
            HouseForSerialize        serializeMe = new HouseForSerialize(flat, address);
            List <HouseForSerialize> housesForSerialize;

            if (File.Exists("infa.xml"))
            {
                housesForSerialize = Deserialize();
            }
            else
            {
                housesForSerialize = new List <HouseForSerialize>();
            }
            housesForSerialize.Add(serializeMe);
            XmlSerializer xmlf = new XmlSerializer(housesForSerialize.GetType());

            using (FileStream fs = new FileStream("infa.xml", FileMode.OpenOrCreate))
            {
                xmlf.Serialize(fs, housesForSerialize);
            }
        }
Exemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
                {
                    MessageBox.Show(
                        "Введите данные!",
                        "Сообщение об ошибке",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning
                        );
                }
                if (Convert.ToInt32(textBox1.Text) < 30)
                {
                    MessageBox.Show(
                        "Слишком малая площадь!",
                        "Сообщение об ошибке",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning
                        );
                }
                if (
                    textBox1.Text.Length > 0 && comboBox1.Text.Length > 0 &&
                    (radioButton1.Checked || radioButton2.Checked || radioButton3.Checked || radioButton4.Checked) &&
                    textBox3.Text.Length > 0 && comboBox2.Text.Length > 0 &&
                    textBox4.Text.Length > 0 && textBox5.Text.Length > 0
                    )
                {
                    completenessFlag = true;
                }

                if (completenessFlag)
                {
                    richTextBox1.Text = "";
                    Address address = new Address();
                    address.country        = comboBox2.Text;
                    address.city           = textBox5.Text;
                    address.district       = textBox4.Text;
                    address.street         = textBox3.Text;
                    address.buildingNumber = Convert.ToInt32(numericUpDown3.Value);
                    address.housing        = trackBar2.Value;
                    address.flatNumber     = Convert.ToInt32(numericUpDown2.Value);
                    Flat flat = new Flat();
                    flat.meters     = Convert.ToDouble(textBox1.Text);
                    flat.roomsCount = trackBar1.Value;
                    flat.year       = Convert.ToInt32(numericUpDown1.Value);
                    flat.floor      = Convert.ToInt32(comboBox1.Text);
                    CheckedListBox.CheckedItemCollection items = checkedListBox1.CheckedItems;
                    string option = "";
                    foreach (string name in items)
                    {
                        option += " ";
                        option += name;
                    }
                    flat.options = option;
                    foreach (RadioButton rb in groupBox1.Controls)
                    {
                        if (rb.Checked)
                        {
                            flat.material = rb.Text;
                        }
                    }
                    richTextBox1.Text = "Метраж: " + flat.meters + " \nКоличество комнат: " + flat.roomsCount + " \nГод постройки: " + flat.year + " \nЭтаж: " + flat.floor + " \nОпции: " + option + " \nМатериал: " + flat.material + " \nСтрана: " + address.country + " \nГород: " + address.city + " \nРайон: " + address.district + " \nУлица: " + address.street + " \nДом: " + address.buildingNumber + " \nКорпус: " + address.housing + " \nКвартира: " + address.flatNumber;
                    string        str       = richTextBox1.Text;
                    XmlSerializer formatter = new XmlSerializer(typeof(string));
                    using (FileStream fs = new FileStream("infa.xml", FileMode.OpenOrCreate))
                    {
                        formatter.Serialize(fs, str);
                    }
                }
                else
                {
                    MessageBox.Show(
                        "Вы не заполнили все необходимые поля!",
                        "Сообщение об ошибке",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning
                        );
                }
            }
            catch { }
        }
Exemplo n.º 3
0
 public HouseForSerialize(Flat flat, Address address)
 {
     Flat    = flat;
     Address = address;
 }