[Serializable()]
[Bindable(BindableSupport.No)]
public class LetterStructure:
ISerializable,
ILetter_GasServicing,
ICachedType,
IBindableComponent
{
#region " class constructors "
public LetterStructure()
{
// initialise the class
Initialise();
}
public LetterStructure(SerializationInfo info, StreamingContext context)
{
// initialise the class
Initialise();
//Get the values from stream and assign them to the appropriate properties
this.JobReference = (string)info.GetValue(const_job_reference, typeof(string));
this.JobDateDue = (DateTime)info.GetValue(const_job_date_due, typeof(DateTime));
this.JobDateRecieved = (DateTime)info.GetValue(const_job_reference, typeof(DateTime));
this.ContactAddress = (string)info.GetValue(const_contact_address, typeof(string));
this.ContactFullName = (string)info.GetValue(const_contact_full_name, typeof(string));
this.ContactName = (string)info.GetValue(const_contact_name, typeof(string));
}
#endregion
#region " class variables "
// these are the variables used to hold the referenced data
private string _job_reference;
private DateTime _job_date_due;
private DateTime _job_date_received;
private string _contact_fullname;
private string _contact_address;
private string _contact_name;
// serializable names
private const string const_job_reference = "JobReference";
private const string const_job_date_due = "JobDateDue";
private const string const_job_date_received = "JobDateRecieved";
private const string const_contact_full_name = "ContactFullName";
private const string const_contact_name = "ContactName";
private const string const_contact_address = "ContactAddress";
// create a dictionary object containing the bookmarks
[NonSerialized()]
private ArrayList documentBookmarks;
// change tracking
private Boolean dataIsDirty = false;
// binding attributes
[NonSerialized()]
private BindingContext localBindingContext;
[NonSerialized()]
private ControlBindingsCollection localDataBindings;
#endregion
#region " Iletter Properties "
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public string JobReference
{
get
{
return _job_reference;
}
set
{
_job_reference = value;
}
}
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public DateTime JobDateDue
{
get
{
return _job_date_due;
}
set
{
_job_date_due = value;
}
}
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public DateTime JobDateRecieved
{
get
{
return _job_date_received;
}
set
{
_job_date_received = value;
}
}
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public string ContactFullName
{
get
{
return _contact_fullname;
}
set
{
_contact_fullname = value;
}
}
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public string ContactName
{
get
{
return _contact_name;
}
set
{
_contact_name = value;
}
}
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public string ContactAddress
{
get
{
return _contact_address;
}
set
{
_contact_address = value;
}
}
#endregion
#region " private methods "
private void Initialise()
{
try
{
// create a new instance of the document bookmark objects
documentBookmarks = new ArrayList();
// create and populate the list object with bookmark objects
documentBookmarks.Add(const_job_reference);
documentBookmarks.Add(const_job_date_due);
documentBookmarks.Add(const_job_date_received);
documentBookmarks.Add(const_contact_name);
documentBookmarks.Add(const_contact_full_name);
documentBookmarks.Add(const_contact_address);
} catch (Exception ex)
{
// display the error for debugging and
// pass to next level for handling
Debug.WriteLine(ex.Message);
throw (ex);
}
}
#endregion
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
//http://www.codeproject.com/KB/cs/objserial.aspx
// add the current values from the properties to the stream
info.AddValue(const_job_reference, typeof(string));
info.AddValue(const_job_date_due, typeof(DateTime));
info.AddValue(const_job_date_received, typeof(DateTime));
info.AddValue(const_contact_full_name, typeof(string));
info.AddValue(const_contact_name, typeof(string));
info.AddValue(const_contact_address, typeof(string));
}
#endregion
#region ICachedType Members
public void AfterLoad()
{
// reset the document modified state
dataIsDirty = false;
Debug.WriteLine("after load");
}
public void AfterSave()
{
// reset the document modified state
dataIsDirty = false;
Debug.WriteLine("after load");
}
public bool BeforeLoad()
{
return true;
}
public bool BeforeSave()
{
return true;
}
public bool IsDirty
{
get
{
return dataIsDirty;
}
}
#endregion
#region IBindableComponent Members
[Browsable(false)]
public BindingContext BindingContext
{
get
{
if (localBindingContext == null)
{
localBindingContext = new BindingContext();
}
return localBindingContext;
}
set
{
localBindingContext = value;
}
}
public ControlBindingsCollection DataBindings
{
get
{
if (localDataBindings == null)
{
localDataBindings = new ControlBindingsCollection(this);
}
return localDataBindings;
}
}
#endregion
#region IComponent Members
public event EventHandler Disposed;
public System.ComponentModel.ISite Site
{
get
{
return null;
}
set
{
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
// dispose of all items
if (documentBookmarks != null)
{
documentBookmarks.Clear();
documentBookmarks = null;
}
}
#endregion
}