diff --git a/HFUTCourseSimulation/HFUTCourseSimulation.csproj b/HFUTCourseSimulation/HFUTCourseSimulation.csproj
index 917f1a0..ff5d576 100644
--- a/HFUTCourseSimulation/HFUTCourseSimulation.csproj
+++ b/HFUTCourseSimulation/HFUTCourseSimulation.csproj
@@ -83,7 +83,6 @@
Simulator.xaml
-
diff --git a/HFUTCourseSimulation/ImageExport.cs b/HFUTCourseSimulation/ImageExport.cs
deleted file mode 100644
index a93e9c6..0000000
--- a/HFUTCourseSimulation/ImageExport.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-
-namespace HFUTCourseSimulation {
-
- //public static class ImageExport {
-
- // public static readonly int WeekHeaderHeight = 50;
- // public static readonly int BodyCellWidth = 150;
- // public static readonly int BodyCellHeight = 80;
- // public static readonly int HeaderCellHeight = 40;
- // public static readonly int LeftCellWidth = 25;
- // public static readonly int Blank = 20;
-
- // static Dictionary weekDict = new Dictionary() {
- // {0, "星期一"},
- // {1, "星期二"},
- // {2, "星期三"},
- // {3, "星期四"},
- // {4, "星期五"},
- // {5, "星期六"},
- // {6, "星期日"}
- // };
-
- // public static bool Export(DateTime startDate, int weekCount, string file) {
-
- // var simuCore = new SimulationCore(startDate, weekCount);
- // simuCore.Generate();
- // if (simuCore.ErrorList.Count != 0) return false;
-
- // //define size
- // int weekPerLine = (int)Math.Sqrt(weekCount) + 1;
-
- // var weekWidth = (Blank + LeftCellWidth + 7 * BodyCellWidth);
- // var weekHeight = (Blank + WeekHeaderHeight + HeaderCellHeight + 11 * BodyCellHeight);
- // var img = new Bitmap(Blank + weekPerLine * weekWidth, Blank + (weekCount / weekPerLine + (weekCount % weekPerLine == 0 ? 0 : 1)) * weekHeight);
- // var graphics = Graphics.FromImage(img);
-
- // //declare graphics value
- // var background = new SolidBrush(Color.White);
- // var headerBrush = new SolidBrush(Color.Gray);
- // var textBrush = new SolidBrush(Color.Black);
- // Brush cellBrush;
- // var textFont = new Font("Microsoft YaHei UI", 12);
-
- // var textMargin = graphics.MeasureString("测试字符", textFont).Height;
-
- // //overlay all background
- // graphics.FillRectangle(background, 0, 0, Blank + weekPerLine * weekWidth, Blank + (weekCount / weekPerLine + (weekCount % weekPerLine == 0 ? 0 : 1)) * weekHeight);
-
- // //output each week
- // for (int i = 0; i < weekCount; i++) {
- // //generate week data
- // var weekData = simuCore.Render(i + 1);
-
- // //get start position
- // var top = Blank + (i / weekPerLine) * weekHeight;
- // var left = Blank + (i % weekPerLine) * weekWidth;
- // graphics.TranslateTransform(left, top);
-
- // //draw week head
- // graphics.DrawString($"教学周:{weekData.WeekIndex}", textFont, textBrush, 0, 0);
- // //move transform
- // graphics.TranslateTransform(0, WeekHeaderHeight);
-
-
- // //draw header
- // graphics.FillRectangle(headerBrush, 0, 0, weekWidth - Blank, HeaderCellHeight);
- // graphics.FillRectangle(headerBrush, 0, 0, LeftCellWidth, weekHeight - WeekHeaderHeight - Blank);
- // //draw header text
- // for (int j = 0; j < 7; j++) {
- // graphics.DrawString(weekDict[j], textFont, textBrush, LeftCellWidth + j * BodyCellWidth, 0);
- // graphics.DrawString(weekData.WeekDate[j], textFont, textBrush, LeftCellWidth + j * BodyCellWidth, textMargin);
- // }
- // //draw left text
- // for (int j = 0; j < 11; j++) {
- // graphics.DrawString((j + 1).ToString(), textFont, textBrush, 0, HeaderCellHeight + j * BodyCellHeight);
- // }
-
- // //move transform
- // graphics.TranslateTransform(LeftCellWidth, HeaderCellHeight);
- // foreach(var courses in weekData.CourseList) {
- // var cellx = courses.Start.week - 1;
- // var celly = courses.Start.index - 1;
- // //background
- // cellBrush = new SolidBrush(Util.ColorTrans.ToWinformColor(courses.BkColor));
- // graphics.FillRectangle(cellBrush, cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, BodyCellHeight * courses.Span);
-
- // //draw text
- // var rect = new RectangleF(cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, celly * BodyCellHeight);
- // graphics.DrawString(courses.Name, textFont, textBrush, rect);
- // var thisTextMargin = graphics.MeasureString(courses.Name, textFont, BodyCellWidth).Height;
- // graphics.DrawString(courses.Desc, textFont, textBrush, cellx * BodyCellWidth, celly * BodyCellHeight + thisTextMargin);
- // }
-
- // //reset
- // graphics.TranslateTransform(-LeftCellWidth, -HeaderCellHeight);
- // graphics.TranslateTransform(0, -WeekHeaderHeight);
- // graphics.TranslateTransform(-left, -top);
- // }
-
- // System.IO.File.Delete(file);
- // img.Save(file, ImageFormat.Png);
- // img.Dispose();
- // return true;
- // }
-
- //}
-
-}
diff --git a/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs b/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs
index 3a26c30..c225c4b 100644
--- a/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs
+++ b/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs
@@ -16,12 +16,12 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
WeekCount = 1;
}
- [JsonProperty("StartDate")]
+ [JsonProperty("StartDate", Required = Required.Always)]
[JsonConverter(typeof(CustomDateTimeConverter))]
public DateTime StartDate { get; set; }
- [JsonProperty("WeekCount")]
+ [JsonProperty("WeekCount", Required = Required.Always)]
public int WeekCount { get; set; }
- [JsonProperty("Courses")]
+ [JsonProperty("Courses", Required = Required.Always)]
public List Courses { get; set; }
public Storage.Semester ToLatest() {
@@ -40,14 +40,14 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
this.Schedule = new List();
}
- [JsonProperty("Name")]
+ [JsonProperty("Name", Required = Required.Always)]
public string Name { get; set; }
- [JsonProperty("Description")]
+ [JsonProperty("Description", Required = Required.Always)]
public string Description { get; set; }
- [JsonProperty("BkColor")]
+ [JsonProperty("BkColor", Required = Required.Always)]
[JsonConverter(typeof(CustomColorConverter))]
public Color BkColor { get; set; }
- [JsonProperty("Schedule")]
+ [JsonProperty("Schedule", Required = Required.Always)]
public List Schedule { get; set; }
public Storage.Course ToLatest() {
@@ -64,11 +64,11 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
}
public class ScheduleItem {
- [JsonProperty("Week")]
+ [JsonProperty("Week", Required = Required.Always)]
public string Week { get; set; }
- [JsonProperty("Day")]
+ [JsonProperty("Day", Required = Required.Always)]
public string Day { get; set; }
- [JsonProperty("Index")]
+ [JsonProperty("Index", Required = Required.Always)]
public string Index { get; set; }
public Storage.Schedule ToLatest() {
diff --git a/HFUTCourseSimulation/Kernel/Data/Storage.cs b/HFUTCourseSimulation/Kernel/Data/Storage.cs
index 8811f69..eda98cf 100644
--- a/HFUTCourseSimulation/Kernel/Data/Storage.cs
+++ b/HFUTCourseSimulation/Kernel/Data/Storage.cs
@@ -38,38 +38,38 @@ namespace HFUTCourseSimulation.Kernel.Data.Storage {
///
/// 学期开始日期(星期一)
///
- [JsonProperty("start_date")]
+ [JsonProperty("start_date", Required = Required.Always)]
[JsonConverter(typeof(CustomDateTimeConverter))]
public DateTime StartDate { get; set; }
///
/// 教学周个数
///
- [JsonProperty("week_count")]
+ [JsonProperty("week_count", Required = Required.Always)]
public string WeekCount { get; set; }
///
/// 每天课程的节次数
///
- [JsonProperty("index_count")]
+ [JsonProperty("index_count", Required = Required.Always)]
public string IndexCount { get; set; }
///
/// 早餐插入在第几节次后
///
- [JsonProperty("breakfast_at")]
+ [JsonProperty("breakfast_at", Required = Required.Always)]
public string BreakfastAt { get; set; }
///
/// 午餐插入在第几节次后
///
- [JsonProperty("lunch_at")]
+ [JsonProperty("lunch_at", Required = Required.Always)]
public string LunchAt { get; set; }
///
/// 晚餐插入在第几节次后
///
- [JsonProperty("dinner_at")]
+ [JsonProperty("dinner_at", Required = Required.Always)]
public string DinnerAt { get; set; }
///
/// 课程列表
///
- [JsonProperty("courses")]
+ [JsonProperty("courses", Required = Required.Always)]
public List Courses { get; set; }
}
@@ -84,22 +84,22 @@ namespace HFUTCourseSimulation.Kernel.Data.Storage {
///
/// 课程的名称
///
- [JsonProperty("name")]
+ [JsonProperty("name", Required = Required.Always)]
public string Name { get; set; }
///
/// 课程的说明,例如教室位置,教师姓名等。
///
- [JsonProperty("description")]
+ [JsonProperty("description", Required = Required.Always)]
public string Description { get; set; }
///
/// 课程的颜色。
///
- [JsonProperty("color")]
+ [JsonProperty("color", Required = Required.Always)]
public ColorPair Color { get; set; }
///
/// 课程的所有安排
///
- [JsonProperty("schedules")]
+ [JsonProperty("schedules", Required = Required.Always)]
public List Schedules { get; set; }
}
@@ -113,17 +113,17 @@ namespace HFUTCourseSimulation.Kernel.Data.Storage {
///
/// 安排在哪些周
///
- [JsonProperty("week")]
+ [JsonProperty("week", Required = Required.Always)]
public string Week { get; set; }
///
/// 安排在周的星期几
///
- [JsonProperty("day")]
+ [JsonProperty("day", Required = Required.Always)]
public string Day { get; set; }
///
/// 安排在这些日子的哪些节次
///
- [JsonProperty("index")]
+ [JsonProperty("index", Required = Required.Always)]
public string Index { get; set; }
}
@@ -139,13 +139,13 @@ namespace HFUTCourseSimulation.Kernel.Data.Storage {
///
/// 前景色(文本)
///
- [JsonProperty("foreground")]
+ [JsonProperty("foreground", Required = Required.Always)]
[JsonConverter(typeof(CustomColorConverter))]
public Color Foreground { get; set; }
///
/// 背景色(背景)
///
- [JsonProperty("background")]
+ [JsonProperty("background", Required = Required.Always)]
[JsonConverter(typeof(CustomColorConverter))]
public Color Background { get; set; }
}
diff --git a/HFUTCourseSimulation/Kernel/Render.cs b/HFUTCourseSimulation/Kernel/Render.cs
index f811188..86e828b 100644
--- a/HFUTCourseSimulation/Kernel/Render.cs
+++ b/HFUTCourseSimulation/Kernel/Render.cs
@@ -218,14 +218,14 @@ namespace HFUTCourseSimulation.Kernel {
var font = new Font("Sarasa Mono SC", 12);
// 填充背景为白色
- g.Clear(Color.White);
+ g.Clear(ColorTrans.ToGdiColor(ColorConsistency.Backboard.Background));
// 按教学周周分别输出
for (int week = 1; week <= semester.weekCount; ++week) {
var week_instance = semester.weeks[week - 1];
// 教学周文本
- g.DrawString($"教学周:{week}", font, brushes.GetBrush(Color.Black), geometry.GetTitleTextRect(week));
+ g.DrawString($"教学周:{week}", font, brushes.GetBrush(ColorConsistency.Backboard.Foreground), geometry.GetTitleTextRect(week));
// 绘制Headbar底层
g.FillRectangle(brushes.GetBrush(ColorConsistency.HeadbarColor.Background), geometry.GetHeadbarBoxRect(week));
diff --git a/HFUTCourseSimulation/MainWindow.xaml b/HFUTCourseSimulation/MainWindow.xaml
index 6d9ca9f..e2f7eeb 100644
--- a/HFUTCourseSimulation/MainWindow.xaml
+++ b/HFUTCourseSimulation/MainWindow.xaml
@@ -6,34 +6,51 @@
xmlns:local="clr-namespace:HFUTCourseSimulation"
xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel.Data.Ui"
mc:Ignorable="d"
- d:DataContext="{d:DesignInstance uidata:Semester}"
- Title="HFUT课表模拟" Height="600" Width="800">
+ d:DataContext="{d:DesignInstance local:MainWindowContext}"
+ Title="{Binding AppTitle, Mode=OneWay}" Height="600" Width="800">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HFUTCourseSimulation/MainWindow.xaml.cs b/HFUTCourseSimulation/MainWindow.xaml.cs
index bff5a37..fc8251a 100644
--- a/HFUTCourseSimulation/MainWindow.xaml.cs
+++ b/HFUTCourseSimulation/MainWindow.xaml.cs
@@ -1,8 +1,8 @@
-using HFUTCourseSimulation.Dialog;
-using HFUTCourseSimulation.Util;
+using HFUTCourseSimulation.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
@@ -16,86 +16,101 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using System.Windows.Threading;
namespace HFUTCourseSimulation {
- ///
- /// MainWindow.xaml 的交互逻辑
- ///
- public partial class MainWindow : Window {
- public MainWindow() {
- InitializeComponent();
- UpdateUiLayout();
+
+ internal class MainWindowContext : INotifyPropertyChanged {
+ public MainWindowContext() {
+ _semester = null;
+ _filePath = null;
}
- #region Context and Assistant Functions
+ private Kernel.Data.Ui.Semester _semester;
+ private string _filePath;
- private Kernel.Data.Ui.Semester CurrentSemester { get; set; }
- private string CurrentFilePath { get; set; }
+ public Kernel.Data.Ui.Semester Semester {
+ get { return _semester; }
+ set {
+ _semester = value;
+ OnPropertyChanged(nameof(Semester));
+ OnPropertyChanged(nameof(AppTitle));
+ OnPropertyChanged(nameof(MenuOnLoaded));
+ OnPropertyChanged(nameof(MenuOnNotLoaded));
+ OnPropertyChanged(nameof(MainAreaVisibility));
+ }
+ }
+ public string FilePath {
+ get { return _filePath; }
+ set {
+ _filePath = value;
+ OnPropertyChanged(nameof(FilePath));
+ OnPropertyChanged(nameof(AppTitle));
+ }
+ }
+
+ public string AppTitle {
+ get {
+ if (IsFileLoaded()) {
+ if (HasAssocFile()) {
+ return $"HFUT课表模拟 - {_filePath}";
+ } else {
+ return "HFUT课表模拟 - [未命名]";
+ }
+ } else {
+ return "HFUT课表模拟";
+ }
+ }
+ }
+ public bool MenuOnLoaded => IsFileLoaded();
+ public bool MenuOnNotLoaded => !MenuOnLoaded;
+ public Visibility MainAreaVisibility => IsFileLoaded() ? Visibility.Visible : Visibility.Collapsed;
///
/// 返回当前是否有文件被加载。
///
///
- private bool IsFileLoaded() {
- return !(CurrentSemester is null);
+ public bool IsFileLoaded() {
+ return !(_semester is null);
}
-
///
/// 检查当前加载的文件是否是关联到某个本地文件上的。
///
///
- private bool HasAssocFile() {
- return !(CurrentFilePath is null);
+ public bool HasAssocFile() {
+ return !(_filePath is null);
}
+ public event PropertyChangedEventHandler PropertyChanged;
+ protected void OnPropertyChanged(string name = null) {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+ }
+ }
+
+ ///
+ /// MainWindow.xaml 的交互逻辑
+ ///
+ public partial class MainWindow : Window {
+
+ public MainWindow() {
+ InitializeComponent();
+
+ // Setup context and self data context
+ _context = new MainWindowContext();
+ this.DataContext = _context;
+
+ // Setup report timeout timer
+ reportTimeout = new DispatcherTimer();
+ reportTimeout.Interval = TimeSpan.FromSeconds(5);
+ reportTimeout.Tick += reportTimeout_Tick;
+ }
+
+ #region Context and Assistant Functions
+
///
- /// 更新整个界面的UI状态(包括启用与否等)
+ /// 当前主窗口的UI上下文
///
- ///
- private void UpdateUiLayout() {
- bool isFileLoaded = this.IsFileLoaded();
- bool hasAssocFile = this.HasAssocFile();
-
- // Menus
- uiMenuNew.IsEnabled = !isFileLoaded;
- uiMenuOpen.IsEnabled = !isFileLoaded;
- uiMenuOpenOld.IsEnabled = !isFileLoaded;
- uiMenuOpenV1.IsEnabled = uiMenuOpenOld.IsEnabled;
-
- uiMenuSave.IsEnabled = isFileLoaded;
- uiMenuSaveAs.IsEnabled = isFileLoaded;
-
- uiMenuClose.IsEnabled = isFileLoaded;
- uiMenuQuit.IsEnabled = true;
-
- uiMenuSimulator.IsEnabled = isFileLoaded;
- uiMenuRender.IsEnabled = isFileLoaded;
-
- // Main Area
- uiMainTab.Visibility = isFileLoaded ? Visibility.Visible : Visibility.Collapsed;
-
- // Window Caption
- if (isFileLoaded) {
- if (hasAssocFile) {
- this.Title = $"HFUT课表模拟 - {CurrentFilePath}";
- } else {
- this.Title = "HFUT课表模拟 - [未命名]";
- }
- } else {
- this.Title = "HFUT课表模拟";
- }
- }
-
- ///
- /// 更新界面的数据源
- ///
- private void UpdateDataSource() {
- if (this.IsFileLoaded()) {
- this.DataContext = CurrentSemester;
- } else {
- this.DataContext = null;
- }
- }
+ private MainWindowContext _context;
#endregion
@@ -106,12 +121,8 @@ namespace HFUTCourseSimulation {
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();
+ _context.Semester = new Kernel.Data.Ui.Semester(new_obj);
+ _context.FilePath = null;
}
private void uiMenuOpen_Click(object sender, RoutedEventArgs e) {
@@ -125,17 +136,16 @@ namespace HFUTCourseSimulation {
// 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;
+ _context.Semester = new Kernel.Data.Ui.Semester(obj);
+ _context.FilePath = filepath;
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
return;
}
- // Update UI and data source
- UpdateUiLayout();
- UpdateDataSource();
+ // Show report
+ ReportStatus($"成功打开文件:{filepath}");
}
private void OpenLegacy() where T : Kernel.Data.Storage.IFromLegacy {
@@ -150,17 +160,16 @@ namespace HFUTCourseSimulation {
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;
+ _context.Semester = new Kernel.Data.Ui.Semester(latest_obj);
+ _context.FilePath = filepath;
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
return;
}
- // Update UI and data source
- UpdateUiLayout();
- UpdateDataSource();
+ // Show report
+ ReportStatus($"成功迁移文件:{filepath}");
}
private void uiMenuOpenV1_Click(object sender, RoutedEventArgs e) {
@@ -170,24 +179,24 @@ namespace HFUTCourseSimulation {
private void uiMenuSave_Click(object sender, RoutedEventArgs e) {
// Check whether there is associated file.
// If it not, order user select one.
- if (CurrentFilePath is null) {
+ if (!_context.HasAssocFile()) {
var filepath = Util.Win32Dialog.SaveSemester();
if (filepath is null) return;
- CurrentFilePath = filepath;
+ _context.FilePath = filepath;
}
// Try to save file
try {
- using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) {
- fs.Write(JsonConvert.SerializeObject(CurrentSemester.ToStorage()));
+ using (var fs = new StreamWriter(_context.FilePath, false, Encoding.UTF8)) {
+ fs.Write(JsonConvert.SerializeObject(_context.Semester.ToStorage()));
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
return;
}
- // Update UI
- UpdateUiLayout();
+ // Show report
+ ReportStatus($"已保存文件:{_context.FilePath}");
}
private void uiMenuSaveAs_Click(object sender, RoutedEventArgs e) {
@@ -196,20 +205,20 @@ namespace HFUTCourseSimulation {
if (filepath is null) return;
// Update it to current path for following editing.
- CurrentFilePath = filepath;
+ _context.FilePath = filepath;
// Try to save file
try {
- using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) {
- fs.Write(JsonConvert.SerializeObject(CurrentSemester.ToStorage()));
+ using (var fs = new StreamWriter(_context.FilePath, false, Encoding.UTF8)) {
+ fs.Write(JsonConvert.SerializeObject(_context.Semester.ToStorage()));
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
return;
}
- // Update UI
- UpdateUiLayout();
+ // Show report
+ ReportStatus($"已另存文件:{_context.FilePath}");
}
private void uiMenuClose_Click(object sender, RoutedEventArgs e) {
@@ -218,17 +227,16 @@ namespace HFUTCourseSimulation {
if (!rv) return;
// Clear semester and assoc file
- CurrentSemester = null;
- CurrentFilePath = null;
+ _context.Semester = null;
+ _context.FilePath = null;
- // Update UI and data source
- UpdateUiLayout();
- UpdateDataSource();
+ // Show report
+ ReportStatus($"文件已关闭");
}
private void uiMenuQuit_Click(object sender, RoutedEventArgs e) {
// If there is an opened document, let we confirm it first
- if (IsFileLoaded()) {
+ if (_context.IsFileLoaded()) {
var rv = Util.Win32Dialog.Confirm("确认退出吗?所有未保存的更改都将永久丢失!", "确认退出");
if (!rv) return;
}
@@ -238,13 +246,13 @@ namespace HFUTCourseSimulation {
}
private void uiMenuCheck_Click(object sender, RoutedEventArgs e) {
- var semester = CurrentSemester.ToStorage();
+ var semester = _context.Semester.ToStorage();
var reporter = new Kernel.Reporter();
var rv = Kernel.Arranger.Arrange(semester, reporter);
}
private void uiMenuSimulator_Click(object sender, RoutedEventArgs e) {
- var semester = CurrentSemester.ToStorage();
+ var semester = _context.Semester.ToStorage();
var reporter = new Kernel.Reporter();
var rv = Kernel.Arranger.Arrange(semester, reporter);
if (rv is null) return;
@@ -255,31 +263,7 @@ namespace HFUTCourseSimulation {
}
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;
- //}
-
- ////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);
-
- var semester = CurrentSemester.ToStorage();
+ var semester = _context.Semester.ToStorage();
var reporter = new Kernel.Reporter();
var rv = Kernel.Arranger.Arrange(semester, reporter);
if (rv is null) return;
@@ -289,7 +273,7 @@ namespace HFUTCourseSimulation {
if (filepath is null) return;
if (Kernel.Render.Rending(rv, filepath)) {
- Win32Dialog.Info("导出成功", "导出结果");
+ ReportStatus($"已导出图片:{filepath}");
} else {
Win32Dialog.Error("导出失败。请检查文件是否被占用,或检查GDI是否能正常使用。", "导出结果");
}
@@ -303,6 +287,17 @@ namespace HFUTCourseSimulation {
#endregion
+ #region Shortcut Handlers
+
+ private void commandCanExec_Loaded(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnLoaded;
+ private void commandCanExec_NotLoaded(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
+
+ private void commandMenuNew_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuNew_Click(sender, e);
+ private void commandMenuOpen_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuOpen_Click(sender, e);
+ private void commandMenuSave_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuSave_Click(sender, e);
+
+ #endregion
+
#region Main Area Handlers
private void uiCoursesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
@@ -321,10 +316,10 @@ namespace HFUTCourseSimulation {
var idx = uiCoursesList.SelectedIndex;
if (idx < 0) {
// No selection, append.
- CurrentSemester.Courses.Add(dialog.CurrentCourse);
+ _context.Semester.Courses.Add(dialog.CurrentCourse);
} else {
// Has selection, insert
- CurrentSemester.Courses.Insert(idx, dialog.CurrentCourse);
+ _context.Semester.Courses.Insert(idx, dialog.CurrentCourse);
}
}
@@ -333,7 +328,7 @@ namespace HFUTCourseSimulation {
if (idx < 0) return;
var dialog = new Dialog.EditCourse();
- dialog.CurrentCourse = CurrentSemester.Courses[idx];
+ dialog.CurrentCourse = _context.Semester.Courses[idx];
dialog.ShowDialog();
}
@@ -347,7 +342,7 @@ namespace HFUTCourseSimulation {
if (!rv) return;
// Remove it
- CurrentSemester.Courses.RemoveAt(idx);
+ _context.Semester.Courses.RemoveAt(idx);
}
private void uiCtxMenuClearCourse_Click(object sender, RoutedEventArgs e) {
@@ -356,7 +351,23 @@ namespace HFUTCourseSimulation {
if (!rv) return;
// Clear all schedules
- CurrentSemester.Courses.Clear();
+ _context.Semester.Courses.Clear();
+ }
+
+ #endregion
+
+ #region Status Bar
+
+ private DispatcherTimer reportTimeout;
+
+ private void ReportStatus(string message) {
+ reportTimeout.Stop();
+ reportTimeout.Start();
+ uiReportText.Text = message;
+ }
+
+ private void reportTimeout_Tick(object sender, EventArgs e) {
+ uiReportText.Text = "";
}
#endregion
diff --git a/HFUTCourseSimulation/Util/ColorConsistency.cs b/HFUTCourseSimulation/Util/ColorConsistency.cs
index 9d0cddb..109d71a 100644
--- a/HFUTCourseSimulation/Util/ColorConsistency.cs
+++ b/HFUTCourseSimulation/Util/ColorConsistency.cs
@@ -12,6 +12,12 @@ namespace HFUTCourseSimulation.Util {
///
public static class ColorConsistency {
+ ///
+ /// UI界面的背景色(白天或夜晚(然而没有实现,现在全是白天模式))
+ ///
+ public static ColorPair Backboard = new ColorPair(Colors.Black, Colors.White);
+ //public static ColorPair Backboard = new ColorPair(Colors.White, Colors.Black);
+
///
/// 获取标题栏的配色(星期几和日期)
///
@@ -40,7 +46,7 @@ namespace HFUTCourseSimulation.Util {
///
/// 棋盘中的异色颜色的配置
///
- public static Color ChessboardColor => Color.FromArgb(10, 0, 0, 0);
+ public static Color ChessboardColor => Color.FromArgb(20, 127, 127, 127);
}