Exemplo n.º 1
0
        public string DataImportRain08(DateTime yearMonth)
        {
            StringBuilder message = new StringBuilder();

            string yearMonthString = yearMonth.ToString("yyyyMM");

            LiveData_BLL    bll         = new LiveData_BLL();
            List <FileInfo> allFileList = FileHelper.GetShareFileInfos(@"\\172.18.226.109\市县一体化平台文档\检验\r24-8-p", yearMonthString.Substring(2, 4) + "*.000", "administrator", "yubk0501!");

            if (allFileList.Count == 0)
            {
                return("未发现该月份降水文件!<br/>");
            }
            foreach (FileInfo fileInfo in allFileList)
            {
                //DateTime datetime = DateTime.ParseExact("20" + fileInfo.Name.Substring(0, 6), "yyyyMMdd", CultureInfo.InvariantCulture);
                DateTime fileDateTime = DateTime.ParseExact("20" + fileInfo.Name.Substring(0, 6), "yyyyMMdd", CultureInfo.InvariantCulture);


                if (fileDateTime.Day == 9)
                {
                    var aaa = fileDateTime;
                }
                DateTime dataDateTime = fileDateTime.AddDays(-1);

                string[]      contents  = FileHelper.GetShareTextLines(@"\\172.18.226.109\市县一体化平台文档\检验\r24-8-p\" + fileInfo.Name, "Administrator", "yubk0501!");
                List <string> citycodes = CityUtility.AllCodeList();
                foreach (string citycode in citycodes)
                {
                    string  line = contents.Where(a => a.Contains(citycode)).FirstOrDefault();
                    decimal rain = 0;
                    if (!string.IsNullOrEmpty(line))
                    {
                        rain = decimal.Parse(line.Substring(27, line.Length - 27).Trim());
                    }
                    LiveData liveData = bll.Get(a => a.CountryCode == citycode && a.FDate == dataDateTime && a.Category == "08时");
                    if (liveData != null)
                    {
                        liveData.Rain = rain;
                        bll.Update(liveData);
                    }
                    else
                    {
                        LiveData newModel = new LiveData();
                        newModel.LDID        = Guid.NewGuid();
                        newModel.Category    = "08时";
                        newModel.CountryCode = citycode;
                        newModel.CountryName = CityUtility.GetName(citycode);
                        newModel.CreateTime  = DateTime.Now;
                        newModel.Rain        = rain;
                        newModel.FDate       = dataDateTime;
                        bll.Add(newModel);
                    }
                }
            }

            message.Append("导入降水量文件成功,共计导入" + allFileList.Count.ToString() + "个文件。<br/>");
            return(message.ToString());
        }
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());
        }