/// <summary> /// 墒情数据查询,结构为(时间) /// </summary> /// <param name="fromTime"></param> /// <param name="toTime"></param> /// <param name="stationIds"></param> /// <returns></returns> public static QueryResult ListHourSoil_Standard(DateTime fromTime, DateTime toTime, string stationId) { //查询为空 if (stationId == null) { return(new QueryResult()); } //创建数据库对象 using (RWDB rw = new RWDB()) { using (Maintain mt = new Maintain()) { //获取数据 IQueryable <ST_SOIL_R> rainRecord = ListHourSoil_Standard(rw, fromTime, toTime, stationId); QueryResult result = new QueryResult(); List <ST_SOIL_R> singleStationRecord = new List <ST_SOIL_R>(); singleStationRecord = rainRecord.Where(r => r.STCD.Equals(stationId)).OrderByDescending(r => r.TM).ToList(); Station station = StationService.GetStationById(stationId); TimeRecord record = new TimeRecord { stationId = station.stationId, stationName = station.stationName, stationType = station.stationType }; foreach (var r in singleStationRecord) { //gm 20190221 TimeSoil ts = new TimeSoil(r.TM, null, r.SLM10, r.SLM20, r.SLM40); record.tsoils.Add(ts); } result.records.Add(record); return(result); } } }
/// <summary> /// 河道水情数据查询 /// </summary> /// <param name="fromTime"></param> /// <param name="toTime"></param> /// <param name="stationIds"></param> /// <returns></returns> public static QueryResult ListHourWater_Standard(DateTime fromTime, DateTime toTime, string stationId) { //查询为空 if (stationId == null) { return(new QueryResult()); } //创建数据库对象 using (RWDB rw = new RWDB()) { QueryResult result = new QueryResult(); //获取数据 IQueryable <ST_RIVER_R> riverRecord = ListHourRiver_Standard(rw, fromTime, toTime, stationId); IQueryable <ST_RSVR_R> rsvrRecord = ListHourReservoir_Standard(rw, fromTime, toTime, stationId); if (riverRecord.Count() != 0) { //是河道水情站 List <ST_RIVER_R> singleStationRecord = new List <ST_RIVER_R>(); singleStationRecord = riverRecord.Where(r => r.STCD.Equals(stationId)).OrderByDescending(r => r.TM).ToList(); Station station = StationService.GetStationById(stationId); TimeRecord record = new TimeRecord { stationId = station.stationId, stationName = station.stationName, stationType = station.stationType }; foreach (var r in singleStationRecord) { TimeRiver tr = new TimeRiver(r.TM, r.Z, r.Q); record.trivers.Add(tr); } result.records.Add(record); } else if (rsvrRecord.Count() != 0) { //是水库水情站 //是河道水情站 List <ST_RSVR_R> singleStationRecord = new List <ST_RSVR_R>(); singleStationRecord = rsvrRecord.Where(r => r.STCD.Equals(stationId)).OrderByDescending(r => r.TM).ToList(); Station station = StationService.GetStationById(stationId); TimeRecord record = new TimeRecord { stationId = station.stationId, stationName = station.stationName, stationType = station.stationType }; foreach (var r in singleStationRecord) { TimeReservoir tr = new TimeReservoir(r.TM, r.RZ, r.W); record.treserviors.Add(tr); } result.records.Add(record); } else { //两个表都没有这个站点的数据 } return(result); } }
/// <summary> /// 将一条水情信息写入标准库 /// </summary> /// <param name="stationid"></param> /// <param name="time"></param> /// <param name="value"></param> public static void AddHourWater(string stationid, DateTime time, decimal value) { using (RWDB rw = new RWDB()) { ST_RIVER_R river = new ST_RIVER_R(); river.Z = value; river.STCD = stationid; river.TM = time; rw.ST_RIVER_R.Add(river); rw.SaveChanges(); } }
public static IQueryable <Models.ST_RSVR_R> ListHourReservoir_Standard(RWDB rw, DateTime timeFrom, DateTime timeTo, string stationId) { return(from ST_RSVR_R in rw.ST_RSVR_R where stationId == ST_RSVR_R.STCD && ST_RSVR_R.TM >= timeFrom && ST_RSVR_R.TM <= timeTo select ST_RSVR_R); }
public static IQueryable <Models.ST_SOIL_R> ListHourSoil_Standard(RWDB rw, DateTime timefrom, DateTime to, string stationid) { return(from ST_SOIL_R in rw.ST_SOIL_R where stationid == ST_SOIL_R.STCD && ST_SOIL_R.TM <= to && ST_SOIL_R.TM >= timefrom select ST_SOIL_R); }