-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEbControlContainer.cs
More file actions
428 lines (344 loc) · 16.6 KB
/
EbControlContainer.cs
File metadata and controls
428 lines (344 loc) · 16.6 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using ServiceStack.Redis;
using ExpressBase.Common.Objects.Attributes;
using ServiceStack;
using ExpressBase.Common.Extensions;
using System.Linq;
using Newtonsoft.Json;
using System.Runtime.Serialization;
using ExpressBase.Objects;
using ExpressBase.Common.Constants;
namespace ExpressBase.Common.Objects
{
public enum EnumOperator
{
Equal,
NotEqual,
StartsWith,
Contains,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual
}
[EnableInBuilder(BuilderType.WebForm, BuilderType.FilterDialog, BuilderType.BotForm, BuilderType.UserControl)]
public class EbControlContainer : EbControlUI
{
[OnDeserialized]
public void OnDeserializedMethod(StreamingContext context)
{
if (this.Padding == null)
this.Padding = new UISides();
}
[EnableInBuilder(BuilderType.WebForm, BuilderType.FilterDialog, BuilderType.BotForm, BuilderType.UserControl, BuilderType.SurveyControl)]
[HideInPropertyGrid]
[PropertyPriority(70)]
[PropertyGroup("Behavior")]
public virtual List<EbControl> Controls { get; set; }
//[HideInPropertyGrid]
//public EbTable Table { get; set; }
public EbControlContainer()
{
this.Controls = new List<EbControl>();
}
public override string BackColor { get; set; }
public override string ForeColor { get; set; }
//[JsonIgnore]
public override bool Hidden { get; set; }
//[JsonIgnore]
public override EbScript HiddenExpr { get; set; }
[JsonIgnore]
public override EbScript DisableExpr { get; set; }
[JsonIgnore]
public override EbScript ValueExpr { get; set; }
public override bool SelfTrigger { get; set; }
//[JsonIgnore] //this prop using in DG -to prevent attribute propagation
public override bool IsDisable { get; set; }
public override bool DoNotPersist { get; set; }
public override bool DoNotImport { get; set; }
public override bool DoNotExport { get; set; }
public override bool DoNotClone { get; set; }
public override bool ExternalColumn { get; set; }
public override EbScript OnChangeFn { get; set; }
[JsonIgnore]
public override bool IsNonDataInputControl { get; set; }
public override bool IgnoreDataConsistencyCheck { get; set; }
[EnableInBuilder(BuilderType.WebForm, BuilderType.UserControl)]
[HideInPropertyGrid]
public virtual bool IsSpecialContainer { get; set; }
[EnableInBuilder(BuilderType.WebForm, BuilderType.UserControl)]
[HideInPropertyGrid]
public virtual bool isTableNameFromParent { get; set; }
[EnableInBuilder(BuilderType.WebForm, BuilderType.BotForm, BuilderType.UserControl)]
[PropertyEditor(PropertyEditorType.Expandable)]
[PropertyGroup(PGConstants.APPEARANCE)]
[UIproperty]
[OnChangeUIFunction("Common.PADDING")]
//[DefaultPropValue(4, 4, 4, 4)]
public virtual UISides Padding { get; set; }
[EnableInBuilder(BuilderType.WebForm, BuilderType.UserControl)]
[PropertyGroup(PGConstants.DATA)]
[PropertyPriority(70)]
[HelpText("Name Of database-table Which you want to store Data collected using this Form")]
[InputMask("[a-z][a-z0-9]*(_[a-z0-9]+)*")]
public virtual string TableName { get; set; }
[JsonIgnore]
public override bool Required { get; set; }
[JsonIgnore]
public override bool Unique { get; set; }
[JsonIgnore]
public override string ToolTipText { get; set; }
//[JsonIgnore]
//public override string FontFamily { get; set; }
public override List<EbValidator> Validators { get; set; }
[JsonIgnore]
public override EbScript DefaultValueExpression { get; set; }
[JsonIgnore]
public override string GetValueJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string GetValueFromDOMJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string GetDisplayMemberFromDOMJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string GetDisplayMemberJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string IsRequiredOKJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string SetValueJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string SetDisplayMemberJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string JustSetValueJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string IsEmptyJSfn { get { return string.Empty; } set { } }
//[JsonIgnore]
//public override string HideJSfn { get { return string.Empty; } set { } }
//[JsonIgnore]
//public override string ShowJSfn { get { return string.Empty; } set { } }
//[JsonIgnore]
//public override string EnableJSfn { get { return string.Empty; } set { } }
//[JsonIgnore]
//public override string DisableJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string ResetJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string RefreshJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string ClearJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string OnChangeBindJSFn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string AddInvalidStyleJSFn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string RemoveInvalidStyleJSFn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string GetColumnJSfn { get { return string.Empty; } set { } }
[JsonIgnore]
public override string StyleJSFn { get { return string.Empty; } set { } }
//methods
public void SetContextId(string ContextId)
{
this.ContextId = ContextId;
for (int i = 0; i < Controls.Count; i++)
{
EbControl control = Controls[i];
control.ContextId = ContextId;
if (control is EbControlContainer)
(control as EbControlContainer).SetContextId(ContextId);
}
}
public virtual string GetHtml(bool isRootObj)
{
return string.Empty;
}
//foreach (EbControl control in Controls)
//{
// if (control is EbControlContainer)
// {
// EbControlContainer Cont = control as EbControlContainer;
// if (Cont.TableName.IsNullOrEmpty()|| Cont.TableName.Trim() == string.Empty)
// {
// Cont.TableName = TableName;
// }
// }
//}
//public virtual string GetSelectQuery(string _parentTblName)
//{
// string ColoumsStr = Get1stLvlColNames();
// string qry = string.Empty;
// if (ColoumsStr.Length > 0)
// {
// if (TableName == _parentTblName)
// qry = string.Format("SELECT id, {0} FROM {1} WHERE {3} = {2};", ColoumsStr, TableName, TableRowId, "id");
// else
// qry = string.Format("SELECT id, {0} FROM {1} WHERE {3}={2};", ColoumsStr, TableName, TableRowId, _parentTblName + "_id");
// }
// foreach (EbControl control in Controls)
// {
// if (control is EbControlContainer)
// {
// EbControlContainer _control = (control as EbControlContainer);
// if (_control.TableName.IsNullOrEmpty())
// {
// _control.TableName = TableName;
// }
// //_control.TableName = _control.TableName.IsNullOrEmpty() ? TableName : _control.TableName;
// _control.TableRowId = (_control.TableRowId == 0) ? TableRowId : _control.TableRowId;
// qry += _control.GetSelectQuery(_parentTblName);
// }
// }
// return qry;
//}
public static string GetControlOpsJS(EbControlContainer ebControlContainer, BuilderType FormTypeEnum)
{
string JSCode = "var ControlOps = {}";
Type[] _typeArray = (ebControlContainer.GetType().GetTypeInfo().Assembly.GetTypes());
Dictionary<string, string> DictControlOps = new Dictionary<string, string>();
foreach (Type ctrlType in _typeArray)
{
try
{
TypeInfo _typeInfo = ctrlType.GetTypeInfo();
var _enableInBuider = _typeInfo.GetCustomAttribute<EnableInBuilder>();
string TypeName = ctrlType.Name.Substring(2, ctrlType.Name.Length - 2);
if (_enableInBuider != null && _enableInBuider.BuilderTypes.Contains(FormTypeEnum))
{
object ctrlObj = Activator.CreateInstance(ctrlType);
if (
//(!_typeInfo.IsDefined(typeof(HideInToolBox))) && // temp
ctrlObj is EbControl)
if (!DictControlOps.ContainsKey(TypeName))
{
EbControl _ctrlObj = (ctrlObj as EbControl);
string opFnsJs = string.Empty;
opFnsJs += GetOpFnJs("getValue", _ctrlObj.GetValueJSfn, TypeName);
opFnsJs += GetOpFnJs("getPreviousValue", _ctrlObj.GetPreviousValueJSfn, TypeName);
opFnsJs += GetOpFnJs("getValueFromDOM", _ctrlObj.GetValueFromDOMJSfn, TypeName);
opFnsJs += GetOpFnJs("getDisplayMember", _ctrlObj.GetDisplayMemberJSfn, TypeName);
opFnsJs += GetOpFnJs("getDisplayMemberFromDOM", _ctrlObj.GetDisplayMemberFromDOMJSfn, TypeName);
opFnsJs += GetOpFnJs("isRequiredOK", _ctrlObj.IsRequiredOKJSfn, TypeName);
opFnsJs += GetOpFnJs("isEmpty", _ctrlObj.IsEmptyJSfn, TypeName);
opFnsJs += GetOpFnJs("setValue", _ctrlObj.SetValueJSfn, TypeName);
opFnsJs += GetOpFnJs("setDisplayMember", _ctrlObj.SetDisplayMemberJSfn, TypeName);
opFnsJs += GetOpFnJs("justSetValue", _ctrlObj.JustSetValueJSfn, TypeName);
opFnsJs += GetOpFnJs("hide", _ctrlObj.HideJSfn, TypeName);
opFnsJs += GetOpFnJs("show", _ctrlObj.ShowJSfn, TypeName);
opFnsJs += GetOpFnJs("enable", _ctrlObj.EnableJSfn, TypeName);
opFnsJs += GetOpFnJs("disable", _ctrlObj.DisableJSfn, TypeName);
opFnsJs += GetOpFnJs("reset", _ctrlObj.ResetJSfn, TypeName);
opFnsJs += GetOpFnJs("refresh", _ctrlObj.RefreshJSfn, TypeName);
opFnsJs += GetOpFnJs("clear", _ctrlObj.ClearJSfn, TypeName);
opFnsJs += GetOpFnJs("addInvalidStyle", _ctrlObj.AddInvalidStyleJSFn, TypeName);
opFnsJs += GetOpFnJs("removeInvalidStyle", _ctrlObj.RemoveInvalidStyleJSFn, TypeName);
opFnsJs += GetOpFnJs("bindOnChange", _ctrlObj.OnChangeBindJSFn, TypeName);
if (_ctrlObj.ObjType == "DGPowerSelectColumn")
{
opFnsJs += GetOpFnJs("getColumn", _ctrlObj.GetColumnJSfn, TypeName);
}
string fn = string.Concat("function ", TypeName, "(jsonObj){ $.extend(this, jsonObj);", opFnsJs, "}");//.RemoveCR();
JSCode += string.Concat(@"
ControlOps.", TypeName, " = ", fn); ;
DictControlOps.Add(TypeName, "fn placeholder");
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return JSCode;
}
private static string GetOpFnJs(string opFnName, string JSfn, string TypeName)
{
return string.Concat(@"
this.", opFnName, " = function(p1, p2, p3, p4) { ", JSfn, "};");//.RemoveCR();
}
public static void SetContextId(EbControlContainer FormObj, string contextId)
{
try
{
FormObj.ContextId = contextId;
foreach (EbControl control in FormObj.Controls)
{
if (control is EbControlContainer)
{
EbControlContainer.SetContextId(control as EbControlContainer, contextId);
}
else
{
control.ContextId = contextId;
}
}
}
catch (Exception e)
{
if (FormObj == null)
throw new NullReferenceException();
else throw e;
}
}
public virtual string Get1stLvlColNames()
{
string ColoumsStr = String.Empty;
IEnumerable<EbControl> controls = Controls.Get1stLvlControls();
foreach (var control in controls)
{
ColoumsStr += control.Name + ", ";
}
return (ColoumsStr.Length > 0) ? ColoumsStr.Substring(0, ColoumsStr.Length - 2) : string.Empty;
}
public virtual int TableRowId { get; set; }
public override string HelpText { get; set; }
[EnableInBuilder(BuilderType.WebForm, BuilderType.FilterDialog, BuilderType.BotForm, BuilderType.UserControl)]
[HideInPropertyGrid]
public virtual bool IsContainer { get { return true; } private set { } }
[EnableInBuilder(BuilderType.WebForm, BuilderType.FilterDialog, BuilderType.BotForm, BuilderType.UserControl)]
[Alias("Title")]
public override string Label { get; set; }
public override void Init4Redis(IRedisClient redisclient, IServiceClient serviceclient)
{
base.Redis = redisclient;
base.ServiceStackClient = serviceclient;
}
public override string GetHtml() { return string.Empty; }
public string GetInsertQry()
{
string qry = string.Empty;
return qry;
}
public string GetCtrlNamesOfTable(string tableName)
{
string cols = string.Empty;
if (TableName == tableName)
{
string _1stLvlColNames = Get1stLvlColNames();
if (!_1stLvlColNames.IsNullOrEmpty())
cols += string.Concat(_1stLvlColNames, ", ");
}
GetCtrlNamesOfTableRec(tableName, ref cols);
return cols.Substring(0, cols.Length - 2);
}
private void GetCtrlNamesOfTableRec(string tableName, ref string cols)
{
foreach (EbControl control in Controls)
{
if (control is EbControlContainer)
{
EbControlContainer Cont = control as EbControlContainer;
Cont.TableName = Cont.TableName.IsNullOrEmpty() ? TableName : Cont.TableName;
if (Cont.TableName == tableName)
{
string _1stLvlColNames = Cont.Get1stLvlColNames();
if (!_1stLvlColNames.IsNullOrEmpty())
cols += string.Concat(_1stLvlColNames, ", ");
}
Cont.GetCtrlNamesOfTableRec(tableName, ref cols);
}
}
}
}
}