Beispiel #1
0
        private void ReadLessons_Loaded(object sender, RoutedEventArgs e)
        {
            ReadLessons dblessons = new ReadLessons();

            DB_LessonList       = dblessons.GetAllLessons();                 //Get all DB contacts
            listBox.ItemsSource = DB_LessonList.OrderBy(i => i.Id).ToList(); //Binding DB data to LISTBOX and Latest contact ID can Display first.
        }
Beispiel #2
0
        async private void ReadDataFromWeb()
        {
            progressbar.Text = "Fetching new data";
            progressbar.ShowAsync();

            var client = new HttpClient();

            Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            if (!localSettings.Containers.ContainsKey("userInfo"))
            {
                MessageDialog msgbox = new MessageDialog("Please log-in first. Go to settings from the main menu.");
                await msgbox.ShowAsync();

                return;
            }

            var lastcheck = localSettings.Containers["userInfo"].Values["lastchecklessons"].ToString();

            Debug.WriteLine(System.Uri.EscapeUriString(lastcheck));
            var response = await client.GetAsync(new Uri("http://codeinn-acecoders.rhcloud.com:8000/query/data?Timestamp=" + System.Uri.EscapeUriString(lastcheck) + "&Table=Lessons"));

            var result = await response.Content.ReadAsStringAsync();

            result = result.Trim(new Char[] { '"' });
            Debug.WriteLine(result);

            DatabaseLesson Db_Helper = new DatabaseLesson();

            try
            {
                List <Lessons> newless = JsonConvert.DeserializeObject <List <Lessons> >(result);
                foreach (Lessons less in newless)
                {
                    try
                    {
                        Db_Helper.InsertLesson(less);
                    }
                    catch
                    {
                        Debug.WriteLine("DB error for item of id: " + less.Id);
                    }
                }
                localSettings.Containers["userInfo"].Values["lastchecklessons"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
                progressbar.Text = "New items";
            }
            catch
            {
                Debug.WriteLine("No new items");
                progressbar.Text = "No New items";
            }
            finally
            {
                ReadLessons dblessons = new ReadLessons();
                DB_LessonList       = dblessons.GetAllLessons();
                listBox.ItemsSource = DB_LessonList.OrderByDescending(i => i.Id).ToList();
            }
            progressbar.HideAsync();
        }