예제 #1
0
        //确认添加课程
        public async void btnAddConfirm_Click(object sender, RoutedEventArgs e)
        {
            var current = CoursePage.Current;

            if (string.IsNullOrEmpty(current.txtCourseName.Text) ||
                current.ComboDayOfWeek.SelectedIndex == -1 || current.ComboSelectedMode.SelectedIndex == -1 ||
                current.ComboCourseStart.SelectedIndex == -1 || current.ComboCourseEnd.SelectedIndex == -1 ||
                current.ComboWeekStart.SelectedIndex == -1 || current.ComboWeekEnd.SelectedIndex == -1)
            {
                await new MessageDialog("亲,带 * 的都是必填选项哟,先check一下下吧(●'◡'●)").ShowAsync();

                return;
            }

            Course course = new Course();

            course.FullName   = current.txtCourseName.Text;
            course.Classroom  = current.txtClassroom.Text;
            course.Teacher    = current.txtTeacher.Text;
            course.Credits    = current.txtCredit.Text;
            course.Classify   = current.txtClassify.Text;
            course.StartMark  = current.ComboCourseStart.SelectedIndex;
            course.CourseSpan = current.ComboCourseEnd.SelectedIndex - current.ComboCourseStart.SelectedIndex + 1;

            //处理UI及后台逻辑
            current.TipPanel.Visibility      = Visibility.Visible;
            current.AddCourseGrid.Visibility = Visibility.Collapsed;

            string termlyString = await CourseDataService.ProcessCourse(course, current.ComboSelectedMode.SelectedIndex, current.ComboDayOfWeek.SelectedIndex, current.ComboWeekStart.SelectedIndex, current.ComboWeekEnd.SelectedIndex);

            if (!string.IsNullOrEmpty(termlyString))
            {
                await CourseDataService.SaveTermlyJsonToIsoStoreAsync(termlyString);

                current.ViewModel.InitializeRootGrid(current.CourseGrid);

                current.TipPanel.Visibility      = Visibility.Collapsed;
                current.btnUserControl.IsEnabled = true;
            }
            else
            {
                current.TipPanel.Visibility      = Visibility.Collapsed;
                current.btnUserControl.IsEnabled = true;

                await new MessageDialog("添加课程失败了,再试一次吧~_~").ShowAsync();
            }
        }