Add color support

This commit is contained in:
2018-12-26 16:38:29 +08:00
parent 2aa5e38035
commit c6012ef490
6 changed files with 35 additions and 2 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace HFUTCourseSimulation {
@ -22,11 +23,13 @@ namespace HFUTCourseSimulation {
public class CourseItem {
public CourseItem() {
BkColor = Colors.LightBlue.ColorToInt();
this.Schedule = new List<ScheduleItem>();
}
public string Name { get; set; }
public string Description { get; set; }
public int BkColor { get; set; }
public List<ScheduleItem> Schedule { get; set; }
@ -34,6 +37,7 @@ namespace HFUTCourseSimulation {
var newobj = new CourseItem();
newobj.Name = this.Name;
newobj.Description = this.Description;
newobj.BkColor = this.BkColor;
newobj.Schedule = new List<ScheduleItem>();
newobj.Schedule.AddRange((from item in this.Schedule select item.Clone()));
return newobj;

View File

@ -39,6 +39,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />

View File

@ -113,6 +113,17 @@ namespace HFUTCourseSimulation {
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));
}
}
}

View File

@ -73,6 +73,10 @@
<TextBlock Text="课程名称" Margin="10,10,10,5"/>
<TextBox x:Name="uiCourseName" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" TextChanged="uiCourseName_TextChanged"/>
<TextBlock Text="课程颜色" Margin="10,10,10,5"/>
<Border x:Name="uiCourseColor" Height="20" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" BorderBrush="Black" BorderThickness="1"/>
<Button x:Name="uiCourseBtnColor" Content="选择颜色" HorizontalAlignment="Left" Margin="10,0,10,10" Click="uiCourseBtnColor_Click"/>
<TextBlock Text="注释" Margin="10,10,10,5"/>
<TextBox x:Name="uiCourseDescription" Height="100" Width="400" HorizontalAlignment="Left" Margin="10,0,10,10" AcceptsReturn="True" TextChanged="uiCourseDescription_TextChanged"/>
</StackPanel>

View File

@ -176,7 +176,7 @@ namespace HFUTCourseSimulation {
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);
@ -260,6 +260,7 @@ namespace HFUTCourseSimulation {
this.uiCourseName.Text = General.CourseCache.Name;
this.uiCourseDescription.Text = General.CourseCache.Description;
this.uiCourseColor.Background = new SolidColorBrush(General.CourseCache.BkColor.IntToColor());
SyncScheduleListData();
@ -365,6 +366,18 @@ namespace HFUTCourseSimulation {
General.CourseCache.Description = this.uiCourseDescription.Text;
}
private void uiCourseBtnColor_Click(object sender, RoutedEventArgs e) {
var cor = new System.Windows.Forms.ColorDialog();
var status = cor.ShowDialog();
if (!(status == System.Windows.Forms.DialogResult.OK)) return;
var color = cor.Color.ConvertWinformColor();
//force a channel
color.A = 255;
General.CourseCache.BkColor = color.ColorToInt();
this.uiCourseColor.Background = new SolidColorBrush(color);
}
//main
private void uiDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e) {
if (isUpdatingData) return;

View File

@ -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 = Colors.LightBlue });
itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = item.BkColor.IntToColor() });
}
}
}