/// <summary>
        /// Reads the contents of a CSV file into a data grid
        /// </summary>
        /// <param name="filePath">The CSV file path</param>
        /// <returns>A data grid containing the CSV data</returns>
        public IDataGrid ReadCsvFile
        (
            string filePath
        )
        {
            Validate.IsNotEmpty(filePath);

            using (var textReader = File.OpenText(filePath))
            {
                var csv  = new CsvReader(textReader);
                var grid = new DataGrid(filePath);

                while (csv.Read())
                {
                    var rowValues = new Dictionary <string, object>();

                    foreach (var header in csv.FieldHeaders)
                    {
                        rowValues[header] = csv.GetField
                                            (
                            header
                                            );
                    }

                    grid.AddRow
                    (
                        rowValues.ToArray()
                    );
                }

                return(grid);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reads an SQL data reader into a new data grid
        /// </summary>
        /// <param name="reader">The data reader</param>
        /// <returns>The data grid generated</returns>
        private IDataGrid ReadToGrid
        (
            SqlDataReader reader
        )
        {
            var grid = new DataGrid("QueryResults");

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    var rowValues = new Dictionary <string, object>();

                    for (var i = 0; i < reader.FieldCount; i++)
                    {
                        var fieldName  = reader.GetName(i);
                        var fieldValue = reader.GetValue(i);

                        rowValues.Add
                        (
                            fieldName,
                            fieldValue
                        );
                    }

                    grid.AddRow(rowValues);
                }
            }

            return(grid);
        }
 public static void AddRow(this DataGrid dataGrid, int duration, bool isConvert, string type)
 {
     if (isConvert) dataGrid.AddRow(duration, type);
     else dataGrid.Items.Add(new ActivityModel { Date = DateTime.Now, Duration = duration, Type = type });
 }
Beispiel #4
0
 public void AddGridRow(string careerName)
 {
     DataGrid.AddRow(careerName);
     NPC.AddCareer(careerName);
     UpdateStatBlock();
 }