コード例 #1
0
        private void TextBox_TextChanged_1(object sender, TextChangedEventArgs e)
        {
            try
            {
                var numtask = (numOfTask.Text == String.Empty) ? 1 : Convert.ToInt32(numOfTask.Text);
                if (numtask > ItemListView.Items.Count)
                {
                    numtask        = ItemListView.Items.Count;
                    numOfTask.Text = numtask.ToString();
                }
                ItemListView.SelectedIndex = numtask - 1;
                ItemListView.ScrollIntoView(ItemListView.SelectedItem);
            }

            catch (FormatException)
            {
                ItemListView.SelectedIndex = 0;
                numOfTask.Text             = (ItemListView.SelectedIndex + 1).ToString();
                ItemListView.ScrollIntoView(ItemListView.SelectedItem);
            }
            catch (Exception)
            {
                throw new Exception("Не возможно переместиться к задаче, так как недействителен номер её");
            }
        }
コード例 #2
0
        private async void GetReddits()
        {
            if (Subreddits.LoggedIn)
            {
                try
                {
                    HttpClientHandler handler = new HttpClientHandler();

                    //var request = (HttpWebRequest)WebRequest.Create("http://www.reddit.com/reddits/mine.json");
                    //request.CookieContainer = new CookieContainer();

                    Cookie c = new Cookie("reddit_session", App.cookie.Replace(",", "%2C"));
                    handler.CookieContainer.Add(new Uri("http://www.reddit.com"), c);

                    App.JsonClient = new HttpClient(handler);

                    var response = App.JsonClient.GetAsync("http://www.reddit.com/reddits/mine.json").Result.Content;
                    await Subreddits.LoadCollection(response);
                }
                catch (Exception)
                {
                }
            }
            else
            {
                App.JsonClient = new HttpClient();
                var response = App.JsonClient.GetAsync("http://www.reddit.com/reddits.json").Result.Content;
                await Subreddits.LoadCollection(response);
            }

            ItemListView.ScrollIntoView(ItemListView.Items[0]);
        }
コード例 #3
0
        private void BtnAddCourse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(TxtNewTitle.Text) || string.IsNullOrEmpty(TxtNewCode.Text))
                {
                    MessageBox.Show(@"All field required");
                    return;
                }

                var course = new Course {
                    Code  = TxtNewCode.Text.Trim(),
                    Title = TxtNewTitle.Text.Trim()
                };

                var maxId = (_db.Courses.Select(p => (int?)p.ID).Max() ?? 0) + 1;

                course.ID = maxId;

                try
                {
                    _db.Courses.AddObject(course);
                }
                catch
                {
                    _repo.Courses = new List <Course> {
                        course
                    };
                }

                _db.SaveChanges();

                MessageBox.Show("Course Added");
                Refresh();
                TxtNewTitle.Clear();
                TxtNewCode.Clear();

                ItemListView.ScrollIntoView(course);
                ItemListView.SelectedIndex = course.ID - 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }