Beispiel #1
0
        /// <summary>
        /// 设置一门课程需要上课的学生和上课教师
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SetStudentsAndTeacherOfCourseButtonClick(object sender, RoutedEventArgs e)
        {
            if (WaitingForUpdating())
            {
                TaskDialog.ShowError("请先更新数据,然后进行相关操作");
                return;
            }
            if (dgrdStudents.SelectedItems.Count == 0)
            {
                TaskDialog.ShowError("请至少选择一位学生");
                return;
            }
            if (dgrdTeachers.SelectedItems.Count != 1)
            {
                TaskDialog.ShowError("请选择一位教师");
                return;
            }
            if (dgrdCourses.SelectedItems.Count != 1)
            {
                TaskDialog.ShowError("请选择一门课程");
                return;
            }
            int id = (dgrdCourses.SelectedItem as UICourse).Id;
            IEnumerable <long> studentsId = dgrdStudents.SelectedItems.Cast <Person>().Select(p => p.Id);
            long teacherId = (dgrdTeachers.SelectedItem as Person).Id;

            JObject json = await NetHelper.Send(new { Command = Admin_SetStudentsAndTeacherOfCourse, ID = id, Students = studentsId, Teacher = teacherId }) as JObject;

            TaskDialog.Show(json[Message].Value <string>(),
                            icon: json[OK].Value <bool>() ? TaskDialogStandardIcon.None : TaskDialogStandardIcon.Error);
            await LoadCourses();
        }
Beispiel #2
0
        /// <summary>
        /// 获取一个课程的上课教师和需要上课的学生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void GetStudentsAndTeacherButtonClick(object sender, RoutedEventArgs e)
        {
            if (WaitingForUpdating())
            {
                TaskDialog.ShowError("请先更新数据,然后进行相关操作");
                return;
            }
            if (dgrdCourses.SelectedItems.Count != 1)
            {
                TaskDialog.ShowError("请选择且仅选择一门课程");
                return;
            }
            JObject json = await NetHelper.Send(new { Command = Admin_StudentsAndTeacherOfCourses, ID = (dgrdCourses.SelectedItem as UICourse).Id });

            if (!json[OK].Value <bool>())
            {
                TaskDialog.ShowError("获取失败:" + json[Message].Value <string>());
                return;
            }
            JArray students = json[Data][ApiCommands.Students] as JArray;
            JValue teacher  = json[Data][Teacher] as JValue;

            dgrdStudents.SelectedItems.Clear();
            dgrdTeachers.SelectedItems.Clear();
            foreach (JValue item in students)
            {
                dgrdStudents.SelectedItems.Add(Students.First(p => p.Id == item.Value <long>()));
            }
            dgrdTeachers.SelectedItem = Teachers.First(p => p.Id == teacher.Value <long>());
        }
Beispiel #3
0
        /// <summary>
        /// 获取一位教师需要上的课程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void GetCoursesOfTeacherButtonClick(object sender, RoutedEventArgs e)
        {
            if (WaitingForUpdating())
            {
                TaskDialog.ShowError("请先更新数据,然后进行相关操作");
                return;
            }
            if (dgrdTeachers.SelectedItems.Count != 1)
            {
                TaskDialog.ShowError("请选择且仅选择一个教师");
                return;
            }
            JObject json = await NetHelper.Send(new { Command = Admin_CourseOfTeacher, ID = (dgrdTeachers.SelectedItem as Person).Id });

            if (!json[OK].Value <bool>())
            {
                TaskDialog.ShowError("获取失败:" + json[Message].Value <string>());
                return;
            }
            JArray array = json[Data] as JArray;

            dgrdCourses.SelectedItems.Clear();
            foreach (JValue item in array)
            {
                dgrdCourses.SelectedItems.Add(Courses.First(p => p.Id == item.Value <int>()));
            }
        }
