@@ -22,41 +22,55 @@ public class AddDataRowCommand : ScriptCommand
22
22
[ Attributes . PropertyAttributes . SampleUsage ( "**myData**" ) ]
23
23
[ Attributes . PropertyAttributes . Remarks ( "" ) ]
24
24
public string v_DataTableName { get ; set ; }
25
- [ XmlAttribute ]
26
- [ Attributes . PropertyAttributes . PropertyDescription ( "Please input the data you want entered." ) ]
27
- [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
28
- [ Attributes . PropertyAttributes . InputSpecification ( "Enter a string of comma seperated values. " ) ]
29
- [ Attributes . PropertyAttributes . SampleUsage ( "name1,name2,name3,name4 " ) ]
25
+
26
+ [ XmlElement ]
27
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Define Data" ) ]
28
+ [ Attributes . PropertyAttributes . InputSpecification ( "Enter the Column Names required for each column of data " ) ]
29
+ [ Attributes . PropertyAttributes . SampleUsage ( "" ) ]
30
30
[ Attributes . PropertyAttributes . Remarks ( "" ) ]
31
- public string v_InputData { get ; set ; }
31
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
32
+ public DataTable v_AddDataDataTable { get ; set ; }
33
+
34
+
35
+ [ XmlIgnore ]
36
+ [ NonSerialized ]
37
+ private List < CreateDataTableCommand > DataTableCreationCommands ;
32
38
33
39
public AddDataRowCommand ( )
34
40
{
35
41
this . CommandName = "AddDataRowCommand" ;
36
42
this . SelectionName = "Add DataRow" ;
37
43
this . CommandEnabled = true ;
38
44
this . CustomRendering = true ;
45
+
46
+ //initialize data table
47
+ this . v_AddDataDataTable = new System . Data . DataTable
48
+ {
49
+ TableName = "AddDataDataTable" + DateTime . Now . ToString ( "MMddyy.hhmmss" )
50
+ } ;
51
+
52
+ this . v_AddDataDataTable . Columns . Add ( "Column Name" ) ;
53
+ this . v_AddDataDataTable . Columns . Add ( "Data" ) ;
54
+
39
55
}
40
56
41
57
public override void RunCommand ( object sender )
42
58
{
43
59
var engine = ( Core . Automation . Engine . AutomationEngineInstance ) sender ;
44
60
var dataSetVariable = LookupVariable ( engine ) ;
45
- var vInputData = v_InputData . ConvertToUserVariable ( engine ) ;
61
+
46
62
DataTable Dt = ( DataTable ) dataSetVariable . VariableValue ;
47
- vInputData = vInputData . Trim ( '\\ ' , '"' , '/' ) ;
48
- var splittext = vInputData . Split ( ',' ) ;
63
+ var newRow = Dt . NewRow ( ) ;
49
64
50
- int i = 0 ;
51
- foreach ( string str in splittext )
65
+ foreach ( DataRow rw in v_AddDataDataTable . Rows )
52
66
{
53
- splittext [ i ] = str . Trim ( '\\ ' , '"' , '[' , ']' ) ;
54
- if ( splittext [ i ] == null )
55
- splittext [ i ] = string . Empty ;
56
- i ++ ;
67
+ var columnName = rw . Field < string > ( "Column Name" ) . ConvertToUserVariable ( sender ) ;
68
+ var data = rw . Field < string > ( "Data" ) . ConvertToUserVariable ( sender ) ;
69
+ newRow . SetField ( columnName , data ) ;
57
70
}
58
71
59
- Dt . Rows . Add ( splittext . ToArray ( ) ) ;
72
+ Dt . Rows . Add ( newRow ) ;
73
+
60
74
dataSetVariable . VariableValue = Dt ;
61
75
}
62
76
private Script . ScriptVariable LookupVariable ( Core . Automation . Engine . AutomationEngineInstance sendingInstance )
@@ -79,15 +93,54 @@ public override List<Control> Render(frmCommandEditor editor)
79
93
base . Render ( editor ) ;
80
94
81
95
RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_DataTableName" , this , editor ) ) ;
82
- RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_InputData" , this , editor ) ) ;
96
+
97
+
98
+ RenderedControls . AddRange ( CommandControls . CreateDataGridViewGroupFor ( "v_AddDataDataTable" , this , editor ) ) ;
99
+
100
+ taskt . UI . CustomControls . CommandItemControl loadSchemaControl = new taskt . UI . CustomControls . CommandItemControl ( ) ;
101
+ loadSchemaControl . ForeColor = System . Drawing . Color . White ;
102
+ loadSchemaControl . CommandDisplay = "Load Column Names From Existing Table" ;
103
+ loadSchemaControl . Click += LoadSchemaControl_Click ;
104
+ RenderedControls . Add ( loadSchemaControl ) ;
105
+
106
+ DataTableCreationCommands = editor . configuredCommands . Where ( f => f is CreateDataTableCommand ) . Select ( f => ( CreateDataTableCommand ) f ) . ToList ( ) ;
107
+
108
+
83
109
84
110
85
111
return RenderedControls ;
86
112
}
87
113
114
+ private void LoadSchemaControl_Click ( object sender , EventArgs e )
115
+ {
116
+ UI . Forms . Supplemental . frmItemSelector selectionForm = new UI . Forms . Supplemental . frmItemSelector ( ) ;
117
+ selectionForm . Text = "Load Schema" ;
118
+ selectionForm . lblHeader . Text = "Select a table from the list" ;
119
+ foreach ( var item in DataTableCreationCommands )
120
+ {
121
+ selectionForm . lstVariables . Items . Add ( item . v_DataTableName ) ;
122
+ }
123
+
124
+ var result = selectionForm . ShowDialog ( ) ;
125
+
126
+ if ( result == DialogResult . OK )
127
+ {
128
+ var tableName = selectionForm . lstVariables . SelectedItem . ToString ( ) ;
129
+ var schema = DataTableCreationCommands . Where ( f => f . v_DataTableName == tableName ) . FirstOrDefault ( ) ;
130
+
131
+ v_AddDataDataTable . Rows . Clear ( ) ;
132
+
133
+ foreach ( DataRow rw in schema . v_ColumnNameDataTable . Rows )
134
+ {
135
+ v_AddDataDataTable . Rows . Add ( rw . Field < string > ( "Column Name" ) , "" ) ;
136
+ }
137
+
138
+ }
139
+ }
140
+
88
141
public override string GetDisplayValue ( )
89
142
{
90
- return base . GetDisplayValue ( ) + " [Add Datarow: " + v_InputData + " to DataTable: " + v_DataTableName + " ]";
143
+ return base . GetDisplayValue ( ) + $ " [{ v_AddDataDataTable . Rows . Count } Fields, apply to ' { v_DataTableName } ' ]";
91
144
}
92
145
}
93
146
}
0 commit comments