using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
namespace VEPROMS.CSLA.Library
{
[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class DocumentConfig : ConfigDynamicTypeDescriptor, INotifyPropertyChanged
{
#region XML
private XMLProperties _Xp;
private XMLProperties Xp
{
get { return _Xp; }
}
#endregion
#region Constructors
public Document _Document;
private DocumentInfo _DocumentInfo;
public DocumentConfig(Document document)
{
_Document = document;
string xml = _Document.Config;
if (xml == string.Empty) xml = "";
_Xp = new XMLProperties(xml);
}
public DocumentConfig(DocumentInfo documentInfo)
{
_DocumentInfo = documentInfo;
string xml = _DocumentInfo.Config;
if (xml == string.Empty) xml = "";
_Xp = new XMLProperties(xml);
}
internal string GetValue(string group, string item)
{
return _Xp[group, item];
}
#endregion
#region Properties
[Category("General")]
[DisplayName("Name")]
[Description("Name")]
public string Name
{
get { return (_Document != null ? _Document.LibTitle : _DocumentInfo.LibTitle); }
set { if (_Document != null) _Document.LibTitle = value; }
}
[Category("General")]
[DisplayName("Comment")]
[RefreshProperties(RefreshProperties.All)]
[Description("Comment")]
public string LibDoc_Comment
{
get
{
string s = _Xp["LibDoc", "Comment"];// get the saved value
return s;
}
set
{
_Xp["LibDoc", "Comment"] = value;
OnPropertyChanged("LibDoc_Comment");
}
}
[Category("Printing")]
[DisplayName("Length")]
[Description("Length of Document in Full and Partial Pages")]
public float Printing_Length
{
get
{
string s = _Xp["Printing", "Length"];// get the saved value
return float.Parse(s);
}
set
{
_Xp["Printing", "Length"] = string.Format("{0:0.0000}", value);
OnPropertyChanged("Printing_Length");
}
}
private static Regex byARGB = new Regex(@"Color \[A=([0-9]*), R=([0-9]*), G=([0-9]*), B=([0-9]*)\]");
private static Regex byName = new Regex(@"Color \[(.*)\]");
public static Color ColorFromString(string sColor)
{
Match myMatch = byARGB.Match(sColor);
if (myMatch.Groups.Count == 5)
return Color.FromArgb(int.Parse(myMatch.Groups[1].Value), int.Parse(myMatch.Groups[2].Value), int.Parse(myMatch.Groups[3].Value), int.Parse(myMatch.Groups[4].Value));
myMatch = byName.Match(sColor);
if (myMatch.Groups.Count == 2)
return Color.FromName(myMatch.Groups[1].Value);
if (sColor[0] == '[')
{
string[] parts = sColor.Substring(1, sColor.Length - 2).Split(",".ToCharArray());
return Color.FromArgb(Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2]), Int32.Parse(parts[3]));
}
else return Color.FromName(sColor);
}
[Category("Printing")]
[DisplayName("Color")]
[Description("Color of Document Text")]
public Color Printing_Color
{
get
{
string sColor = _Xp["Printing", "Color"];
return ColorFromString(sColor);
}
set
{
_Xp["Printing", "Color"] = value.ToString();
OnPropertyChanged("Printing_Color");
}
}
#endregion
#region ToString
public override string ToString()
{
string s = _Xp.ToString();
if (s == "" || s == "") return string.Empty;
return s;
}
#endregion
}
}