private void saveButton_Click(object sender, EventArgs e) { if (!(maleRadioButton.Checked || femaleRadioButton.Checked)) { var box = new NoNoMessageBox(); box.ShowDialog(this); return; } var sfd = new SaveFileDialog() {Title = "Сохранение данных", Filter = "файл паспорта|*.passport" }; var result = sfd.ShowDialog(this); if(result!=DialogResult.OK) return; var pd = new PassportData(); pd.Name = nameTextBox.Text; pd.Surname = surenameTextbox.Text; pd.Patronimyc = patronimicTextBox.Text; if (pictureBox1.Image != null) { var ms = new MemoryStream(); pictureBox1.Image.Save(ms,ImageFormat.Png); pd.Photo = ms.GetBuffer(); } if (maleRadioButton.Checked) { pd.Gender = Gender.Male; } else { pd.Gender = Gender.Female; } foreach (EmploymentData ed in listBox1.Items) { pd.Employments.Add(ed); } /* File.WriteAllText(sfd.FileName,nameTextBox.Text + Environment.NewLine); File.AppendAllText(sfd.FileName, surenameTextbox.Text + "\r\n"); File.AppendAllText(sfd.FileName, patronimicTextBox.Text+"\r\n"); */ var xs = new XmlSerializer(typeof(PassportData)); var file = File.Create(sfd.FileName); xs.Serialize(file,pd); file.Close(); }
private void saveButton_Click(object sender, EventArgs e) { if (!(maleRadioButton.Checked || femaleRadioButton.Checked)) { var box = new NoNoMessageBox(); box.ShowDialog(this); return; } var sfd = new SaveFileDialog() {Title = "Сохранение данных", Filter = "файл паспорта|*.passport" }; var result = sfd.ShowDialog(this); if(result!=DialogResult.OK) return; PassportData pd = GetPassportData(); /* File.WriteAllText(sfd.FileName,nameTextBox.Text + Environment.NewLine); File.AppendAllText(sfd.FileName, surenameTextbox.Text + "\r\n"); File.AppendAllText(sfd.FileName, patronimicTextBox.Text+"\r\n"); */ var xs = new XmlSerializer(typeof(PassportData)); var file = File.Create(sfd.FileName); xs.Serialize(file,pd); file.Close(); }