public void GetData(UIClass classModel)
        {
            var cp = CommonDataManager.GetCPCase(base.LocalID);

            if (cp != null)
            {
                _cpcase = cp;

                List <UIStudent> students = new List <UIStudent>();
                _class = cp.Classes.FirstOrDefault(c => c.ID.Equals(classModel.ID));
                _class.Students?.ForEach(s =>
                {
                    UIStudent student = new UIStudent()
                    {
                        ID   = s.ID,
                        Name = s.Name
                    };
                    students.Add(student);
                });

                this.Students = new ObservableCollection <UIStudent>(students);

                _studentCollectionView        = (ListCollectionView)CollectionViewSource.GetDefaultView(this.Students);
                _studentCollectionView.Filter = StudentContains;
            }
        }
        void deleteCommand(object obj)
        {
            UIStudent student = obj as UIStudent;
            var       result  = this.ShowDialog("提示信息", "确认删除?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning);

            if (result == CustomControl.Enums.DialogResultType.OK)
            {
                this.Students.Remove(student);
            }
        }
        /// <summary>
        /// 调整学生志愿
        /// </summary>
        void AdjustStudentPreselection(object obj)
        {
            if (obj == null)
            {
                this.ShowDialog("提示信息", "没有选中学生!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                return;
            }

            UIStudent model = obj as UIStudent;

            SetStudentPreselectionWindow window = new SetStudentPreselectionWindow(model);

            window.Closed += (s, arg) =>
            {
                if (window.DialogResult.Value)
                {
                    var cl = base.GetClCase(base.LocalID);

                    model.Preselections.Clear();
                    window.Preselections.ForEach(p =>
                    {
                        model.Preselections.Add(p);
                    });

                    IDictionary <string, object> dics = new ExpandoObject();
                    cl.Courses.ForEach(c =>
                    {
                        dics.Add(c.Name, string.Empty);
                    });

                    model.Preselections.ForEach(p =>
                    {
                        // 列头显示情况。
                        var hasColumn = dics.ContainsKey(p.Course);
                        if (hasColumn)
                        {
                            if (!p.LevelID.Equals("0"))
                            {
                                dics[p.Course] = p.Level;
                            }
                            else
                            {
                                var has = dics.ContainsKey(p.Course);
                                if (has)
                                {
                                    dics[p.Course] = p.Course;
                                }
                            }
                        }
                    });
                    model.ExpandoObject = dics;
                }
            };
            window.ShowDialog();
        }
Example #4
0
 /// <summary>
 /// 绑定数据
 /// </summary>
 public void BindData(UIStudent student)
 {
     student.Preselections?.ForEach(sp =>
     {
         var preselection = this.Preselections.FirstOrDefault(p => p.CourseID.Equals(sp.CourseID) && p.LevelID.Equals(sp.LevelID));
         if (preselection != null)
         {
             preselection.IsChecked = true;
         }
     });
 }
        void deleteCommand(object obj)
        {
            UIStudent student = obj as UIStudent;
            var       result  = this.ShowDialog("提示信息", "确认删除?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning);

            if (result == CustomControl.Enums.DialogResultType.OK)
            {
                var removeStudent = this.Students.FirstOrDefault(s => s.ID.Equals(student.ID));
                if (removeStudent != null)
                {
                    this.Students.Remove(removeStudent);
                }
            }
        }
        bool StudentContains(object contain)
        {
            UIStudent student = contain as UIStudent;

            if (string.IsNullOrEmpty(this.SearchStudent))
            {
                return(true);
            }

            if (student.Name.IndexOf(this.SearchStudent) != -1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        void importStudentSelectionsCommand()
        {
            var cl = base.GetClCase(base.LocalID);

            var preselections = (from c in cl.Courses
                                 from cc in c.Levels
                                 select new UIPreselection()
            {
                CourseID = c.ID,
                Course = c.Name,
                LevelID = cc.ID,
                Level = cc.Name,
            })?.ToList();

            ImportStudentSelectionWindow window = new ImportStudentSelectionWindow();

            window.Closed += (s, args) =>
            {
                if (window.DialogResult.Value)
                {
                    var tables       = window.DT;
                    var columnsCount = tables.Columns.Count;

                    foreach (var st in this.Students)
                    {
                        st.Preselections?.Clear();
                    }
                    this.Students.Clear();

                    this.ShowLoading = true;

                    ObservableCollection <UIStudent> students = new ObservableCollection <UIStudent>();

                    Task.Run(() =>
                    {
                        for (int i = 1; i < tables.Rows.Count; i++)
                        {
                            var name = tables.Rows[i][0].ToString();

                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }

                            var student = students.FirstOrDefault(st => st.Name.Equals(name));
                            if (student == null)
                            {
                                int number = students.Count == 0 ? 0 : students.Max(st => Convert.ToInt32(st.ID));
                                int no     = students.Count == 0 ? 0 : students.Max(st => st.NO);

                                student = new UIStudent()
                                {
                                    ID   = (number + 1).ToString(),
                                    NO   = no + 1,
                                    Name = name,
                                };

                                students.Add(student);
                            }

                            // 遍历其它志愿
                            for (int h = 1; h < columnsCount; h++)
                            {
                                var value = tables.Rows[i][h].ToString();
                                if (!string.IsNullOrEmpty(value))
                                {
                                    var columnName = tables.Rows[0][h].ToString();

                                    // 如果有层没有输入层的名字,直接输入科目的名字。
                                    var firstCourse = cl.Courses.FirstOrDefault(clc => clc.Name.Equals(value));
                                    if (firstCourse?.Levels?.Count > 1)
                                    {
                                        continue;
                                    }

                                    UIPreselection selection;
                                    var selections = preselections.Where(p => p.Course.Equals(columnName))?.ToList();

                                    if (!columnName.Equals(value))
                                    {
                                        selection = selections?.FirstOrDefault(ss => ss.Level.Equals(value));
                                    }
                                    else
                                    {
                                        selection = selections.FirstOrDefault();
                                    }

                                    if (selection != null)
                                    {
                                        var has = student.Preselections.Any(p => p.Course.Equals(selection.Course));
                                        if (!has)
                                        {
                                            student.Preselections.Add(selection);
                                        }
                                    }
                                }
                            }
                        }
                    }).ContinueWith((r) =>
                    {
                        this.Students = students;

                        GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(() =>
                        {
                            this.loadDataGrid();
                            this.RefreshStudentFromUI();
                            _dg.ItemsSource = this.Students;

                            _studentCollectionView        = (ListCollectionView)CollectionViewSource.GetDefaultView(this.Students);
                            _studentCollectionView.Filter = StudentContains;
                        });

                        this.ShowLoading = false;
                    });
                }
            };
            window.ShowDialog();
        }
        void importStudentSelectionsCommand()
        {
            var cl = CommonDataManager.GetCLCase(base.LocalID);

            var preselections = (from c in cl.Courses
                                 from cc in c.Levels
                                 select new UIPreselection()
            {
                CourseID = c.ID,
                Course = c.Name,
                LevelID = cc.ID,
                Level = cc.Name,
            })?.ToList();

            ImportStudentSelectionWindow window = new ImportStudentSelectionWindow();

            window.Closed += (s, args) =>
            {
                if (window.DialogResult.Value)
                {
                    // 清空当前志愿
                    //foreach (var st in this.Students)
                    //{
                    //    st.Preselections?.Clear();
                    //}

                    //清空所有学生
                    this.Students.Clear();

                    var tables       = window.DT;
                    var columnsCount = tables.Columns.Count;

                    // 内容
                    for (int i = 1; i < tables.Rows.Count; i++)
                    {
                        var name = tables.Rows[i][0].ToString();

                        if (string.IsNullOrEmpty(name))
                        {
                            continue;
                        }

                        var student = this.Students.FirstOrDefault(st => st.Name.Equals(name));

                        if (student == null)
                        {
                            int number = this.Students.Count == 0 ? 0 : this.Students.Max(st => Convert.ToInt32(st.ID));
                            int no     = this.Students.Count == 0 ? 0 : this.Students.Max(st => st.NO);

                            student = new UIStudent()
                            {
                                ID   = (number + 1).ToString(),
                                NO   = no + 1,
                                Name = name,
                            };

                            this.Students.Add(student);
                        }

                        // 遍历其它志愿
                        for (int h = 1; h < columnsCount; h++)
                        {
                            var value = tables.Rows[i][h].ToString();
                            if (!string.IsNullOrEmpty(value))
                            {
                                var columnName = tables.Rows[0][h].ToString();

                                // 如果有层没有输入层的名字,直接输入科目的名字。
                                var firstCourse = cl.Courses.FirstOrDefault(clc => clc.Name.Equals(value));
                                if (firstCourse?.Levels?.Count > 1)
                                {
                                    continue;
                                }

                                UIPreselection selection;
                                var            selections = preselections.Where(p => p.Course.Equals(columnName))?.ToList();

                                if (!columnName.Equals(value))
                                {
                                    selection = selections?.FirstOrDefault(ss => ss.Level.Equals(value));
                                }
                                else
                                {
                                    selection = selections.FirstOrDefault();
                                }

                                if (selection != null)
                                {
                                    var has = student.Preselections.Any(p => p.Course.Equals(selection.Course));
                                    if (!has)
                                    {
                                        student.Preselections.Add(selection);
                                    }
                                }
                            }
                        }
                    }

                    // 重新绑定界面
                    windowCommand(_view);
                }
            };
            window.ShowDialog();
        }
Example #9
0
        public SetStudentPreselectionWindow(UIStudent student) : this()
        {
            this.Title = $"设置学生:{student.Name} 志愿";

            (this.DataContext as SetStudentPreselectionWindowModel).BindData(student);
        }