Exemplo n.º 1
0
        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/>");
            }
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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"));
            }
        }