示例#1
0
文件: Form1.cs 项目: 1extra/prog2015
        private void LoadButton_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog() { Title = "Загрузка данных", Filter = "файл регистрации|*.rgsr" };
            var result = ofd.ShowDialog(this);
            if (result!=DialogResult.OK)
                return;

            var xs = new XmlSerializer(typeof(RegestrationData));
            var file = File.OpenRead(ofd.FileName);
            rd = (RegestrationData) xs.Deserialize(file);
            file.Close();

            NameTextBox.Text = rd.Name;
            SurnameTextBox.Text = rd.Surname;
            PatronimycTextBox.Text = rd.Patronimyc;

            if (rd.Gender == Gender.Male)
            {
                MaleRadioButton.Checked = true;
                FemaleRadioButton.Checked = false;
            }
            else
            {
                MaleRadioButton.Checked = false;
                FemaleRadioButton.Checked = true;
            }

            foreach (ConcertData ed in rd.Concerts)
            {
                listBox1.Items.Add(ed);
            }

            if (rd.Photo == null)
            {
                PictureBox.Image = null;
            }
            else
            {
                var ms = new MemoryStream(rd.Photo);
                PictureBox.Image = Image.FromStream(ms);
            }
        }
示例#2
0
文件: Form1.cs 项目: 1extra/prog2015
 public Form1()
 {
     rd = new RegestrationData();
     InitializeComponent();
 }
示例#3
0
文件: Form1.cs 项目: 1extra/prog2015
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if(!(FemaleRadioButton.Checked || MaleRadioButton.Checked))
            {
                var box = new NoNoMessageBox();
                box.ShowDialog(this);
                return;
            }

            var sfd = new SaveFileDialog() {Title = "Сохранение данных", Filter = "Файл регистрации|*.rgsr"};
            var result = sfd.ShowDialog(this);
            if(result!=DialogResult.OK)
            return;

            rd = new RegestrationData();
            rd.Name = NameTextBox.Text;
            rd.Surname = SurnameTextBox.Text;
            rd.Patronimyc = PatronimycTextBox.Text;

            if (PictureBox.Image != null)
            {
                var ms = new MemoryStream();
                PictureBox.Image.Save(ms,ImageFormat.Png);

                rd.Photo = ms.GetBuffer();
            }

            if (MaleRadioButton.Checked)
            {
                rd.Gender = Gender.Male;
            }
            else
            {
                rd.Gender = Gender.Female;
            }

            foreach (ConcertData ed in listBox1.Items)
            {
                rd.Concerts.Add(ed);
            }

            var xs = new XmlSerializer(typeof(RegestrationData));
            var file = File.Create(sfd.FileName);
            xs.Serialize(file,rd);
            file.Close();
        }