Exemple #1
0
 public static string AirCondition(int AC12, int AC24)
 {
     try
     {
         using (ForecastDatumDataContext forecontext = new ForecastDatumDataContext())
         {
             string tmpAC12 = string.Format("{0:D2}", (int)(AC12 / 10));
             string tmpAC24 = string.Format("{0:D2}", (int)(AC24 / 10));
             WeatherPhenomenon pheno24 = forecontext.WeatherPhenomenons.Where(c => c.Code.Equals(tmpAC12 + tmpAC24)).FirstOrDefault();
             if (pheno24 != null)
                 return pheno24.CName;
             else
             {
                 if (AC12 <= AC24)
                 {
                     int tmp = (int)(AC24 / 10);
                     WeatherPhenomenon phenotmp = forecontext.WeatherPhenomenons.Where(c => c.Code.Equals(tmp)).FirstOrDefault();
                     return phenotmp.CName;
                 }
                 else
                 {
                     int tmp = (int)(AC12 / 10);
                     WeatherPhenomenon phenotmp = forecontext.WeatherPhenomenons.Where(c => c.Code.Equals(tmp)).FirstOrDefault();
                     return phenotmp.CName;
                 }
             }
         }
     }
     catch
     {
         return "";
     }
 }
Exemple #2
0
 public static string WindSpeedVDirection(int WD12, int WS12)
 {
     try
     {
         using (ForecastDatumDataContext forecontext = new ForecastDatumDataContext())
         {
             int tmpWS12 = (int)(WS12 / 10);
             int tmpWD12 = (int)(WD12 / 10);
             Wind winds = forecontext.Winds.Where(c => c.WindID.Equals(tmpWS12)).FirstOrDefault();
             Wind windd = forecontext.Winds.Where(c => c.WindID.Equals(tmpWD12)).FirstOrDefault();
             return winds.WSCName + "," + windd.WDCName;
         }
     }
     catch
     {
         return "";
     }
 }
Exemple #3
0
 public static string AirCondition12(int AC12)
 {
     try
     {
         using (ForecastDatumDataContext forecontext = new ForecastDatumDataContext())
         {
             string tmpAC12 = string.Format("{0:D2}", (int)(AC12 / 10));
             WeatherPhenomenon pheno12 = forecontext.WeatherPhenomenons.Where(c => c.Code.Equals(tmpAC12)).FirstOrDefault();
             if (pheno12 != null)
                 return pheno12.CName;
             else
                 return "";
         }
     }
     catch
     {
         return "";
     }
 }
