/// <summary> /// Add our constants to every row in the specified table beginning with the specified StartRow. /// </summary> public void AddConstantsToData(DataTable Table) { const string VersionName = "ApsimVersion"; // We want to treat ApsimVersion as a string, not a numeric, to versions like "7.10" display correctly foreach (APSIMConstant Constant in Constants) { Type ColumnType = StringManip.DetermineType(Constant.Value, ""); if (Constant.Name.Equals(VersionName)) { ColumnType = typeof(String); } if (Table.Columns.IndexOf(Constant.Name) == -1) { Table.Columns.Add(new DataColumn(Constant.Name, ColumnType)); } for (int Row = 0; Row < Table.Rows.Count; Row++) { double Value; if (ColumnType != typeof(String) && Double.TryParse(Constant.Value, NumberStyles.Float, new CultureInfo("en-US"), out Value)) { Table.Rows[Row][Constant.Name] = Value; } else { Table.Rows[Row][Constant.Name] = Constant.Value; } } } }
private static Type DetermineTypeOfColumn(DataGridView Grid, int Col) { for (int Row = 0; Row != Grid.Rows.Count; Row++) { if (Grid.Rows[Row].Cells[Col].Value != null) { return(StringManip.DetermineType(Grid.Rows[Row].Cells[Col].Value.ToString(), "")); } } return(typeof(string)); }
private static Type DetermineTypeOfColumn(SheetView Grid, int Col) { for (int Row = 0; Row != Grid.Rows.Count; Row++) { if (Grid.Cells[Row, Col].Text != "") { return(StringManip.DetermineType(Grid.Cells[Row, Col].Text, "")); } } return(typeof(string)); }
/// <summary> /// Determine and return the data types of the specfied words. /// </summary> private Type[] DetermineColumnTypes(StreamReaderRandomAccess In, StringCollection Words) { Type[] Types = new Type[Words.Count]; for (int w = 0; w != Words.Count; w++) { if (Words[w] == "?" || Words[w] == "*" || Words[w] == "") { Types[w] = StringManip.DetermineType(LookAheadForNonMissingValue(In, w), Units[w]); } else { Types[w] = StringManip.DetermineType(Words[w], Units[w]); } } return(Types); }