0

//Update I've added the corrections and provided the Form1.c code in it's entirety.

In the interest of Simplicity I've dumbed this down a bit. So all my form controls are set. Date as DateTimePicker(Short), Employee Number as maskedTextBox("###-##"), Employee Name as simple textBox, SS Number as maskedTextBox(standard SSNum), etc. for the sake of this question. In order to handle all this data I've created a Class called Employee_Data, as Follows...

namespace Employee
{
    public class Employee_Data
    {
        //Make Members Xml elements
        [XmlElement("EmployeeNumber")]
        public String EmployeeNumber {get; set;}
        [XmlElement("Date")]
        public DateTime Date {get; set;}
        [XmlElement("EmployeeName")]
        public String EmployeeName {get; set;}
        [XmlElement("SSNumber")]
        public String SSNumber {get; set;}


    }
}

I create an object in the Form1.cs called e_d and use the automatic event handling in VS. Debugger shows that the values are being stored to the class object just fine (maskedText values are including the dashes). However once I attempt to serialize the data as shown below, the masked textValues are omitted from the xml file...

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace Employee
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Employee_Data e_d = new Employee_Data();

        private void EmployyeeNumber_TextChanged(object sender, EventArgs e)
        {
            e_d.EmployeeNumber=EmployeeNumber.Text;
        }

        private void Date_ValueChanged(object sender, EventArgs e)
        {
            e_d.Date=Date.Value;

        }

        private void EmployeeName_TextChanged(object sender, EventArgs e)
        {
            e_d.EmployeeName=EmployeeName.Text;
        }



        private void SSNumber_ValueChanged(object sender, EventArgs e)
        {
          e_d.SSNumber=SSNumber.Text;
    }


    private void saveButton_Click(object sender, EventArgs e)
    {
        saveFileDialog1.DefaultExt = "xml";
        saveFileDialog1.Filter = "XML File (.xml)|*.xml";
        saveFileDialog1.AddExtension = true;
        saveFileDialog1.RestoreDirectory = true;
        saveFileDialog1.ShowDialog();
    }


private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
    string name = saveFileDialog1.FileName;


    using (TextWriter texWrt =  new StreamWriter(saveFileDialog1.FileName))
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Employee_Data));
        serializer.Serialize(texWrt, e_d);
    }
}

I have researched this issue and there doesn't seem to be much on this specific subject.

1 Answers1

0

The answer was event handling, or PROGRAMMER FAILURE. When programmer hand coded the event handling for text input (because the default in VS is MaskInputRejected), he forgot to set the event handler. I'll make sure to have a talk with programmer about this whole thing, everyone. But he learned a lot about csharp and xml in the process. Thanks to all for putting in their time to help.