Exemple #4
0
        private static void getNowcating()
        {
            string filepath = @"E:\Projects\CSharp\Test\Test\Products";
            #region shorttermprediction
            try
            {
                Report wrd = new Report();
                DirectoryInfo dir = new DirectoryInfo(filepath);
                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    bool istitle = true;
                    if (Regex.IsMatch(file.Name, AllConsts.NOWCASTING))
                    {
                        wrd.OpenDocFile(file.FullName);
                        bool isPredic = false;
                        int predictions = 0;
                        int ShortTermWeatherPredictionNum = 0;
                        int UnitNum = AllConsts.QIXIANGTAI_UNIT_NUM;
                        string LastModifyUserName = AllConsts.QIXIANGTAI_Admin_UserName;
                        string Prediction6 = AllConsts.NULLSTRING;
                        string Prediction12 = AllConsts.NULLSTRING;
                        DateTime startTime = DateTime.ParseExact(AllConsts.MAX_DATETIME_HOUR, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
                        DateTime CreateDate = file.LastWriteTime;

                        //if (CreateDate.Year != DateTime.Now.Year || CreateDate.Month != DateTime.Now.Month || CreateDate.Day != DateTime.Now.Day)
                        //    continue;
                        foreach (word.Paragraph item in wrd.Document.Paragraphs)
                        {
                            if (item != null)
                            {
                                if (item.Range.Text.Trim() != "")
                                {
                                    string ShorTermPat_zhi = @"[0-9]+日[0-9]+时至";
                                    string ShorTermPat_Hour = @"[0-9]+(?=(时))";

                                    Match ShortTermRx_zhi = Regex.Match(item.Range.Text.Trim(), ShorTermPat_zhi);
                                    if ("" != ShortTermRx_zhi.Value && istitle.Equals(true))
                                    {
                                        int hour = int.Parse(Regex.Match(ShortTermRx_zhi.Value, ShorTermPat_Hour).Value);
                                        startTime = DateTime.ParseExact(CreateDate.ToString("yyyyMMdd") + String.Format("{0:D2}", hour), "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
                                        if (startTime.Hour.Equals(8))
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D4}", startTime.DayOfYear * 3 + 1));
                                        if (startTime.Hour.Equals(14))
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D4}", startTime.DayOfYear * 3 + 2));
                                        if (startTime.Hour.Equals(20))
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D4}", startTime.DayOfYear * 3 + 3));
                                        istitle = false;
                                    }
                                    if ("" != ShortTermRx_zhi.Value)
                                    {
                                        isPredic = true;
                                        predictions += 6;
                                        continue;
                                    }
                                    if (predictions.Equals(6) && isPredic)
                                    {
                                        Prediction6 = item.Range.Text.Trim();
                                        isPredic = false;
                                        continue;
                                    }
                                    if (predictions.Equals(12) && isPredic)
                                    {
                                        Prediction12 = item.Range.Text.Trim();
                                        isPredic = false;
                                        continue;
                                    }
                                }
                            }
                        }
                        wrd.CloseWord();
                        wrd.killWinWordProcess();

                        using (ForecastDatumDataContext datumcontext = new ForecastDatumDataContext())
                        {
                            Nowcasting shorterm = new Nowcasting();
                            shorterm.LastModifyUserName = LastModifyUserName;
                            shorterm.UnitNum = UnitNum;
                            shorterm.startTime = startTime;
                            shorterm.NowcastingNum = ShortTermWeatherPredictionNum;
                            shorterm.CreateDate = CreateDate;
                            shorterm.LastmodifyDate = DateTime.Now;
                            shorterm.Prediction6 = Prediction6;
                            shorterm.Prediction12 = Prediction12;
                            Nowcasting oldshorterm = datumcontext.Nowcastings.Where(c => c.NowcastingNum.Equals(shorterm.NowcastingNum)).FirstOrDefault();
                            if (null == oldshorterm)
                                datumcontext.Nowcastings.Add(shorterm);
                            else
                            {
                                oldshorterm.LastModifyUserName = shorterm.LastModifyUserName;
                                oldshorterm.UnitNum = shorterm.UnitNum;
                                oldshorterm.startTime = shorterm.startTime;
                                oldshorterm.CreateDate = shorterm.CreateDate;
                                oldshorterm.LastmodifyDate = shorterm.LastmodifyDate;
                                oldshorterm.Prediction6 = shorterm.Prediction6;
                                oldshorterm.Prediction12 = shorterm.Prediction12;
                            }
                            datumcontext.SaveChanges();
                        }
                    }
                }
            }
            catch
            {
            }
            #endregion
        }
