예제 #1
0
        protected async Task RefreshClaimLectures()
        {
            MyDB DB = new MyDB();

            if (CrossConnectivity.Current.IsConnected)
            {
                try
                {
                    App_activity_indicator.IsVisible = true;
                    App_activity_indicator.IsRunning = true;
                    string webaddress = Libraries.MobileConfig.GetWebAddress(Application.Current.Properties["campus"].ToString()) +
                                        string.Format("DataFinder.aspx?dataFormat=myclaimslectures&CID={0}", claimID);
                    _client.Timeout = TimeSpan.Parse("00:00:15");
                    var content = await _client.GetStringAsync(webaddress);

                    var n = JsonConvert.DeserializeObject <List <Model.LectureModel> >(content);
                    List <Model.LectureModel> L_data = new List <Model.LectureModel>(n);
                    // await DisplayAlert("Content ", "Items " + L_data.Count, "OK");
                    if (L_data.Count > 0)
                    {
                        DB.resetLectures();
                        DB.AddLectures(content);
                    }
                    else
                    {
                        //await DisplayAlert("Content ", "Sem " + content, "OK");
                        DB.resetLectures();
                        lv_claimlectures.ItemsSource = null;
                    }

                    App_activity_indicator.IsVisible = false;
                    App_activity_indicator.IsRunning = false;
                }
                catch (Exception)
                {
                    //await DisplayAlert("Error!", "" + ex.Message, "OK");
                    DB.resetLectures();
                    lv_claimlectures.ItemsSource     = null;
                    App_activity_indicator.IsVisible = false;
                    App_activity_indicator.IsRunning = false;
                }
            }
            else
            {
                await DisplayAlert("Warning", "No Internet Connection", "OK");
            }
            // await DisplayAlert("Content ", "Content " + DB.GetAllLectures(), "OK");
            var list = JsonConvert.DeserializeObject <List <Model.LectureModel> >(DB.GetAllLectures());
            List <Model.LectureModel> display_data = new List <Model.LectureModel>(list);

            lv_claimlectures.ItemsSource = display_data;
            lv_claimlectures.EndRefresh();
        }