Пример #1
0
        //Allows selected rows to modify data displayed in chart
        private void grid_SelectionChanged(object sender, C1.Xamarin.Forms.Grid.GridCellRangeEventArgs e)
        {
            WeatherModel selectedData;
            ObservableCollection <WeatherModel> selectedDataCollection = new ObservableCollection <WeatherModel>();
            var range = e.CellRange;

            if (range == null)
            {
                range = new GridCellRange(0, 0, grid.Rows.Count - 1, grid.Columns.Count - 1);
            }
            int upperRow = range.Row;
            int lowerRow = range.Row2;

            if (range.Row2 < range.Row)
            {
                upperRow = range.Row2;
                lowerRow = range.Row;
            }

            for (int i = upperRow; i <= lowerRow; i++)
            {
                selectedData             = new WeatherModel();
                selectedData.date        = (DateTime)grid.GetCellValue(new C1.Xamarin.Forms.Grid.GridCellRange(i, grid.Columns["date"].Index));
                selectedData.description = (string)grid.GetCellValue(new C1.Xamarin.Forms.Grid.GridCellRange(i, grid.Columns["description"].Index));
                selectedData.hightemp    = (double)grid.GetCellValue(new C1.Xamarin.Forms.Grid.GridCellRange(i, grid.Columns["hightemp"].Index));
                selectedData.lowtemp     = (double)grid.GetCellValue(new C1.Xamarin.Forms.Grid.GridCellRange(i, grid.Columns["lowtemp"].Index));
                selectedData.humidity    = (int)grid.GetCellValue(new C1.Xamarin.Forms.Grid.GridCellRange(i, grid.Columns["humidity"].Index));
                selectedData.pressure    = (double)grid.GetCellValue(new C1.Xamarin.Forms.Grid.GridCellRange(i, grid.Columns["pressure"].Index));

                selectedDataCollection.Add(selectedData);
            }
            chart.ItemsSource = selectedDataCollection;
            if ((lowerRow - upperRow) == 0)
            {
                TemperatureSeries.ChartType = ChartType.Scatter;
                HumiditySeries.ChartType    = ChartType.Scatter;
            }
            else
            {
                TemperatureSeries.ChartType = ChartType.Spline;
                HumiditySeries.ChartType    = ChartType.SplineArea;
            }
        }
Пример #2
0
        private static async Task <Tuple <ObservableCollection <WeatherModel>, String> > GetWeather(string url)
        {
            var client   = new HttpClient();
            var response = await client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                ObservableCollection <WeatherModel> weatherList = new ObservableCollection <WeatherModel>();
                string content = await response.Content.ReadAsStringAsync();

                var          data = JsonConvert.DeserializeObject <WeatherResult>(content);
                WeatherModel model;
                foreach (var item in data.list)
                {
                    model             = new WeatherModel();
                    model.date        = Convert.ToDateTime(item.dt_txt);
                    model.humidity    = item.main.humidity;
                    model.pressure    = item.main.pressure;
                    model.description = item.weather[0].description;
                    model.lowtemp     = item.main.temp_min;
                    model.hightemp    = item.main.temp_max;
                    model.icon        = ("http://openweathermap.org/img/w/" + item.weather[0].icon + ".png");
                    weatherList.Add(model);
                }
                return(new Tuple <ObservableCollection <WeatherModel>, String>(new ObservableCollection <WeatherModel>(weatherList), data.city.name + " " + data.city.country));
                //return new C1CollectionView<WeatherModel>(weatherList);
            }
            else
            {
                string content = await response.Content.ReadAsStringAsync();

                WeatherError errorData = JsonConvert.DeserializeObject <WeatherError>(content);
                //throw new Exception(await response.Content.ReadAsStringAsync());
                throw new Exception(errorData.COD + " " + errorData.Message);
            }
        }
Пример #3
0
 public void EndEdit()
 {
     _clone = null;
 }
Пример #4
0
 public void BeginEdit()
 {
     _clone = (WeatherModel)this.MemberwiseClone();
 }