Exemple #5
0
        private static void getTrafficPrediction()
        {
            string filepath = @"E:\Projects\CSharp\Test\Test\Products";
            #region trafficprediction
            try
            {
                Report wrd = new Report();
                DirectoryInfo dir = new DirectoryInfo(filepath);
                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (Regex.IsMatch(file.Name, AllConsts.TRAFFICPREDICTION))
                    {
                        wrd.OpenDocFile(file.FullName);
                        int ShortTermWeatherPredictionNum = 0;
                        int UnitNum = AllConsts.QIXIANGTAI_UNIT_NUM;
                        string LastModifyUserName = AllConsts.QIXIANGTAI_Admin_UserName;
                        string Prediction24 = AllConsts.NULLSTRING;
                        string Prediction24Pic = AllConsts.NULLSTRING;
                        string Prediction48 = AllConsts.NULLSTRING;
                        string Prediction48Pic = AllConsts.NULLSTRING;
                        string Prediction72 = AllConsts.NULLSTRING;
                        string Prediction72Pic = AllConsts.NULLSTRING;
                        DateTime startTime = DateTime.ParseExact(AllConsts.MAX_DATETIME_HOUR, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
                        DateTime CreateDate = file.LastWriteTime;
                        //if (CreateDate.Year != DateTime.Now.Year || CreateDate.Month != DateTime.Now.Month || CreateDate.Day != DateTime.Now.Day)
                        //    return;
                        foreach (word.Paragraph item in wrd.Document.Paragraphs)
                        {
                            if (item != null)
                            {
                                if (item.Range.Text.Trim() != "")
                                {
                                    string ShorTermPat_zhi = @"[0-9]+日[0-9]+时至[0-9]+日[0-9]+时";
                                    string ShorTermPat_Day = @"[0-9]+(?=(日))";
                                    string ShorTermPat_Hour = @"[0-9]+(?=(时))";

                                    Match ShortTermRx_fabu = Regex.Match(item.Range.Text.Trim(), ShorTermPat_zhi);
                                    if ("" != ShortTermRx_fabu.Value)
                                    {
                                        int day = int.Parse(Regex.Match(ShortTermRx_fabu.Value, ShorTermPat_Day).Value);
                                        int hour = int.Parse(Regex.Match(ShortTermRx_fabu.Value, ShorTermPat_Hour).Value);
                                        startTime = DateTime.ParseExact(CreateDate.ToString("yyyyMMdd") + String.Format("{0:D2}", hour), "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
                                        if (startTime.Hour.Equals(8))
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D3}", startTime.DayOfYear * 2 + 1));
                                        else
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D3}", startTime.DayOfYear * 2 + 2));
                                        Prediction24 = item.Range.Text.Trim();
                                    }
                                }
                            }
                        }
                        wrd.CloseWord();
                        wrd.killWinWordProcess();

                        using (ForecastDatumDataContext datumcontext = new ForecastDatumDataContext())
                        {
                            TrafficPredictin shorterm = new TrafficPredictin();
                            shorterm.LastModifyUserName = LastModifyUserName;
                            shorterm.UnitNum = UnitNum;
                            shorterm.startTime = startTime;
                            shorterm.TrafficPredictinNum = ShortTermWeatherPredictionNum;
                            shorterm.CreateDate = CreateDate;
                            shorterm.LastmodifyDate = DateTime.Now;
                            shorterm.Prediction24 = Prediction24;
                            shorterm.Prediction24Pic = Prediction24Pic;
                            shorterm.Prediction48 = Prediction48;
                            shorterm.Prediction48Pic = Prediction48Pic;
                            shorterm.Prediction72 = Prediction72;
                            shorterm.Prediction72Pic = Prediction72Pic;
                            TrafficPredictin oldshorterm = datumcontext.TrafficPredictins.Where(c => c.TrafficPredictinNum.Equals(shorterm.TrafficPredictinNum)).FirstOrDefault();
                            if (null == oldshorterm)
                                datumcontext.TrafficPredictins.Add(shorterm);
                            else
                            {
                                oldshorterm.LastModifyUserName = shorterm.LastModifyUserName;
                                oldshorterm.UnitNum = shorterm.UnitNum;
                                oldshorterm.startTime = shorterm.startTime;
                                oldshorterm.CreateDate = shorterm.CreateDate;
                                oldshorterm.LastmodifyDate = shorterm.LastmodifyDate;
                                oldshorterm.Prediction24 = shorterm.Prediction24;
                                oldshorterm.Prediction24Pic = shorterm.Prediction24Pic;
                                oldshorterm.Prediction48 = shorterm.Prediction48;
                                oldshorterm.Prediction48Pic = shorterm.Prediction48Pic;
                                oldshorterm.Prediction72 = shorterm.Prediction72;
                                oldshorterm.Prediction72Pic = shorterm.Prediction72Pic;
                            }
                            datumcontext.SaveChanges();
                        }
                    }
                }
            }
            catch
            {
            }
            #endregion
        }
