Ejemplo n.º 1
0
        private void _initMailBody()
        {
            List <ForeseeWeatherInfo> ForeseeWeatherData = WeatherDataDAO.GetForeseeWeatherData();

            MailSubject = string.Format("預測天氣信({0}  ~  {1})", ForeseeWeatherData[0].Date, ForeseeWeatherData[ForeseeWeatherData.Count - 1].Date);

            StringBuilder retHtml = new StringBuilder();

            retHtml.Append("<table class=\"table\" style=\"width: 80%; border: 1px solid #E8EEF4; border-color: #DDDDDD #DDDDDD #DDDDDD -moz-use-text-color;\" ><tbody>");
            retHtml.Append("<tr><th style=\"border: 1px solid #DDDDDD;\">時間</th><th style=\"border: 1px solid #DDDDDD;\">地點</th><th style=\"border: 1px solid #DDDDDD;\">溫度</th><th style=\"border: 1px solid #DDDDDD;\">天氣狀況</th><th style=\"border: 1px solid #DDDDDD;\">天氣說明</th></tr>");
            foreach (var w in ForeseeWeatherData)
            {
                retHtml.Append("<tr>");
                retHtml.Append(string.Format("<td style=\"border: 1px solid #DDDDDD;\">{0}</td>", w.Date));
                retHtml.Append(string.Format("<td style=\"border: 1px solid #DDDDDD;\">{0}</td>", w.AreaName + " - " + w.CountryName));
                retHtml.Append(string.Format("<td style=\"border: 1px solid #DDDDDD;\">{0}</td>", w.Low + " ~ " + w.High));
                retHtml.Append(string.Format("<td style=\"border: 1px solid #DDDDDD;\"><img width=\"55\" height=\"45\" title=\"{0}\" src=\"{1}\" /></td>", w.WeatherStatus, w.SkycodeImg));
                retHtml.Append(string.Format("<td style=\"border: 1px solid #DDDDDD;\">{0}</td>", w.WeatherStatus));
                retHtml.Append("</tr>");
            }
            retHtml.Append("</tbody></table>");

            MailBody = "<html><body><strong>Hi ##USERNAME##:</strong><br><br><br>##DATA##</body></html>"
                       //.Replace(BOOTSTRAPCSS, "https://dl.dropboxusercontent.com/u/29103482/css/bootstrap.min.css")
                       .Replace(USER_NAME, UserName)
                       .Replace(DATA, retHtml.ToString());
        }
Ejemplo n.º 2
0
        public ActionResult DoQuery(DateTime STime, DateTime ETime)
        {
            try
            {
                DateTime sdate;
                DateTime edate;

                if (STime == null)
                {
                    sdate = CommonType.MinDateTime;
                }
                else
                {
                    sdate = STime;
                }

                if (ETime == null)
                {
                    edate = CommonType.MaxDateTime;
                }
                else
                {
                    edate = ETime;
                }

                List <WeatherInfo> weatherinfos = WeatherDataDAO.GetWeatherInfo(sdate, edate);
                if (weatherinfos != null && weatherinfos.Count > 0)
                {
                    ViewBag.WeatherInfos = weatherinfos;
                    return(View("Result"));
                }
                else
                {
                    ViewBag.Message = "查無資料!";
                }
                return(RedirectToAction("Index"));
            }
            catch (System.Net.WebException ex)
            {
                //ViewBag.ErrMsg = "網路斷線或遠端伺服器錯誤,請通知管理者";
                ErrorPageModel errModel = new ErrorPageModel
                {
                    ErrorTitle = "Network Error",
                    ErrorMsg   = "網路斷線或遠端伺服器錯誤,請通知管理者"
                };

                return(View("Error", errModel));
            }
            catch (System.Exception ex)
            {
                return(View("Error"));
            }
        }
Ejemplo n.º 3
0
 public void NewWeatherData_Null_Test()
 {
     WeatherDataDAO.NewWeatherData(null);
 }
Ejemplo n.º 4
0
        public void WeatherDataDAO_NewWeatherData_ConnectionString_Error_Test()
        {
            WeatherInfo data = new WeatherInfo();

            WeatherDataDAO.NewWeatherData(data);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            DateTime starttime;
            DateTime endtime;
            TimeSpan spentime;
            int      index = 1;

            List <WCCountry> wccountries = CityAndAreaConfig.Instance.getWCCountryList();

            try
            {
                Console.WriteLine("==============================================================================");
                starttime = DateTime.Now;
                Console.WriteLine(string.Format("Program start : Time =>{0}", starttime.ToString("yyyy/MM/dd HH:mm:ss")));
                Console.WriteLine("==============================================================================");
                foreach (var item in wccountries)
                {
                    Console.WriteLine("");
                    Console.WriteLine("==============================================================================");
                    Console.WriteLine(string.Format("Index = {0} , WCCode = {1} , AreaName = {2} , Name ={3}",
                                                    index, item.WCCode, CityAndAreaConfig.Instance.getAreaNameByAreaCode(item.AreaCode), item.Name));

                    QueryWeatherRequest request = new QueryWeatherRequest {
                        WCCode = item.WCCode, AreaCode = item.AreaCode
                    };
                    QueryWeatherResponse response = QueryServices.GetWeatherInfo(request);

                    if (response != null && response.CurrentDay != null)
                    {
                        Console.WriteLine(string.Format("天氣狀況:{0} , 地點:{1} , 溫度:{2} , 舒適度:{3} , 溫度範圍:{4} ~ {5} , 濕度:{6} , 風速:{7} , 觀測時間:{8}"
                                                        , response.CurrentDay.WeatherStatus
                                                        , CityAndAreaConfig.Instance.getAreaNameByAreaCode(item.AreaCode) + " - " + CityAndAreaConfig.Instance.getWCCountryNameByWCCode(item.WCCode)
                                                        , response.CurrentDay.Temperature
                                                        , response.CurrentDay.Feelslike
                                                        , response.CurrentDay.Low
                                                        , response.CurrentDay.High
                                                        , response.CurrentDay.Humidity
                                                        , response.CurrentDay.Windspeed
                                                        , response.CurrentDay.Observationtime
                                                        ));

                        WeatherDataDAO.NewWeatherData(response.CurrentDay);

                        //WeatherDataDAO.AddForeseeWeatherData(response.OthreDays);
                    }
                    index++;
                    Console.WriteLine("==============================================================================");
                }
                Console.WriteLine("");
                Console.WriteLine("==============================================================================");
                endtime = DateTime.Now;
                Console.WriteLine(string.Format("Program End : Time =>{0}", endtime.ToString("yyyy/MM/dd HH:mm:ss")));
                spentime = endtime - starttime;
                Console.WriteLine("Count : {0} , Spend Time:{1} 分  {2} 秒", index, spentime.Minutes, spentime.Seconds);
                Console.WriteLine("==============================================================================");
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(string.Format("System Error : {0}", ex.ToString()));
            }
        }