-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIPLCustomMacroMethods.cs
91 lines (71 loc) · 3.84 KB
/
SIPLCustomMacroMethods.cs
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
using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.Helpers;
using CMS.MacroEngine;
// Makes all methods in the 'CustomMacroMethods' container class available for string objects
[assembly: RegisterExtension(typeof(SIPLCustomMacroMethods), typeof(string))]
// Registers methods from the 'CustomMacroMethods' container into the "String" macro namespace
[assembly: RegisterExtension(typeof(SIPLCustomMacroMethods), typeof(StringNamespace))]
/// <summary>
/// Summary description for SIPLCustomMacroMethods
/// </summary>
public class SIPLCustomMacroMethods : MacroMethodContainer
{
public SIPLCustomMacroMethods()
{
//
// TODO: Add constructor logic here
//
}
[MacroMethod(typeof(object), "This macro is used to fetch column field value from a custom table on passing Custom table name, Unique ID and Column name", 3)]
[MacroMethodParam(0, "CustomTableName", typeof(string), "Custom Table Name")]
[MacroMethodParam(1, "ItemID", typeof(string), "ItemID to get the record of the custom table from which the field value is to be returned.")]
[MacroMethodParam(2, "ColumnName", typeof(string), "Column Name")]
public static object GetValueFromCustomTableByItemID(EvaluationContext context, params object[] parameters)
{
if (parameters[0] == null || parameters[1] == null || parameters[2] == null)
return null;
string CustomTableName = ValidationHelper.GetString(parameters[0], "");
string UniqueID = ValidationHelper.GetString(parameters[1], "");
string ColumnName = ValidationHelper.GetString(parameters[2], "");
DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(CustomTableName);
if (customTable != null)
{
var ds = CustomTableItemProvider.GetItems(CustomTableName)
.Column(ColumnName)
.WhereEquals("ItemID", UniqueID)
.TopN(1);
if (!DataHelper.DataSourceIsEmpty(ds) && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0].Rows[0][0];
}
}
return null;
}
[MacroMethod(typeof(object), "This macro is used to fetch column field value from a custom table on passing Custom table name, Unique ID and Column name", 3)]
[MacroMethodParam(0, "CustomTableName", typeof(string), "Custom Table Name")]
[MacroMethodParam(1, "ItemGUID", typeof(string), "ItemGUID to get the record of the custom table from which the field value is to be returned.")]
[MacroMethodParam(2, "ColumnName", typeof(string), "Column Name")]
public static object GetValueFromCustomTableByItemGUID(EvaluationContext context, params object[] parameters)
{
if (parameters[0] == null || parameters[1] == null || parameters[2] == null)
return null;
string CustomTableName = ValidationHelper.GetString(parameters[0], "");
string UniqueID = ValidationHelper.GetString(parameters[1], "");
string ColumnName = ValidationHelper.GetString(parameters[2], "");
DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(CustomTableName);
if (customTable != null)
{
var ds = CustomTableItemProvider.GetItems(CustomTableName)
.Column(ColumnName)
.WhereEquals("ItemGUID", UniqueID)
.TopN(1);
if (!DataHelper.DataSourceIsEmpty(ds) && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0].Rows[0][0];
}
}
return null;
}
}