diff --git a/PROMS/VEPROMS User Interface/frmVersionsProperties.cs b/PROMS/VEPROMS User Interface/frmVersionsProperties.cs index c1e552cc..0c51c285 100644 --- a/PROMS/VEPROMS User Interface/frmVersionsProperties.cs +++ b/PROMS/VEPROMS User Interface/frmVersionsProperties.cs @@ -13,11 +13,15 @@ using Volian.Controls.Library; using DescriptiveEnum; using DevComponents.DotNetBar; using DevComponents.DotNetBar.Controls; +using System.Xml.Serialization; +using Volian.Base.Library; namespace VEPROMS { public partial class frmVersionsProperties : DevComponents.DotNetBar.Office2007Form { + private List _Apples; + private List _DeletedApples; private bool _Initializing = false; private DocVersionConfig _DocVersionConfig; @@ -62,9 +66,78 @@ namespace VEPROMS //build the caption this.Text = string.Format("{0} Properties", _DocVersionConfig.Name); } - + private string AddSlaveNode(MiniConfig mc) + { + System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); + xd.LoadXml(_DocVersionConfig.ToString()); + System.Xml.XmlNodeList nl = xd.SelectNodes("//Slave"); + int max = 0; + foreach (System.Xml.XmlNode n in nl) + { + max = int.Parse(n.Attributes.GetNamedItem("index").InnerText); + } + max++; + System.Xml.XmlNode nn = xd.CreateElement("Slave"); + AddSlaveAttribute(nn,"index",max.ToString()); + AddSlaveAttribute(nn, "ID", mc.ID); + AddSlaveAttribute(nn, "Name", mc.Name); + AddSlaveAttribute(nn, "Number", mc.Number); + AddSlaveAttribute(nn, "Text", mc.Text); + AddSlaveAttribute(nn, "ProcedureNumber", mc.ProcedureNumber); + AddSlaveAttribute(nn, "SetID", mc.SetID); + AddSlaveAttribute(nn, "SetName", mc.SetName); + AddSlaveAttribute(nn, "OtherID", mc.OtherID); + AddSlaveAttribute(nn, "OtherName", mc.OtherName); + AddSlaveAttribute(nn, "OtherNumber", mc.OtherNumber); + AddSlaveAttribute(nn, "OtherText", mc.OtherText); + System.Xml.XmlNode sn = xd.SelectSingleNode("//Slaves"); + sn.AppendChild(nn); + return xd.OuterXml; + } + private void AddSlaveAttribute(System.Xml.XmlNode nn,string name,string value) + { + System.Xml.XmlAttribute xa = nn.OwnerDocument.CreateAttribute(name); + xa.InnerText = value; + nn.Attributes.SetNamedItem(xa); + } private void btnVersionsPropOK_Click(object sender, EventArgs e) { + if (_DocVersionConfig.Unit_Count > 1) + { + if (_DeletedApples != null && _DeletedApples.Count > 0) + { + foreach(MiniConfig mc in _DeletedApples) + _DocVersionConfig.RemoveSlave(mc.Index); + } + foreach (MiniConfig mc in _Apples) + { + if (mc.IsDirty) + { + if (mc.Index < 0) + { + mc.Index = _DocVersionConfig.MaxSlaveIndex + 1; + _DocVersionConfig.AddSlave(mc.MyXml); + } + else + { + int k = _DocVersionConfig.SelectedSlave; + _DocVersionConfig.SelectedSlave = mc.Index; + _DocVersionConfig.Unit_ID = mc.ID; + _DocVersionConfig.Unit_Name = mc.Name; + _DocVersionConfig.Unit_Number = mc.Number; + _DocVersionConfig.Unit_Text = mc.Text; + _DocVersionConfig.Unit_ProcedureNumber = mc.ProcedureNumber; + _DocVersionConfig.Unit_ProcedureSetID = mc.SetID; + _DocVersionConfig.Unit_ProcedureSetName = mc.SetName; + _DocVersionConfig.Other_Unit_ID = mc.OtherID; + _DocVersionConfig.Other_Unit_Name = mc.OtherName; + _DocVersionConfig.Other_Unit_Number = mc.OtherNumber; + _DocVersionConfig.Other_Unit_Text = mc.OtherText; + _DocVersionConfig.SelectedSlave = k; + } + } + } + } docVersionConfigBindingSource.EndEdit(); // Save Default settings for User // @@ -243,7 +316,32 @@ namespace VEPROMS ppLblAutoDuplexDefault.Visible = false; ppBtnDeftDisAutoDuplx.Visible = false; } - + //add new applicability stuff + if (_DocVersionConfig.Unit_Count > 1) + { + int k = _DocVersionConfig.SelectedSlave; + _Apples = new List(); + for (int i = 1; i <= _DocVersionConfig.MaxSlaveIndex; i++) + { + _DocVersionConfig.SelectedSlave = i; + try + { + MiniConfig cfg = new MiniConfig(i, _DocVersionConfig.Unit_ID, _DocVersionConfig.Unit_Name, _DocVersionConfig.Unit_Number, _DocVersionConfig.Unit_Text, _DocVersionConfig.Unit_ProcedureNumber, _DocVersionConfig.Unit_ProcedureSetID, _DocVersionConfig.Unit_ProcedureSetName, _DocVersionConfig.Other_Unit_ID, _DocVersionConfig.Other_Unit_Name, _DocVersionConfig.Other_Unit_Number, _DocVersionConfig.Other_Unit_Text); + _Apples.Add(cfg); + } + catch + { + } + } + _DocVersionConfig.SelectedSlave = k; + bsApples.DataSource = _Apples; + } + else + { + btnApplicability.Visible = false; + tiApplicability.Visible = false; + } + //end add new applicability stuff _Initializing = false; } @@ -625,6 +723,7 @@ namespace VEPROMS btnOutputSettings.Checked = false; btnFmtSettings.Checked = false; btnLibDocs.Checked = false; + btnApplicability.Checked = false; } /// @@ -906,6 +1005,201 @@ namespace VEPROMS } } - + private void btnApplicability_Click(object sender, EventArgs e) + { + ProcessButtonClick(tiApplicability, btnApplicability); + } + + private void lbApplicabilities_SelectedIndexChanged(object sender, EventArgs e) + { + if (lbApplicabilities.SelectedIndex > -1) + { + bsMiniApple.DataSource = bsApples.Current as MiniConfig; + btnDelApple.Enabled = true; + } + + } + private void btnNewApple_Click(object sender, EventArgs e) + { + MiniConfig cfg = new MiniConfig(); + cfg.Name = "New Applicability"; + _Apples.Add(cfg); + bsApples.DataSource = null; + bsApples.DataSource = _Apples; + lbApplicabilities.SelectedItem = cfg; + } + private void btnDelApple_Click(object sender, EventArgs e) + { + MiniConfig cfg = bsApples.Current as MiniConfig; + if (MessageBox.Show(string.Format("Are you sure you want to delete {0}", cfg.Name), "Confirm Delete", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) + { + if (_DeletedApples == null) + _DeletedApples = new List(); + _DeletedApples.Add(cfg); + _Apples.Remove(cfg); + bsApples.DataSource = null; + bsApples.DataSource = _Apples; + } + } + } + + [XmlRoot("Slave")] + public class MiniConfig + { + private static int lastindex = 0; + private bool _isDeleted; + [XmlIgnore] + public bool IsDeleted + { + get { return _isDeleted; } + set { _isDeleted = value; } + } + private bool _isDirty; + [XmlIgnore] + public bool IsDirty + { + get { return _isDirty; } + set { _isDirty = value; } + } + private int _index; + [XmlAttribute("index")] + public int Index + { + get { return _index; } + set { _index = value; IsDirty = true; } + } + private string _iD; + [XmlAttribute("ID")] + public string ID + { + get { return _iD; } + set { _iD = value; IsDirty = true; } + } + private string _name; + [XmlAttribute("Name")] + public string Name + { + get { return _name; } + set { _name = value; IsDirty = true; } + } + private string _number; + [XmlAttribute("Number")] + public string Number + { + get { return _number; } + set { _number = value; IsDirty = true; } + } + private string _text; + [XmlAttribute("Text")] + public string Text + { + get { return _text; } + set { _text = value; IsDirty = true; } + } + private string _procedureNumber; + [XmlAttribute("ProcedureNumber")] + public string ProcedureNumber + { + get { return _procedureNumber; } + set { _procedureNumber = value; IsDirty = true; } + } + private string _setID; + [XmlAttribute("SetID")] + public string SetID + { + get { return _setID; } + set { _setID = value; IsDirty = true; } + } + private string _setName; + [XmlAttribute("SetName")] + public string SetName + { + get { return _setName; } + set { _setName = value; IsDirty = true; } + } + private string _otherID; + [XmlAttribute("OtherID")] + public string OtherID + { + get { return _otherID; } + set { _otherID = value; IsDirty = true; } + } + private string _otherName; + [XmlAttribute("OtherName")] + public string OtherName + { + get { return _otherName; } + set { _otherName = value; IsDirty = true; } + } + private string _otherNumber; + [XmlAttribute("OtherNumber")] + public string OtherNumber + { + get { return _otherNumber; } + set { _otherNumber = value; IsDirty = true; } + } + private string _otherText; + [XmlAttribute("OyherText")] + public string OtherText + { + get { return _otherText; } + set { _otherText = value; IsDirty = true; } + } + public MiniConfig() + { + _index = --lastindex; + _iD = string.Empty; + _name = string.Empty; + _number = string.Empty; + _text = string.Empty; + _procedureNumber = string.Empty; + _setID = string.Empty; + _setName = string.Empty; + _otherID = string.Empty; + _otherName = string.Empty; + _otherNumber = string.Empty; + _otherText = string.Empty; + _isDirty = false; + } + public MiniConfig(int index,string id,string name,string number,string text,string procedurenumber,string setid,string setname,string otherid,string othername,string othernumber,string othertext) + { + _index = index; + _iD = id; + _name = name; + _number = number; + _text = text; + _procedureNumber = procedurenumber; + _setID = setid; + _setName = setname; + _otherID = otherid; + _otherName = othername; + _otherNumber = othernumber; + _otherText = othertext; + _isDirty = false; + } + public override string ToString() + { + return Name; + } + public string MyXml + { + get { return GenericSerializer.StringSerialize(this); } + } + //#region XML Serializer Namespaces + //private XmlSerializerNamespaces _Namespaces = null; + //[XmlNamespaceDeclarations] + //public XmlSerializerNamespaces Namespaces + //{ + // get + // { + // if (_Namespaces == null) + // { + // _Namespaces = new XmlSerializerNamespaces(); + // } + // return _Namespaces; + // } + // set { _Namespaces = value; } + //} + //#endregion } } \ No newline at end of file