/// <summary>Send the DataTable to the View</summary> /// <param name="data">The data set</param> private void WriteTable(DataTable data) { // format the data into useful columns if (data != null) { int siteIdx = data.Columns.IndexOf("site"); if (siteIdx >= 0) { data.Columns.RemoveAt(siteIdx); } // modLMC - 10/03/2016 - Add the Qmax (Max Radiation) column that we require for the graphs // This is done here so that we can use the "day" or "doy" column if it exists, as it will be quicker MetUtilities.CalcQmax(data, this.weatherData.Latitude); // modLMC - 10/03/2016 - Modified to use this new function, as some data has "doy" and not "day" int dayCol = data.Columns.IndexOf("day"); int yearCol = data.Columns.IndexOf("year"); if ((yearCol >= 0) && (dayCol >= 0)) { // add a new column for the date string DataColumn dateCol = data.Columns.Add("Date", Type.GetType("System.String")); dateCol.SetOrdinal(0); yearCol++; // moved along dayCol++; int yr, day; // for each row in the grid for (int r = 0; r < data.Rows.Count; r++) { yr = Convert.ToInt32(data.Rows[r][yearCol]); day = Convert.ToInt32(data.Rows[r][dayCol]); DateTime rowDate = new DateTime(yr, 1, 1); rowDate = rowDate.AddDays(day - 1); // calc date data.Rows[r][0] = rowDate.ToShortDateString(); // store in Date col } if (dayCol > yearCol) { data.Columns.RemoveAt(dayCol); data.Columns.RemoveAt(yearCol); // remove unwanted columns } else { data.Columns.RemoveAt(yearCol); // remove unwanted columns data.Columns.RemoveAt(dayCol); } } this.graphMetData = data; this.weatherDataView.PopulateData(data); } }
/// <summary>Send the DataTable to the View</summary> /// <param name="data">The data set</param> private void WriteTable(DataTable data) { // format the data into useful columns if (data != null) { int siteIdx = data.Columns.IndexOf("site"); if (siteIdx >= 0) { data.Columns.RemoveAt(siteIdx); } // modLMC - 10/03/2016 - Add the Qmax (Max Radiation) column that we require for the graphs // This is done here so that we can use the "day" or "doy" column if it exists, as it will be quicker MetUtilities.CalcQmax(data, this.weatherData.Latitude); // modLMC - 10/03/2016 - Modified to use this new function, as some data has "doy" and not "day" int dayCol = data.Columns.IndexOf("day"); int yearCol = data.Columns.IndexOf("year"); if ((yearCol >= 0) && (dayCol >= 0)) { // add a new column for the date string DataColumn dateCol = data.Columns.Add("Date", typeof(DateTime)); dateCol.SetOrdinal(0); yearCol++; // moved along dayCol++; int yr, day; // for each row in the grid for (int r = 0; r < data.Rows.Count; r++) { DateTime rowDate; try { yr = Convert.ToInt32(data.Rows[r][yearCol], CultureInfo.InvariantCulture); day = Convert.ToInt32(data.Rows[r][dayCol], CultureInfo.InvariantCulture); rowDate = new DateTime(yr, 1, 1); } catch (Exception err) { DateTime previousRowDate; if (r > 0 && DateTime.TryParse((string)data.Rows[r - 1][0], out previousRowDate)) { throw new Exception("Invalid date detected in file: " + this.weatherData.FileName + ". Previous row: " + previousRowDate.ToShortDateString() + " (day of year = " + previousRowDate.DayOfYear + ")"); } else { throw new Exception("Encountered an error while parsing date: " + err.Message); } } rowDate = rowDate.AddDays(day - 1); // calc date data.Rows[r][0] = rowDate; } if (dayCol > yearCol) { data.Columns.RemoveAt(dayCol); data.Columns.RemoveAt(yearCol); // remove unwanted columns } else { data.Columns.RemoveAt(yearCol); // remove unwanted columns data.Columns.RemoveAt(dayCol); } } this.graphMetData = data; this.weatherDataView.PopulateData(data); } }