Exemple #6
0
        private static void getShorTermPrediction()
        {
            string filepath = @"E:\Projects\CSharp\Test\Test\Products";
            #region shorttermprediction
            try
            {
                Report wrd = new Report();
                DirectoryInfo dir = new DirectoryInfo(filepath);
                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (Regex.IsMatch(file.Name, AllConsts.SHORTTERMWEATHERPREDICTION))
                    {
                        wrd.OpenDocFile(file.FullName);
                        bool isPredic = false;
                        int predictions = 0;
                        int ShortTermWeatherPredictionNum = 0;
                        int UnitNum = AllConsts.QIXIANGTAI_UNIT_NUM;
                        string LastModifyUserName = AllConsts.QIXIANGTAI_Admin_UserName;
                        string Prediction24 = "";
                        string Prediction24Pic = "";
                        string Prediction48 = "";
                        string Prediction48Pic = "";
                        string Prediction72 = "";
                        string Prediction72Pic = "";
                        DateTime startTime = DateTime.ParseExact(AllConsts.MAX_DATETIME_HOUR, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
                        DateTime CreateDate = file.LastWriteTime;

                        //if (CreateDate.Year != DateTime.Now.Year || CreateDate.Month != DateTime.Now.Month || CreateDate.Day != DateTime.Now.Day)
                        //    return;
                        foreach (word.Paragraph item in wrd.Document.Paragraphs)
                        {
                            if (item != null)
                            {
                                if (item.Range.Text.Trim() != "")
                                {
                                    string ShorTermPat_fabu = @"[0-9]+月[0-9]+日[0-9]+时+(?=(发布))";
                                    string ShorTermPat_zhi = @"[0-9]+日[0-9]+时至[0-9]+日[0-9]+时";
                                    string ShorTermPat_Month = @"[0-9]+(?=(月))";
                                    string ShorTermPat_Day = @"[0-9]+(?=(日))";
                                    string ShorTermPat_Hour = @"[0-9]+(?=(时))";

                                    Match ShortTermRx_fabu = Regex.Match(item.Range.Text.Trim(), ShorTermPat_fabu);
                                    if ("" != ShortTermRx_fabu.Value)
                                    {
                                        int month = int.Parse(Regex.Match(ShortTermRx_fabu.Value, ShorTermPat_Month).Value);
                                        int day = int.Parse(Regex.Match(ShortTermRx_fabu.Value, ShorTermPat_Day).Value);
                                        int hour = int.Parse(Regex.Match(ShortTermRx_fabu.Value, ShorTermPat_Hour).Value);
                                        startTime = DateTime.ParseExact(CreateDate.ToString("yyyyMMdd") + String.Format("{0:D2}", hour), "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
                                        if (startTime.Hour.Equals(8))
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D3}", startTime.DayOfYear * 2 + 1));
                                        else
                                            ShortTermWeatherPredictionNum = int.Parse(startTime.ToString("yyyyMM") + String.Format("{0:D3}", startTime.DayOfYear * 2 + 2));
                                    }
                                    Match ShortTermRx_zhi = Regex.Match(item.Range.Text.Trim(), ShorTermPat_zhi);
                                    if ("" != ShortTermRx_zhi.Value)
                                    {
                                        isPredic = true;
                                        predictions += 24;
                                        continue;
                                    }
                                    if (predictions.Equals(24) && isPredic)
                                    {
                                        Prediction24 = item.Range.Text.Trim();
                                        isPredic = false;
                                        continue;
                                    }
                                    if (predictions.Equals(48) && isPredic)
                                    {
                                        Prediction48 = item.Range.Text.Trim();
                                        isPredic = false;
                                        continue;
                                    }
                                    if (predictions.Equals(72) && isPredic)
                                    {
                                        Prediction72 = item.Range.Text.Trim();
                                        isPredic = false;
                                        continue;
                                    }
                                    //判断该范围内是否存在图片
                                    if (item.Range.InlineShapes.Count != 0)
                                    {
                                        foreach (word.InlineShape shape in item.Range.InlineShapes)
                                        {
                                            //判断类型
                                            if (shape.Type == word.WdInlineShapeType.wdInlineShapePicture)
                                            {
                                                ////获取Word中的图片
                                                //byte[] img = (byte[])shape.Range.EnhMetaFileBits;
                                                //Bitmap bmp = new Bitmap(new MemoryStream(img));
                                                //string fileName = System.Guid.NewGuid() + ".png";
                                                //bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                                                if (predictions.Equals(24))
                                                {
                                                    byte[] img = (byte[])shape.Range.EnhMetaFileBits;
                                                    Prediction24Pic = Convert.ToBase64String(img);
                                                }
                                                if (predictions.Equals(48))
                                                {
                                                    byte[] img = (byte[])shape.Range.EnhMetaFileBits;
                                                    Prediction48Pic = Convert.ToBase64String(img);
                                                }
                                                if (predictions.Equals(72))
                                                {
                                                    byte[] img = (byte[])shape.Range.EnhMetaFileBits;
                                                    Prediction72Pic = Convert.ToBase64String(img);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        wrd.CloseWord();
                        wrd.killWinWordProcess();

                        using (ForecastDatumDataContext datumcontext = new ForecastDatumDataContext())
                        {
                            ShortTermWeatherPrediction shorterm = new ShortTermWeatherPrediction();
                            shorterm.LastModifyUserName = LastModifyUserName;
                            shorterm.UnitNum = UnitNum;
                            shorterm.startTime = startTime;
                            shorterm.ShortTermWeatherPredictionNum = ShortTermWeatherPredictionNum;
                            shorterm.CreateDate = CreateDate;
                            shorterm.LastmodifyDate = DateTime.Now;
                            shorterm.Prediction24 = Prediction24;
                            shorterm.Prediction24Pic = Prediction24Pic;
                            shorterm.Prediction48 = Prediction48;
                            shorterm.Prediction48Pic = Prediction48Pic;
                            shorterm.Prediction72 = Prediction72;
                            shorterm.Prediction72Pic = Prediction72Pic;
                            ShortTermWeatherPrediction oldshorterm = datumcontext.ShortTermWeatherPredictions.Where(c => c.ShortTermWeatherPredictionNum.Equals(shorterm.ShortTermWeatherPredictionNum)).FirstOrDefault();
                            if (null == oldshorterm)
                                datumcontext.ShortTermWeatherPredictions.Add(shorterm);
                            else
                            {
                                oldshorterm.LastModifyUserName = shorterm.LastModifyUserName;
                                oldshorterm.UnitNum = shorterm.UnitNum;
                                oldshorterm.startTime = shorterm.startTime;
                                oldshorterm.CreateDate = shorterm.CreateDate;
                                oldshorterm.LastmodifyDate = shorterm.LastmodifyDate;
                                oldshorterm.Prediction24 = shorterm.Prediction24;
                                oldshorterm.Prediction24Pic = shorterm.Prediction24Pic;
                                oldshorterm.Prediction48 = shorterm.Prediction48;
                                oldshorterm.Prediction48Pic = shorterm.Prediction48Pic;
                                oldshorterm.Prediction72 = shorterm.Prediction72;
                                oldshorterm.Prediction72Pic = shorterm.Prediction72Pic;
                            }
                            datumcontext.SaveChanges();
                        }
                    }
                }
            }
            catch
            {
            }
            #endregion
        }
 public ActionResult AjaxGetSingledateMultistationList()
 {
     try
     {
         using (ForecastDatumDataContext context = new ForecastDatumDataContext())
         {
             //List<dynamic> res = new List<dynamic>();
             string yyyyDDmm = DateTime.Now.ToString("yyyyMMdd");
             DateTime startTime = (DateTime)DateTime.ParseExact(yyyyDDmm, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
             if (10 < DateTime.Now.Hour && DateTime.Now.Hour < 23)
                 startTime = startTime.AddHours(12);
             StringBuilder table = new StringBuilder(255);
             table.Append("<style type='text/css'>");
             table.Append("</style>");
             table.Append("<table class='table table-borderd table-hover table-striped' style='width:80%'><tbody>");
             for (int vaildtime = 24; vaildtime <= 168; vaildtime += 24)
             {
                 SqlParameter[] sqlParameters = { new SqlParameter { ParameterName = "startTime", Value = startTime }, new SqlParameter { ParameterName = "vaildTime", Value = vaildtime } };
                 List<TownPrediction> townlist = context.Database.SqlQuery<TownPrediction>("SELECT * FROM dbo.TownPrediction where startTime = @startTime AND vaildTime = @vaildTime", sqlParameters).ToList<TownPrediction>();
                 table.Append("<tr><th colspan='4'>");
                 table.Append(townlist[0].startTime.AddHours(8 + townlist[0].vaildTime - 24).ToString("d日H时—") + townlist[0].startTime.AddHours(8 + townlist[0].vaildTime).ToString("d日H时"));
                 table.Append("</th></tr>");
                 table.Append("<tr>");
                 foreach (TownPrediction town in townlist)
                 {
                     if (town.stationNum != "53083" && town.stationNum != "53276")
                     {
                         table.Append("<td style='vertical-align: middle'>");
                         table.Append(town.stationName);
                         table.Append("</td>");
                         table.Append("<td style='vertical-align: middle'>");
                         table.Append(town.T24MIN / 10 + "&#8451 ~ " + town.T24MAX / 10 + "&#8451");
                         table.Append("</td>");
                         if (town.startTime.Hour.Equals(0))
                         {
                             table.Append("<td style='vertical-align: middle'>");
                             table.Append("白天:" + AllConsts.AirCondition12(town.AC12) + "," + AllConsts.WindSpeedVDirection(town.WD12, town.WS12));
                             table.Append("</td>");
                             table.Append("<td style='vertical-align: middle'>");
                             table.Append("夜间:" + AllConsts.AirCondition12(town.AC24) + "," + AllConsts.WindSpeedVDirection(town.WD24, town.WS24));
                             table.Append("</td>");
                         }
                         else
                         {
                             table.Append("<td style='vertical-align: middle'>");
                             table.Append("夜间:" + AllConsts.AirCondition12(town.AC12) + "," + AllConsts.WindSpeedVDirection(town.WD12, town.WS12));
                             table.Append("</td>");
                             table.Append("<td style='vertical-align: middle'>");
                             table.Append("白天:" + AllConsts.AirCondition12(town.AC24) + "," + AllConsts.WindSpeedVDirection(town.WD24, town.WS24));
                             table.Append("</td>");
                         }                                                                
                         table.Append("</tr>");
                     }
                 }
             }
             table.Append("</table></tbody>");
             return Json(table.ToString(), JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("", JsonRequestBehavior.AllowGet);
     }
 }