Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/WindowsFormsApplication2/WindowsFormsApplication2/Customer.cs
blob: d636af52efa1d4ccd81dff59a4e617727cc01668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Xml.Serialization;  // Does XML serializing for a class.
using System.Drawing;            // Required for storing a Bitmap.
using System.IO;			     // Required for using Memory stream objects.
using System.ComponentModel;     // Required for conversion of Bitmap objects.

namespace disc1
{
	/// <summary>
	/// Customer test class to demonstrate how to include custom metadata attributes in a 
	/// class so that it can be serialized/deserialized to/from XML.
	/// 
	/// References: 
	/// XML Serialization at http://samples.gotdotnet.com/:
	/// http://samples.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/xmlserialization/rwobjfromxml.aspx
	/// 
	/// How do I serialize an image file as XML in .NET?
	/// http://www.perfectxml.com/Answers.asp?ID=2
	/// </summary>
	
	// Set this 'Customer' class as the root node of any XML file its serialized to.
	[XmlRootAttribute("Customer", Namespace="", IsNullable=false)]

    //Each customer here refers to the picture and properties of each cell of the TableLayoutPanel
	public class Customer
	{
		private Bitmap picture;

		/// <summary>
		/// Default constructor for this class (required for serialization).
		/// </summary>
		public Customer()
		{
		}

		// Set this 'DateTimeValue' field to be an attribute of the root node.	

		// By NOT specifing any custom Metadata Attributes, fields will be created
		// as an element by default.		
		public string CustomerName;
        public int ColorName;
        public int PanelPadding;

		// Set serialization to IGNORE this field (ie. not add it to the XML).
		[XmlIgnoreAttribute()]
		public bool CustomerPaid;

		// Set serialization to IGNORE this property because the 'PictureByteArray' property
		// is used instead to serialize the 'Picture' Bitmap as an array of bytes.
		[XmlIgnoreAttribute()]
		public Bitmap Picture
		{
			get { return picture; }
			set { picture = value; }
		}
        public int Index;
		// Serializes the 'Picture' Bitmap to XML.
		[XmlElementAttribute("Picture")]
		public byte[] PictureByteArray
		{
			get 
			{ 
				if (picture != null)
				{
					TypeConverter BitmapConverter = TypeDescriptor.GetConverter(picture.GetType());
					return (byte[])	BitmapConverter.ConvertTo(picture, typeof(byte[]));					
				}
				else
					return null;
			}			
			set 
			{ 
				if (value != null)
					picture = new Bitmap(new MemoryStream(value)); 
				else
					picture = null; 
			}
		}		
	}
}