Esempio n. 1
0
        public static List <WeatherInfo> GetWeatherInfo(DateTime sdate, DateTime edate, int q_count = 1000)
        {
            Database WeatherHelperDataContext = DatabaseConfig.GetWeatherHelperDatabase();

            if (q_count <= 0 || q_count > 1000)
            {
                throw new ArgumentOutOfRangeException("q_count should > 0 and q_count should <= 10000");
            }

            List <WeatherInfo> result = null;

            try
            {
                using (DbCommand command = WeatherHelperDataContext.GetSqlStringCommand(
                           @"SELECT TOP " + q_count + @" 
                           [AreaName]
                          ,[WCCountryName]
                          ,[WeatherID]
                          ,[AreaCode]
                          ,[WCCode]
                          ,[Temperature]
                          ,[Skycode]
                          ,[Skytext]
                          ,[Observationtime]
                          ,[Observationpoint]
                          ,[Feelslike]
                          ,[Humidity]
                          ,[Windspeed]
                          ,[Winddisplay]
                          ,[SkycodeImg]
                          ,[Low]
                          ,[High]
                          ,[Shortday]
                          ,[WeatherStatus]
                          ,[CDate] 
                            FROM [V_WeatherData]
                            where  (CDate <= @edate and CDate >= @sdate) 
                           order by left(CDate,8), CAST([AreaCode] as int) 
"))
                {
                    WeatherHelperDataContext.AddInParameter(command, "@sdate", DbType.DateTime, sdate);
                    WeatherHelperDataContext.AddInParameter(command, "@edate", DbType.DateTime, edate);
                    IDataReader reader = WeatherHelperDataContext.ExecuteReader(command);
                    result = new List <WeatherInfo>();

                    while (reader.Read())
                    {
                        WeatherInfo response = new WeatherInfo();
                        response.AreaName         = reader["AreaName"].ToString();
                        response.CountryName      = reader["WCCountryName"].ToString();
                        response.WeatherID        = reader["WeatherID"].ToString();
                        response.AreaCode         = reader["AreaCode"].ToString();
                        response.WCCode           = reader["WCCode"].ToString();
                        response.Temperature      = reader["Temperature"].ToString();
                        response.Skycode          = reader["Skycode"].ToString();
                        response.Skytext          = reader["Skytext"].ToString();
                        response.Observationtime  = reader["Observationtime"].ToString();
                        response.Observationpoint = reader["Observationpoint"].ToString();
                        response.Feelslike        = reader["Feelslike"].ToString();
                        response.Humidity         = reader["Humidity"].ToString();
                        response.Windspeed        = reader["Windspeed"].ToString();
                        response.Winddisplay      = reader["Winddisplay"].ToString();
                        //response.SkycodeImg = reader["SkycodeImg"].ToString();
                        response.Low           = reader["Low"].ToString();
                        response.High          = reader["High"].ToString();
                        response.Shortday      = reader["Shortday"].ToString();
                        response.WeatherStatus = reader["WeatherStatus"].ToString();
                        response.CDate         = Convert.ToDateTime(reader["CDate"]);

                        result.Add(response);
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }