Click here to Skip to main content
15,880,427 members
Articles / Web Development / HTML

XML Data Files, XML Serialization, and .NET

Rate me:
Please Sign up or sign in to vote.
4.82/5 (28 votes)
27 Aug 200317 min read 337.9K   6.4K   130  
Describes a means to build XML data files using XML Schema and xsd.exe to facilitate easy XML Serialization
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace CardfileCE
{
	/// <summary>
	/// Summary description for ContactPanel.
	/// </summary>
	public class ContactPanel : System.Windows.Forms.Panel
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label lblName;
		private System.Windows.Forms.Label lblEMail;
		private System.Windows.Forms.ComboBox cmbPhone;
		private System.Windows.Forms.TextBox tbFName;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox tbMName;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox tbLName;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox tbAddr1;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox tbAddr2;
		private System.Windows.Forms.TextBox tbAddr3;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox tbCity;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox tbState;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox tbPCode;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox tbHomePh;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.TextBox tbWorkPh;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox tbMobilePh;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.TextBox tbFAXPh;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.TextBox tbCompany;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox tbCountry;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.TextBox tbEMail;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.TextBox tbNote;
		private System.Windows.Forms.Panel panel1;
	
		public ContactPanel()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.tbFName = new System.Windows.Forms.TextBox();
			this.lblName = new System.Windows.Forms.Label();
			this.lblEMail = new System.Windows.Forms.Label();
			this.cmbPhone = new System.Windows.Forms.ComboBox();
			this.panel1 = new System.Windows.Forms.Panel();
			this.label2 = new System.Windows.Forms.Label();
			this.tbMName = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.tbLName = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.tbAddr1 = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.tbAddr2 = new System.Windows.Forms.TextBox();
			this.tbAddr3 = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.tbCity = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.tbState = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.tbPCode = new System.Windows.Forms.TextBox();
			this.label9 = new System.Windows.Forms.Label();
			this.tbHomePh = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.tbWorkPh = new System.Windows.Forms.TextBox();
			this.label11 = new System.Windows.Forms.Label();
			this.tbMobilePh = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.tbFAXPh = new System.Windows.Forms.TextBox();
			this.label13 = new System.Windows.Forms.Label();
			this.tbCompany = new System.Windows.Forms.TextBox();
			this.label14 = new System.Windows.Forms.Label();
			this.tbCountry = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.tbEMail = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.tbNote = new System.Windows.Forms.TextBox();
			this.label17 = new System.Windows.Forms.Label();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 104);
			this.label1.Size = new System.Drawing.Size(80, 20);
			this.label1.Text = "First name:";
			// 
			// tbFName
			// 
			this.tbFName.BackColor = System.Drawing.Color.Ivory;
			this.tbFName.Location = new System.Drawing.Point(88, 104);
			this.tbFName.Size = new System.Drawing.Size(120, 22);
			this.tbFName.Text = "";
			// 
			// lblName
			// 
			this.lblName.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Italic);
			this.lblName.Location = new System.Drawing.Point(8, 8);
			this.lblName.Size = new System.Drawing.Size(200, 20);
			this.lblName.Text = "<full contact name>";
			// 
			// lblEMail
			// 
			this.lblEMail.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Italic);
			this.lblEMail.Location = new System.Drawing.Point(8, 32);
			this.lblEMail.Size = new System.Drawing.Size(200, 20);
			this.lblEMail.Text = "<contact email>";
			// 
			// cmbPhone
			// 
			this.cmbPhone.Location = new System.Drawing.Point(8, 56);
			this.cmbPhone.Size = new System.Drawing.Size(200, 22);
			// 
			// panel1
			// 
			this.panel1.Location = new System.Drawing.Point(8, 88);
			this.panel1.Size = new System.Drawing.Size(200, 2);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 136);
			this.label2.Text = "Middle name:";
			// 
			// tbMName
			// 
			this.tbMName.BackColor = System.Drawing.Color.Ivory;
			this.tbMName.Location = new System.Drawing.Point(88, 136);
			this.tbMName.Size = new System.Drawing.Size(120, 22);
			this.tbMName.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 168);
			this.label3.Text = "Last name:";
			// 
			// tbLName
			// 
			this.tbLName.BackColor = System.Drawing.Color.Ivory;
			this.tbLName.Location = new System.Drawing.Point(88, 168);
			this.tbLName.Size = new System.Drawing.Size(120, 22);
			this.tbLName.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 200);
			this.label4.Text = "Address 1:";
			// 
			// tbAddr1
			// 
			this.tbAddr1.BackColor = System.Drawing.Color.Ivory;
			this.tbAddr1.Location = new System.Drawing.Point(88, 200);
			this.tbAddr1.Size = new System.Drawing.Size(120, 22);
			this.tbAddr1.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 232);
			this.label5.Text = "Address 2:";
			// 
			// tbAddr2
			// 
			this.tbAddr2.BackColor = System.Drawing.Color.Ivory;
			this.tbAddr2.Location = new System.Drawing.Point(88, 232);
			this.tbAddr2.Size = new System.Drawing.Size(120, 22);
			this.tbAddr2.Text = "";
			// 
			// tbAddr3
			// 
			this.tbAddr3.BackColor = System.Drawing.Color.Ivory;
			this.tbAddr3.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbAddr3.Location = new System.Drawing.Point(88, 264);
			this.tbAddr3.Size = new System.Drawing.Size(120, 22);
			this.tbAddr3.Text = "";
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label6.Location = new System.Drawing.Point(8, 264);
			this.label6.Text = "Address 3:";
			// 
			// tbCity
			// 
			this.tbCity.BackColor = System.Drawing.Color.Ivory;
			this.tbCity.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbCity.Location = new System.Drawing.Point(88, 296);
			this.tbCity.Size = new System.Drawing.Size(120, 22);
			this.tbCity.Text = "";
			// 
			// label7
			// 
			this.label7.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label7.Location = new System.Drawing.Point(8, 296);
			this.label7.Text = "City:";
			// 
			// tbState
			// 
			this.tbState.BackColor = System.Drawing.Color.Ivory;
			this.tbState.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbState.Location = new System.Drawing.Point(88, 328);
			this.tbState.Size = new System.Drawing.Size(120, 22);
			this.tbState.Text = "";
			// 
			// label8
			// 
			this.label8.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label8.Location = new System.Drawing.Point(8, 328);
			this.label8.Text = "State:";
			// 
			// tbPCode
			// 
			this.tbPCode.BackColor = System.Drawing.Color.Ivory;
			this.tbPCode.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbPCode.Location = new System.Drawing.Point(88, 360);
			this.tbPCode.Size = new System.Drawing.Size(120, 22);
			this.tbPCode.Text = "";
			// 
			// label9
			// 
			this.label9.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label9.Location = new System.Drawing.Point(8, 360);
			this.label9.Text = "Postal code:";
			// 
			// tbHomePh
			// 
			this.tbHomePh.BackColor = System.Drawing.Color.Ivory;
			this.tbHomePh.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbHomePh.Location = new System.Drawing.Point(88, 392);
			this.tbHomePh.Size = new System.Drawing.Size(120, 22);
			this.tbHomePh.Text = "";
			// 
			// label10
			// 
			this.label10.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label10.Location = new System.Drawing.Point(8, 392);
			this.label10.Text = "Home phone:";
			// 
			// tbWorkPh
			// 
			this.tbWorkPh.BackColor = System.Drawing.Color.Ivory;
			this.tbWorkPh.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbWorkPh.Location = new System.Drawing.Point(88, 424);
			this.tbWorkPh.Size = new System.Drawing.Size(120, 22);
			this.tbWorkPh.Text = "";
			// 
			// label11
			// 
			this.label11.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label11.Location = new System.Drawing.Point(8, 424);
			this.label11.Text = "Work phone:";
			// 
			// tbMobilePh
			// 
			this.tbMobilePh.BackColor = System.Drawing.Color.Ivory;
			this.tbMobilePh.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbMobilePh.Location = new System.Drawing.Point(88, 456);
			this.tbMobilePh.Size = new System.Drawing.Size(120, 22);
			this.tbMobilePh.Text = "";
			// 
			// label12
			// 
			this.label12.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label12.Location = new System.Drawing.Point(8, 456);
			this.label12.Text = "Mobile ph:";
			// 
			// tbFAXPh
			// 
			this.tbFAXPh.BackColor = System.Drawing.Color.Ivory;
			this.tbFAXPh.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbFAXPh.Location = new System.Drawing.Point(88, 488);
			this.tbFAXPh.Size = new System.Drawing.Size(120, 22);
			this.tbFAXPh.Text = "";
			// 
			// label13
			// 
			this.label13.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label13.Location = new System.Drawing.Point(8, 488);
			this.label13.Text = "FAX:";
			// 
			// tbCompany
			// 
			this.tbCompany.BackColor = System.Drawing.Color.Ivory;
			this.tbCompany.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbCompany.Location = new System.Drawing.Point(88, 520);
			this.tbCompany.Size = new System.Drawing.Size(120, 22);
			this.tbCompany.Text = "";
			// 
			// label14
			// 
			this.label14.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label14.Location = new System.Drawing.Point(8, 520);
			this.label14.Text = "Company:";
			// 
			// tbCountry
			// 
			this.tbCountry.BackColor = System.Drawing.Color.Ivory;
			this.tbCountry.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbCountry.Location = new System.Drawing.Point(88, 552);
			this.tbCountry.Size = new System.Drawing.Size(120, 22);
			this.tbCountry.Text = "";
			// 
			// label15
			// 
			this.label15.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label15.Location = new System.Drawing.Point(8, 552);
			this.label15.Text = "Country:";
			// 
			// tbEMail
			// 
			this.tbEMail.BackColor = System.Drawing.Color.Ivory;
			this.tbEMail.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbEMail.Location = new System.Drawing.Point(88, 584);
			this.tbEMail.Size = new System.Drawing.Size(120, 22);
			this.tbEMail.Text = "";
			// 
			// label16
			// 
			this.label16.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label16.Location = new System.Drawing.Point(8, 584);
			this.label16.Text = "E-Mail:";
			// 
			// tbNote
			// 
			this.tbNote.BackColor = System.Drawing.Color.Ivory;
			this.tbNote.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.tbNote.Location = new System.Drawing.Point(8, 640);
			this.tbNote.Multiline = true;
			this.tbNote.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.tbNote.Size = new System.Drawing.Size(200, 120);
			this.tbNote.Text = "";
			// 
			// label17
			// 
			this.label17.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular);
			this.label17.Location = new System.Drawing.Point(8, 616);
			this.label17.Text = "Notes:";
			// 
			// ContactPanel
			// 
			this.BackColor = System.Drawing.Color.Ivory;
			this.ClientSize = new System.Drawing.Size(218, 767);
			this.Controls.Add(this.tbNote);
			this.Controls.Add(this.label17);
			this.Controls.Add(this.tbEMail);
			this.Controls.Add(this.label16);
			this.Controls.Add(this.tbCountry);
			this.Controls.Add(this.label15);
			this.Controls.Add(this.tbCompany);
			this.Controls.Add(this.label14);
			this.Controls.Add(this.tbFAXPh);
			this.Controls.Add(this.label13);
			this.Controls.Add(this.tbMobilePh);
			this.Controls.Add(this.label12);
			this.Controls.Add(this.tbWorkPh);
			this.Controls.Add(this.label11);
			this.Controls.Add(this.tbHomePh);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.tbPCode);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.tbState);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.tbCity);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.tbAddr3);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.tbAddr2);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.tbAddr1);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.tbLName);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.tbMName);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.cmbPhone);
			this.Controls.Add(this.lblEMail);
			this.Controls.Add(this.lblName);
			this.Controls.Add(this.tbFName);
			this.Controls.Add(this.label1);
			this.Text = "ContactPanel";

		}
		#endregion

		public CardTypeBodyContact ContactInfo
		{
			get
			{
				// Extract the data
				CardTypeBodyContact contact = new CardTypeBodyContact();
				contact.FName = tbFName.Text;
				contact.MName = tbMName.Text;
				contact.LName = tbLName.Text;
				contact.Addr1 = tbAddr1.Text;
				contact.Addr2 = tbAddr2.Text;
				contact.Addr3 = tbAddr3.Text;
				contact.City = tbCity.Text;
				contact.State = tbState.Text;
				contact.PCode = tbPCode.Text;
				contact.Country = tbCountry.Text;
				contact.Company = tbCompany.Text;
				contact.HomePh = tbHomePh.Text;
				contact.MobilePh = tbMobilePh.Text;
				contact.WorkPh = tbWorkPh.Text;
				contact.FaxPh = tbFAXPh.Text;
				contact.EMail = tbEMail.Text;
				contact.Notes = tbNote.Text;

				// Return it
				return contact;
			}
			set
			{
				// Initialize the contact panel
				tbFName.Text = value.FName;
				tbMName.Text = value.MName;
				tbLName.Text = value.LName;
				tbAddr1.Text = value.Addr1;
				tbAddr2.Text = value.Addr2;
				tbAddr3.Text = value.Addr3;
				tbCity.Text = value.City;
				tbState.Text = value.State;
				tbPCode.Text = value.PCode;
				tbCountry.Text = value.Country;
				tbCompany.Text = value.Company;
				tbHomePh.Text = value.HomePh;
				tbMobilePh.Text = value.MobilePh;
				tbWorkPh.Text = value.WorkPh;
				tbFAXPh.Text = value.FaxPh;
				tbEMail.Text = value.EMail;
				tbNote.Text = value.Notes;

				// Set the lookup info
				lblName.Text = String.Format("{0}, {1} {2}",value.LName,value.FName,value.MName);
				lblEMail.Text = value.EMail;
				if ( value.HomePh.Length > 0 ) cmbPhone.Items.Add(String.Format("(H) {0}",value.HomePh));
				if ( value.WorkPh.Length > 0 ) cmbPhone.Items.Add(String.Format("(W) {0}",value.WorkPh));
				if ( value.MobilePh.Length > 0 ) cmbPhone.Items.Add(String.Format("(M) {0}",value.MobilePh));
				if ( value.FaxPh.Length > 0 ) cmbPhone.Items.Add(String.Format("(F) {0}",value.FaxPh));
				if ( cmbPhone.Items.Count > 0 ) cmbPhone.SelectedItem = cmbPhone.Items[0];
			}
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions