protected void BtnImport_Click(object sender, EventArgs e) { DATAHOUR_BLL hbll = new DATAHOUR_BLL(); LiveData_BLL lbll = new LiveData_BLL(); DateTime startTime = DateTime.ParseExact("2017" + MonthDDL.SelectedItem.Value + "01" + "08", "yyyyMMddHH", CultureInfo.InvariantCulture); DateTime endTime = startTime.AddMonths(1); TimeSpan ts = endTime - startTime; for (int i = 0; i < ts.Days; i++) { DateTime stime = startTime.AddDays(i); DateTime etime = stime.AddDays(1); List <string> citynames = CityUtility.AllNameList(); foreach (string cityname in citynames) { string selectname = cityname; if (cityname == "黄岛") { selectname = "胶南"; } List <DATAHOUR> dlist = hbll.GetList(a => a.STANAME == selectname && a.MINTEMP != 9999 && a.MAXTEMP != 9999 && a.FDATE >= stime && a.FDATE < etime).ToList(); if (dlist.Count > 0) { DateTime seletime = DateTime.Parse(stime.ToShortDateString()); LiveData liveData = lbll.Get(a => a.CountryName == cityname && a.FDate == seletime && a.Category == "08时"); if (liveData != null) { liveData.MaxTemp = dlist.Max(a => a.MAXTEMP); liveData.MinTemp = dlist.Min(a => a.MINTEMP); lbll.Update(liveData); } else { LiveData newModel = new LiveData(); newModel.LDID = Guid.NewGuid(); newModel.FDate = stime; newModel.Category = "08时"; newModel.CountryCode = CityUtility.GetCode(cityname); newModel.CountryName = cityname; newModel.CreateTime = DateTime.Now; newModel.MaxTemp = dlist.Max(a => a.MAXTEMP); newModel.MinTemp = dlist.Min(a => a.MINTEMP); lbll.Add(newModel); } Response.Write(cityname + "<br/>"); } } Response.Write(stime.ToString("yyyy-MM-dd HH:mm") + "~" + etime.ToString("yyyy-MM-dd HH:mm") + "<br/>"); } }
public string DataImportTemp08(DateTime yearMonth) { StringBuilder message = new StringBuilder(); string yearMonthString = yearMonth.ToString("yyyyMM"); DATAHOUR_BLL hbll = new DATAHOUR_BLL(); LiveData_BLL lbll = new LiveData_BLL(); DateTime startTime = DateTime.ParseExact(yearMonthString + "01" + "08", "yyyyMMddHH", CultureInfo.InvariantCulture); DateTime endTime = startTime.AddMonths(1); TimeSpan ts = endTime - startTime; for (int i = 0; i < ts.Days; i++) { DateTime stime = startTime.AddDays(i); DateTime etime = stime.AddDays(1); List <string> citynames = CityUtility.AllNameList(); foreach (string cityname in citynames) { string selectname = cityname; if (cityname == "黄岛") { selectname = "胶南"; } List <DATAHOUR> dlist = hbll.GetList(a => a.STANAME == selectname && a.MINTEMP != 9999 && a.MAXTEMP != 9999 && a.FDATE >= stime && a.FDATE < etime).ToList(); if (dlist.Count > 0) { DateTime seletime = DateTime.Parse(stime.ToShortDateString()); LiveData liveData = lbll.Get(a => a.CountryName == cityname && a.FDate == seletime && a.Category == "08时"); if (liveData != null) { liveData.MaxTemp = dlist.Max(a => a.MAXTEMP); liveData.MinTemp = dlist.Min(a => a.MINTEMP); lbll.Update(liveData); } else { LiveData newModel = new LiveData(); newModel.LDID = Guid.NewGuid(); newModel.FDate = stime; newModel.Category = "08时"; newModel.CountryCode = CityUtility.GetCode(cityname); newModel.CountryName = cityname; newModel.CreateTime = DateTime.Now; newModel.MaxTemp = dlist.Max(a => a.MAXTEMP); newModel.MinTemp = dlist.Min(a => a.MINTEMP); lbll.Add(newModel); } //message.Append(cityname + "<br/>"); } } //message.Append("导入08时温度成功,"stime.ToString("yyyy-MM-dd HH:mm") + "~" + etime.ToString("yyyy-MM-dd HH:mm") + "<br/>"); } message.Append("导入08时温度成功,共计" + ts.Days + "天数据。<br/>"); return(message.ToString()); }
public bool DataCheck(DateTime yearMonth, string category) { DateTime startTime = yearMonth; DateTime endTime = startTime.AddMonths(1); LiveData_BLL bll = new LiveData_BLL(); List <LiveData> list = bll.GetList( a => a.FDate >= startTime & a.FDate < endTime && a.Category == category) .OrderBy(a => a.FDate).ThenBy(a => a.CountryCode) .ToList(); //GridView1.DataSource = list; //GridView1.DataBind(); TimeSpan timeSpan = endTime - startTime; List <LiveData_Check> ldcList = new List <LiveData_Check>(); List <string> citys = CityUtility.AllNameList(); for (int i = 0; i < timeSpan.Days; i++) { DateTime currentDate = startTime.AddDays(i); List <LiveData> daylist = list.Where(a => a.FDate == currentDate).ToList(); LiveData_Check ldc = new LiveData_Check(); ldc.Date = currentDate; StringBuilder dataMissStr = new StringBuilder(); foreach (string city in citys) { LiveData dayCity = daylist.Where(a => a.CountryName == city).FirstOrDefault(); if (dayCity != null) { if (dayCity.MaxTemp == null || dayCity.MinTemp == null || dayCity.Rain == null) { dataMissStr.Append("<li style='color:#ff6a00;'>" + city + " 缺少 "); string missElement = string.Empty; if (dayCity.MaxTemp == null) { missElement += "最高温度 "; } if (dayCity.MinTemp == null) { missElement += "最低温度 "; } if (dayCity.Rain == null) { missElement += "降水 "; } dataMissStr.Append(missElement); dataMissStr.Append("数据<br/></li>"); } } else { dataMissStr.Append("<li style='color:#ff0000;'>" + city + " 缺少 最高温度 最低温度 降水 数据<br/></li>"); } } ldc.DataMiss = dataMissStr.ToString(); if (!String.IsNullOrWhiteSpace(ldc.DataMiss)) { ldcList.Add(ldc); } } if (ldcList.Count() > 0) { return(false); } else { return(true); } }
protected void Btn_DataCheck_Click(object sender, EventArgs e) { DateTime startTime = DateTime.Parse(DropDownList_Year.SelectedItem.Value + "-" + DropDownList_Month.SelectedItem.Value + "-01"); DateTime endTime = startTime.AddMonths(1); LiveData_BLL bll = new LiveData_BLL(); List <LiveData> list = bll.GetList( a => a.FDate >= startTime & a.FDate < endTime && a.Category == DropDownList_YBTime.SelectedItem.Value) .OrderBy(a => a.FDate).ThenBy(a => a.CountryCode) .ToList(); //GridView1.DataSource = list; //GridView1.DataBind(); TimeSpan timeSpan = endTime - startTime; List <LiveData_Check> ldcList = new List <LiveData_Check>(); List <string> citys = CityUtility.AllNameList(); for (int i = 0; i < timeSpan.Days; i++) { DateTime currentDate = startTime.AddDays(i); List <LiveData> daylist = list.Where(a => a.FDate == currentDate).ToList(); LiveData_Check ldc = new LiveData_Check(); ldc.Date = currentDate; StringBuilder dataMissStr = new StringBuilder(); foreach (string city in citys) { LiveData dayCity = daylist.Where(a => a.CountryName == city).FirstOrDefault(); if (dayCity != null) { if (dayCity.MaxTemp == null || dayCity.MinTemp == null || dayCity.Rain == null) { dataMissStr.Append("<li style='color:#ff6a00;'>" + city + " 缺少 "); string missElement = string.Empty; if (dayCity.MaxTemp == null) { missElement += "最高温度 "; } if (dayCity.MinTemp == null) { missElement += "最低温度 "; } if (dayCity.Rain == null) { missElement += "降水 "; } dataMissStr.Append(missElement); dataMissStr.Append("数据<br/></li>"); } } else { dataMissStr.Append("<li style='color:#ff0000;'>" + city + " 缺少 最高温度 最低温度 降水 数据<br/></li>"); } } ldc.DataMiss = dataMissStr.ToString(); if (!String.IsNullOrWhiteSpace(ldc.DataMiss)) { ldcList.Add(ldc); } } Repeater_DataCheck.DataSource = ldcList; Repeater_DataCheck.DataBind(); if (ldcList.Count() > 0) { Label_DataMiss.Text = startTime.ToString("yyyy年MM月") + DropDownList_YBTime.SelectedItem.Value + "实况数据有缺失,请及时补充!"; Panel_DataMiss.Visible = true; } else { Label_DataMiss.Text = startTime.ToString("yyyy年MM月") + DropDownList_YBTime.SelectedItem.Value + "实况数据齐全!"; Panel_DataMiss.Visible = false; } }
public void Temp20() { DATAHOUR_BLL hbll = new DATAHOUR_BLL(); LiveData_BLL lbll = new LiveData_BLL(); DateTime.Now.AddDays(-1).ToString("yyyyMMdd"); DateTime startTime = DateTime.ParseExact(DateTime.Now.AddDays(-5).ToString("yyyyMMdd") + "20", "yyyyMMddHH", CultureInfo.InvariantCulture); DateTime endTime = startTime.AddDays(4); TimeSpan ts = endTime - startTime; for (int i = 0; i < ts.Days; i++) { DateTime stime = startTime.AddDays(i); DateTime etime = stime.AddDays(1); List <string> citynames = CityUtility.AllNameList(); foreach (string cityname in citynames) { string selectname = cityname; if (cityname == "黄岛") { selectname = "胶南"; } List <DATAHOUR> dlist = hbll.GetList(a => a.STANAME == selectname && a.MINTEMP != 9999 && a.MAXTEMP != 9999 && a.FDATE >= stime && a.FDATE < etime).ToList(); if (dlist.Count > 0) { DateTime seletime = DateTime.Parse(etime.ToShortDateString()); LiveData liveData = lbll.Get(a => a.CountryName == cityname && a.FDate == seletime && a.Category == "20时"); if (liveData != null) { liveData.MaxTemp = dlist.Max(a => a.MAXTEMP); liveData.MinTemp = dlist.Min(a => a.MINTEMP); lbll.Update(liveData); } else { LiveData newModel = new LiveData(); newModel.LDID = Guid.NewGuid(); newModel.FDate = etime; newModel.Category = "20时"; newModel.CountryCode = CityUtility.GetCode(cityname); newModel.CountryName = cityname; newModel.CreateTime = DateTime.Now; newModel.MaxTemp = dlist.Max(a => a.MAXTEMP); newModel.MinTemp = dlist.Min(a => a.MINTEMP); lbll.Add(newModel); } Console.WriteLine(cityname); } } Console.WriteLine(stime.ToString("yyyy-MM-dd HH:mm") + "~" + etime.ToString("yyyy-MM-dd HH:mm")); } }