5
5
using System . Windows . Forms ;
6
6
using taskt . UI . Forms ;
7
7
using taskt . UI . CustomControls ;
8
+ using System . Drawing ;
9
+ using System . Linq ;
8
10
9
11
namespace taskt . Core . Automation . Commands
10
12
{
@@ -16,64 +18,88 @@ namespace taskt.Core.Automation.Commands
16
18
public class CreateDataTableCommand : ScriptCommand
17
19
{
18
20
[ XmlAttribute ]
19
- [ Attributes . PropertyAttributes . PropertyDescription ( "Please create a DataTable name " ) ]
21
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please Indicate DataTable Name " ) ]
20
22
[ Attributes . PropertyAttributes . InputSpecification ( "Indicate a unique reference name for later use" ) ]
21
23
[ Attributes . PropertyAttributes . SampleUsage ( "vMyDatatable" ) ]
22
24
[ Attributes . PropertyAttributes . Remarks ( "" ) ]
23
25
public string v_DataTableName { get ; set ; }
24
26
25
- [ XmlAttribute ]
26
- [ Attributes . PropertyAttributes . PropertyDescription ( "Please indicate the names of your columns" ) ]
27
- [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
28
- [ Attributes . PropertyAttributes . InputSpecification ( "Enter the actual names of your columns." ) ]
29
- [ Attributes . PropertyAttributes . SampleUsage ( "name1,name2,name3,name4" ) ]
27
+ [ XmlElement ]
28
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Define Column Names" ) ]
29
+ [ Attributes . PropertyAttributes . InputSpecification ( "Enter the Column Names required for each column of data" ) ]
30
+ [ Attributes . PropertyAttributes . SampleUsage ( "" ) ]
30
31
[ Attributes . PropertyAttributes . Remarks ( "" ) ]
31
- public string v_DataTableColumnNames { get ; set ; }
32
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
33
+ public DataTable v_ColumnNameDataTable { get ; set ; }
34
+
32
35
33
36
public CreateDataTableCommand ( )
34
37
{
35
38
this . CommandName = "CreateDataTableCommand" ;
36
39
this . SelectionName = "Create DataTable" ;
37
40
this . CommandEnabled = true ;
38
41
this . CustomRendering = true ;
42
+
43
+ //initialize data table
44
+ this . v_ColumnNameDataTable = new System . Data . DataTable
45
+ {
46
+ TableName = "ColumnNamesDataTable" + DateTime . Now . ToString ( "MMddyy.hhmmss" )
47
+ } ;
48
+
49
+ this . v_ColumnNameDataTable . Columns . Add ( "Column Name" ) ;
50
+
51
+
39
52
}
40
53
41
54
public override void RunCommand ( object sender )
42
55
{
43
56
var engine = ( Core . Automation . Engine . AutomationEngineInstance ) sender ;
44
- var vDataTableColumnNames = v_DataTableColumnNames . ConvertToUserVariable ( sender ) ;
57
+ var dataTableName = v_DataTableName . ConvertToUserVariable ( sender ) ;
45
58
46
- var splittext = vDataTableColumnNames . Split ( ',' ) ;
47
59
DataTable Dt = new DataTable ( ) ;
48
60
49
- foreach ( var item in splittext )
61
+ foreach ( DataRow rwColumnName in v_ColumnNameDataTable . Rows )
50
62
{
51
- Dt . Columns . Add ( item ) ;
63
+ Dt . Columns . Add ( rwColumnName . Field < string > ( "Column Name" ) ) ;
52
64
}
53
65
54
- Script . ScriptVariable newDataTable = new Script . ScriptVariable
66
+
67
+
68
+
69
+ //add or override existing variable
70
+ if ( engine . VariableList . Any ( f => f . VariableName == dataTableName ) )
55
71
{
56
- VariableName = v_DataTableName ,
57
- VariableValue = Dt
58
- } ;
72
+ var selectedVariable = engine . VariableList . Where ( f => f . VariableName == dataTableName ) . FirstOrDefault ( ) ;
73
+ selectedVariable . VariableValue = Dt ;
74
+ }
75
+ else
76
+ {
77
+ Script . ScriptVariable newDataTable = new Script . ScriptVariable
78
+ {
79
+ VariableName = dataTableName ,
80
+ VariableValue = Dt
81
+ } ;
59
82
60
- engine . VariableList . Add ( newDataTable ) ;
83
+ engine . VariableList . Add ( newDataTable ) ;
84
+ }
85
+
86
+
87
+
61
88
}
62
89
public override List < Control > Render ( frmCommandEditor editor )
63
90
{
64
91
base . Render ( editor ) ;
65
92
66
93
//create standard group controls
67
94
RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_DataTableName" , this , editor ) ) ;
68
- RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_DataTableColumnNames" , this , editor ) ) ;
69
-
95
+ RenderedControls . AddRange ( CommandControls . CreateDataGridViewGroupFor ( "v_ColumnNameDataTable" , this , editor ) ) ;
70
96
return RenderedControls ;
71
97
72
98
}
73
99
74
100
public override string GetDisplayValue ( )
75
101
{
76
- return base . GetDisplayValue ( ) + "[Create DataTable with name: " + v_DataTableName + " ]";
102
+ return base . GetDisplayValue ( ) + $ " [Name: ' { v_DataTableName } ' with { v_ColumnNameDataTable . Rows . Count } Columns ]";
77
103
}
78
104
}
79
105
}
0 commit comments