diff --git a/HFUTCourseSimulation/Dialog/EditCourse.xaml b/HFUTCourseSimulation/Dialog/EditCourse.xaml index bdf3d9e..ac4e52a 100644 --- a/HFUTCourseSimulation/Dialog/EditCourse.xaml +++ b/HFUTCourseSimulation/Dialog/EditCourse.xaml @@ -4,9 +4,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:HFUTCourseSimulation.Dialog" - xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData" + xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel.Data.Ui" mc:Ignorable="d" - d:DataContext="{d:DesignInstance userdata:Course}" + d:DataContext="{d:DesignInstance uidata:Course}" x:Name="uiMainWindow" Title="编辑课程" Height="500" Width="600" WindowStyle="ToolWindow" Loaded="uiMainWindow_Loaded" Closed="uiMainWindow_Closed"> @@ -27,11 +27,11 @@ - + - + @@ -45,7 +45,7 @@ - + diff --git a/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs b/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs index 340b0e9..5c7a2c4 100644 --- a/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs +++ b/HFUTCourseSimulation/Dialog/EditCourse.xaml.cs @@ -21,7 +21,7 @@ namespace HFUTCourseSimulation.Dialog { InitializeComponent(); } - public Kernel.UserData.Course CurrentCourse { get; set; } + public Kernel.Data.Ui.Course CurrentCourse { get; set; } private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) { this.DataContext = CurrentCourse; @@ -38,19 +38,19 @@ namespace HFUTCourseSimulation.Dialog { private void uiCtxMenuNewSchedule_Click(object sender, RoutedEventArgs e) { // Create new item and order user edit it - var item = new Kernel.UserData.Schedule(); + var item = new Kernel.Data.Storage.Schedule(); var dialog = new EditSchedule(); - dialog.CurrentSchedule = item; + dialog.CurrentSchedule = new Kernel.Data.Ui.Schedule(item); dialog.ShowDialog(); // Then insert or append it into list var idx = uiSchedulesList.SelectedIndex; if (idx < 0) { // No selection, append. - CurrentCourse.Schedules.Add(item); + CurrentCourse.Schedules.Add(dialog.CurrentSchedule); } else { // Has selection, insert - CurrentCourse.Schedules.Insert(idx, item); + CurrentCourse.Schedules.Insert(idx, dialog.CurrentSchedule); } } diff --git a/HFUTCourseSimulation/Dialog/EditSchedule.xaml b/HFUTCourseSimulation/Dialog/EditSchedule.xaml index 14c8f57..e63eb31 100644 --- a/HFUTCourseSimulation/Dialog/EditSchedule.xaml +++ b/HFUTCourseSimulation/Dialog/EditSchedule.xaml @@ -4,9 +4,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:HFUTCourseSimulation.Dialog" - xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData" + xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel.Data.Ui" mc:Ignorable="d" - d:DataContext="{d:DesignInstance userdata:Schedule}" + d:DataContext="{d:DesignInstance uidata:Schedule}" x:Name="uiMainWindow" Title="编辑课程安排" Height="450" Width="600" WindowStyle="ToolWindow" Loaded="uiMainWindow_Loaded" Closed="uiMainWindow_Closed"> diff --git a/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs b/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs index b8b37bf..e2db6c5 100644 --- a/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs +++ b/HFUTCourseSimulation/Dialog/EditSchedule.xaml.cs @@ -21,7 +21,7 @@ namespace HFUTCourseSimulation.Dialog { InitializeComponent(); } - public Kernel.UserData.Schedule CurrentSchedule { get; set; } + public Kernel.Data.Ui.Schedule CurrentSchedule { get; set; } private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) { this.DataContext = CurrentSchedule; diff --git a/HFUTCourseSimulation/HFUTCourseSimulation.csproj b/HFUTCourseSimulation/HFUTCourseSimulation.csproj index 33155b3..f868ca5 100644 --- a/HFUTCourseSimulation/HFUTCourseSimulation.csproj +++ b/HFUTCourseSimulation/HFUTCourseSimulation.csproj @@ -83,10 +83,11 @@ + + + - - - + Simulation.xaml diff --git a/HFUTCourseSimulation/Kernel/OldUserData/V1.cs b/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs similarity index 87% rename from HFUTCourseSimulation/Kernel/OldUserData/V1.cs rename to HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs index 09c5243..3a26c30 100644 --- a/HFUTCourseSimulation/Kernel/OldUserData/V1.cs +++ b/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs @@ -7,9 +7,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; -namespace HFUTCourseSimulation.Kernel.OldUserData.V1 { +namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 { - public class Semester { + public class Semester : Storage.IFromLegacy { public Semester() { this.Courses = new List(); StartDate = DateTime.Today; @@ -24,8 +24,8 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 { [JsonProperty("Courses")] public List Courses { get; set; } - public UserData.Semester ToLatest() { - return new UserData.Semester() { + public Storage.Semester ToLatest() { + return new Storage.Semester() { StartDate = StartDate, WeekCount = WeekCount.ToString(), // Other properties keep original value. @@ -50,12 +50,14 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 { [JsonProperty("Schedule")] public List Schedule { get; set; } - public UserData.Course ToLatest() { - return new UserData.Course() { + public Storage.Course ToLatest() { + return new Storage.Course() { Name = Name, Description = Description, - Foreground = Colors.Black, - Background = BkColor, + Color = new Storage.ColorPair() { + Foreground = Colors.Black, + Background = BkColor + }, Schedules = Schedule.Select((item) => item.ToLatest()).ToList() }; } @@ -69,8 +71,8 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 { [JsonProperty("Index")] public string Index { get; set; } - public UserData.Schedule ToLatest() { - return new UserData.Schedule() { + public Storage.Schedule ToLatest() { + return new Storage.Schedule() { Week = Week, Day = Day, Index = Index diff --git a/HFUTCourseSimulation/Kernel/SimData.cs b/HFUTCourseSimulation/Kernel/Data/Presentation.cs similarity index 98% rename from HFUTCourseSimulation/Kernel/SimData.cs rename to HFUTCourseSimulation/Kernel/Data/Presentation.cs index bc2fd8e..69d1d9c 100644 --- a/HFUTCourseSimulation/Kernel/SimData.cs +++ b/HFUTCourseSimulation/Kernel/Data/Presentation.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HFUTCourseSimulation.Kernel.SimData { +namespace HFUTCourseSimulation.Kernel.Data.Presentation { /// /// 节次的类型 diff --git a/HFUTCourseSimulation/Kernel/UserData.cs b/HFUTCourseSimulation/Kernel/Data/Storage.cs similarity index 86% rename from HFUTCourseSimulation/Kernel/UserData.cs rename to HFUTCourseSimulation/Kernel/Data/Storage.cs index 1db15fa..1e67692 100644 --- a/HFUTCourseSimulation/Kernel/UserData.cs +++ b/HFUTCourseSimulation/Kernel/Data/Storage.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using HFUTCourseSimulation.Util; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; @@ -6,9 +7,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; -using HFUTCourseSimulation.Util; -namespace HFUTCourseSimulation.Kernel.UserData { +namespace HFUTCourseSimulation.Kernel.Data.Storage { + + /// + /// 表示可以从旧版数据结构转换为最新版本的接口。 + /// + public interface IFromLegacy { + Semester ToLatest(); + } /// /// 学期数据 @@ -66,9 +73,7 @@ namespace HFUTCourseSimulation.Kernel.UserData { public Course() { Name = ""; Description = ""; - var color = Util.ColorPreset.MdColors.Indigo; - Foreground = color.Foreground; - Background = color.Background; + Color = ColorTrans.ToStorageColorPair(Util.ColorPreset.MdColors.Indigo); Schedules = new List(); } @@ -83,17 +88,10 @@ namespace HFUTCourseSimulation.Kernel.UserData { [JsonProperty("description")] public string Description { get; set; } /// - /// 课程的前景色(文本) + /// 课程的颜色。 /// - [JsonProperty("foreground")] - [JsonConverter(typeof(CustomColorConverter))] - public Color Foreground { get; set; } - /// - /// 课程的背景色(背景) - /// - [JsonProperty("background")] - [JsonConverter(typeof(CustomColorConverter))] - public Color Background { get; set; } + [JsonProperty("color")] + public ColorPair Color { get; set; } /// /// 课程的所有安排 /// @@ -125,6 +123,29 @@ namespace HFUTCourseSimulation.Kernel.UserData { public string Index { get; set; } } + /// + /// 课程颜色对,包含前景色和背景色 + /// + public class ColorPair { + public ColorPair() { + Foreground = Colors.Black; + Background = Colors.White; + } + + /// + /// 前景色(文本) + /// + [JsonProperty("foreground")] + [JsonConverter(typeof(CustomColorConverter))] + public Color Foreground { get; set; } + /// + /// 背景色(背景) + /// + [JsonProperty("background")] + [JsonConverter(typeof(CustomColorConverter))] + public Color Background { get; set; } + } + internal class CustomDateTimeConverter : JsonConverter { private static readonly string DatetimeFormat = "yyyy-MM-dd"; diff --git a/HFUTCourseSimulation/Kernel/Data/Ui.cs b/HFUTCourseSimulation/Kernel/Data/Ui.cs new file mode 100644 index 0000000..87b0352 --- /dev/null +++ b/HFUTCourseSimulation/Kernel/Data/Ui.cs @@ -0,0 +1,206 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace HFUTCourseSimulation.Kernel.Data.Ui { + + public class Semester : INotifyPropertyChanged { + public Semester(Storage.Semester rhs) { + _startDate = rhs.StartDate; + _weekCount = rhs.WeekCount; + _indexCount = rhs.IndexCount; + _breakfastAt = rhs.BreakfastAt; + _lunchAt = rhs.LunchAt; + _dinnerAt = rhs.DinnerAt; + _courses = new ObservableCollection(rhs.Courses.Select((item) => new Course(item))); + } + public Storage.Semester ToStorage() { + return new Storage.Semester() { + StartDate = _startDate, + WeekCount = _weekCount, + IndexCount = _indexCount, + BreakfastAt = _breakfastAt, + LunchAt = _lunchAt, + DinnerAt = _dinnerAt, + Courses = _courses.Select((item) => item.ToStorage()).ToList() + }; + } + + private DateTime _startDate; + private string _weekCount; + private string _indexCount; + private string _breakfastAt; + private string _lunchAt; + private string _dinnerAt; + private ObservableCollection _courses; + + public DateTime StartDate { + get { return _startDate; } + set { _startDate = value; OnPropertyChanged(nameof(StartDate)); } + } + public string WeekCount { + get { return _weekCount; } + set { _weekCount = value; OnPropertyChanged(nameof(WeekCount)); } + } + public string IndexCount { + get { return _indexCount; } + set { _indexCount = value; OnPropertyChanged(nameof(IndexCount)); } + } + public string BreakfastAt { + get { return _breakfastAt; } + set { _breakfastAt = value; OnPropertyChanged(nameof(BreakfastAt)); } + } + public string LunchAt { + get { return _lunchAt; } + set { _lunchAt = value; OnPropertyChanged(nameof(LunchAt)); } + } + public string DinnerAt { + get { return _dinnerAt; } + set { _dinnerAt = value; OnPropertyChanged(nameof(DinnerAt)); } + } + public ObservableCollection Courses { + get { return _courses; } + set { _courses = value; OnPropertyChanged(nameof(Courses)); } + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string name = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + } + + public class Course : INotifyPropertyChanged { + public Course(Storage.Course rhs) { + _name = rhs.Name; + _description = rhs.Description; + _color = new ColorPair(rhs.Color); + _schedules = new ObservableCollection(rhs.Schedules.Select((item) => new Schedule(item))); + SubscribeScheduleChanges(); + } + public Storage.Course ToStorage() { + return new Storage.Course() { + Name = _name, + Description = _description, + Color = _color.ToStorage(), + Schedules = _schedules.Select((item) => item.ToStorage()).ToList() + }; + } + + private string _name; + private string _description; + private ColorPair _color; + private ObservableCollection _schedules; + + public string Name { + get { return _name; } + set { _name = value; OnPropertyChanged(nameof(Name)); } + } + public string Description { + get { return _description; } + set { _description = value; OnPropertyChanged(nameof(Description)); } + } + public ColorPair Color { + get { return _color; } + set { _color = value; OnPropertyChanged(nameof(Color)); } + } + public ObservableCollection Schedules { + get { return _schedules; } + set { + // Common codes + _schedules = value; + OnPropertyChanged(nameof(Schedule)); + // We also need register a event for the change of this list, + // because showcase schedules need it. + SubscribeScheduleChanges(); + } + } + + public string ShowcaseSchedules => $"共计{_schedules.Count}个课程安排"; + /// + /// 用于订阅Schedules集合改变的通知,用于通知ShowcaseSchedules的改变。 + /// + protected void SubscribeScheduleChanges() { + _schedules.CollectionChanged += (sender, e) => { + OnPropertyChanged(nameof(ShowcaseSchedules)); + }; + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string name = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + } + + public class Schedule : INotifyPropertyChanged { + public Schedule(Storage.Schedule rhs) { + _week = rhs.Week; + _day = rhs.Day; + _index = rhs.Index; + } + public Storage.Schedule ToStorage() { + return new Storage.Schedule() { + Week = _week, + Day = _day, + Index = _index + }; + } + + private string _week; + private string _day; + private string _index; + + public string Week { + get { return _week; } + set { _week = value; OnPropertyChanged(nameof(Week)); } + } + public string Day { + get { return _day; } + set { _day = value; OnPropertyChanged(nameof(Day)); } + } + public string Index { + get { return _index; } + set { _index = value; OnPropertyChanged(nameof(Index)); } + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string name = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + } + + public class ColorPair : INotifyPropertyChanged { + public ColorPair(Storage.ColorPair rhs) { + _foreground = rhs.Foreground; + _background = rhs.Background; + } + public Storage.ColorPair ToStorage() { + return new Storage.ColorPair() { + Foreground = _foreground, + Background = _background + }; + } + + private Color _foreground; + private Color _background; + + public Color Foreground { + get { return _foreground; } + set { _foreground = value; OnPropertyChanged(nameof(Foreground)); } + } + public Color Background { + get { return _background; } + set { _background = value; OnPropertyChanged(nameof(Background)); } + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string name = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + } + +} diff --git a/HFUTCourseSimulation/MainWindow.xaml b/HFUTCourseSimulation/MainWindow.xaml index 4d4f8ce..96260ef 100644 --- a/HFUTCourseSimulation/MainWindow.xaml +++ b/HFUTCourseSimulation/MainWindow.xaml @@ -4,9 +4,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:HFUTCourseSimulation" - xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData" + xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel.Data.Ui" mc:Ignorable="d" - d:DataContext="{d:DesignInstance userdata:Semester}" + d:DataContext="{d:DesignInstance uidata:Semester}" Title="HFUT课表模拟" Height="600" Width="800"> @@ -65,25 +65,25 @@ - + - + - + - - + + diff --git a/HFUTCourseSimulation/MainWindow.xaml.cs b/HFUTCourseSimulation/MainWindow.xaml.cs index cdefffd..716c371 100644 --- a/HFUTCourseSimulation/MainWindow.xaml.cs +++ b/HFUTCourseSimulation/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using HFUTCourseSimulation.Dialog; +using HFUTCourseSimulation.Util; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -28,7 +29,7 @@ namespace HFUTCourseSimulation { #region Context and Assistant Functions - private Kernel.UserData.Semester CurrentSemester { get; set; } + private Kernel.Data.Ui.Semester CurrentSemester { get; set; } private string CurrentFilePath { get; set; } /// @@ -101,8 +102,14 @@ namespace HFUTCourseSimulation { #region Menu Handlers private void uiMenuNew_Click(object sender, RoutedEventArgs e) { - CurrentSemester = new Kernel.UserData.Semester(); + // Create new blank semester. + var new_obj = new Kernel.Data.Storage.Semester(); + + // Convert into struct for Ui and clean assoc file path. + CurrentSemester = new Kernel.Data.Ui.Semester(new_obj); CurrentFilePath = null; + + // Update UI and data source UpdateUiLayout(); UpdateDataSource(); } @@ -115,7 +122,35 @@ namespace HFUTCourseSimulation { // Try to read file. try { using (var fs = new StreamReader(filepath, Encoding.UTF8)) { - CurrentSemester = JsonConvert.DeserializeObject(fs.ReadToEnd()); + // Read semester object. + var obj = JsonConvert.DeserializeObject(fs.ReadToEnd()); + // Convert into struct for Ui and add assoc file path. + CurrentSemester = new Kernel.Data.Ui.Semester(obj); + CurrentFilePath = filepath; + } + } catch (Exception ex) { + Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错"); + return; + } + + // Update UI and data source + UpdateUiLayout(); + UpdateDataSource(); + } + + private void OpenLegacy() where T : Kernel.Data.Storage.IFromLegacy { + // Fetch file path. + var filepath = Util.Win32Dialog.OpenSemester(); + if (filepath is null) return; + + // Try to read file. + try { + using (var fs = new StreamReader(filepath, Encoding.UTF8)) { + // Read legacy file and convert it into latest file. + var obj = JsonConvert.DeserializeObject(fs.ReadToEnd()); + var latest_obj = obj.ToLatest(); + // Convert into struct for Ui and add assoc file path. + CurrentSemester = new Kernel.Data.Ui.Semester(latest_obj); CurrentFilePath = filepath; } } catch (Exception ex) { @@ -129,25 +164,7 @@ namespace HFUTCourseSimulation { } private void uiMenuOpenV1_Click(object sender, RoutedEventArgs e) { - // Fetch file path. - var filepath = Util.Win32Dialog.OpenSemester(); - if (filepath is null) return; - - // Try to read file. - try { - using (var fs = new StreamReader(filepath, Encoding.UTF8)) { - var obj = JsonConvert.DeserializeObject(fs.ReadToEnd()); - CurrentSemester = obj.ToLatest(); - CurrentFilePath = filepath; - } - } catch (Exception ex) { - Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错"); - return; - } - - // Update UI and data source - UpdateUiLayout(); - UpdateDataSource(); + OpenLegacy(); } private void uiMenuSave_Click(object sender, RoutedEventArgs e) { @@ -162,7 +179,7 @@ namespace HFUTCourseSimulation { // Try to save file try { using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) { - fs.Write(JsonConvert.SerializeObject(CurrentSemester)); + fs.Write(JsonConvert.SerializeObject(CurrentSemester.ToStorage())); } } catch (Exception ex) { Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错"); @@ -184,7 +201,7 @@ namespace HFUTCourseSimulation { // Try to save file try { using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) { - fs.Write(JsonConvert.SerializeObject(CurrentSemester)); + fs.Write(JsonConvert.SerializeObject(CurrentSemester.ToStorage())); } } catch (Exception ex) { Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错"); @@ -221,39 +238,40 @@ namespace HFUTCourseSimulation { } private void uiMenuSimulator_Click(object sender, RoutedEventArgs e) { - var win = new Simulation(); - win.ShowDialog(); + //var win = new Simulation(); + //win.ShowDialog(); } private void uiMenuRender_Click(object sender, RoutedEventArgs e) { - //convert data - int weekCount; - DateTime originDate; - try { - originDate = DateTime.Parse(General.GeneralSheet.StartDate); - weekCount = General.GeneralSheet.WeekCount; - } catch (Exception) { - MessageBox.Show("周数或日期转换错误,无法输出", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); - return; - } + ////convert data + //int weekCount; + //DateTime originDate; + //try { + // originDate = DateTime.Parse(General.GeneralSheet.StartDate); + // weekCount = General.GeneralSheet.WeekCount; + //} catch (Exception) { + // MessageBox.Show("周数或日期转换错误,无法输出", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + // return; + //} - //open file - var sp = new Microsoft.Win32.SaveFileDialog(); - sp.RestoreDirectory = true; - sp.Filter = "图片文件(*.png)|*.png|所有文件(*.*)|*.*"; - var status = sp.ShowDialog(); - if (!(status.HasValue && status.Value)) return; - var getFile = sp.FileName; + ////open file + //var sp = new Microsoft.Win32.SaveFileDialog(); + //sp.RestoreDirectory = true; + //sp.Filter = "图片文件(*.png)|*.png|所有文件(*.*)|*.*"; + //var status = sp.ShowDialog(); + //if (!(status.HasValue && status.Value)) return; + //var getFile = sp.FileName; - //export - var res = ImageExport.Export(originDate, weekCount, getFile); - if (!res) MessageBox.Show("当前课程安排存在冲突,请通过实时预览消除所有错误后才能使用此功能来导出为图片", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); - else MessageBox.Show("导出成功", "关于", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); + ////export + //var res = ImageExport.Export(originDate, weekCount, getFile); + //if (!res) MessageBox.Show("当前课程安排存在冲突,请通过实时预览消除所有错误后才能使用此功能来导出为图片", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + //else MessageBox.Show("导出成功", "关于", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); } private void uiMenuAbout_Click(object sender, RoutedEventArgs e) { - MessageBox.Show("本程序为开源程序。" + Environment.NewLine + "开源地址:https://gitee.com/yyc12345/HFUTCourseSimulation" + Environment.NewLine + - "本程序旨在为各位选课的同学提供一个用于查验课程冲突以及查看课表的功能。如果您想参与开发,提交PullRequest即可,欢迎您的加入。", "关于", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); + Win32Dialog.Info(@"本程序为开源程序。 +开源地址:https://gitee.com/yyc12345/HFUTCourseSimulation +本程序旨在为各位选课的同学提供一个用于查验课程冲突以及查看课表的功能。如果您想参与开发,提交PullRequest即可,欢迎您的加入。", "关于"); } #endregion @@ -267,19 +285,19 @@ namespace HFUTCourseSimulation { private void uiCtxMenuNewCourse_Click(object sender, RoutedEventArgs e) { // Create new item and order user edit it - var item = new Kernel.UserData.Course(); + var item = new Kernel.Data.Storage.Course(); var dialog = new Dialog.EditCourse(); - dialog.CurrentCourse = item; + dialog.CurrentCourse = new Kernel.Data.Ui.Course(item); dialog.ShowDialog(); // Then insert or append it into list var idx = uiCoursesList.SelectedIndex; if (idx < 0) { // No selection, append. - CurrentSemester.Courses.Add(item); + CurrentSemester.Courses.Add(dialog.CurrentCourse); } else { // Has selection, insert - CurrentSemester.Courses.Insert(idx, item); + CurrentSemester.Courses.Insert(idx, dialog.CurrentCourse); } } diff --git a/HFUTCourseSimulation/Util/ColorTrans.cs b/HFUTCourseSimulation/Util/ColorTrans.cs index 06a7210..9178e8b 100644 --- a/HFUTCourseSimulation/Util/ColorTrans.cs +++ b/HFUTCourseSimulation/Util/ColorTrans.cs @@ -7,6 +7,9 @@ using System.Threading.Tasks; using WpfColor = System.Windows.Media.Color; using WinformColor = System.Drawing.Color; +using StandardColorPair = HFUTCourseSimulation.Util.ColorPair; +using StorageColorPair = HFUTCourseSimulation.Kernel.Data.Storage.ColorPair; + namespace HFUTCourseSimulation.Util { public static class ColorTrans { @@ -49,5 +52,23 @@ namespace HFUTCourseSimulation.Util { #endregion + #region Color Pair + + public static StandardColorPair ToStandardColorPair(StorageColorPair cp) { + return new StandardColorPair() { + Background = cp.Background, + Foreground = cp.Foreground + }; + } + + public static StorageColorPair ToStorageColorPair(StandardColorPair cp) { + return new StorageColorPair() { + Background = cp.Background, + Foreground = cp.Foreground + }; + } + + #endregion + } } diff --git a/HFUTCourseSimulation/Util/Win32Dialog.cs b/HFUTCourseSimulation/Util/Win32Dialog.cs index d6972ef..25ae2a6 100644 --- a/HFUTCourseSimulation/Util/Win32Dialog.cs +++ b/HFUTCourseSimulation/Util/Win32Dialog.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media; namespace HFUTCourseSimulation.Util { public static class Win32Dialog { @@ -48,6 +49,17 @@ namespace HFUTCourseSimulation.Util { else return sp.FileName; } + /// + /// 颜色选择框 + /// + /// 如果用户选择颜色并点击了确定,则返回用户选择的颜色,否则返回null + public static Color? PickColor() { + var picker = new System.Windows.Forms.ColorDialog(); + var rv = picker.ShowDialog(); + if (rv != System.Windows.Forms.DialogResult.OK) return null; + else return ColorTrans.ToWpfColor(picker.Color); + } + /// /// 显示一个经典的Windows错误对话框 ///