private static PastureDataType DataRow2PastureDataType(DataRow dr) { PastureDataType pasturedata = new PastureDataType { Region = int.Parse(dr["Region"].ToString(), CultureInfo.InvariantCulture), Soil = int.Parse(dr["Soil"].ToString(), CultureInfo.InvariantCulture), ForageNo = int.Parse(dr["ForageNo"].ToString(), CultureInfo.InvariantCulture), GrassBA = int.Parse(dr["GrassBA"].ToString(), CultureInfo.InvariantCulture), LandCon = int.Parse(dr["LandCon"].ToString(), CultureInfo.InvariantCulture), StkRate = int.Parse(dr["StkRate"].ToString(), CultureInfo.InvariantCulture), YearNum = int.Parse(dr["YearNum"].ToString(), CultureInfo.InvariantCulture), Year = int.Parse(dr["Year"].ToString(), CultureInfo.InvariantCulture), CutNum = int.Parse(dr["CutNum"].ToString(), CultureInfo.InvariantCulture), Month = int.Parse(dr["Month"].ToString(), CultureInfo.InvariantCulture), Growth = double.Parse(dr["Growth"].ToString(), CultureInfo.InvariantCulture), BP1 = double.Parse(dr["BP1"].ToString(), CultureInfo.InvariantCulture), BP2 = double.Parse(dr["BP2"].ToString(), CultureInfo.InvariantCulture), Utilisn = double.Parse(dr["Utilisn"].ToString(), CultureInfo.InvariantCulture), SoilLoss = double.Parse(dr["SoilLoss"].ToString(), CultureInfo.InvariantCulture), Cover = double.Parse(dr["Cover"].ToString(), CultureInfo.InvariantCulture), TreeBA = double.Parse(dr["TreeBA"].ToString(), CultureInfo.InvariantCulture), Rainfall = double.Parse(dr["Rainfall"].ToString(), CultureInfo.InvariantCulture), Runoff = double.Parse(dr["Runoff"].ToString(), CultureInfo.InvariantCulture) }; pasturedata.CutDate = new DateTime(pasturedata.Year, pasturedata.Month, 1); return(pasturedata); }
/// <summary> /// Searches the DataTable created from the PastureFile using the specified parameters. /// </summary> /// <param name="region"></param> /// <param name="soil"></param> /// <param name="forageNo"></param> /// <param name="grassBasalArea"></param> /// <param name="landCondition"></param> /// <param name="stockingRate"></param> /// <param name="year"></param> /// <param name="month"></param> /// <returns>CropDataType containg the crop data for this month</returns> public PastureDataType GetMonthsPastureData(int region, int soil, int forageNo, int grassBasalArea, int landCondition, int stockingRate, int year, int month) { object[] keyVals = new Object[8]; keyVals[0] = region; keyVals[1] = soil; keyVals[2] = forageNo; keyVals[3] = grassBasalArea; keyVals[4] = landCondition; keyVals[5] = stockingRate; keyVals[6] = year; keyVals[7] = month; DataRow dr = this.pastureFileAsTable.Rows.Find(keyVals); if (dr != null) { PastureDataType pasturedata = DataRow2PastureDataType(dr); return(pasturedata); } else { throw new ApsimXException(this, "Unable to find pasture data for : " + "[Region = " + region + ", Soil = " + soil + ", ForageNo = " + forageNo + ", GrassBA = " + grassBasalArea + ", LandCon = " + landCondition + ", StkRate = " + stockingRate + ", Year = " + year + ", Month = " + month + "]" ); } }
private static PastureDataType DataRow2PastureDataType(DataRow dr) { PastureDataType pasturedata = new PastureDataType(); pasturedata.Region = int.Parse(dr["Region"].ToString()); pasturedata.Soil = int.Parse(dr["Soil"].ToString()); pasturedata.ForageNo = int.Parse(dr["ForageNo"].ToString()); pasturedata.GrassBA = int.Parse(dr["GrassBA"].ToString()); pasturedata.LandCon = int.Parse(dr["LandCon"].ToString()); pasturedata.StkRate = int.Parse(dr["StkRate"].ToString()); pasturedata.YearNum = int.Parse(dr["YearNum"].ToString()); pasturedata.Year = int.Parse(dr["Year"].ToString()); pasturedata.CutNum = int.Parse(dr["CutNum"].ToString()); pasturedata.Month = int.Parse(dr["Month"].ToString()); pasturedata.Growth = double.Parse(dr["Growth"].ToString()); pasturedata.BP1 = double.Parse(dr["BP1"].ToString()); pasturedata.BP2 = double.Parse(dr["BP2"].ToString()); pasturedata.Utilisn = double.Parse(dr["Utilisn"].ToString()); pasturedata.SoilLoss = double.Parse(dr["SoilLoss"].ToString()); pasturedata.Cover = double.Parse(dr["Cover"].ToString()); pasturedata.TreeBA = double.Parse(dr["TreeBA"].ToString()); pasturedata.Rainfall = double.Parse(dr["Rainfall"].ToString()); pasturedata.Runoff = double.Parse(dr["Runoff"].ToString()); pasturedata.CutDate = new DateTime(pasturedata.Year, pasturedata.Month, 1); return(pasturedata); }
private static PastureDataType DataRow2PastureDataType(DataRowView dr) { PastureDataType pasturedata = new PastureDataType { Year = int.Parse(dr["Year"].ToString()), CutNum = int.Parse(dr["CutNum"].ToString()), Month = int.Parse(dr["Month"].ToString()), Growth = double.Parse(dr["Growth"].ToString()), BP1 = double.Parse(dr["BP1"].ToString()), BP2 = double.Parse(dr["BP2"].ToString()) }; return(pasturedata); }
private PastureDataType DataRow2PastureDataType(DataRowView dr) { PastureDataType pasturedata = new PastureDataType { Year = int.Parse(dr["Year"].ToString(), CultureInfo.InvariantCulture), Month = int.Parse(dr["Month"].ToString(), CultureInfo.InvariantCulture), Growth = double.Parse(dr["Growth"].ToString(), CultureInfo.InvariantCulture), SoilLoss = ((ErosionColumnName != "" & dr.DataView.Table.Columns.Contains(ErosionColumnName))?double.Parse(dr[ErosionColumnName].ToString(), CultureInfo.InvariantCulture):0), Runoff = ((RunoffColumnName != "" & dr.DataView.Table.Columns.Contains(RunoffColumnName)) ? double.Parse(dr[RunoffColumnName].ToString(), CultureInfo.InvariantCulture) : 0), Rainfall = ((RainfallColumnName != "" & dr.DataView.Table.Columns.Contains(RainfallColumnName)) ? double.Parse(dr[RainfallColumnName].ToString(), CultureInfo.InvariantCulture) : 0), Cover = ((CoverColumnName != "" & dr.DataView.Table.Columns.Contains(CoverColumnName)) ? double.Parse(dr[CoverColumnName].ToString(), CultureInfo.InvariantCulture) : 0), TreeBA = ((TBAColumnName != "" & dr.DataView.Table.Columns.Contains(TBAColumnName)) ? double.Parse(dr[TBAColumnName].ToString(), CultureInfo.InvariantCulture) : 0), }; return(pasturedata); }
/// <summary> /// Searches the DataTable created from the PastureFile using the specified parameters. /// </summary> /// <param name="Region"></param> /// <param name="Soil"></param> /// <param name="ForageNo"></param> /// <param name="GrassBA"></param> /// <param name="LandCon"></param> /// <param name="StkRate"></param> /// <param name="Year"></param> /// <param name="Month"></param> /// <returns>CropDataType containg the crop data for this month</returns> public PastureDataType GetMonthsPastureData(int Region, int Soil, int ForageNo, int GrassBA, int LandCon, int StkRate, int Year, int Month) { //string climRegion = ClimRegion.ToString(); //' Climatic region //string soil = Native_land.ToString(); //' soil //string grassBA = Grass_BA.ToString(); //' Grass Basal area //string landCond = Land_Con.ToString(); //' Land condition //string stkRate = St_Rate.ToString(); //' Stocking rate //string year = Pyr[x].ToString(); //' year object[] keyVals = new Object[8]; keyVals[0] = Region; keyVals[1] = Soil; keyVals[2] = ForageNo; keyVals[3] = GrassBA; keyVals[4] = LandCon; keyVals[5] = StkRate; keyVals[6] = Year; keyVals[7] = Month; DataRow dr = this.PastureFileAsTable.Rows.Find(keyVals); if (dr != null) { PastureDataType pasturedata = DataRow2PastureDataType(dr); return(pasturedata); } else { throw new ApsimXException(this, "Unable to find pasture data for : " + "[Region = " + Region + ", Soil = " + Soil + ", ForageNo = " + ForageNo + ", GrassBA = " + GrassBA + ", LandCon = " + LandCon + ", StkRate = " + StkRate + ", Year = " + Year + ", Month = " + Month + "]" ); } }