Пример #1
0
        public PassportData GetPassportData()
        {
            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);
            }
            return pd;
        }
Пример #2
0
 private void InitPassport()
 {
     var passportName = GetPassportName();
     if (passportName != null && System.IO.File.Exists(passportName))
     {
         var xs = new XmlSerializer(typeof (PassportData));
         var file = System.IO.File.OpenRead(passportName);
         pd = (PassportData) xs.Deserialize(file);
         file.Close();
     }
     else
     {
         pd = new PassportData();
     }
 }
Пример #3
0
        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();
        }