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

You are not allowed to attach a file to this page.