Beispiel #4
0
        /// <summary>
        /// 加载课程信息
        /// </summary>
        /// <returns></returns>
        private async Task LoadCourses()
        {
            Courses.Clear();
            JObject json = await NetHelper.Send(new { Command = Admin_Courses });

            if (!json[OK].Value <bool>())
            {
                TaskDialog.ShowError("加载课程列表失败:" + json[Message].Value <string>());
                return;
            }
            JArray array = json[Data] as JArray;

            foreach (dynamic item in array)
            {
                UICourse course = new UICourse();
                course.Id        = item.Id;
                course.Name      = item.Name;
                course.Teacher   = item.Teacher;
                course.TeacherId = item.TeacherId;
                course.Year      = item.Year;
                course.Term      = item.Term;

                Courses.Add(course);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 加载教师信息
        /// </summary>
        /// <returns></returns>
        private async Task LoadTeachers()
        {
            Teachers.Clear();
            JObject json = await NetHelper.Send(new { Command = ApiCommands.Admin_Teachers });

            if (!json[OK].Value <bool>())
            {
                TaskDialog.ShowError("加载教师列表失败:" + json[Message].Value <string>());
                return;
            }
            JArray array = json[Data] as JArray;

            foreach (dynamic item in array)
            {
                Person person = new Person();
                person.Id        = item.Id;
                person.Name      = item.Name;
                person.Born      = item.Born;
                person.Gender    = item.Gender;
                person.StartYear = item.StartYear;
                person.Major     = item.Major;
                person.Role      = item.Role;

                Teachers.Add(person);
            }
        }
Beispiel #6
0
 public bool PageClosing()
 {
     if (WaitingForUpdating())
     {
         if (TaskDialog.ShowWithYesNoButtons("还有已修改的数据没有更新,是否退出?", "正在关闭程序") == true)
         {
             return(true);
         }
         return(false);
     }
     return(true);
 }
Beispiel #7
0
        /// <summary>
        /// 单击新建条目按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewItemButtonClick(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn.Tag.Equals("2"))
            {
                AddNewCourseDialog dialog = new AddNewCourseDialog(Courses.Max(p => p.Id) + 1, "新增课程");
                if (dialog.ShowDialog() == true)
                {
                    Course course = dialog.Course;
                    if (Courses.Any(p => p.Id == course.Id))
                    {
                        TaskDialog.ShowError("该ID已存在");
                        return;
                    }
                    ModifiedCourses.Add(new UICourse(course));
                    Courses.Add(new UICourse(course));
                }
            }
            else
            {
                bool teacher = btn.Tag.Equals("1");
                AddNewPersonDialog dialog = new AddNewPersonDialog(teacher? Students.Max(p => p.Id) + 1:Teachers.Max(p => p.Id) + 1, teacher);
                if (dialog.ShowDialog() == true)
                {
                    Person person = dialog.Person;
                    if (Students.Any(p => p.Id == person.Id) || Teachers.Any(p => p.Id == person.Id))
                    {
                        TaskDialog.ShowError("该ID已存在");
                        return;
                    }
                    if (btn.Tag.Equals("0"))
                    {
                        Students.Add(person);
                    }
                    else
                    {
                        Teachers.Add(person);
                    }
                    ModifiedPersons.Add(person);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// 更新课程信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void UpdateCourseButtonClick(object sender, RoutedEventArgs e)
        {
            if (ModifiedCourses.Count + DeletedCourses.Count == 0)
            {
                TaskDialog.ShowError("没有修改或删除的课程");
                return;
            }
            JObject json = await NetHelper.Send(new { Command = Admin_Update_Courses, Modified = ModifiedCourses.Select(p => p.ToCourse()), Deleted = DeletedCourses.Select(p => p.ToCourse()) }) as JObject;

            if (json[OK].Value <bool>())
            {
                TaskDialog.Show(json[Message].Value <string>());
                ModifiedCourses.Clear();
                DeletedCourses.Clear();
            }
            else
            {
                TaskDialog.ShowError(json[Message].Value <string>());
            }
        }