Exemplo n.º 1
0
        private void OnClickSaveToXml(object sender, EventArgs e)
        {
            City    _city = new City();
            Address _add  = new Address();

            if (!Validate())
            {
                MessageBox.Show("Невалидные данные");
            }
            else
            {
                _city.city = textBoxCity.Text;
                _city.zip  = Convert.ToInt32(textBoxZIP.Text);

                _add.street     = textBoxStreet.Text;
                _add.house      = textBoxHouse.Text;
                _add.apartament = textBoxApartament.Text;

                AddressWithCity a         = new AddressWithCity(_city, _add);
                Student         s         = new Student(textBoxName.Text, Convert.ToInt32(textBoxVoz.Text), comboBoxSpec.SelectedItem.ToString(), comboBoxDay.SelectedItem.ToString() + "@" + comboBoxMonth.SelectedItem.ToString() + "@" + comboBoxYear.SelectedItem.ToString(), comboBoxKurs.SelectedItem.ToString(), comboBoxGroup.SelectedItem.ToString(), radioButton1.Checked ? "М" : "Ж", textBoxSrBall.Text, a);
                XmlSerializer   formatter = new XmlSerializer(typeof(Student));

                // получаем поток, куда будем записывать сериализованный объект
                using (FileStream fs = new FileStream("student_" + s.Name + "_" + s.City + "_" + s.BirthDay + ".xml", FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, s);
                    MessageBox.Show("Объект сериализован");
                }
                //Process.Start("student.xml");
            }
        }
Exemplo n.º 2
0
        public Student(string name, int age, string spec, string birthday, string k, string group, string gender, string sr, AddressWithCity add)
        {
            Name        = name;
            Age         = age;
            Spec        = spec;
            BirthDay    = birthday;
            this.k      = k;
            this.group  = group;
            this.gender = gender;
            this.sr     = sr;
            AddressWithCity address = add;

            City       = add._city.city;
            Zip        = add._city.zip;
            street     = add._address.street;
            house      = add._address.house;
            apartament = add._address.apartament;
        }