Attachment 'netDataTable.v1.1.txt'

Download

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