|
| 1 | +/* |
| 2 | + * COPYRIGHT: See COPYING in the top level directory |
| 3 | + * PROJECT: SqliteHelper |
| 4 | + * FILE: DataSet.cs |
| 5 | + * PURPOSE: Used in add Statement and Select |
| 6 | + * PROGRAMER: Peter Geinitz (Wayfarer) |
| 7 | + */ |
| 8 | + |
| 9 | +// ReSharper disable UnusedMember.Global |
| 10 | +// ReSharper disable MemberCanBeInternal |
| 11 | + |
| 12 | +using System.Collections.Generic; |
| 13 | +using System.Data; |
| 14 | +using System.Linq; |
| 15 | + |
| 16 | +namespace SqliteHelper |
| 17 | +{ |
| 18 | + /// <summary> |
| 19 | + /// Alternative View of the select unlike Data View for Data Binding, with some added extras |
| 20 | + /// </summary> |
| 21 | + public sealed class DataSet |
| 22 | + { |
| 23 | + /// <summary> |
| 24 | + /// Initializes a new instance of the <see cref="DataSet" /> class. |
| 25 | + /// </summary> |
| 26 | + internal DataSet() |
| 27 | + { |
| 28 | + Row = new List<TableSet>(); |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Gets the height. |
| 33 | + /// </summary> |
| 34 | + public int Height => Row.Count; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Gets the width. |
| 38 | + /// </summary> |
| 39 | + public int Width => Row[0].Row.Count; |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Only Used for DataBinding |
| 43 | + /// </summary> |
| 44 | + public DataView Raw { get; internal set; } |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Custom Data View, |
| 48 | + /// Infos about the Table and the Data it Contains |
| 49 | + /// </summary> |
| 50 | + public List<TableSet> Row { get; internal init; } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Get a specific Column of the Data set |
| 54 | + /// </summary> |
| 55 | + /// <param name="height">Height of the Column</param> |
| 56 | + /// <returns> |
| 57 | + /// Specific Column at that position, on Error return null. |
| 58 | + /// </returns> |
| 59 | + public List<string> Columns(int height) |
| 60 | + { |
| 61 | + if (height >= Height || height < 0) |
| 62 | + { |
| 63 | + return null; |
| 64 | + } |
| 65 | + |
| 66 | + return Row?[height].Row; |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Rows the specified width. |
| 71 | + /// </summary> |
| 72 | + /// <param name="width">The width.</param> |
| 73 | + /// <returns> |
| 74 | + /// Specific row at that position, on Error return null. |
| 75 | + /// </returns> |
| 76 | + public List<string> Rows(int width) |
| 77 | + { |
| 78 | + if (width >= Width || width < 0) |
| 79 | + { |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + if (Row == null) |
| 84 | + { |
| 85 | + return null; |
| 86 | + } |
| 87 | + |
| 88 | + var lst = new List<string>(Width); |
| 89 | + |
| 90 | + lst.AddRange(from TableSet cell in Row |
| 91 | + let element = cell.Row[width] |
| 92 | + select element); |
| 93 | + return lst; |
| 94 | + } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Get a specific cell of the DataSet |
| 98 | + /// </summary> |
| 99 | + /// <param name="height">Height of the Column</param> |
| 100 | + /// <param name="width">Width of the Row</param> |
| 101 | + /// <returns>Specific element at that position</returns> |
| 102 | + public string Cell(int height, int width) |
| 103 | + { |
| 104 | + if (height >= Height || height < 0) |
| 105 | + { |
| 106 | + return null; |
| 107 | + } |
| 108 | + |
| 109 | + if (width >= Width || width < 0) |
| 110 | + { |
| 111 | + return null; |
| 112 | + } |
| 113 | + |
| 114 | + var lst = Row[height].Row; |
| 115 | + |
| 116 | + return lst[width]; |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments