public void upload(UIResult result) { var adjustRecord = base.LocalID.DeSerializeAdjustRecord <ResultAdjustmentModel>(result.TaskID); if (adjustRecord == null) { this.ShowDialog("提示信息", "没有调整记录,无法上传!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } var confirm = this.ShowDialog("提示信息", "确认上传方案?", DialogSettingType.OkAndCancel, DialogType.Warning); if (confirm == DialogResultType.OK) { var operation = WebAPI.Instance.WriteBackResult(result.TaskID, adjustRecord); if (operation.Item1) { result.IsUploaded = true; var local = CommonDataManager.GetLocalCase(base.LocalID); var results = ResultDataManager.GetResults(base.LocalID); local.Serizlize(results); this.ShowDialog("提示信息", "上传成功!", DialogSettingType.NoButton, DialogType.None); } else { this.ShowDialog("提示信息", operation.Item3, DialogSettingType.OnlyOkButton, DialogType.Warning); } } }
void save(HostView host) { if (this.SelectResult == null) { this.ShowDialog("提示信息", "选择结果为空!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); return; } var local = CommonDataManager.GetLocalCase(base.LocalID); local.LockedTaskID = this.SelectResult.TaskID; local.Serialize(); var rule = CommonDataManager.GetAminRule(base.LocalID); if (_lockedRule.LockedTimeTable?.Count == 0) { rule.TimeTableLockedTimes = null; } else { rule.TimeTableLockedTimes = _lockedRule; } rule.Serialize(base.LocalID); this.ShowDialog("提示信息", "保存成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); }
void setColorCommand(object obj) { UICourse model = obj as UICourse; var local = CommonDataManager.GetLocalCase(base.LocalID); ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SolidBrush sb = new SolidBrush(colorDialog.Color); SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(sb.Color.A, sb.Color.R, sb.Color.G, sb.Color.B)); var colorString = solidColorBrush.ToString(); model.ColorString = colorString; var has = local.CourseColors.ContainsKey(model.ID); if (!has) { local.CourseColors.Add(model.ID, colorString); } else { local.CourseColors[model.ID] = colorString; } // 保存方案 local.Serialize(); } }
public void Initilize() { this.Courses.Clear(); var cl = base.GetClCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); cl.Courses.ForEach(c => { UICourse course = new UICourse() { ID = c.ID, Name = c.Name, Levels = new ObservableCollection <UILevel>() }; var has = local.CourseColors.ContainsKey(c.ID); if (has) { course.ColorString = local.CourseColors[c.ID]; } if (c.Levels != null) { // 查找空层 if (c.Levels.Any(l => l.ID.Equals("0"))) { // 空层 course.DefaultLevel = new UILevel() { CourseID = course.ID, ID = "0", Name = string.Empty, Lessons = 5 }; } else { var levels = c.Levels.Select(l => { return(new UILevel() { CourseID = c.ID, ID = l.ID, Name = l.Name, Lessons = l.Lessons, }); }); if (levels != null) { course.Levels = new ObservableCollection <UILevel>(levels); } } } this.Courses.Add(course); }); }
public void Initilize() { Messenger.Default.Register <HostView>(this, save); this.Comments = CommonDataManager.GetAdminRuleComments(AdministrativeRuleEnum.LockedCourse); var tempResults = ResultDataManager.GetResults(base.LocalID); this.Results = tempResults.Where(r => r.IsUsed)?.ToList(); var local = CommonDataManager.GetLocalCase(base.LocalID); _colors = local.CourseColors; #region 获取规则 var rule = CommonDataManager.GetAminRule(base.LocalID); if (rule.TimeTableLockedTimes == null) { _lockedRule = new TimeTableLockRule(); } else { _lockedRule = new TimeTableLockRule() { LockedTimeTable = rule.TimeTableLockedTimes.LockedTimeTable?.Select(t => { return(new LockedClassTimeTable() { ClassID = t.ClassID, LockedCourseTimeTable = t.LockedCourseTimeTable?.Select(tt => { return new LockedClassCourseTimeTable() { CourseID = tt.CourseID, LockedTimes = tt.LockedTimes?.ToList() }; })?.ToList() }); })?.ToList() }; } #endregion #region 锁定任务ID if (local.LockedTaskID != 0) { this.SelectResult = this.Results.FirstOrDefault(r => r.TaskID.Equals(local.LockedTaskID)); if (this.SelectResult != null) { Refresh(); } } #endregion }
public void analysis(UIResult result) { ResultDataManager.CurrentResult = result; var local = CommonDataManager.GetLocalCase(base.LocalID); Analysis.Result.Administrative.HostWindow host = new Analysis.Result.Administrative.HostWindow(result.Name); host.ShowDialog(); }
void Export() { var local = CommonDataManager.GetLocalCase(base.LocalID); var cp = CommonDataManager.GetCPCase(base.LocalID); System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog(); saveDialog.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx"; saveDialog.FileName = $"{local.Name}(教师批量设置)"; var result = saveDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataColumn classColumn = new System.Data.DataColumn() { ColumnName = "班级" }; dt.Columns.Add(classColumn); cp.Courses.ForEach(c => { var newColumn = new System.Data.DataColumn() { ColumnName = c.Name }; dt.Columns.Add(newColumn); }); this.values.ForEach(v => { System.Data.DataRow newRow = dt.NewRow(); newRow["班级"] = v.Name; if (v.Courses != null) { foreach (var course in v.Courses) { newRow[course.Course] = course.TeacherString; } } dt.Rows.Add(newRow); }); var excelResult = NPOIClass.DataTableToExcel(dt, saveDialog.FileName); if (excelResult.Item1) { this.ShowDialog("提示信息", "导出成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); } else { this.ShowDialog("提示信息", excelResult.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } }
void saveCommand() { var local = CommonDataManager.GetLocalCase(base.LocalID); local.Serialize(); _cpcase.Serialize(base.LocalID); this.ShowDialog("提示信息", "保存成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); }
public void Initilize() { var cl = CommonDataManager.GetCLCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); _colors = local.CourseColors; #region 班级课位 List <UIResultWeek> resultWeeks = new List <UIResultWeek>(); var groups = cl.Positions.OrderBy(p => p.DayPeriod.Period).GroupBy(p => p.DayPeriod.Period); if (groups != null) { foreach (var g in groups) { var item = g.First(); UIResultWeek weekItem = new UIResultWeek() { Period = item.DayPeriod, PositionType = item.Position, }; resultWeeks.Add(weekItem); } } this.Results = resultWeeks; #endregion #region 教师课位 List <UIResultWeek> teacherResults = new List <UIResultWeek>(); var teacherGroups = cl.Positions.OrderBy(p => p.DayPeriod.Period).GroupBy(p => p.DayPeriod.Period); if (teacherGroups != null) { foreach (var g in teacherGroups) { var item = g.First(); UIResultWeek weekItem = new UIResultWeek() { Period = item.DayPeriod, PositionType = item.Position, }; teacherResults.Add(weekItem); } } this.TeacherResults = teacherResults; #endregion }
public void SerializePatternAlgo(AlgoRule algo, string localID) { var caseModel = CommonDataManager.GetLocalCase(localID); if (caseModel.Pattern == Models.Enums.PatternTypeEnum.None) { algo.Serialize(localID); } else { algo.SerializePatternAlgo(localID); } }
public void SerializePatternRule(Rule rule, string localID) { var caseModel = CommonDataManager.GetLocalCase(localID); if (caseModel.Pattern == Models.Enums.PatternTypeEnum.None) { rule.Serialize(localID); } else { rule.SerializePatternRule(localID); } }
public void Serialize(CLCase cl, string localID) { var caseModel = CommonDataManager.GetLocalCase(localID); if (caseModel.Pattern == Models.Enums.PatternTypeEnum.None) { cl.Serialize(localID); } else { cl.SerializePatternCase(localID); } }
/// <summary> /// 获取算法规则 /// </summary> /// <param name="localID"></param> /// <returns></returns> public AlgoRule GetCLAlgoRule(string localID) { var caseModel = CommonDataManager.GetLocalCase(localID); if (caseModel.Pattern == Models.Enums.PatternTypeEnum.None) { return(CommonDataManager.GetMixedAlgoRule(localID)); } else { return(PatternDataManager.GetAlgoRule(localID)); } }
void deleteCommand(object obj) { var result = this.ShowDialog("提示信息", "确认删除?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning); if (result == CustomControl.Enums.DialogResultType.OK) { var local = CommonDataManager.GetLocalCase(base.LocalID); UICourse uiCourse = obj as UICourse; this.Courses.Remove(uiCourse); _toDeleteCourses.Add(uiCourse); this.RaisePropertyChanged(() => ShowCreateLevel); } }
public void Delete(UIResult result) { var confirm = this.ShowDialog("提示信息", $"是否确认删除?\r\n {result.Name}", DialogSettingType.OkAndCancel, DialogType.Warning); if (confirm == DialogResultType.OK) { Results.Remove(result); var results = ResultDataManager.GetResults(base.LocalID); results.RemoveAll(r => r.TaskID == result.TaskID); var caseModel = CommonDataManager.GetLocalCase(base.LocalID); if (caseModel != null) { caseModel.Serizlize(results); } } }
void batchDeleteCommand() { var hasCheckedCourse = this.Courses.Any(c => c.IsChecked); if (!hasCheckedCourse) { this.ShowDialog("提示信息", "没有选中要删除的课程!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } var confirm = this.ShowDialog("提示信息", "确定删除选中课程?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning); if (confirm == CustomControl.Enums.DialogResultType.OK) { // 验证是否确认删除? var toDeletes = this._toDeleteCourses.Count == 0 ? this.Courses.Where(t => t.IsChecked)?.ToList() : this._toDeleteCourses.Where(t => t.IsChecked); if (toDeletes != null) { var local = CommonDataManager.GetLocalCase(base.LocalID); foreach (var t in toDeletes) { // 更新UI this.Courses.Remove(t); _cpcase.Courses.RemoveAll(c => c.ID.Equals(t.ID)); _cpcase.Classes?.ForEach(c => { c.Settings?.RemoveAll(cs => cs.CourseID.Equals(t.ID)); }); // 移除颜色 local.CourseColors.Remove(t.ID); // 移除课程 GalaSoft.MvvmLight.Messaging.Messenger.Default.Send <UICourse>(t); AdministrativeDataHelper.CourseChanged(t, base.LocalID, CommonDataManager); } // 保存 _cpcase.Serialize(base.LocalID); local.Serialize(); } } }
void deleteCurrentPattern() { var result = this.ShowDialog("提示信息", "确认删除当前模式?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning); if (result == CustomControl.Enums.DialogResultType.OK) { // 保存本地方案模式状态 var local = CommonDataManager.GetLocalCase(base.LocalID); local.Pattern = Models.Enums.PatternTypeEnum.None; local.Serialize(); // 删除所有模式 base.LocalID.DeleteAllPatternData(); base.PatternDataManager.RemoveAll(base.LocalID); this.HasPattern = false; this.refreshPattern(); } }
public void Initilize() { var local = CommonDataManager.GetLocalCase(base.LocalID); if (local.Pattern != Models.Enums.PatternTypeEnum.None) { this._patternType = local.Pattern; this.RaisePropertyChanged(() => PatternName); this.HasPattern = true; } this.ClassVM = CacheManager.Instance.UnityContainer.Resolve <ClassViewModel>(); this.CourseVM = CacheManager.Instance.UnityContainer.Resolve <CourseViewModel>(); this.RuleVM = CacheManager.Instance.UnityContainer.Resolve <RuleViewModel>(); this.StudentVM = CacheManager.Instance.UnityContainer.Resolve <StudentViewModel>(); this.TagVM = CacheManager.Instance.UnityContainer.Resolve <TagViewModel>(); this.TeacherVM = CacheManager.Instance.UnityContainer.Resolve <TeacherViewModel>(); this.TimeVM = CacheManager.Instance.UnityContainer.Resolve <TimeViewModel>(); }
void deleteAllCourse() { var confirm = this.ShowDialog("提示信息", "确认删除全部课程?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning); if (confirm == CustomControl.Enums.DialogResultType.OK) { foreach (var c in this.Courses) { _toDeleteCourses.Add(c); } this.Courses.Clear(); var rule = base.GetClRule(base.LocalID); var algo = base.GetCLAlgoRule(base.LocalID); var cl = base.GetClCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); var isPatern = local.Pattern != Models.Enums.PatternTypeEnum.None ? true : false; MixedDataHelper.CourseChanged(_toDeleteCourses, base.LocalID, rule, algo, cl, isPatern); } }
public void Initilize() { var cp = CommonDataManager.GetCPCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); if (cp != null) { _cpcase = cp; if (cp.Teachers != null) { List <UICourse> courses = new List <UICourse>(); cp.Courses.ForEach(t => { UICourse course = new UICourse() { ID = t.ID, Name = t.Name, }; var has = local.CourseColors.ContainsKey(t.ID); if (has) { course.ColorString = local.CourseColors[t.ID]; } courses.Add(course); }); this.Courses = new ObservableCollection <UICourse>(courses); _courseCollectionView = (ListCollectionView)CollectionViewSource.GetDefaultView(this.Courses); _courseCollectionView.Filter = CourseContains; } } else { _cpcase = new CPCase(); } }
public void Initilize() { Messenger.Default.Register <HostView>(this, save); this.Comments = CommonDataManager.GetMixedRuleComments(MixedRuleEnum.ClassHourSameOpen); var local = CommonDataManager.GetLocalCase(base.LocalID); var rule = base.GetClRule(base.LocalID); if (rule.ClassHourSameOpens?.Count > 0) { if (local.Pattern != PatternTypeEnum.None) { this.Rules = Models.Enums.MixedRuleEnum.ClassHourSameOpen.RulePaternDeSerialize <ObservableCollection <UISameOpenTime> >(base.LocalID); } else { this.Rules = Models.Enums.MixedRuleEnum.ClassHourSameOpen.RuleDeSerialize <ObservableCollection <UISameOpenTime> >(base.LocalID); } } }
public void exportTable(UIResult result) { var adjustRecord = base.LocalID.DeSerializeAdjustRecord <ResultAdjustmentModel>(result.TaskID); if (adjustRecord != null) { if (!result.IsUploaded) { this.ShowDialog("提示信息", "本地结果发生改变请先上传结果!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } } // (1:班级 2:教师) int exportType = 1; ExportTypeWindow window = new ExportTypeWindow(false); window.Closed += (s, arg) => { if (window.DialogResult.Value) { exportType = window.Type; #region 导出 var cp = CommonDataManager.GetCPCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); ResultModel resultModel = base.LocalID.DeSerializeLocalResult <ResultModel>(result.TaskID); if (resultModel == null) { var value = OSHttpClient.Instance.GetAdminResult(result.TaskID); if (value.Item1) { resultModel = value.Item2; } else { this.ShowDialog("提示信息", "获取行政班结果失败", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } } string typeName = exportType == 1 ? "班级课表" : "教师课表"; System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog(); saveDialog.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx"; saveDialog.FileName = $"{local.Name}-{result.TaskID}-({typeName})"; var confirm = saveDialog.ShowDialog(); if (confirm == System.Windows.Forms.DialogResult.OK) { Dictionary <string, DataTable> values = new Dictionary <string, DataTable>(); if (exportType == 1) { foreach (var rc in resultModel.ResultClasses) { // 创建基础结构 var dt = this.CreateTableFrame(); // 创建sheet var firstClass = cp.Classes.FirstOrDefault(c => rc.ClassID.Equals(c.ID)); values.Add(firstClass.Name, dt); // 常规 var normals = rc.ResultDetails.Where(rd => rd.ResultType == XYKernel.OS.Common.Enums.ClassHourResultType.Normal)?.ToList(); normals?.ForEach(n => { var classHourInfo = cp.GetClassHours(new int[] { n.ClassHourId })?.FirstOrDefault(); SetCellData(dt, classHourInfo.Course + "\n" + classHourInfo.TeacherString, n.DayPeriod); }); // 单双周 var mulitplys = rc.ResultDetails.Where(rd => rd.ResultType != XYKernel.OS.Common.Enums.ClassHourResultType.Normal)?.ToList(); var groups = mulitplys?.GroupBy(m => $"{m.DayPeriod.Day}{m.DayPeriod.Period}"); if (groups != null) { foreach (var g in groups) { var first = g.FirstOrDefault(); var courseName = g.Select(gi => { return(cp.Courses.FirstOrDefault(c => c.ID.Equals(gi.CourseID))?.Name); })?.Parse("|"); var teacherName = g.Select(gi => { return(cp.GetTeachersByIds(gi.Teachers.ToList()).Select(a => a.Name).ToArray().Parse(",")); })?.Parse("|"); SetCellData(dt, courseName + "\n" + teacherName, first.DayPeriod); } } } } else if (exportType == 2) { // 获取所有教师 var classHourIDs = from c in resultModel.ResultClasses from rd in c.ResultDetails select rd.ClassHourId; var classHours = cp.GetClassHours(classHourIDs?.ToArray()); List <UITeacher> teachers = new List <UITeacher>(); classHours?.ForEach(ch => { ch.Teachers.ForEach(t => { var teacher = teachers.FirstOrDefault(tt => tt.ID.Equals(t.ID)); if (teacher == null) { teachers.Add(new UITeacher() { ID = t.ID, Name = t.Name, ClassHourIDs = new List <int> { ch.ID } }); } else { teacher.ClassHourIDs.Add(ch.ID); } }); }); if (teachers.Count == 0) { this.ShowDialog("提示信息", "没有教师信息无法导出教师课表!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } teachers.ForEach(t => { // 创建基础结构 var dt = this.CreateTableFrame(); values.Add(t.Name, dt); var resultDetails = (from rc in resultModel.ResultClasses from rd in rc.ResultDetails select new { rc.ClassID, rd.ClassHourId, rd.CourseID, rd.DayPeriod, rd.ResultType }); var filters = (from ch in t.ClassHourIDs from rc in resultDetails where ch == rc.ClassHourId select rc)?.ToList(); var groups = filters?.GroupBy(g => $"{g.DayPeriod.Day}{g.DayPeriod.Period}"); if (groups != null) { foreach (var g in groups) { var dayPeriod = g.FirstOrDefault().DayPeriod; var ids = g.Select(gs => { return(gs.ClassHourId); })?.ToArray(); var setValue = cp.GetClassHours(ids)?.Select(ss => $"{ss.Course}-{ss.Class}")?.Parse("|"); SetCellData(dt, setValue, dayPeriod); } } }); } List <int> enableIndex = new List <int>(); var abIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.AB); if (abIndex != null) { enableIndex.Add(abIndex.DayPeriod.Period); } var noonIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.Noon); if (noonIndex != null) { enableIndex.Add(noonIndex.DayPeriod.Period); } var pbIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.PB); if (pbIndex != null) { enableIndex.Add(pbIndex.DayPeriod.Period); } var table = NPOIClass.DataTableToExcel(values, saveDialog.FileName, enableIndex); if (table.Item1) { this.ShowDialog("提示信息", "导出成功!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); } else { this.ShowDialog("提示信息", table.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } } #endregion } }; window.ShowDialog(); }
void systemCourseCommand() { SystemCourseWindow window = new SystemCourseWindow(); window.Closed += (s, arg) => { if (window.DialogResult.Value) { var cl = CommonDataManager.GetCLCase(base.LocalID); var courses = window.Courses.Where(sc => sc.IsChecked)?.ToList(); var has = this.Courses.Any(c => { return(courses.Any(cc => cc.Name.Equals(c.Name))); }); if (has) { var result = this.ShowDialog("提示信息", "存在相同科目,是否继续添加", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning); if (result != CustomControl.Enums.DialogResultType.OK) { return; } } var local = CommonDataManager.GetLocalCase(base.LocalID); courses.ForEach(c => { var any = this.Courses.Any(cc => cc.Name.Equals(c.Name)); if (!any) { var courseID = this.Courses.Count == 0 ? 0 : this.Courses.Max(cs => Convert.ToInt64(cs.ID)); string id = (courseID + 1).ToString(); // 更新UI this.Courses.Add(new UICourse { ID = id, Name = c.Name, ColorString = c.ColorString, DefaultLevel = new UILevel() { ID = "0", Name = string.Empty, Lessons = 5 } }); var hasColor = local.CourseColors.ContainsKey(id); if (!hasColor) { local.CourseColors.Add(id, c.ColorString); } else { local.CourseColors[id] = c.ColorString; } } }); local.Serialize(); this.RaisePropertyChanged(() => ShowCreateLevel); } }; window.ShowDialog(); }
void Export() { var local = CommonDataManager.GetLocalCase(base.LocalID); var cp = CommonDataManager.GetCPCase(base.LocalID); System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog(); saveDialog.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx"; saveDialog.FileName = $"{local.Name}(教师批量设置)"; var result = saveDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataColumn courseColumn = new System.Data.DataColumn() { ColumnName = "课程" }; dt.Columns.Add(courseColumn); System.Data.DataColumn levelColumn = new System.Data.DataColumn() { ColumnName = "层" }; dt.Columns.Add(levelColumn); System.Data.DataColumn classColumn = new System.Data.DataColumn() { ColumnName = "班级" }; dt.Columns.Add(classColumn); System.Data.DataColumn teacherColumn = new System.Data.DataColumn() { ColumnName = "教师" }; dt.Columns.Add(teacherColumn); this.values.ForEach(v => { if (v.Classes != null) { foreach (var classInfo in v.Classes) { System.Data.DataRow newRow = dt.NewRow(); newRow["课程"] = v.Course; newRow["层"] = v.Level; newRow["班级"] = classInfo.Name; newRow["教师"] = classInfo.TeacherIDs?.Select(tid => { return(this.Teachers.FirstOrDefault(t => t.ID.Equals(tid))?.Name); })?.Parse(); dt.Rows.Add(newRow); } } }); var excelResult = NPOIClass.DataTableToExcel(dt, saveDialog.FileName); if (excelResult.Item1) { this.ShowDialog("提示信息", "导出成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); } else { this.ShowDialog("提示信息", excelResult.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } }
void exportStudentSelectionsCommand() { var local = CommonDataManager.GetLocalCase(base.LocalID); System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog(); saveDialog.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx"; saveDialog.FileName = $"{local.Name}(学生志愿)"; var result = saveDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { #region 获取所有学生志愿 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(); #endregion string filePath = saveDialog.FileName; System.Data.DataTable dt = new System.Data.DataTable(); #region 学生姓名 System.Data.DataColumn studentColumn = new System.Data.DataColumn() { ColumnName = "姓名" }; dt.Columns.Add(studentColumn); #endregion #region 动态添加其它列 foreach (var c in cl.Courses) { dt.Columns.Add( new System.Data.DataColumn() { ColumnName = c.Name }); } #endregion #region 填充行内容 foreach (var student in this.Students) { System.Data.DataRow newRow = dt.NewRow(); newRow["姓名"] = student.Name; student.Preselections.ForEach(sp => { var ps = preselections.FirstOrDefault(p => p.CourseID.Equals(sp.CourseID) && p.LevelID.Equals(sp.LevelID)); if (ps != null) { if (string.IsNullOrEmpty(ps.Level)) { newRow[ps.Course] = ps.Course; } else { newRow[ps.Course] = ps.Level; } } }); dt.Rows.Add(newRow); } #endregion var excelResult = NPOIClass.DataTableToExcel(dt, filePath); if (excelResult.Item1) { this.ShowDialog("提示信息", "导出成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); FileHelper.OpenFilePath(filePath); } else { this.ShowDialog("提示信息", excelResult.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } }
public void precharge(UIResult result) { var sample = WebAPI.Instance.SampleTask(result.TaskID); if (sample.Item1) { // 预览 PrechargeResultWindow precharge = new PrechargeResultWindow(result.Name, sample.Item2); precharge.Closed += (s, arg) => { // 如果预览结果为True. if (precharge.DialogResult == true) { var results = ResultDataManager.GetResults(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); if (precharge.IsUseResult) { var value = WebAPI.Instance.ConfirmTask(result.TaskID); if (value.Item1) { result.IsUsed = true; local.Serizlize(results); // 更新界面 var uiTask = this.Results.FirstOrDefault(r => r.TaskID.Equals(result.TaskID)); if (uiTask != null) { uiTask.IsUsed = true; uiTask.RaiseChanged(); } this.ShowDialog("提示信息", "操作成功!", DialogSettingType.NoButton, DialogType.None); } else { this.ShowDialog("提示信息", "操作失败!", DialogSettingType.OnlyOkButton, DialogType.Warning); } } else { var value = WebAPI.Instance.AbandonTask(result.TaskID); if (value.Item1) { this.Results.Remove(result); results.RemoveAll(r => r.TaskID == result.TaskID); local.Serizlize(results); this.ShowDialog("提示信息", "操作成功!", DialogSettingType.NoButton, DialogType.None); } else { this.ShowDialog("提示信息", "操作失败!", DialogSettingType.OnlyOkButton, DialogType.Warning); } } } }; precharge.ShowDialog(); } else { this.ShowDialog("提示信息", sample.Item3, DialogSettingType.OnlyOkButton, DialogType.Warning); } }
void saveCommand(object obj) { if (this.SelectPattern == null) { this.ShowDialog("提示信息", "模式为空!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } var clModel = base.LocalID.DeSerializeCL(); var algoRule = base.LocalID.DeSerializePatternAlgo(); var rule = base.LocalID.DeSerializeMixedRule(); // 1.获取操作 // 1.1 去除组合 var combinationView = this.sourceOperators.FirstOrDefault(p => p.Operator == UIPatternOperator.OperatorEnum.RemoveCombination); var removeCombinations = (combinationView.View.DataContext as RemoveCombinationViewModel).GetRemovedCombination(); // 1.2 班额调整 var classView = this.sourceOperators.FirstOrDefault(p => p.Operator == UIPatternOperator.OperatorEnum.ClassCapacity); var classCapacitys = (classView.View.DataContext as ClassCapacityViewModel).GetCapacitys(); // 1.3 课位调整 var positionView = this.sourceOperators.FirstOrDefault(p => p.Operator == UIPatternOperator.OperatorEnum.Position); var positions = (positionView.View.DataContext as PositionViewModel).GetCoursePositions(); object severialPattern = null; DataProcessing dataProcess = new DataProcessing(); MixedModel.CLCase patternCase = null; MixedModel.AlgoRule.AlgoRule patternAlgoRule = null; MixedModel.Rule.Rule patternRule = null; List <DataValidationResultInfo> validationResultInfo = new List <DataValidationResultInfo>() { }; switch (this.SelectPattern.Pattern) { case Models.Enums.PatternTypeEnum.Normal: NormalModel normal = new NormalModel() { ClassCapacity = classCapacitys, Positions = positions, RemovedCombination = removeCombinations }; severialPattern = normal; Tuple <MixedModel.CLCase, bool, List <DataValidationResultInfo> > normalTuple = dataProcess.GetModelByNormal(clModel, rule, algoRule, normal); if (normalTuple.Item2) { patternCase = normalTuple.Item1; } else { StringBuilder message = new StringBuilder(); normalTuple.Item3?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } break; case Models.Enums.PatternTypeEnum.Extraction: ExtractionViewModel value = this.SelectPattern.View.DataContext as ExtractionViewModel; StudentExtractionModel extraction = new StudentExtractionModel() { ExtractionRatio = value.ExtractionRate, IncreasedCapacity = value.ClassCapacity, Positions = positions, RemovedCombination = removeCombinations }; severialPattern = extraction; Tuple <MixedModel.CLCase, bool, List <DataValidationResultInfo> > extractionTuple = dataProcess.GetModelByStudentExtraction(clModel, rule, algoRule, extraction); if (extractionTuple.Item2) { patternCase = extractionTuple.Item1; } else { StringBuilder message = new StringBuilder(); extractionTuple.Item3?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } break; case Models.Enums.PatternTypeEnum.OptimizedExtraction: OptimizedExtractionViewModel optimizedExtractionVM = this.SelectPattern.View.DataContext as OptimizedExtractionViewModel; if (optimizedExtractionVM.SelectResult == null) { this.ShowDialog("提示信息", "没有选择结果", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } var result = Core.Http.OSHttpClient.Instance.GetResult(optimizedExtractionVM.SelectResult.TaskID); if (result.Item1) { UIOptimizedExtraction optimizedExtraction = new UIOptimizedExtraction() { ClassCapacity = optimizedExtractionVM.ClassCapacity, Result = result.Item2, RemovedCombination = removeCombinations }; severialPattern = optimizedExtraction; var extractionOptimzeTuple = dataProcess.GetModelByFixedClassTimeTable(clModel, rule, algoRule, new NormalModel() { RemovedCombination = removeCombinations }, optimizedExtraction.Result, optimizedExtraction.ClassCapacity); if (extractionOptimzeTuple.Item3) { patternCase = extractionOptimzeTuple.Item1; patternAlgoRule = extractionOptimzeTuple.Item2; } else { StringBuilder message = new StringBuilder(); extractionOptimzeTuple.Item4?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } break; case Models.Enums.PatternTypeEnum.Compression: CompressionViewModel compressionVM = this.SelectPattern.View.DataContext as CompressionViewModel; TimeCompressionModel compression = new TimeCompressionModel() { CompressionRatio = compressionVM.Compression, ClassCapacity = classCapacitys, RemovedCombination = removeCombinations }; severialPattern = compression; var compressionTuple = dataProcess.GetModelByTimeCompression(clModel, rule, algoRule, compression); if (compressionTuple.Item4) { patternCase = compressionTuple.Item1; patternRule = compressionTuple.Item2; patternAlgoRule = compressionTuple.Item3; } else { StringBuilder message = new StringBuilder(); compressionTuple.Item5?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } break; case Models.Enums.PatternTypeEnum.OptimizedCompression: OptimizedCompressionViewModel optimizedCompressionVM = this.SelectPattern.View.DataContext as OptimizedCompressionViewModel; severialPattern = optimizedCompressionVM.SelectResult; if (optimizedCompressionVM.SelectResult == null) { this.ShowDialog("提示信息", "没有选择结果", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } var optimizedResult = Core.Http.OSHttpClient.Instance.GetResult(optimizedCompressionVM.SelectResult.TaskID); if (optimizedResult != null) { var compressionOptimize = dataProcess.GetModelByStudentsClassificationResult(clModel, rule, algoRule, optimizedResult.Item2); if (compressionOptimize.Item4) { patternCase = compressionOptimize.Item1; patternRule = compressionOptimize.Item2; patternAlgoRule = compressionOptimize.Item3; } else { StringBuilder message = new StringBuilder(); compressionOptimize.Item5?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } break; case Models.Enums.PatternTypeEnum.Validation: ValidationViewModel validationVM = this.SelectPattern.View.DataContext as ValidationViewModel; UIValidation validation = new UIValidation() { AssignedStudents = validationVM.IncludeAssinged, OnlyTeacher = validationVM.OnlyTeacher }; severialPattern = validation; if (validationVM.IncludeAssinged) { var IncludeAssingedTuple = dataProcess.GetModelWithOnlyStudentsAssignedToClass(clModel, rule, algoRule); if (IncludeAssingedTuple.Item2) { patternCase = IncludeAssingedTuple.Item1; } else { StringBuilder message = new StringBuilder(); IncludeAssingedTuple.Item3?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } else { var OnlyTeacherTuple = dataProcess.GetModelWithoutStudents(clModel, rule, algoRule); if (OnlyTeacherTuple.Item2) { patternCase = OnlyTeacherTuple.Item1; } else { StringBuilder message = new StringBuilder(); OnlyTeacherTuple.Item3?.ForEach(m => { message.Append($"描述:{m.ErrorCode}-{m.Description}"); }); this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error); return; } } break; } if (patternCase != null) { var local = CommonDataManager.GetLocalCase(base.LocalID); local.Pattern = this.SelectPattern.Pattern; local.Serialize(); base.LocalID.Serialize(severialPattern); patternCase.SerializePatternCase(base.LocalID); PatternDataManager.AddCase(base.LocalID, patternCase); if (patternAlgoRule == null) { if (algoRule != null) { algoRule.SerializePatternAlgo(base.LocalID); PatternDataManager.AddAlgoRule(base.LocalID, algoRule); } } else { patternAlgoRule.SerializePatternAlgo(base.LocalID); PatternDataManager.AddAlgoRule(base.LocalID, patternAlgoRule); } if (patternRule == null) { if (rule != null) { rule.SerializePatternRule(base.LocalID); PatternDataManager.AddRule(base.LocalID, rule); } } else { patternRule.SerializePatternRule(base.LocalID); PatternDataManager.AddRule(base.LocalID, patternRule); } SetPatternWindow win = obj as SetPatternWindow; win.PatternType = this.SelectPattern.Pattern; win.DialogResult = true; } else { this.ShowDialog("提示信息", "模式实体转换失败!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } }
public void exportTable(UIResult result) { var adjustRecord = base.LocalID.DeSerializeAdjustRecord <ResultAdjustmentModel>(result.TaskID); if (adjustRecord != null) { if (!result.IsUploaded) { this.ShowDialog("提示信息", "本地结果发生改变请先上传结果!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } } // (1:班级 2:教师 4 年级) int exportType = 1; ExportTypeWindow window = new ExportTypeWindow(false); window.Closed += (s, arg) => { if (window.DialogResult.Value) { exportType = window.Type; #region 导出 var cp = CommonDataManager.GetCPCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); ResultModel resultModel = base.LocalID.DeSerializeLocalResult <ResultModel>(result.TaskID); if (resultModel == null) { var value = WebAPI.Instance.GetAdminResult(result.TaskID); if (value.Item1) { resultModel = value.Item2; } else { this.ShowDialog("提示信息", "获取行政班结果失败", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } } string typeName = string.Empty; if (exportType == 1) { typeName = "班级课表"; } else if (exportType == 2) { typeName = "教师课表"; } else if (exportType == 4) { typeName = "年级课表"; } System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog(); saveDialog.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx"; saveDialog.FileName = $"{local.Name}-{result.TaskID}-({typeName})"; var confirm = saveDialog.ShowDialog(); if (confirm == System.Windows.Forms.DialogResult.OK) { if (exportType == 1) { Dictionary <string, DataTable> values = new Dictionary <string, DataTable>(); foreach (var rc in resultModel.ResultClasses) { // 创建基础结构 var dt = this.CreateTableFrame(); // 创建sheet var firstClass = cp.Classes.FirstOrDefault(c => rc.ClassID.Equals(c.ID)); values.Add(firstClass.Name, dt); // 常规 var normals = rc.ResultDetails.Where(rd => rd.ResultType == XYKernel.OS.Common.Enums.ClassHourResultType.Normal)?.ToList(); normals?.ForEach(n => { var classHourInfo = cp.GetClassHours(new int[] { n.ClassHourId })?.FirstOrDefault(); SetCellData(dt, classHourInfo.Course + "\n" + classHourInfo.TeacherString, n.DayPeriod); }); // 单双周 var mulitplys = rc.ResultDetails.Where(rd => rd.ResultType != XYKernel.OS.Common.Enums.ClassHourResultType.Normal)?.ToList(); var groups = mulitplys?.GroupBy(m => $"{m.DayPeriod.Day}{m.DayPeriod.Period}"); if (groups != null) { foreach (var g in groups) { var first = g.FirstOrDefault(); var courseName = g.Select(gi => { return(cp.Courses.FirstOrDefault(c => c.ID.Equals(gi.CourseID))?.Name); })?.Parse("|"); var teacherName = g.Select(gi => { return(cp.GetTeachersByIds(gi.Teachers.ToList()).Select(a => a.Name).ToArray().Parse(",")); })?.Parse("|"); SetCellData(dt, courseName + "\n" + teacherName, first.DayPeriod); } } } #region 导出 List <int> enableIndex = new List <int>(); var abIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.AB); if (abIndex != null) { enableIndex.Add(abIndex.DayPeriod.Period); } var noonIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.Noon); if (noonIndex != null) { enableIndex.Add(noonIndex.DayPeriod.Period); } var pbIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.PB); if (pbIndex != null) { enableIndex.Add(pbIndex.DayPeriod.Period); } var table = NPOIClass.DataTableToExcel(values, saveDialog.FileName, enableIndex); if (table.Item1) { this.ShowDialog("提示信息", "导出成功!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); FileHelper.OpenFilePath(saveDialog.FileName); } else { this.ShowDialog("提示信息", table.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } #endregion } else if (exportType == 4) { GradeExcelModel excelModel = new GradeExcelModel(); // 检查是否有周六周日 List <string> weeks = new List <string>() { "星期一", "星期二", "星期三", "星期四", "星期五", }; // 是否有周末 var hasWeekend = resultModel.ResultClasses.Any(rc => rc.ResultDetails.Any(rd => (rd.DayPeriod.Day == DayOfWeek.Saturday || rd.DayPeriod.Day == DayOfWeek.Sunday))); if (hasWeekend) { weeks.Add("星期六"); weeks.Add("星期日"); } // 节次 List <string> periods = new List <string>(); cp.Positions.GroupBy(p => p.DayPeriod.PeriodName)?.ToList()?.ForEach(p => { periods.Add(p.Key); }); // 设置节次 excelModel.SetPeriods(periods); // 设置星期 excelModel.SetWeeks(weeks); foreach (var rc in resultModel.ResultClasses) { var classInfo = resultModel.Classes.FirstOrDefault(c => rc.ClassID.Equals(c.ID)); // 添加结果 List <string> values = new List <string>(); excelModel.AddClassesDictionary(classInfo.Name, values); var mondays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Monday)?.ToList(); var tuesdays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Tuesday)?.ToList(); var wednesdays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Wednesday)?.ToList(); var thursdays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Thursday)?.ToList(); var fridays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Friday)?.ToList(); var saturdays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Saturday)?.ToList(); var sundays = rc.ResultDetails.Where(rd => rd.DayPeriod.Day == DayOfWeek.Sunday)?.ToList(); values.AddRange(FillGradeExportValues(mondays, periods)); values.AddRange(FillGradeExportValues(tuesdays, periods)); values.AddRange(FillGradeExportValues(wednesdays, periods)); values.AddRange(FillGradeExportValues(thursdays, periods)); values.AddRange(FillGradeExportValues(fridays, periods)); if (saturdays?.Count > 0) { values.AddRange(FillGradeExportValues(saturdays, periods)); } if (sundays?.Count > 0) { values.AddRange(FillGradeExportValues(sundays, periods)); } } var table = GradeExcel.Export(excelModel, saveDialog.FileName); if (table.Item1) { this.ShowDialog("提示信息", "导出成功!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); FileHelper.OpenFilePath(saveDialog.FileName); } else { this.ShowDialog("提示信息", table.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } } else if (exportType == 2) { Dictionary <string, DataTable> values = new Dictionary <string, DataTable>(); // 获取所有教师 var classHourIDs = from c in resultModel.ResultClasses from rd in c.ResultDetails select rd.ClassHourId; var classHours = cp.GetClassHours(classHourIDs?.ToArray()); List <UITeacher> teachers = new List <UITeacher>(); classHours?.ForEach(ch => { ch.Teachers.ForEach(t => { var teacher = teachers.FirstOrDefault(tt => tt.ID.Equals(t.ID)); if (teacher == null) { teachers.Add(new UITeacher() { ID = t.ID, Name = t.Name, ClassHourIDs = new List <int> { ch.ID } }); } else { teacher.ClassHourIDs.Add(ch.ID); } }); }); if (teachers.Count == 0) { this.ShowDialog("提示信息", "没有教师信息无法导出教师课表!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } teachers.ForEach(t => { // 创建基础结构 var dt = this.CreateTableFrame(); values.Add(t.Name, dt); var resultDetails = (from rc in resultModel.ResultClasses from rd in rc.ResultDetails select new { rc.ClassID, rd.ClassHourId, rd.CourseID, rd.DayPeriod, rd.ResultType }); var filters = (from ch in t.ClassHourIDs from rc in resultDetails where ch == rc.ClassHourId select rc)?.ToList(); var groups = filters?.GroupBy(g => $"{g.DayPeriod.Day}{g.DayPeriod.Period}"); if (groups != null) { foreach (var g in groups) { var dayPeriod = g.FirstOrDefault().DayPeriod; var ids = g.Select(gs => { return(gs.ClassHourId); })?.ToArray(); var setValue = cp.GetClassHours(ids)?.Select(ss => $"{ss.Course}-{ss.Class}")?.Parse("|"); SetCellData(dt, setValue, dayPeriod); } } }); #region 导出 List <int> enableIndex = new List <int>(); var abIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.AB); if (abIndex != null) { enableIndex.Add(abIndex.DayPeriod.Period); } var noonIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.Noon); if (noonIndex != null) { enableIndex.Add(noonIndex.DayPeriod.Period); } var pbIndex = cp.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.PB); if (pbIndex != null) { enableIndex.Add(pbIndex.DayPeriod.Period); } var table = NPOIClass.DataTableToExcel(values, saveDialog.FileName, enableIndex); if (table.Item1) { this.ShowDialog("提示信息", "导出成功!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); FileHelper.OpenFilePath(saveDialog.FileName); } else { this.ShowDialog("提示信息", table.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } #endregion } } #endregion } }; window.ShowDialog(); }
public void Initilize() { this.Patterns = new List <UIPattern>() { new UIPattern() { Pattern = Models.Enums.PatternTypeEnum.Normal, View = new NormalView() }, new UIPattern() { Pattern = Models.Enums.PatternTypeEnum.Validation, View = new ValidationView() }, new UIPattern() { Pattern = Models.Enums.PatternTypeEnum.Extraction, View = new ExtractionView() }, new UIPattern() { Pattern = Models.Enums.PatternTypeEnum.OptimizedExtraction, View = new OptimizedExtractionView() }, new UIPattern() { Pattern = Models.Enums.PatternTypeEnum.Compression, View = new CompressionView() }, new UIPattern() { Pattern = Models.Enums.PatternTypeEnum.OptimizedCompression, View = new OptimizedCompressionView() }, }; var local = CommonDataManager.GetLocalCase(base.LocalID); var firstDefault = this.Patterns.FirstOrDefault(p => p.Pattern == local.Pattern); if (firstDefault != null) { this.SelectPattern = firstDefault; switch (this.SelectPattern.Pattern) { case Models.Enums.PatternTypeEnum.Normal: break; case Models.Enums.PatternTypeEnum.Validation: var vm = this.SelectPattern.View.DataContext as ValidationViewModel; var value = base.LocalID.DeSerialize <UIValidation>(); if (value != null) { vm.IncludeAssinged = value.AssignedStudents; vm.OnlyTeacher = value.OnlyTeacher; } break; case Models.Enums.PatternTypeEnum.Extraction: var extractionVM = this.SelectPattern.View.DataContext as ExtractionViewModel; var extractionModel = base.LocalID.DeSerialize <StudentExtractionModel>(); if (extractionModel != null) { extractionVM.ClassCapacity = extractionModel.IncreasedCapacity; extractionVM.ExtractionRate = extractionModel.ExtractionRatio; } break; case Models.Enums.PatternTypeEnum.OptimizedExtraction: // 优化部分的结果绑定TODO break; case Models.Enums.PatternTypeEnum.Compression: var compressionVM = this.SelectPattern.View.DataContext as CompressionViewModel; var compressionModel = base.LocalID.DeSerialize <TimeCompressionModel>(); if (compressionModel != null) { compressionVM.Compression = compressionModel.CompressionRatio; } break; case Models.Enums.PatternTypeEnum.OptimizedCompression: // 优化部分的结果绑定TODO break; } } else { this.SelectPattern = this.Patterns.First(); } }
public void exportTable(UIResult result) { var adjustRecord = base.LocalID.DeSerializeAdjustRecord <ResultAdjustmentModel>(result.TaskID); if (adjustRecord != null) { if (!result.IsUploaded) { this.ShowDialog("提示信息", "本地结果发生改变上传后才可以导出!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } } // (1:班级 2:教师 3:学生) int exportType = 1; ExportTypeWindow window = new ExportTypeWindow(true); window.Closed += (s, arg) => { if (window.DialogResult.Value) { exportType = window.Type; #region 导出 var cl = CommonDataManager.GetCLCase(base.LocalID); var local = CommonDataManager.GetLocalCase(base.LocalID); ResultModel resultModel = base.LocalID.DeSerializeLocalResult <ResultModel>(result.TaskID); if (resultModel == null) { var value = OSHttpClient.Instance.GetResult(result.TaskID); if (value.Item1) { resultModel = value.Item2; } else { this.ShowDialog("提示信息", "获取走班结果失败", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); return; } } string typeName = "班级课表"; if (exportType == 2) { typeName = "教师课表"; } else if (exportType == 3) { typeName = "学生课表"; } System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog(); saveDialog.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx"; saveDialog.FileName = $"{local.Name}-{result.TaskID}-({typeName})"; var confirm = saveDialog.ShowDialog(); if (confirm == System.Windows.Forms.DialogResult.OK) { Dictionary <string, DataTable> values = new Dictionary <string, DataTable>(); Dictionary <string, List <UIExcelExport> > studentPreselections = new Dictionary <string, List <UIExcelExport> >(); if (exportType == 1) { var dt = this.CreateTableFrame(); values.Add("课表", dt); var details = (from c in resultModel.ResultClasses from rc in c.ResultDetails select new { c.ClassID, rc.ClassHourId, rc.DayPeriod, rc.Teachers, rc }); var groups = details.GroupBy(g => $"{g.DayPeriod.Day}|{g.DayPeriod.Period}|{g.DayPeriod.PeriodName}")?.ToList(); groups?.ForEach(g => { var first = g.First(); var dayPeriod = first.DayPeriod; StringBuilder sb = new StringBuilder(); g.ToList()?.ForEach(gi => { sb.AppendLine(cl.GetClassByID(gi.ClassID)?.Display); if (gi.Teachers != null) { var teachers = cl.GetTeachersByIds(gi.Teachers.ToList()); sb.AppendLine(teachers.Select(t => t.Name).Parse()); sb.AppendLine(); } }); //var setValue = g.ToList()?.Select(gi => // { // return cl.GetClassByID(gi.ClassID)?.Display; // })?.Parse("\n"); if (sb.Length > 0) { SetCellData(dt, sb.ToString(), dayPeriod); } }); } else if (exportType == 2) { // 获取所有教师 var classHourIDs = from c in resultModel.ResultClasses from rd in c.ResultDetails select rd.ClassHourId; var classHours = cl.GetClassHours(classHourIDs?.ToArray()); List <UITeacher> teachers = new List <UITeacher>(); classHours?.ForEach(ch => { ch.Teachers.ForEach(t => { var teacher = teachers.FirstOrDefault(tt => tt.ID.Equals(t.ID)); if (teacher == null) { teachers.Add(new UITeacher() { ID = t.ID, Name = t.Name, ClassHourIDs = new List <int> { ch.ID } }); } else { teacher.ClassHourIDs.Add(ch.ID); } }); }); if (teachers.Count == 0) { this.ShowDialog("提示信息", "没有教师信息无法导出教师课表!", DialogSettingType.OnlyOkButton, DialogType.Warning); return; } teachers.ForEach(t => { // 创建基础结构 var dt = this.CreateTableFrame(); values.Add(t.Name, dt); var resultDetails = (from rc in resultModel.ResultClasses from rd in rc.ResultDetails select new { rc.ClassID, rd.ClassHourId, rd.DayPeriod, }); var filters = (from ch in t.ClassHourIDs from rc in resultDetails where ch == rc.ClassHourId select rc)?.ToList(); var groups = filters?.GroupBy(g => $"{g.DayPeriod.Day}|{g.DayPeriod.Period}|{g.DayPeriod.PeriodName}")?.ToList(); groups?.ForEach(g => { var first = g.First(); var dayPeriod = first.DayPeriod; var setValue = g.ToList()?.Select(gi => { return(cl.GetClassByID(gi.ClassID)?.Display); })?.Parse("\n"); SetCellData(dt, setValue, dayPeriod); }); }); } else if (exportType == 3) { var preselectionsGroups = (from stu in cl.Students from sp in stu.Preselections where stu.Preselections?.Count > 0 select new { stu.ID, stu.Name, stu.Preselections, groupString = stu.Preselections.OrderBy(o => o.CourseID).OrderBy(o => o.LevelID).Select(pss => $"{pss.CourseID}|{pss.LevelID}")?.Parse() })?.GroupBy(g => g.groupString)?.ToList(); preselectionsGroups?.ForEach(g => { var first = g.First(); var sheetString = first.Preselections.Select(p => { var courseInfo = cl.Courses.FirstOrDefault(c => c.ID.Equals(p.CourseID)); if (courseInfo != null) { var levelInfo = courseInfo.Levels.FirstOrDefault(l => l.ID.Equals(p.LevelID)); if (levelInfo != null) { return($"{courseInfo.Name}{levelInfo.Name}"); } else { return($"{courseInfo.Name}"); } } else { return(string.Empty); } })?.Parse(); List <UIExcelExport> exports = new List <UIExcelExport>(); var students = g.Distinct()?.ToList(); students.ForEach(gi => { // 创建表格 var dt = this.CreateTableFrame(); UIExcelExport export = new UIExcelExport(); export.Table = dt; export.CreateTime = DateTime.Now; export.StudentID = gi.ID; export.Student = gi.Name; // 获取结果数据 var resultDetails = (from rc in resultModel.ResultClasses from rd in rc.ResultDetails where rc.ResultStudents.Contains(gi.ID) select new { rc.ClassID, rd.ClassHourId, rd.DayPeriod, }); // 根据位置分组 var groups = resultDetails?.Where(rd => { var classHour = cl.GetClassHours(new int[] { rd.ClassHourId })?.FirstOrDefault(); if (classHour == null) { return(false); } else { if (gi.Preselections == null) { return(false); } else { return(gi.Preselections.Any(p => p.CourseID.Equals(classHour.CourseID) && p.LevelID.Equals(classHour.LevelID))); } } })?.GroupBy(gg => $"{gg.DayPeriod.Day}{gg.DayPeriod.Period}")?.ToList(); // 填充表格数据 groups?.ForEach(gg => { var firstgg = gg.First(); var dayPeriod = firstgg.DayPeriod; StringBuilder sb = new StringBuilder(); gg.ToList()?.ForEach(ggi => { sb.AppendLine(cl.GetClassByID(ggi.ClassID)?.Display); var classInfo = cl.GetClassByID(ggi.ClassID); if (classInfo != null) { if (classInfo.TeacherIDs?.Count > 0) { var teachers = cl.GetTeachersByIds(classInfo.TeacherIDs); var teacherString = teachers?.Select(t => t.Name)?.Parse(); sb.AppendLine(teacherString); sb.AppendLine(); } } }); //var setValue = gg.ToList()?.Select(ggi => //{ // return cl.GetClassByID(ggi.ClassID)?.Display; //})?.Parse("\n"); if (sb.Length > 0) { SetCellData(dt, sb.ToString(), dayPeriod); } }); // 向集合中添加 exports.Add(export); }); studentPreselections.Add(sheetString, exports); }); } List <int> enableIndex = new List <int>(); var abIndex = cl.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.AB); if (abIndex != null) { enableIndex.Add(abIndex.DayPeriod.Period); } var noonIndex = cl.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.Noon); if (noonIndex != null) { enableIndex.Add(noonIndex.DayPeriod.Period); } var pbIndex = cl.Positions.FirstOrDefault(p => p.Position == XYKernel.OS.Common.Enums.Position.PB); if (pbIndex != null) { enableIndex.Add(pbIndex.DayPeriod.Period); } if (exportType == 3) { var table = NPOIClass.DataTableToExcel(studentPreselections, saveDialog.FileName, enableIndex); if (table.Item1) { this.ShowDialog("提示信息", "导出成功!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); } else { this.ShowDialog("提示信息", table.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } } else { var table = NPOIClass.DataTableToExcel(values, saveDialog.FileName, enableIndex); if (table.Item1) { this.ShowDialog("提示信息", "导出成功!", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); } else { this.ShowDialog("提示信息", table.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning); } } } #endregion } }; window.ShowDialog(); }