using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using VRH.Log4Pro.MultiLanguageManager; using Vrh.XmlProcessing; namespace Vrh.iScheduler { /// /// Egy kezelő gomb leírására szolgáló osztály /// public class ButtonElement : XmlLinqBase { #region Constants private const string ERR_ROWCOL = "The value of the attribute \"{0}\" must be less than 11 and more than 0!"; #endregion Constants #region Built'in classes #region ElementNames class /// /// Az XML fájlban ilyen elem nevek találhatóak egy "Button" elemben. /// private new class ElementNames : XmlLinqBase.ElementNames { /// /// 'url' elem név. /// public const string URL = "url"; } #endregion ElementNames class #region AttributeNames static class /// /// Az XML fájlban ilyen attribútum nevek találhatóak egy 'Button' elemben. /// private static class AttributeNames { /// /// 'Col' attribútum név. /// public const string COL = "Col"; /// /// 'Dialog' attribútum név. /// public const string DIALOG = "Dialog"; /// /// 'DialogSize' attribútum név. /// public const string DIALOGSIZE = "DialogSize"; /// /// 'HSpan' attribútum név. /// public const string HSPAN = "HSpan"; /// /// 'Name' attribútum név. /// public const string NAME = "Name"; /// /// 'Row' attribútum név. /// public const string ROW = "Row"; /// /// 'Style' attribútum név. /// public const string STYLE = "Style"; /// /// 'Type' attribútum név. /// public const string TYPE = "Type"; /// /// 'Label' attribútum név. /// public const string LABEL = "Label"; /// /// 'WSpan' attribútum név. /// public const string WSPAN = "WSpan"; } #endregion AttributeNames static class #region SysButtonNames public static class /// /// sys típusú kezelő gombok lehetséges nevei. /// public static class SysButtonNames { /// /// Konzisztencia ellenőrzése rendszer gomb neve. /// public const string ConsistencyCheck = "ConsistencyCheck"; /// /// A listanézetre való váltás gombjának a neve. /// public const string GoToListView = "GoToListView"; /// /// A naptár nézetre való váltás gombjának a neve. /// public const string GoToMonthView = "GoToMonthView"; /// /// Az új ütemezés létrehozás gombjának neve. /// public const string NewSchedule = "NewSchedule"; /// /// Az ütemezendő objektum kezelő felületét elindító gomb neve. /// public const string ObjectManager = "ObjectManager"; //WA20170626-#8390 } #endregion SysButtonNames public static class #endregion Built'in classes #region Properties /// /// A gomb megnevezése a HTML-ben a name attribútum értéke. /// public string Name { get; set; } /// /// A gomb típusa. "sys", ha beépített, "url", ha nem. /// public ButtonTypes ButtonType { get; set; } /// /// A megjelenítendő szöveg. /// Kapcsoló gomb esetén a bekapcsolt állapot szövege. /// Ide már a lefordított szöveg kerül. /// public string ButtonLabel { get; set; } /// /// Kapcsoló gomb esetén a kikapcsolt állapot szövege. /// Ide már a lefordított szöveg kerül. /// .- public string ButtonlabelOff { get; set; } /// /// A gomb mátrixban elfoglalt cella sora. /// public int Row { get; set; } /// /// A gomb mátrixban elfoglalt cella oszlopa. /// public int Col { get; set; } /// /// Magasságban (Heigth, HSpan) egyesítendő cellák száma. Alapértelmezése 1. /// public int RowSpan { get; set; } /// /// Szélességben (Width, WSpan) egyesítendő cellák száma. Alapértelmezése 1. /// public int ColSpan { get; set; } /// /// HTML stílusokban alkalmazható stílus. /// public string Style { get; set; } /// /// Az elindítandó url ablakban jelenjen-e meg. /// Ha a gomb neve "NewSchedule", akkor mindig true! /// public bool IsDialog { get; set; } /// /// Ha az elindítandó url ablakban jelenik meg, akkor az milyen széles legyen. /// Alapértelmezett értéke 600px. /// public string DialogSize { get; set; } /// /// url típusú gombok esetében a meghívandó akció leírója. /// public UrlElement Url { get; set; } #endregion Properties #region Constructors /// /// Példányosítás egy 'Button' XElement alapján. /// /// A 'Button' 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 ButtonElement(XElement xelement, string lcid, string wordCodePrefix) public ButtonElement(XElement xelement, string lcid) { if (xelement != null) { this.Name = GetValue(AttributeNames.NAME, xelement, "", true, true); #region ButtonType beolvasása és ellenőrzése string type = GetValue(AttributeNames.TYPE, xelement, "", true, true); if (Enum.TryParse(type, true, out ButtonTypes btype)) { this.ButtonType = btype; } else { throw new ApplicationException(string.Format( "The possible values for \"Button.Type\" attribute \"{0}\"! Button.Name = \"{1}\"", string.Join(", ", Enum.GetNames(typeof(ButtonTypes))), this.Name )); } #endregion ButtonType beolvasása és ellenőrzése this.Row = GetValue(AttributeNames.ROW, xelement, 1, true, true); this.Col = GetValue(AttributeNames.COL, xelement, 1, true, true); this.RowSpan = GetValue(AttributeNames.HSPAN, xelement, 1); this.ColSpan = GetValue(AttributeNames.WSPAN, xelement, 1); this.Style = GetValue(AttributeNames.STYLE, xelement, "color:white;background-color:#45b845;"); this.IsDialog = GetValue(AttributeNames.DIALOG, xelement, false); string ds = GetValue(AttributeNames.DIALOGSIZE, xelement, ""); this.DialogSize = string.IsNullOrWhiteSpace(ds) ? "600px" : ds; #region Row, Col, RowSpan, ColSpan ellenőrzése if (this.Row < 1 || this.Row > 10) { throw new ApplicationException(string.Format(ERR_ROWCOL,"Button.Row")); } if (this.Col < 1 || this.Col > 10) { throw new ApplicationException(string.Format(ERR_ROWCOL, "Button.Col")); } if (this.RowSpan < 1 || this.RowSpan > 10) { throw new ApplicationException(string.Format(ERR_ROWCOL, "Button.HSpan")); } if (this.ColSpan < 1 || this.ColSpan > 10) { throw new ApplicationException(string.Format(ERR_ROWCOL, "Button.WSpan")); } #endregion Row, Col, RowSpan, ColSpan ellenőrzése #region Display if (this.ButtonType == ButtonTypes.Sys) { switch (this.Name) { case SysButtonNames.ConsistencyCheck: this.ButtonLabel = MultiLanguageManager.GetTranslation(typeof(SchedulerWordCodes.iScheduler.Manager.Button.ConsistencyCheckOn), lcid); this.ButtonlabelOff = MultiLanguageManager.GetTranslation(typeof(SchedulerWordCodes.iScheduler.Manager.Button.ConsistencyCheckOff), lcid); break; case SysButtonNames.GoToListView: this.ButtonLabel = MultiLanguageManager.GetTranslation(typeof(SchedulerWordCodes.iScheduler.Manager.Button.GoToListView), lcid); break; case SysButtonNames.GoToMonthView: this.ButtonLabel = MultiLanguageManager.GetTranslation(typeof(SchedulerWordCodes.iScheduler.Manager.Button.GoToMonthView), lcid); break; case SysButtonNames.NewSchedule: this.ButtonLabel = MultiLanguageManager.GetTranslation(typeof(SchedulerWordCodes.iScheduler.Manager.Button.NewSchedule), lcid); break; case SysButtonNames.ObjectManager: this.ButtonLabel = MultiLanguageManager.GetTranslation(typeof(SchedulerWordCodes.iScheduler.Manager.Button.ObjectManager), lcid); break; } } else { this.ButtonLabel = GetValue(AttributeNames.LABEL, xelement, this.Name); if (string.IsNullOrEmpty(this.ButtonLabel)) { this.ButtonLabel = this.Name; } } #endregion Display #region Gomb nevének ellenőrzése, url típus beolvasása if (this.ButtonType == ButtonTypes.Sys) { switch(this.Name) { case SysButtonNames.ConsistencyCheck: case SysButtonNames.NewSchedule: case SysButtonNames.GoToListView: case SysButtonNames.GoToMonthView: case SysButtonNames.ObjectManager: //WA20170629-#8390 break; default: throw new ApplicationException(string.Format( "The possible values for 'Button.Name' attribute if the Type='sys' " + "{0}, {1}, {2}, {3}, {4} ! Name = {5}", SysButtonNames.ConsistencyCheck, SysButtonNames.ObjectManager, SysButtonNames.GoToListView, SysButtonNames.GoToMonthView, SysButtonNames.NewSchedule, this.Name)); } } else { //nem sys típusú gombok, azok viszont nem vehetik fel a sys gombok nevét! switch (this.Name) { case SysButtonNames.ConsistencyCheck: case SysButtonNames.NewSchedule: case SysButtonNames.GoToListView: case SysButtonNames.GoToMonthView: case SysButtonNames.ObjectManager: //WA20170629-#8390 throw new ApplicationException(string.Format( "If the Type='url', then the names can not be the following: " + "{0}, {1}, {2}, {3}, {4} ! Name = {5}", SysButtonNames.ConsistencyCheck, SysButtonNames.ObjectManager, SysButtonNames.GoToListView, SysButtonNames.GoToMonthView, SysButtonNames.NewSchedule, this.Name)); default: break; } XElement urlXE = xelement.Element(ElementNames.URL); if (urlXE == null) { throw new ApplicationException(string.Format(XmlLinqBase.Messages.ERR_MISSINGELEMENT, ElementNames.URL)); } this.Url = new UrlElement(urlXE); if (this.Url != null && this.Url.UrlParameters != null) { if (this.Url.UrlParameters.Any(x => x.PassTo.ToLower() == UrlElement.ParameterTypes.dict)) { throw new ApplicationException("The Button.Url.inputparameter.PassTo=\"dict\" attribute are not allowed in this context!"); } } } #endregion Gomb nevének ellenőrzése, url típus beolvasása } } #endregion Constructors } }