示例#1
0
文件: Program.cs 项目: MadIHI/Test
        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
        }
示例#2
0
文件: Program.cs 项目: MadIHI/Test
        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
        }
示例#3
0
文件: Program.cs 项目: MadIHI/Test
        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
        }