ButtonElement.cs
13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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
{
/// <summary>
/// Egy kezelő gomb leírására szolgáló osztály
/// </summary>
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
/// <summary>
/// Az XML fájlban ilyen elem nevek találhatóak egy "Button" elemben.
/// </summary>
private new class ElementNames : XmlLinqBase.ElementNames
{
/// <summary>
/// 'url' elem név.
/// </summary>
public const string URL = "url";
}
#endregion ElementNames class
#region AttributeNames static class
/// <summary>
/// Az XML fájlban ilyen attribútum nevek találhatóak egy 'Button' elemben.
/// </summary>
private static class AttributeNames
{
/// <summary>
/// 'Col' attribútum név.
/// </summary>
public const string COL = "Col";
/// <summary>
/// 'Dialog' attribútum név.
/// </summary>
public const string DIALOG = "Dialog";
/// <summary>
/// 'DialogSize' attribútum név.
/// </summary>
public const string DIALOGSIZE = "DialogSize";
/// <summary>
/// 'HSpan' attribútum név.
/// </summary>
public const string HSPAN = "HSpan";
/// <summary>
/// 'Name' attribútum név.
/// </summary>
public const string NAME = "Name";
/// <summary>
/// 'Row' attribútum név.
/// </summary>
public const string ROW = "Row";
/// <summary>
/// 'Style' attribútum név.
/// </summary>
public const string STYLE = "Style";
/// <summary>
/// 'Type' attribútum név.
/// </summary>
public const string TYPE = "Type";
/// <summary>
/// 'Label' attribútum név.
/// </summary>
public const string LABEL = "Label";
/// <summary>
/// 'WSpan' attribútum név.
/// </summary>
public const string WSPAN = "WSpan";
}
#endregion AttributeNames static class
#region SysButtonNames public static class
/// <summary>
/// sys típusú kezelő gombok lehetséges nevei.
/// </summary>
public static class SysButtonNames
{
/// <summary>
/// Konzisztencia ellenőrzése rendszer gomb neve.
/// </summary>
public const string ConsistencyCheck = "ConsistencyCheck";
/// <summary>
/// A listanézetre való váltás gombjának a neve.
/// </summary>
public const string GoToListView = "GoToListView";
/// <summary>
/// A naptár nézetre való váltás gombjának a neve.
/// </summary>
public const string GoToMonthView = "GoToMonthView";
/// <summary>
/// Az új ütemezés létrehozás gombjának neve.
/// </summary>
public const string NewSchedule = "NewSchedule";
/// <summary>
/// Az ütemezendő objektum kezelő felületét elindító gomb neve.
/// </summary>
public const string ObjectManager = "ObjectManager"; //WA20170626-#8390
}
#endregion SysButtonNames public static class
#endregion Built'in classes
#region Properties
/// <summary>
/// A gomb megnevezése a HTML-ben a name attribútum értéke.
/// </summary>
public string Name { get; set; }
/// <summary>
/// A gomb típusa. "sys", ha beépített, "url", ha nem.
/// </summary>
public ButtonTypes ButtonType { get; set; }
/// <summary>
/// A megjelenítendő szöveg.
/// Kapcsoló gomb esetén a bekapcsolt állapot szövege.
/// Ide már a lefordított szöveg kerül.
/// </summary>
public string ButtonLabel { get; set; }
/// <summary>
/// Kapcsoló gomb esetén a kikapcsolt állapot szövege.
/// Ide már a lefordított szöveg kerül.
/// </summary>.-
public string ButtonlabelOff { get; set; }
/// <summary>
/// A gomb mátrixban elfoglalt cella sora.
/// </summary>
public int Row { get; set; }
/// <summary>
/// A gomb mátrixban elfoglalt cella oszlopa.
/// </summary>
public int Col { get; set; }
/// <summary>
/// Magasságban (Heigth, HSpan) egyesítendő cellák száma. Alapértelmezése 1.
/// </summary>
public int RowSpan { get; set; }
/// <summary>
/// Szélességben (Width, WSpan) egyesítendő cellák száma. Alapértelmezése 1.
/// </summary>
public int ColSpan { get; set; }
/// <summary>
/// HTML stílusokban alkalmazható stílus.
/// </summary>
public string Style { get; set; }
/// <summary>
/// Az elindítandó url ablakban jelenjen-e meg.
/// Ha a gomb neve "NewSchedule", akkor mindig true!
/// </summary>
public bool IsDialog { get; set; }
/// <summary>
/// Ha az elindítandó url ablakban jelenik meg, akkor az milyen széles legyen.
/// Alapértelmezett értéke 600px.
/// </summary>
public string DialogSize { get; set; }
/// <summary>
/// url típusú gombok esetében a meghívandó akció leírója.
/// </summary>
public UrlElement Url { get; set; }
#endregion Properties
#region Constructors
/// <summary>
/// Példányosítás egy 'Button' XElement alapján.
/// </summary>
/// <param name="xelement">A 'Button' elem XElement objektuma.</param>
/// <param name="lcid">A környezetben érvényes nyelvi kód.</param>
/// A gomboknál lévő szókód lesz hozzáfűzve.
/// Így alkotják a gomb megjelenő nevének szókódját.
/// </param>
//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<ButtonTypes>(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
}
}