Пример #1
0
        public void FillDataRain(CityData cityData)
        {
            bool isRain = false;

            for (int i = 0; i < 8; i++)
            {
                DateTime time = DateTime.Parse(cityData.RainTime[i],
                                               null, DateTimeStyles.AssumeUniversal);
                City cityinfo = new City();
                cityinfo.Id          = cityData.Id;
                cityinfo.CityName    = cityData.CityName;
                cityinfo.CountryName = cityData.CountryName;
                cityinfo.Latitude    = cityData.Latitude;
                cityinfo.Longtitude  = cityData.Longtitude;
                cityinfo.Temp        = cityData.Temp[i];
                cityinfo.MaxTemp     = cityData.MaxTemp[i];
                cityinfo.MinTemp     = cityData.MinTemp[i];
                cityinfo.RainTime    = time.DayOfWeek.ToString();
                cityinfo.Main        = cityData.Main[i];
                cityinfo.RainIn3H    = cityData.RainIn3H[i];
                cityinfo.Time        = time.ToShortTimeString();
                cityinfo.Description = cityData.Description[i];
                Cities.Add(cityinfo);
                if (cityData.RainIn3H[i] != null)
                {
                    isRain = true;
                }
            }
            if (isRain == true)
            {
                MessageBox.Show("It will rain soon!");
            }
        }
Пример #2
0
        public ApplicationViewModel(string city)
        {
            Cities = new ObservableCollection <City>();
            DataTable tab = dataAccess.GetCityData();
            DataRow   row = tab.Rows[0];

            cityData = converter.Convert(city);
            if (string.IsNullOrEmpty(city))
            {
                MessageBox.Show("Input name of city");
            }
            else
            {
                if (cityData == null)
                {
                    MessageBox.Show("Wrong name of city");
                }
                else
                {
                    if (row["CityName"].ToString().Trim() == city)
                    {
                        FillData(row, cityData);
                    }
                    else
                    {
                        FillDataRain(cityData);
                    }
                    bool result = dataAccess.EditCityData(cityData);
                    if (!result)
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
        }
Пример #3
0
        public CityData Convert(string name)
        {
            JsonParser jsonParser = new JsonParser();
            CityList   cityList;
            CityData   cityData = new CityData();

            cityList = jsonParser.Parsing(name);
            if (cityList == null)
            {
                cityData = null;
            }
            else
            {
                cityData.Id          = 1;
                cityData.CityName    = cityList.city.name;
                cityData.CountryName = cityList.city.country;
                cityData.Latitude    = cityList.city.coord.lat.ToString();
                cityData.Longtitude  = cityList.city.coord.lon.ToString();
                for (int i = 0; i < 8; i++)
                {
                    cityData.RainTime.Add(cityList.list[i].dt_txt);
                    cityData.Temp.Add(cityList.list[i].main.temp.ToString());
                    cityData.MaxTemp.Add(cityList.list[i].main.temp_max.ToString());
                    cityData.MinTemp.Add(cityList.list[i].main.temp_min.ToString());
                    cityData.RainIn3H.Add(cityList.list[i].rain?.rain3h?.ToString());
                    cityData.Main.Add(cityList.list[i].weather[0].main);
                    cityData.Description.Add(cityList.list[i].weather[0].description);
                }
            }

            return(cityData);
        }
Пример #4
0
        public ApplicationViewModel()
        {
            Cities = new ObservableCollection <City>();

            DataTable tab = dataAccess.GetCityData();
            DataRow   row = tab.Rows[0];

            cityData = converter.Convert(row["CityName"].ToString().Trim());
            FillData(row, cityData);
        }
Пример #5
0
        public bool EditCityData(CityData data)
        {
            bool check = false;

            try
            {
                string   sql       = "UPDATE CityData SET CityName = @name, RainTime = @raintime WHERE Id =@ID ";
                DateTime startTime = DateTime.Parse(data.RainTime[0],
                                                    null, DateTimeStyles.AssumeUniversal);
                SqlParameter Id       = new SqlParameter("@ID", data.Id);
                SqlParameter Name     = new SqlParameter("@name", data.CityName);
                SqlParameter RainTime = new SqlParameter("@raintime", startTime.DayOfWeek.ToString());
                check = ExecuteNonQuery(sql, CommandType.Text, Id, Name, RainTime);
            }
            catch
            {
                MessageBox.Show("Неправильный формат данных");
            }
            return(check);
        }
Пример #6
0
        public void FillData(DataRow row, CityData citydata)
        {
            DateTime initTime = DateTime.Parse(citydata.RainTime[0],
                                               null, DateTimeStyles.AssumeUniversal);
            string day = initTime.DayOfWeek.ToString();

            if (row["RainTime"].ToString().Trim() == day)
            {
                for (int i = 0; i < 8; i++)
                {
                    DateTime time = DateTime.Parse(citydata.RainTime[i],
                                                   null, DateTimeStyles.AssumeUniversal);
                    City cityinfo = new City
                    {
                        Id          = citydata.Id,
                        CityName    = citydata.CityName,
                        CountryName = citydata.CountryName,
                        Latitude    = citydata.Latitude,
                        Longtitude  = citydata.Longtitude,
                        Temp        = citydata.Temp[i],
                        MaxTemp     = citydata.MaxTemp[i],
                        MinTemp     = citydata.MinTemp[i],
                        RainTime    = time.DayOfWeek.ToString(),
                        Main        = citydata.Main[i],
                        RainIn3H    = citydata.RainIn3H[i],
                        Description = citydata.Description[i],
                        Time        = time.ToShortTimeString()
                    };
                    Cities.Add(cityinfo);
                }
            }
            else
            {
                bool isRain = false;
                for (int i = 0; i < 8; i++)
                {
                    DateTime time = DateTime.Parse(citydata.RainTime[i],
                                                   null, DateTimeStyles.AssumeUniversal);
                    City cityinfo = new City
                    {
                        Id          = citydata.Id,
                        CityName    = citydata.CityName,
                        CountryName = citydata.CountryName,
                        Latitude    = citydata.Latitude,
                        Longtitude  = citydata.Longtitude,
                        Temp        = citydata.Temp[i],
                        MaxTemp     = citydata.MaxTemp[i],
                        MinTemp     = citydata.MinTemp[i],
                        RainTime    = time.DayOfWeek.ToString(),
                        Main        = citydata.Main[i],
                        RainIn3H    = citydata.RainIn3H[i],
                        Description = citydata.Description[i],
                        Time        = time.ToShortTimeString()
                    };
                    Cities.Add(cityinfo);
                    if (cityinfo.RainIn3H != null)
                    {
                        isRain = true;
                    }
                }
                if (isRain == true)
                {
                    MessageBox.Show("It will rain soon!");
                }
            }
        }