public static units getUnitsElement(int unitsID, VariablesDataset ds) { DataRow[] dr = ds.Tables["units"].Select("unitsID = " + unitsID); if (dr.Length > 0) { VariablesDataset.UnitsRow row = (VariablesDataset.UnitsRow)dr[0]; string uID = row.UnitsID.ToString(); string unitType = String.IsNullOrEmpty(row.UnitsType) ? null : row.UnitsType; string unitAbbrev = String.IsNullOrEmpty(row.UnitsAbbreviation) ? null : row.UnitsAbbreviation; string unitName = String.IsNullOrEmpty(row.UnitsName) ? null : row.UnitsName; units u = CuahsiBuilder.CreateUnitsElement(null, uID, unitAbbrev, unitName); CuahsiBuilder.SetEnumFromText(u, row, "unitsType", typeof(UnitsTypeEnum)); return(u); } else { return(null); } }
/// <summary> /// Builds a VariableInfoType from a dataset row /// the dataSet is stored in the NWISService variableDataSet. /// Find the rwo you want with the command: /// /// and convert. /// </summary> /// <param name="row"></param> /// <returns></returns> public static VariableInfoType rowToVariableInfoType(VariablesDataset.VariablesRow row, VariablesDataset ds) { units aUnit = null; aUnit = getUnitsElement(row.VariableUnitsID, ds); String vCode = !String.IsNullOrEmpty(row.VariableCode) ? row.VariableCode : null; int vid = row.VariableID; // appSetting['vocabulary'] String vocab = System.Configuration.ConfigurationManager.AppSettings["vocabulary"]; String varName = !String.IsNullOrEmpty(row.VariableName) ? row.VariableName : null; VariableInfoType vt = CuahsiBuilder.CreateVariableInfoType( vid.ToString(), vocab, vCode, varName, null, //variable description aUnit ); // add time support vt.timeSupport = new VariableInfoTypeTimeSupport(); if (row.IsRegular) { vt.timeSupport.isRegular = true; vt.timeSupport.isRegularSpecified = true; vt.timeSupport.timeInterval = Convert.ToInt32(row.TimeSupport); vt.timeSupport.timeIntervalSpecified = true; // this is different that the other "units", so populate by code units tUnit = getUnitsElement(row.TimeUnitsID, ds); if (tUnit != null) { vt.timeSupport.unit = new UnitsType(); vt.timeSupport.unit.UnitID = int.Parse(tUnit.unitsCode); vt.timeSupport.unit.UnitIDSpecified = true; vt.timeSupport.unit.UnitDescription = tUnit.Value; vt.timeSupport.unit.UnitAbbreviation = tUnit.unitsAbbreviation; if (tUnit.unitsTypeSpecified) { // if it's specified in the units, then it's a valid enum vt.timeSupport.unit.UnitType = tUnit.unitsType; vt.timeSupport.unit.UnitTypeSpecified = true; } } } else { vt.timeSupport.isRegular = false; vt.timeSupport.isRegularSpecified = true; } CuahsiBuilder.SetEnumFromText(vt, row, "valueType", typeof(valueTypeEnum)); CuahsiBuilder.SetEnumFromText(vt, row, "sampleMedium", typeof(SampleMediumEnum)); CuahsiBuilder.SetEnumFromText(vt, row, "dataType", typeof(dataTypeEnum)); CuahsiBuilder.SetEnumFromText(vt, row, "generalCategory", typeof(generalCategoryEnum)); // if (!String.IsNullOrEmpty(row.NoDataValue)) { vt.NoDataValue = row.NoDataValue.ToString(); // } return(vt); }