refactor: add old format support
This commit is contained in:
@ -23,7 +23,7 @@ namespace HFUTCourseSimulation {
|
||||
public class CourseItem {
|
||||
|
||||
public CourseItem() {
|
||||
BkColor = Colors.LightBlue.ColorToInt();
|
||||
//BkColor = Colors.LightBlue.ColorToInt();
|
||||
this.Schedule = new List<ScheduleItem>();
|
||||
}
|
||||
|
||||
|
@ -21,22 +21,22 @@
|
||||
<ScrollViewer>
|
||||
<StackPanel Orientation="Vertical" Margin="10,0,10,0">
|
||||
<TextBlock Text="课程名称" FontWeight="Bold" Margin="0,10,0,0"/>
|
||||
<TextBox Text="{Binding name, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding Name, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0"/>
|
||||
|
||||
<TextBlock Text="课程颜色" FontWeight="Bold" Padding="5" Margin="0,10,0,0"/>
|
||||
<Border ToolTip="单击改变颜色" Width="200" HorizontalAlignment="Left" BorderBrush="Black" BorderThickness="1" Cursor="Hand" Margin="0,5,0,0">
|
||||
<Border.Background>
|
||||
<SolidColorBrush Color="{Binding color.background, Mode=TwoWay}"/>
|
||||
<SolidColorBrush Color="{Binding Color.Background, Mode=TwoWay}"/>
|
||||
</Border.Background>
|
||||
<TextBlock Text="示例颜色" Margin="5">
|
||||
<TextBlock.Foreground>
|
||||
<SolidColorBrush Color="{Binding color.foreground, Mode=TwoWay}"/>
|
||||
<SolidColorBrush Color="{Binding Color.Foreground, Mode=TwoWay}"/>
|
||||
</TextBlock.Foreground>
|
||||
</TextBlock>
|
||||
</Border>
|
||||
|
||||
<TextBlock Text="注释" FontWeight="Bold" Margin="0,10,0,0"/>
|
||||
<TextBox Text="{Binding description, Mode=TwoWay}" Height="100" Width="400" HorizontalAlignment="Left" AcceptsReturn="True" Padding="5" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding Description, Mode=TwoWay}" Height="100" Width="400" HorizontalAlignment="Left" AcceptsReturn="True" Padding="5" Margin="0,5,0,0"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
@ -21,17 +21,17 @@
|
||||
<TextBlock Text="周设置" FontWeight="Bold" Margin="0,10,0,0"/>
|
||||
<TextBlock Text="输入格式:开始周-结束周 或 周号1,周号2,周号3" Margin="0,5,0,0"/>
|
||||
<TextBlock Text="例如:3-11 或 1,3,5" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding week, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding Week, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
|
||||
|
||||
<TextBlock Text="课程星期" FontWeight="Bold" Margin="0,10,0,0"/>
|
||||
<TextBlock Text="输入格式:开始星期-结束星期 或 星期号1,星期号2,星期号3 或 星期号" Margin="0,5,0,0"/>
|
||||
<TextBlock Text="例如:3-7 或 1,3,5 或 6" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding day, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding Day, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
|
||||
|
||||
<TextBlock Text="当日课程节次" FontWeight="Bold" Margin="0,10,0,0"/>
|
||||
<TextBlock Text="输入格式:开始节次-结束节次 或 节次号1,节次号2,节次号3" Margin="0,5,0,0"/>
|
||||
<TextBlock Text="例如:3-11 或 1,3,5" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding index, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding Index, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
@ -85,6 +85,7 @@
|
||||
<Compile Include="ImageExport.cs" />
|
||||
<Compile Include="Kernel\Context.cs" />
|
||||
<Compile Include="Kernel\MsgRecorder.cs" />
|
||||
<Compile Include="Kernel\OldUserData\V1.cs" />
|
||||
<Compile Include="Kernel\SimData.cs" />
|
||||
<Compile Include="Kernel\UserData.cs" />
|
||||
<Compile Include="Simulation.xaml.cs">
|
||||
@ -92,7 +93,8 @@
|
||||
</Compile>
|
||||
<Compile Include="SimulationCore.cs" />
|
||||
<Compile Include="SimulationItem.cs" />
|
||||
<Compile Include="Util\ColorPreset.cs" />
|
||||
<Compile Include="Util\ColorPair.cs" />
|
||||
<Compile Include="Util\ColorTrans.cs" />
|
||||
<Compile Include="Util\Win32Dialog.cs" />
|
||||
<Page Include="Dialog\EditCourse.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
|
@ -89,7 +89,7 @@ namespace HFUTCourseSimulation {
|
||||
var cellx = courses.Start.week - 1;
|
||||
var celly = courses.Start.index - 1;
|
||||
//background
|
||||
cellBrush = new SolidBrush(courses.BkColor.ConvertWPFColor());
|
||||
cellBrush = new SolidBrush(Util.ColorTrans.ToWpfColor(courses.BkColor));
|
||||
graphics.FillRectangle(cellBrush, cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, BodyCellHeight * courses.Span);
|
||||
|
||||
//draw text
|
||||
@ -113,21 +113,4 @@ namespace HFUTCourseSimulation {
|
||||
|
||||
}
|
||||
|
||||
public static class WPFColorConvert {
|
||||
public static System.Drawing.Color ConvertWPFColor(this System.Windows.Media.Color c) {
|
||||
return System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
|
||||
}
|
||||
public static System.Windows.Media.Color ConvertWinformColor(this System.Drawing.Color c) {
|
||||
return System.Windows.Media.Color.FromArgb(c.A, c.R, c.G, c.B);
|
||||
}
|
||||
public static int ColorToInt(this System.Windows.Media.Color c) {
|
||||
return (c.R << 16) + (c.G << 8) + c.B;
|
||||
}
|
||||
public static System.Windows.Media.Color IntToColor(this int num) {
|
||||
var cache = (num >> 16) << 16;
|
||||
var cache2 = (num >> 8) << 8;
|
||||
return System.Windows.Media.Color.FromArgb(255, (byte)(num >> 16), (byte)((cache2 - cache) >> 8), (byte)(num - cache2));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
126
HFUTCourseSimulation/Kernel/OldUserData/V1.cs
Normal file
126
HFUTCourseSimulation/Kernel/OldUserData/V1.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using HFUTCourseSimulation.Kernel.UserData;
|
||||
using HFUTCourseSimulation.Util;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HFUTCourseSimulation.Kernel.OldUserData.V1 {
|
||||
|
||||
public class Semester {
|
||||
public Semester() {
|
||||
this.Courses = new List<CourseItem>();
|
||||
StartDate = DateTime.Today;
|
||||
WeekCount = 1;
|
||||
}
|
||||
|
||||
[JsonProperty("StartDate")]
|
||||
[JsonConverter(typeof(CustomDateTimeConverter))]
|
||||
public DateTime StartDate { get; set; }
|
||||
[JsonProperty("WeekCount")]
|
||||
public int WeekCount { get; set; }
|
||||
[JsonProperty("Courses")]
|
||||
public List<CourseItem> Courses { get; set; }
|
||||
|
||||
public UserData.Semester ToLatest() {
|
||||
return new UserData.Semester() {
|
||||
StartDate = StartDate,
|
||||
WeekCount = WeekCount.ToString(),
|
||||
// Other properties keep original value.
|
||||
Courses = Courses.Select((item) => item.ToLatest()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class CourseItem {
|
||||
public CourseItem() {
|
||||
BkColor = Colors.LightBlue;
|
||||
this.Schedule = new List<ScheduleItem>();
|
||||
}
|
||||
|
||||
[JsonProperty("Name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("Description")]
|
||||
public string Description { get; set; }
|
||||
[JsonProperty("BkColor")]
|
||||
[JsonConverter(typeof(CustomColorConverter))]
|
||||
public Color BkColor { get; set; }
|
||||
[JsonProperty("Schedule")]
|
||||
public List<ScheduleItem> Schedule { get; set; }
|
||||
|
||||
public UserData.Course ToLatest() {
|
||||
return new UserData.Course() {
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Color = new UserData.ColorPair() {
|
||||
Foreground = System.Drawing.Color.White,
|
||||
Background = ColorTrans.ToWpfColor(BkColor)
|
||||
},
|
||||
Schedules = Schedule.Select((item) => item.ToLatest()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class ScheduleItem {
|
||||
[JsonProperty("Week")]
|
||||
public string Week { get; set; }
|
||||
[JsonProperty("Day")]
|
||||
public string Day { get; set; }
|
||||
[JsonProperty("Index")]
|
||||
public string Index { get; set; }
|
||||
|
||||
public UserData.Schedule ToLatest() {
|
||||
return new UserData.Schedule() {
|
||||
Week = Week,
|
||||
Day = Day,
|
||||
Index = Index
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class CustomDateTimeConverter : JsonConverter<DateTime> {
|
||||
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer) {
|
||||
if (reader.TokenType == JsonToken.String) {
|
||||
var value = reader.Value as string;
|
||||
if (DateTime.TryParse(value, out DateTime rv)) {
|
||||
return rv;
|
||||
} else {
|
||||
throw new JsonSerializationException($"given string can not be parsed as DateTime: {value}");
|
||||
}
|
||||
} else {
|
||||
throw new JsonSerializationException($"expect a string but got {reader.TokenType}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer) {
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal class CustomColorConverter : JsonConverter<Color> {
|
||||
public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer) {
|
||||
if (reader.TokenType == JsonToken.Integer) {
|
||||
var argb = Convert.ToInt32(reader.Value);
|
||||
// Read color and force set its Alpha to zero.
|
||||
var rv = Util.ColorTrans.ToWinformColor(argb);
|
||||
rv.A = 255;
|
||||
return rv;
|
||||
} else {
|
||||
throw new JsonSerializationException($"expect a integer but got {reader.TokenType}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, Color value, JsonSerializer serializer) {
|
||||
// Reset its alpha to zero when saving.
|
||||
var copied = value;
|
||||
copied.A = 255;
|
||||
writer.WriteValue(Util.ColorTrans.ToInt(copied));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@ -7,6 +6,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HFUTCourseSimulation.Util;
|
||||
|
||||
namespace HFUTCourseSimulation.Kernel.UserData {
|
||||
|
||||
@ -15,13 +15,13 @@ namespace HFUTCourseSimulation.Kernel.UserData {
|
||||
/// </summary>
|
||||
public class Semester {
|
||||
public Semester() {
|
||||
startDate = DateTime.Today;
|
||||
weekCount = 20.ToString();
|
||||
indexCount = 11.ToString();
|
||||
breakfastAt = 0.ToString();
|
||||
lunchAt = 4.ToString();
|
||||
dinnerAt = 8.ToString();
|
||||
courses = new List<Course>();
|
||||
StartDate = DateTime.Today;
|
||||
WeekCount = 20.ToString();
|
||||
IndexCount = 11.ToString();
|
||||
BreakfastAt = 0.ToString();
|
||||
LunchAt = 4.ToString();
|
||||
DinnerAt = 8.ToString();
|
||||
Courses = new List<Course>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -29,100 +29,100 @@ namespace HFUTCourseSimulation.Kernel.UserData {
|
||||
/// </summary>
|
||||
[JsonProperty("start_date")]
|
||||
[JsonConverter(typeof(CustomDateTimeConverter))]
|
||||
public DateTime startDate { get; set; }
|
||||
public DateTime StartDate { get; set; }
|
||||
/// <summary>
|
||||
/// 教学周个数
|
||||
/// </summary>
|
||||
[JsonProperty("week_count")]
|
||||
public string weekCount { get; set; }
|
||||
public string WeekCount { get; set; }
|
||||
/// <summary>
|
||||
/// 每天课程的节次数
|
||||
/// </summary>
|
||||
[JsonProperty("index_count")]
|
||||
public string indexCount { get; set; }
|
||||
public string IndexCount { get; set; }
|
||||
/// <summary>
|
||||
/// 早餐插入在第几节次后
|
||||
/// </summary>
|
||||
[JsonProperty("breakfast_at")]
|
||||
public string breakfastAt { get; set; }
|
||||
public string BreakfastAt { get; set; }
|
||||
/// <summary>
|
||||
/// 午餐插入在第几节次后
|
||||
/// </summary>
|
||||
[JsonProperty("lunch_at")]
|
||||
public string lunchAt { get; set; }
|
||||
public string LunchAt { get; set; }
|
||||
/// <summary>
|
||||
/// 晚餐插入在第几节次后
|
||||
/// </summary>
|
||||
[JsonProperty("dinner_at")]
|
||||
public string dinnerAt { get; set; }
|
||||
public string DinnerAt { get; set; }
|
||||
/// <summary>
|
||||
/// 课程列表
|
||||
/// </summary>
|
||||
[JsonProperty("courses")]
|
||||
public List<Course> courses { get; set; }
|
||||
public List<Course> Courses { get; set; }
|
||||
}
|
||||
|
||||
public class Course {
|
||||
public Course() {
|
||||
name = "";
|
||||
description = "";
|
||||
color = Util.ColorPreset.MdColors.Indigo;
|
||||
schedules = new List<Schedule>();
|
||||
Name = "";
|
||||
Description = "";
|
||||
Color = ColorTrans.ToStorageColor(Util.ColorPreset.MdColors.Indigo);
|
||||
Schedules = new List<Schedule>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 课程的名称
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string name { get; set; }
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 课程的说明,例如教室位置,教师姓名等。
|
||||
/// </summary>
|
||||
[JsonProperty("description")]
|
||||
public string description { get; set; }
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 课程的颜色
|
||||
/// </summary>
|
||||
[JsonProperty("color")]
|
||||
public ColorPair color { get; set; }
|
||||
public ColorPair Color { get; set; }
|
||||
/// <summary>
|
||||
/// 课程的所有安排
|
||||
/// </summary>
|
||||
[JsonProperty("schedules")]
|
||||
public List<Schedule> schedules { get; set; }
|
||||
public List<Schedule> Schedules { get; set; }
|
||||
}
|
||||
|
||||
public class Schedule {
|
||||
public Schedule() {
|
||||
week = "";
|
||||
day = "";
|
||||
index = "";
|
||||
Week = "";
|
||||
Day = "";
|
||||
Index = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 安排在哪些周
|
||||
/// </summary>
|
||||
[JsonProperty("week")]
|
||||
public string week { get; set; }
|
||||
public string Week { get; set; }
|
||||
/// <summary>
|
||||
/// 安排在周的星期几
|
||||
/// </summary>
|
||||
[JsonProperty("day")]
|
||||
public string day { get; set; }
|
||||
public string Day { get; set; }
|
||||
/// <summary>
|
||||
/// 安排在这些日子的哪些节次
|
||||
/// </summary>
|
||||
[JsonProperty("index")]
|
||||
public string index { get; set; }
|
||||
public string Index { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表一个颜色对,包括前景色和背景色
|
||||
/// 存储时所用的颜色对,与辅助类里的颜色对有所区别。
|
||||
/// </summary>
|
||||
public struct ColorPair {
|
||||
public ColorPair(Color foreground, Color background) {
|
||||
this.foreground = foreground;
|
||||
this.background = background;
|
||||
public class ColorPair {
|
||||
public ColorPair() {
|
||||
Foreground = Color.Black;
|
||||
Background = Color.White;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -130,13 +130,13 @@ namespace HFUTCourseSimulation.Kernel.UserData {
|
||||
/// </summary>
|
||||
[JsonProperty("foreground")]
|
||||
[JsonConverter(typeof(CustomColorConverter))]
|
||||
public Color foreground { get; set; }
|
||||
public Color Foreground { get; set; }
|
||||
/// <summary>
|
||||
/// 背景色
|
||||
/// </summary>
|
||||
[JsonProperty("background")]
|
||||
[JsonConverter(typeof(CustomColorConverter))]
|
||||
public Color background { get; set; }
|
||||
public Color Background { get; set; }
|
||||
}
|
||||
|
||||
internal class CustomDateTimeConverter : JsonConverter<DateTime> {
|
||||
|
@ -45,28 +45,28 @@
|
||||
<ScrollViewer>
|
||||
<StackPanel Orientation="Vertical" Margin="10,0,10,0">
|
||||
<TextBlock Text="起始日期(教学第一周星期一的日期)" Margin="0,20,0,0"/>
|
||||
<DatePicker SelectedDate="{Binding startDate}" Height="25" Width="200" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<DatePicker SelectedDate="{Binding StartDate}" Height="25" Width="200" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
|
||||
<TextBlock Text="本学期教学周数" Margin="0,20,0,0"/>
|
||||
<TextBox Text="{Binding weekCount, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBox Text="{Binding WeekCount, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
|
||||
<TextBlock Text="每天节次数" Margin="0,20,0,0"/>
|
||||
<TextBox Text="{Binding indexCount, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBox Text="{Binding IndexCount, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="早餐在哪个节次后" Margin="0,10,0,0"/>
|
||||
<TextBox Text="{Binding breakfastAt, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBox Text="{Binding BreakfastAt, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="午餐在哪个节次后" Margin="0,10,0,0"/>
|
||||
<TextBox Text="{Binding lunchAt, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBox Text="{Binding LunchAt, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="晚餐在哪个节次后" Margin="0,10,0,0"/>
|
||||
<TextBox Text="{Binding dinnerAt, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
<TextBox Text="{Binding DinnerAt, Mode=TwoWay}" Width="200" Padding="5" Margin="0,5,0,0" HorizontalAlignment="Left"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
<TabItem Header="课程设置" Padding="5">
|
||||
<ListBox x:Name="uiCoursesList" ItemsSource="{Binding courses}" Margin="10" MouseDoubleClick="uiCoursesList_MouseDoubleClick">
|
||||
<ListBox x:Name="uiCoursesList" ItemsSource="{Binding Courses}" Margin="10" MouseDoubleClick="uiCoursesList_MouseDoubleClick">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid d:DataContext="{d:DesignInstance userdata:Course}">
|
||||
<TextBlock Text="{Binding name}"/>
|
||||
<TextBlock Text="{Binding Name, Mode=OneWay}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
@ -128,6 +128,21 @@ 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<Kernel.OldUserData.V1.Semester>(fs.ReadToEnd());
|
||||
context.currentSemester = obj.ToLatest();
|
||||
context.currentFilePath = filepath;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
|
||||
return;
|
||||
}
|
||||
|
||||
// Update UI and data source
|
||||
UpdateUiLayout();
|
||||
|
@ -37,7 +37,7 @@ namespace HFUTCourseSimulation {
|
||||
if (this.itemDict.Keys.Contains(vectorCache)) {
|
||||
ErrorList.Add($"课程冲突:无法将{item.Name}安排到 {weekItem}周,星期{dayItem},第{indexItem}节。因为此处已被{itemDict[vectorCache].Name}占据");
|
||||
} else {
|
||||
itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = item.BkColor.IntToColor() });
|
||||
itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWinformColor(item.BkColor) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
61
HFUTCourseSimulation/Util/ColorPair.cs
Normal file
61
HFUTCourseSimulation/Util/ColorPair.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HFUTCourseSimulation.Util {
|
||||
|
||||
/// <summary>
|
||||
/// 代表一个颜色对,包括前景色和背景色
|
||||
/// </summary>
|
||||
public struct ColorPair {
|
||||
public ColorPair(Color foreground, Color background) {
|
||||
this.Foreground = foreground;
|
||||
this.Background = background;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前景色(文本的颜色)
|
||||
/// </summary>
|
||||
public Color Foreground { get; set; }
|
||||
/// <summary>
|
||||
/// 背景色
|
||||
/// </summary>
|
||||
public Color Background { get; set; }
|
||||
}
|
||||
|
||||
namespace ColorPreset {
|
||||
|
||||
/// <summary>
|
||||
/// Material Design颜色合集
|
||||
/// </summary>
|
||||
public static class MdColors {
|
||||
private static Color LightText => Color.White;
|
||||
private static Color DarkText => Color.FromArgb(33, 33, 33);
|
||||
|
||||
public static ColorPair Red => new ColorPair(LightText, Color.FromArgb(244, 67, 54));
|
||||
public static ColorPair Pink => new ColorPair(LightText, Color.FromArgb(233, 30, 99));
|
||||
public static ColorPair Purple => new ColorPair(LightText, Color.FromArgb(156, 39, 176));
|
||||
public static ColorPair DeepPurple => new ColorPair(LightText, Color.FromArgb(103, 58, 183));
|
||||
public static ColorPair Indigo => new ColorPair(LightText, Color.FromArgb(63, 81, 181));
|
||||
public static ColorPair Blue => new ColorPair(LightText, Color.FromArgb(33, 150, 243));
|
||||
public static ColorPair LightBlue => new ColorPair(LightText, Color.FromArgb(3, 169, 244));
|
||||
public static ColorPair Cyan => new ColorPair(LightText, Color.FromArgb(0, 188, 212));
|
||||
public static ColorPair Teal => new ColorPair(LightText, Color.FromArgb(0, 150, 136));
|
||||
public static ColorPair Green => new ColorPair(LightText, Color.FromArgb(76, 175, 80));
|
||||
public static ColorPair LightGreen => new ColorPair(DarkText, Color.FromArgb(139, 195, 74));
|
||||
public static ColorPair Lime => new ColorPair(DarkText, Color.FromArgb(205, 220, 57));
|
||||
public static ColorPair Yellow => new ColorPair(DarkText, Color.FromArgb(255, 235, 59));
|
||||
public static ColorPair Amber => new ColorPair(DarkText, Color.FromArgb(255, 193, 7));
|
||||
public static ColorPair Orange => new ColorPair(DarkText, Color.FromArgb(255, 152, 0));
|
||||
public static ColorPair DeepOrange => new ColorPair(LightText, Color.FromArgb(255, 87, 34));
|
||||
public static ColorPair Brown => new ColorPair(LightText, Color.FromArgb(121, 85, 72));
|
||||
public static ColorPair Grey => new ColorPair(DarkText, Color.FromArgb(158, 158, 158));
|
||||
public static ColorPair BlueGrey => new ColorPair(LightText, Color.FromArgb(96, 125, 139));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
using HFUTCourseSimulation.Kernel.UserData;
|
||||
|
||||
namespace HFUTCourseSimulation.Util.ColorPreset {
|
||||
|
||||
/// <summary>
|
||||
/// Material Design颜色合集
|
||||
/// </summary>
|
||||
public static class MdColors {
|
||||
private static Color LightText => Color.White;
|
||||
private static Color DarkText => Color.FromArgb(33, 33, 33);
|
||||
|
||||
public static ColorPair Red => new ColorPair(LightText, Color.FromArgb(244, 67, 54));
|
||||
public static ColorPair Pink => new ColorPair(LightText, Color.FromArgb(233, 30, 99));
|
||||
public static ColorPair Purple => new ColorPair(LightText, Color.FromArgb(156, 39, 176));
|
||||
public static ColorPair DeepPurple => new ColorPair(LightText, Color.FromArgb(103, 58, 183));
|
||||
public static ColorPair Indigo => new ColorPair(LightText, Color.FromArgb(63, 81, 181));
|
||||
public static ColorPair Blue => new ColorPair(LightText, Color.FromArgb(33, 150, 243));
|
||||
public static ColorPair LightBlue => new ColorPair(LightText, Color.FromArgb(3, 169, 244));
|
||||
public static ColorPair Cyan => new ColorPair(LightText, Color.FromArgb(0, 188, 212));
|
||||
public static ColorPair Teal => new ColorPair(LightText, Color.FromArgb(0, 150, 136));
|
||||
public static ColorPair Green => new ColorPair(LightText, Color.FromArgb(76, 175, 80));
|
||||
public static ColorPair LightGreen => new ColorPair(DarkText, Color.FromArgb(139, 195, 74));
|
||||
public static ColorPair Lime => new ColorPair(DarkText, Color.FromArgb(205, 220, 57));
|
||||
public static ColorPair Yellow => new ColorPair(DarkText, Color.FromArgb(255, 235, 59));
|
||||
public static ColorPair Amber => new ColorPair(DarkText, Color.FromArgb(255, 193, 7));
|
||||
public static ColorPair Orange => new ColorPair(DarkText, Color.FromArgb(255, 152, 0));
|
||||
public static ColorPair DeepOrange => new ColorPair(LightText, Color.FromArgb(255, 87, 34));
|
||||
public static ColorPair Brown => new ColorPair(LightText, Color.FromArgb(121, 85, 72));
|
||||
public static ColorPair Grey => new ColorPair(DarkText, Color.FromArgb(158, 158, 158));
|
||||
public static ColorPair BlueGrey => new ColorPair(LightText, Color.FromArgb(96, 125, 139));
|
||||
}
|
||||
|
||||
}
|
68
HFUTCourseSimulation/Util/ColorTrans.cs
Normal file
68
HFUTCourseSimulation/Util/ColorTrans.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using WinformColor = System.Windows.Media.Color;
|
||||
using WpfColor = System.Drawing.Color;
|
||||
|
||||
using StorageColorPair = HFUTCourseSimulation.Kernel.UserData.ColorPair;
|
||||
using RuntimeColorPair = HFUTCourseSimulation.Util.ColorPair;
|
||||
|
||||
namespace HFUTCourseSimulation.Util {
|
||||
|
||||
public static class ColorTrans {
|
||||
|
||||
#region Color Transform
|
||||
|
||||
public static WpfColor ToWpfColor(int argb) {
|
||||
return WpfColor.FromArgb(argb);
|
||||
}
|
||||
|
||||
public static WpfColor ToWpfColor(WinformColor c) {
|
||||
return WpfColor.FromArgb(c.A, c.R, c.G, c.B);
|
||||
}
|
||||
|
||||
public static WinformColor ToWinformColor(int _argb) {
|
||||
var argb = (uint)_argb;
|
||||
var a = (argb & 0xff000000) >> 24;
|
||||
var r = (argb & 0x00ff0000) >> 16;
|
||||
var g = (argb & 0x0000ff00) >> 8;
|
||||
var b = (argb & 0x000000ff);
|
||||
return WinformColor.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
|
||||
}
|
||||
|
||||
public static WinformColor ToWinformColor(WpfColor c) {
|
||||
return WinformColor.FromArgb(c.A, c.R, c.G, c.B);
|
||||
}
|
||||
|
||||
public static int ToInt(WpfColor c) {
|
||||
return c.ToArgb();
|
||||
}
|
||||
|
||||
public static int ToInt(WinformColor c) {
|
||||
uint argb = 0;
|
||||
argb |= c.A; argb <<= 8;
|
||||
argb |= c.R; argb <<= 8;
|
||||
argb |= c.G; argb <<= 8;
|
||||
argb |= c.B;
|
||||
return (int)argb;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Color Pair Transform
|
||||
|
||||
public static StorageColorPair ToStorageColor(RuntimeColorPair cp) {
|
||||
return new StorageColorPair() { Foreground = cp.Foreground, Background = cp.Background };
|
||||
}
|
||||
|
||||
public static RuntimeColorPair ToRuntimeColor(StorageColorPair cp) {
|
||||
return new RuntimeColorPair(cp.Foreground, cp.Background);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user