using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Vrh.XmlProcessing;
namespace Vrh.iScheduler
{
///
/// A "Manager" elem leképezése.
///
public class ManagerElement : XmlLinqBase
{
#region Built'in classes
#region ElementNames class
///
/// Az XML fájlban ilyen elem nevek találhatóak egy "Button" elemben.
///
public new class ElementNames : XmlLinqBase.ElementNames
{
///
/// 'Button' elem név.
///
public const string BUTTON = "Button";
///
/// 'Buttons' elem név.
///
public const string BUTTONS = "Buttons";
///
/// 'Options' elem név.
///
public const string OPTIONS = "Options";
}
#endregion ElementNames class
#region AttributeNames static class
///
/// Az XML fájlban ilyen attribútum nevek találhatóak egy 'Button' elemben.
///
public static class AttributeNames
{
///
/// 'DefaultDisplayMode' attribútum név.
///
public const string DEFAULTDISPLAYMODE = "DefaultDisplayMode";
}
#endregion AttributeNames static class
#endregion Built'in classes
#region Properties
///
/// A kezelőgombok elhelyezéséhez hány sor fog kelleni.
///
public int ButtonRows { get; set; } = 0;
///
/// A kezelőgombok elhelyezéséhez hány oszlop fog kelleni.
///
public int ButtonCols { get; set; } = 0;
///
/// Kezelő gombok listája.
///
public List Buttons { get; set; }
///
/// Alapértelmezett nézet.
///
public DisplayMode DefaultDisplayMode { get; set; }
#endregion Properties
#region Constructors
///
/// Példányosítás egy 'Manager' XElement alapján.
///
/// A 'Manager' elem XElement objektuma.
/// A környezetben érvényes nyelvi kód.
///
/// A gomboknál lévő szókód lesz hozzáfűzve.
/// Így alkotják a gomb megjelenő nevének szókódját.
///
//public ManagerElement(XElement xelement, string lcid, string wordCodePrefix)
public ManagerElement(XElement xelement, string lcid)
{
if (xelement != null)
{
#region DefaultDisplayMode beállítása
XAttribute xa = xelement.Element(ElementNames.OPTIONS)?.Attribute(AttributeNames.DEFAULTDISPLAYMODE);
if (xa == null)
{
this.DefaultDisplayMode = DisplayMode.List;
}
else
{
this.DefaultDisplayMode = GetEnumValue(xa, DisplayMode.List);
}
#endregion DefaultDisplayMode beállítása
#region Buttons beállítása
XElement xe = xelement.Element(ElementNames.BUTTONS);
if (xe != null)
{
IEnumerable buttonsXE = xe.Elements(ElementNames.BUTTON);
if (buttonsXE != null && buttonsXE.Any())
{
this.Buttons = new List();
foreach (var buttonXE in buttonsXE)
{
//using (var newbttn = new ButtonElement(buttonXE, lcid, wordCodePrefix))
using (var newbttn = new ButtonElement(buttonXE, lcid))
{
if (this.Buttons.Any(x => x.Name == newbttn.Name))
{
throw new ApplicationException(string.Format(
"The 'Button.Name' attribute is not unique in the buttons! Name={0}", newbttn.Name
));
}
if (this.Buttons.Any(x => x.Row == newbttn.Row && x.Col == newbttn.Col))
{
throw new ApplicationException(string.Format(
"The 'Row' and 'Col' attribute is not unique in the buttons! Name='{0}', Row={1}, Col={2}", newbttn.Name, newbttn.Row, newbttn.Col
));
}
this.ButtonRows = this.ButtonRows < (newbttn.Row + newbttn.RowSpan - 1) ? (newbttn.Row + newbttn.RowSpan - 1) : this.ButtonRows;
this.ButtonCols = this.ButtonCols < (newbttn.Col + newbttn.ColSpan - 1) ? (newbttn.Col + newbttn.ColSpan - 1) : this.ButtonCols;
this.Buttons.Add(newbttn);
}
}
}
}
#endregion Buttons beállítása
}
}
#endregion Constructors
}
}