Attachment 'netDataTable.v1.3.txt'
Download 1 :Namespace netDataTable
2
3 ⍝ Methods related to .Net DataTable and DataSet.
4
5 ⍝ February 2015 - Initial version (1.0)
6 ⍝
7 ⍝ April 2015 - DataSet function added (1.1)
8 ⍝
9 ⍝ September 2015 - SelectRows function added (1.2)
10 ⍝
11 ⍝ February 2016 - Methods added (1.3):
12 ⍝ - DeleteRow, DeleteColumn, GetItem, SortAscending, SortDescending
13 ⍝ - Method renamed: GetCol renamed GetColumn
14
15 (⎕IO ⎕ML ⎕WX)←1 3 3
16
17 ∇ dt AddRow apl;newRow
18 ⍝ Add a Row At the End of An Existing DataTable
19 ⍝ dt = DataTable
20 ⍝ apl = Data to Add as Vector or Matrix of proper dimension.
21
22 ⍝ If a Vector, set as a one row matrix:
23 :If 1=⍴⍴apl
24 apl←(1,⍴apl)⍴apl
25 :EndIf
26
27 ⍝ Add the data:
28 2010⌶dt apl
29
30 ⍝ Equivalent way to add only one row:
31 ⍝ newRow←dt.NewRow
32 ⍝ newRow.ItemArray←,apl
33 ⍝ dt.Rows.Add(newRow)
34 ⍝ or
35 ⍝ dt.Rows.Add(⊂apl)
36
37 ∇
38
39 ∇ ds←{dataSetName}AplToDS nss;array;colName;colNames;colType;dt;index;IsChar;IsNum;ns;nsName;parseDate;ptr;test;⎕USING
40 ⍝ Function to convert namespaces within a namespace to a .Net DataSet
41 ⍝
42 ⍝ nss = namespaces within a nameless namespace
43 ⍝ ds = .Net DataSet that contains a collection of DataTable(s)
44 ⍝
45 ⍝ The properties name of the namespace can finish with _? to apply a two way converter:
46 ⍝ _b : Boolean converter 1, 0 ¯1 is True, False, Indeterminate
47 ⍝ _d1 : OADate
48 ⍝ _d2 : 3↑⎕TS or 6↑⎕TS
49 ⍝ _d3 : Character representation of a date
50 ⍝
51 ⍝ Typical usage:
52 ⍝ ns←⎕NS''
53 ⍝ ns.Books←⎕NS''
54 ⍝ ns.Books.Author←'author1' 'author2' 'author3'
55 ⍝ ns.Books.Title←'title1' 'title2' 'title3'
56 ⍝ ns.Books.Price←100 200 300
57 ⍝ ns.Books.IsAvailable_b←1 0 ¯1 ⍝ Boolean converter
58 ⍝ ns.Books.Date_d1←42000 43000 44000 ⍝ OADate converter
59 ⍝ ns.Books.Date_d2←(2014 12 1)(2013 8 4)(2012 6 2) ⍝ 3↑⎕TS converter
60 ⍝ ns.Books.Date_d3←'2014-12-5' '2013/8/9' '2012 6 5' ⍝ Characters of date converter
61 ⍝
62 ⍝ ds←AplToDS ns
63 ⍝ ShowDT ds.Tables[⊂'Books'] ⍝ Show and modify the DataTable
64 ⍝ ns←DStoApl ds ⍝ Convert back to Apl the DataSet
65 ⍝
66 ⍝ or if you are binding use the following statement:
67 ⍝ ItemsSource="{Binding Tables[Books]}"
68 ⍝ and set the DataContext to the DataSet created with AplToDS
69
70 :If 9≠⎕NC'nss'
71 :OrIf '[Namespace]'≢¯11↑⍕nss
72 ⎕←'AplToDS Error: Argument must be a nameless Namespace'
73 →0
74 :EndIf
75
76 IsChar←{' '=↑1↑0⍴⍵}
77 IsNum←{0=↑1↑0⍴⍵}
78
79 :If 0=⎕NC'dataSetName'
80 dataSetName←'DataSet'
81
82 :ElseIf ~IsChar dataSetName
83 ⎕←'AplToDS Error: dataSetName must be Characters'
84 →0
85 :End
86
87 ⎕USING←'System' 'System.Data,System.Data.dll' 'Dyalog' 'System.Windows.Controls,WPF/PresentationFramework.dll'
88 ds←⎕NEW DataSet(⊂dataSetName) ⍝ Default value in case of error
89
90 ⍝ TryParse will return 1 if successful with the parsed value in 'ptr'
91 ptr←⎕NEW ByRef(⎕NEW DateTime ⎕TS) ⍝ Pointer to receive the conversion of 'parseData' if successfull
92 parseDate←{(DateTime.TryParse(⍵ ptr)):ptr.Value ⍝ Parse characters to a .Net DateTime Object
93 ⎕NULL} ⍝ Default value if characters are not a valid date
94
95 :Trap 0
96 ⍝ Convert each simple namespaces into a DataTable and Add it to the DataSet:
97 :For nsName :In nss.⎕NL-9
98 ns←nss.⍎nsName ⍝ Current namespace of variables
99 colNames←(ns.⎕NL-2) ⍝ Get the variable names (colNames) of the namespace
100 array←⍉⊃ns.⍎¨colNames ⍝ Get all the values of the colNames as a matrix
101
102 ⍝ Convert the namespace into a DataTable
103 dt←⎕NEW DataTable(⊂nsName)
104
105 ⍝ Determine the Type of each column
106 colType←''
107
108 :For index :In ⍳2⌷⍴array
109
110 colName←index⊃colNames
111
112 :If '_b'≡¯2↑colName
113 ⍝ 1 and 0 to Boolean. ¯1 is Inderminate state (System.DBNull)
114 :If ∧/IsNum¨array[;index]
115 colType,←Boolean
116 test←array[;index]=¯1 ⍝ ¯1 = Indeterminate state
117 array[{⍵/⍳⍴⍵}test;index]←DBNull.Value ⍝ Change the ¯1 for DBNull.Value
118 array[{⍵/⍳⍴⍵}~test;index]←1⌊0⌈array[{⍵/⍳⍴⍵}~test;index] ⍝ Coerce to 1 or 0 all the other values
119 :Else
120 colType,←String
121 array[;index]←⍕¨array[;index]
122 ⎕←'AplToDS Error: Don''t know what to do with: ',nsName,'.',colName
123 :End
124
125 :ElseIf '_d1'≡¯3↑colName
126 ⍝ Numeric OADates to DateTime
127 :If ∧/IsNum¨array[;index]
128 colType,←DateTime
129 array[;index]←DateTime.FromOADate¨array[;index]
130 :Else
131 colType,←String
132 array[;index]←⍕¨array[;index]
133 ⎕←'AplToDS Error: Don''t know what to do with: ',nsName,'.',colName
134 :End
135
136 :ElseIf '_d2'≡¯3↑colName
137 ⍝ 3↑⎕TS or 6↑⎕TS to DateTime
138 colType,←DateTime
139 array[;index]←parseDate¨⍕¨array[;index] ⍝ parseDate cannot bug
140
141 :ElseIf '_d3'≡¯3↑colName
142 ⍝ Character representation of a date
143 colType,←DateTime
144 array[;index]←parseDate¨⍕¨array[;index] ⍝ parseDate cannot bug
145
146 :ElseIf ∧/IsNum¨array[;index]
147 ⍝ Only numbers with no converters
148 colType,←Double
149
150 :ElseIf ∧/IsChar¨array[;index]
151 ⍝ Only characters with no converters
152 colType,←String
153
154 :Else
155 ⎕←'AplToDS Error: Don''t know what to do with: ',nsName,'.',colName
156 colType,←String
157 array[;index]←⍕¨array[;index]
158
159 :EndIf
160 :EndFor
161
162 ⍝ Set the Column's Types and Names of the DataTable:
163 {}colNames{dt.Columns.Add ⍺ ⍵}¨colType
164
165 ⍝ Fill the DataTable
166 2010⌶dt array
167
168 ⍝ Add the DataTable to the DataSet
169 ds.Tables.Add(dt)
170
171 :EndFor
172 :EndTrap
173 ∇
174
175 ∇ dt←{colNames}AplToDT aplArray;colType;index;IsChar;IsNum;tableName;⎕USING
176 ⍝ Create a DataTable from an Apl Array.
177 ⍝ EACH COLUMN MUST BE OF THE SAME TYPE.
178 ⍝ For dates, convert ⎕TS to an OADate before making the DataTable.
179 ⍝ apl = An APL array of Numbers and Characters.
180 ⍝ colNames = Optional Column names for the DataTable. Works best with 2 characters per name.
181 ⍝ dt = Resulting DataTable
182
183 ⍝ If a Vector, set as a one row matrix:
184 :If 1=⍴⍴aplArray
185 aplArray←(1,⍴aplArray)⍴aplArray
186 :EndIf
187
188 ⍝ Check if aplArray is a 2 dimensional array:
189 :If 2≠⍴⍴aplArray
190 ⎕←'AplToDT Error: Argument must be of rank equal or smaller than 2'
191 →0
192 :End
193
194 ⍝ Check if columnNames is properly formed:
195 :If 0=⎕NC'colNames' ⍝ There is no columnNames
196 :OrIf (⍴colNames)≠1↓⍴aplArray ⍝ Wrong Shape
197 :OrIf 1∊0=1↑¨0⍴¨colNames ⍝ Not characters
198 :OrIf 0∊≡¨colNames ⍝ Wrong Depth
199
200 ⍝ 'colNames' is not supplied or invalid:
201 ⍝ Generate the Column Names as 'C1' 'C2', etc.:
202 colNames←'C',¨⍕¨⍳1↓⍴aplArray
203 :End
204
205 tableName←'Data' ⍝ Default TableName
206 IsChar←{' '=↑1↑0⍴⍵}
207 IsNum←{0=↑1↑0⍴⍵}
208
209 ⍝ Default value in case of error:
210 ⎕USING←'System' 'System.Data,System.Data.dll'
211 dt←⎕NEW DataTable(⊂tableName)
212
213 :Trap 0
214 ⍝ Determine the Type of each column:
215 colType←''
216 :For index :In ⍳2⌷⍴aplArray
217 :If ∧/IsChar¨aplArray[;index]
218 ⍝ Default Type for characters
219 colType,←String
220
221 :ElseIf ∧/IsNum¨aplArray[;index]
222 ⍝ Default Type for numbers
223 colType,←Double
224
225 :Else
226 ⍝ Mixed Type in the same column
227 ⎕←'Don''t know what to do with column no: ',⍕index
228 aplArray[;index]←⍕¨aplArray[;index]
229 colType,←String
230
231 :EndIf
232 :EndFor
233
234 ⍝ Set the Column's Types and Names of the DataTable:
235 {}colNames{dt.Columns.Add ⍺ ⍵}¨colType
236
237 ⍝ Fill the DataTable:
238 2010⌶dt aplArray
239
240 :EndTrap
241 ∇
242
243 ∇ dt←BinFileToDT fileName;binaryFormatter;fileStream;⎕USING
244 ⍝ Retrieves a DataTable from a Binary representation made by DTtoBinFile
245 ⍝ fileName = fully qualified file name
246 ⍝ dt = DataTable
247
248 ⍝ Read the fileName
249 ⎕USING←',mscorlib.dll'
250 fileStream←⎕NEW System.IO.FileStream(fileName System.IO.FileMode.Open)
251
252 ⍝ Get a BinaryFormatter and Deserialize the file stream
253 binaryFormatter←⎕NEW System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
254 dt←binaryFormatter.Deserialize fileStream
255 fileStream.Close
256 ∇
257
258 ∇ dt DeleteColumn colNumber
259 ⍝ Delete one column of the DataTable
260 ⍝ colNumber = Index of the column (Origin 1)
261 ⍝ dt = Data Table
262
263 dt.Columns.RemoveAt(colNumber-1)
264 ∇
265
266 ∇ dt DeleteRow rowNumber
267 ⍝ Delete one row of the DataTable
268 ⍝ rowNumber = Index of the row (Origin 1)
269 ⍝ dt = Data Table
270
271 dt.Rows[rowNumber-1].Delete
272 ∇
273
274 ∇ apl←DStoApl ds;array;colDataType;colDataTypes;colName;colNames;dateCvt;dt;index;ns;test;⎕USING
275 ⍝ Function to convert a .Net DataSet made with AplToDS to an APL namespace
276 ⍝
277 ⍝ ds = .Net DataSet
278 ⍝ apl = Namespaces within a nameless namespace
279
280 :If 9≠⎕NC'ds'
281 :OrIf 'System.Data.DataSet'≢⍕ds
282 ⎕←'DStoApl Error: Argument must be a DataSet'
283 →0
284 :EndIf
285
286 ⎕USING←'System'
287 apl←⎕NS'' ⍝ Default value in case of error
288
289 ⍝ Convert each DataTable to a named namespace
290 :For dt :In ⌷ds.Tables
291
292 ns←⎕NS'' ⍝ Empty nameless namespace
293 colNames←(⌷dt.Columns).ColumnName ⍝ Column names of the DataTable
294 colDataTypes←(⌷dt.Columns).DataType ⍝ Type of the column
295 array←2011⌶dt ⍝ Convert the DataTable to an APL array
296
297 :For index :In ⍳2⌷⍴array
298 colName←index⊃colNames
299 colDataType←⍕index⊃colDataTypes
300
301 :If '_d1'≡¯3↑colName
302 ⍝ Return the .Net DateTime object as numeric OADates
303 :If 'System.DateTime'≡colDataType
304 test←array[;index]≠DBNull.Value
305 array[{⍵/⍳⍴⍵}~test;index]←0 ⍝ Default value if DBNull is returned
306 array[{⍵/⍳⍴⍵}test;index]←(array[{⍵/⍳⍴⍵}test;index]).ToOADate
307 :Else
308 ⎕←'DStoApl Error: Don''t know what to do with: ',(dt.TableName),'.',colName
309 :End
310
311 :ElseIf '_d2'≡¯3↑colName
312 ⍝ Return the .Net DateTime object as numeric 3↑⎕TS
313 :If 'System.DateTime'≡colDataType
314 test←array[;index]≠DBNull.Value
315 array[{⍵/⍳⍴⍵}~test;index]←⊂1900 1 1 ⍝ Default value if DBNull is returned
316 array[{⍵/⍳⍴⍵}test;index]←(array[{⍵/⍳⍴⍵}test;index]).(Year Month Day)
317 :Else
318 ⎕←'DStoApl Error: Don''t know what to do with: ',(dt.TableName),'.',colName
319 :End
320
321 :ElseIf '_d3'≡¯3↑colName
322 ⍝ Return the .Net DateTime object as a character representation of the date
323 :If 'System.DateTime'≡colDataType
324 test←array[;index]≠DBNull.Value
325 array[{⍵/⍳⍴⍵}~test;index]←⊂'1/1/1900' ⍝ Default value if DBNull is returned
326 dateCvt←{⎕USING←'System.Globalization' ⋄ ⍵.ToString((,'G')CultureInfo.InvariantCulture)}
327 array[{⍵/⍳⍴⍵}test;index]←dateCvt¨array[{⍵/⍳⍴⍵}test;index]
328 :Else
329 ⎕←'DStoApl Error: Don''t know what to do with: ',(dt.TableName),'.',colName
330 :End
331
332 :ElseIf '_b'≡¯2↑colName
333 :If 'System.Boolean'≡colDataType
334 ⍝ If equal to DBNull the Boolean is Inderminate and it is changed to ¯1
335 test←array[;index]=DBNull.Value
336 array[{⍵/⍳⍴⍵}test;index]←¯1
337 :End
338 :End
339
340 :EndFor
341
342 colNames{ns.⍎⍺,'←⍵'}¨↓⍉array ⍝ Assign each columns to the colNames in the NameSpace
343
344 ⍎'apl.',(dt.TableName),'←ns' ⍝ Add the new named namespace to the nameless namespace
345 :EndFor
346 ∇
347
348 ∇ apl←DTtoApl dt
349 ⍝ Convert a .Net DataTable to APL
350 ⍝ dt = DataTable
351 ⍝ apl = apl representation of the DataTable
352
353 :If 9≠⎕NC'dt'
354 :OrIf 'System.Data.DataTable'≢dt.GetType.ToString
355 ⎕←'DTtoApl Error: The argument is not a DataTable Object !'
356 :EndIf
357
358 apl←2011⌶dt
359 ∇
360
361 ∇ r←dt DTtoBinFile fileName;binaryFormatter;memStream;⎕USING
362 ⍝ Saves a Binary representation of the DataTable to a file name
363 ⍝ fileName = fully qualified file name
364 ⍝ dt = DataTable
365
366 ⍝ Get a Binary Formatter
367 ⎕USING←',mscorlib.dll'
368 binaryFormatter←⎕NEW System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
369
370 ⍝ Serialize the DataTable to a MemoryStream
371 memStream←⎕NEW System.IO.MemoryStream
372 binaryFormatter.Serialize memStream dt
373
374 ⍝ Write the MemoryStream to fileName and dispose of the MemoryStream
375 System.IO.File.WriteAllBytes((⊂,fileName),(⊂memStream.ToArray))
376 memStream.Close ⋄ memStream.Dispose ⋄ memStream←⎕NULL
377
378 ⍝ Write to fileName and close the FileStream (alternative way to do the same thing)
379 ⍝ fileStream←⎕NEW System.IO.FileStream(fileName System.IO.FileMode.Create)
380 ⍝ binaryFormatter.Serialize fileStream dt
381 ⍝ fileStream.Close
382 ∇
383
384 ∇ xmlDoc←DTtoXml dt;ms;⎕USING
385 ⍝ Generates the Xml representation of a Data Table.
386 ⍝ dt = DataTable
387 ⍝ xmlDoc = XmlDocument
388
389 ⍝ Get an Empty Memory Stream:
390 ⎕USING←'System.IO,mscorlib.dll'
391 ms←⎕NEW MemoryStream
392
393 ⍝ Set the XML Mapping as Attribute for all the columns:
394 (⌷dt.Columns).ColumnMapping←dt.Columns[0].ColumnMapping.Attribute
395
396 ⍝ Write to the Memory Stream the Xml Representation of the Data Table with the Xls Schema:
397 ⎕USING←'System.Data,System.Data.dll' 'System.Xml,System.Xml.dll'
398 dt.WriteXml(ms XmlWriteMode.WriteSchema) ⍝ XmlWriteMode.IgnoreSchema also available
399
400 ⍝ Set the position of the memory stream at the beginning
401 ⎕USING←'System,mscorlib.dll'
402 ms.Position←Convert.ToInt64 0
403
404 ⍝ Write the Memory Stream to an XmlDocument
405 ⎕USING←'System.Xml,System.Xml.dll'
406 xmlDoc←⎕NEW XmlDocument
407 xmlDoc.Load ms
408 xmlDoc.DocumentElement.SetAttribute('xmlns' '')
409
410 ⍝ Clean-up
411 ms.Close ⋄ ms.Dispose ⋄ ms←⎕NULL
412 ∇
413
414 ∇ ds DStoXmlFile fileName;⎕USING
415 ⍝ Saves an Xml representation of the DataSet to a file name
416 ⍝ fileName = fully qualified file name
417 ⍝ ds = DataSet
418
419 ⍝ Write to a Xml file with the Schema
420 ⎕USING←'System.Data,System.Data.dll'
421 ds.WriteXml(fileName XmlWriteMode.WriteSchema)
422 ∇
423
424 ∇ dt DTtoXmlFile fileName;⎕USING
425 ⍝ Saves an Xml representation of the DataTable to a file name
426 ⍝ fileName = fully qualified file name
427 ⍝ dt = DataTable
428
429 ⍝ Set the XML Mapping as Attribute for all the column:
430 (⌷dt.Columns).ColumnMapping←dt.Columns[0].ColumnMapping.Attribute
431
432 ⍝ Write to a Xml file with the Schema
433 ⎕USING←'System.Data,System.Data.dll'
434 dt.WriteXml(fileName XmlWriteMode.WriteSchema)
435 ∇
436
437 ∇ apl←dt GetColumn colNumber;colName;dv;string;⎕USING
438 ⍝ Get the value of a single column of an existing DataTable
439 ⍝ dt = Data Table
440 ⍝ colNumber = Index of the column (Origin 1)
441 ⍝ apl = Apl data
442
443 ⍝ Get the name of the column
444 colName←dt.Columns[colNumber-1].ColumnName
445
446 ⍝ Create a .net string vector (string[]) with that name
447 ⎕USING←'' 'System.Data,System.Data.dll'
448 string←System.Array.CreateInstance(System.Type.GetType⊂'System.String')1
449 string.SetValue(colName 0)
450
451 ⍝ ⍝ Make a DataView and filter the method .ToTable
452 ⍝ dv←⎕NEW DataView dt
453 ⍝ apl←,2011⌶dv.ToTable(0 string)
454
455 ⍝ ↓↓↓ To get a column without using a DataView
456 apl←,2011⌶dt.DefaultView.ToTable(0 string) ⍝ Use (1 string) to remove the duplicates values
457 ∇
458
459 ∇ colNames←GetColNames dt
460 ⍝ Get the names of all the columns
461 ⍝ dt = Data Table
462 ⍝ colNames = Column Names of all the columns
463
464 colNames←(⌷dt.Columns).ColumnName
465 ∇
466
467 ∇ apl←dt GetItem(rowNumber colNumber)
468 ⍝ Select one Item at rowNumber and colNumber
469 ⍝ rowNumber = Index of the row (Origin 1)
470 ⍝ colNumber = Index of the column (Origin 1)
471 ⍝ dt = Data Table
472
473 apl←⊃dt.Rows[rowNumber-1].Item[colNumber-1]
474 ∇
475
476 ∇ apl←dt GetRow rowNumber
477 ⍝ Get the value of a row of an existing DataTable
478 ⍝ rowNumber = Index of the row (Origin 1)
479 ⍝ dt = Data Table
480 ⍝ apl = Apl data
481
482 apl←dt.Rows[rowNumber-1].ItemArray
483 ∇
484
485 ∇ la InsertRow apl;dt;newRow;rowNumber
486 ⍝ Insert a new Row in a DataTable
487 ⍝ apl = New Data to Insert
488 ⍝ dt = DataTable
489 ⍝ rowNumber = Row Number of DataTable after wich the data will
490 ⍝ = be inserted (Origin 1)
491
492 ⍝ Split the Left Argument:
493 (dt rowNumber)←la
494
495 newRow←dt.NewRow
496 newRow.ItemArray←apl
497 dt.Rows.InsertAt(newRow,rowNumber)
498 ∇
499
500 ∇ apl←dt SelectRows query;rows
501 ⍝ Gets an array of all DataRow objects that match the filter criteria.
502 ⍝ Contributed by Richard Proctor
503
504 rows←dt.Select(⊂query)
505 apl←rows.ItemArray
506 ∇
507
508 ∇ la SetRow apl;dt;rowNumber
509 ⍝ Update a row of a DataTable with new values.
510 ⍝ apl = New Data to Replace the Existing Ones
511 ⍝ dt = DataTable
512 ⍝ rowNumber = Row Number of DataTable at Origin 1
513
514 ⍝ Split the Left Argument:
515 (dt rowNumber)←la
516
517 ⍝ If a Vector, set as a one row matrix:
518 :If 1=⍴⍴apl
519 apl←(1,⍴apl)⍴apl
520 :EndIf
521
522 ⍝ Change the Data:
523 2010⌶dt apl ⍬(rowNumber-1)
524 ∇
525
526 ∇ ShowDS ds;dg;dt;index;tc;ti;win;⎕USING
527 ⍝ Show a DataSet in multiple Syncfusion's Grid
528 ⍝ Each Table(s) is shown in a separate Tab
529 ⍝ ds = DataSet to Show
530
531 ⎕USING←'System.Windows,WPF/PresentationFramework.dll'
532 ⎕USING,←⊂'System.Windows.Controls,WPF/PresentationFramework.dll'
533 ⎕USING,←⊂'Syncfusion.UI.Xaml.Grid,Syncfusion/4.5/Syncfusion.SfGrid.WPF.dll'
534 :Trap 0 ⋄ Anything ⋄ :EndTrap ⍝ To load ⎕USING into memory
535
536 ⍝ Get a Window
537 win←⎕NEW Window
538 win.(Width Height)←640 480
539 win.Title←'Show DataSet[ ',(ds.DataSetName),' ]'
540
541 ⍝ Get a TabControl that will hold the TabItem
542 tc←⎕NEW TabControl
543
544 ⍝ Iterate to set each Tables in a TabItem
545 :For index :In ⍳ds.Tables.Count
546
547 dt←ds.Tables[index-1]
548
549 ti←⎕NEW TabItem
550 ti.Header←dt.TableName ⍝ ← Name of the Tab
551
552 dg←⎕NEW SfDataGrid
553 dg.AutoGenerateColumns←1
554 dg.ItemsSource←dt ⍝ ← the DataTable is set here
555 dg.AllowResizingColumns←1
556 dg.(ColumnSizer←ColumnSizer.Star)
557 dg.AllowEditing←1
558
559 ti.Content←dg
560 {}tc.Items.Add(ti)
561
562 :EndFor
563
564 ⍝ Set the content of the Window with the TabControl and Show
565 win.Content←tc
566 win.Show
567 ∇
568
569 ∇ ShowDT dt;dg;win;⎕USING
570 ⍝ Show a DataTable in a Syncfusion's Grid
571 ⍝ dt = DataTable to Show
572
573 ⎕USING←'System.Windows,WPF/PresentationFramework.dll'
574 ⎕USING,←⊂'System.Windows.Controls,WPF/PresentationFramework.dll'
575 ⎕USING,←⊂'Syncfusion.UI.Xaml.Grid,Syncfusion/4.5/Syncfusion.SfGrid.WPF.dll'
576 :Trap 0 ⋄ Anything ⋄ :EndTrap ⍝ To load ⎕USING into memory
577
578 win←⎕NEW Window
579 win.(Width Height)←640 480
580 win.Title←'Show DataTable [ ',(dt.TableName),' ]'
581
582 dg←⎕NEW SfDataGrid
583 dg.AutoGenerateColumns←1
584 dg.ItemsSource←dt ⍝ ← the DataTable is set here
585 dg.AllowResizingColumns←1
586 dg.(ColumnSizer←ColumnSizer.Star)
587 dg.AllowEditing←1
588
589 win.Content←dg
590 win.Show
591 ∇
592
593 ∇ dt SortAscending colNumber;colName
594 ⍝ Sort Ascending a DataTable based on the value of a Column
595 ⍝ colNumber = Index of the column (Origin 1)
596 ⍝ dt = Data Table
597
598 colName←dt.Columns[colNumber-1].ColumnName
599 dt.DefaultView.Sort←colName,' ASC'
600 dt←dt.DefaultView.ToTable ⍬
601 ∇
602
603 ∇ dt SortDescending colNumber;colName
604 ⍝ Sort Descending a DataTable based on the value of a Column
605 ⍝ colNumber = Index of the column (Origin 1)
606 ⍝ dt = Data Table
607
608 colName←dt.Columns[colNumber-1].ColumnName
609 dt.DefaultView.Sort←colName,' DESC'
610 dt←dt.DefaultView.ToTable ⍬
611 ∇
612
613 ∇ ds←XmlFileToDS fileName;⎕USING
614 ⍝ Retrieves a DataSet from an Xml representation made by DStoXmlFile
615 ⍝ fileName = fully qualified file name
616 ⍝ ds = DataSet
617
618 ⎕USING←'System.Data,System.Data.dll'
619 ds←⎕NEW DataSet
620 {}ds.ReadXml(⊂,fileName)
621 ∇
622
623 ∇ dt←XmlFileToDT fileName;⎕USING
624 ⍝ Retrieves a DataTable from an Xml representation made by DTtoXmlFile
625 ⍝ fileName = fully qualified file name
626 ⍝ dt = DataTable
627
628 ⎕USING←'System.Data,System.Data.dll'
629 dt←⎕NEW DataTable
630 {}dt.ReadXml(⊂,fileName)
631 ∇
632
633 ∇ dt←XmlToDT xmlDoc;ds;⎕USING
634 ⍝ Obtain a DataTable from an XmlDoc made with DTtoXml.
635 ⍝ xmlDoc = XmlDocument
636 ⍝ dt = DataTable
637
638 ⎕USING←'System.Data,System.Data.dll' 'System.Xml,System.Xml.dll'
639 ds←⎕NEW DataSet
640 {}ds.ReadXml(⎕NEW XmlNodeReader xmlDoc)
641 dt←ds.Tables[0]
642 ∇
643
644 ∇ ns←makeNs
645 ⍝ Build a sample nameless namespace
646
647 ns←⎕NS''
648 ns.Books←⎕NS''
649 ns.Books.Author←'author1' 'author2' 'author3'
650 ns.Books.Title←'title1' 'title2' 'title3'
651 ns.Books.Price←100 200 300
652 ns.Books.IsAvailable_b←1 0 ¯1
653 ns.Books.Date_d1←42000 43000 44000
654
655 ns.Inventory←⎕NS''
656 ns.Inventory.Title←'title1' 'title2' 'title3'
657 ns.Inventory.Quantity←100 200 300
658 ns.Inventory.IsShipped_b←1 0 ¯1
659 ns.Inventory.DatePurchased_d2←(2014 12 1)(2013 8 4)(2012 6 2)
660 ns.Inventory.DateShipped_d3←'2014-12-5' '2013/8/9' '2012 6 5'
661 ∇
662
663 :EndNamespace
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.