fix: fix arranger error
This commit is contained in:
@ -9,108 +9,108 @@ using System.Windows;
|
|||||||
|
|
||||||
namespace HFUTCourseSimulation {
|
namespace HFUTCourseSimulation {
|
||||||
|
|
||||||
public static class ImageExport {
|
//public static class ImageExport {
|
||||||
|
|
||||||
public static readonly int WeekHeaderHeight = 50;
|
// public static readonly int WeekHeaderHeight = 50;
|
||||||
public static readonly int BodyCellWidth = 150;
|
// public static readonly int BodyCellWidth = 150;
|
||||||
public static readonly int BodyCellHeight = 80;
|
// public static readonly int BodyCellHeight = 80;
|
||||||
public static readonly int HeaderCellHeight = 40;
|
// public static readonly int HeaderCellHeight = 40;
|
||||||
public static readonly int LeftCellWidth = 25;
|
// public static readonly int LeftCellWidth = 25;
|
||||||
public static readonly int Blank = 20;
|
// public static readonly int Blank = 20;
|
||||||
|
|
||||||
static Dictionary<int, string> weekDict = new Dictionary<int, string>() {
|
// static Dictionary<int, string> weekDict = new Dictionary<int, string>() {
|
||||||
{0, "星期一"},
|
// {0, "星期一"},
|
||||||
{1, "星期二"},
|
// {1, "星期二"},
|
||||||
{2, "星期三"},
|
// {2, "星期三"},
|
||||||
{3, "星期四"},
|
// {3, "星期四"},
|
||||||
{4, "星期五"},
|
// {4, "星期五"},
|
||||||
{5, "星期六"},
|
// {5, "星期六"},
|
||||||
{6, "星期日"}
|
// {6, "星期日"}
|
||||||
};
|
// };
|
||||||
|
|
||||||
public static bool Export(DateTime startDate, int weekCount, string file) {
|
// public static bool Export(DateTime startDate, int weekCount, string file) {
|
||||||
|
|
||||||
var simuCore = new SimulationCore(startDate, weekCount);
|
// var simuCore = new SimulationCore(startDate, weekCount);
|
||||||
simuCore.Generate();
|
// simuCore.Generate();
|
||||||
if (simuCore.ErrorList.Count != 0) return false;
|
// if (simuCore.ErrorList.Count != 0) return false;
|
||||||
|
|
||||||
//define size
|
// //define size
|
||||||
int weekPerLine = (int)Math.Sqrt(weekCount) + 1;
|
// int weekPerLine = (int)Math.Sqrt(weekCount) + 1;
|
||||||
|
|
||||||
var weekWidth = (Blank + LeftCellWidth + 7 * BodyCellWidth);
|
// var weekWidth = (Blank + LeftCellWidth + 7 * BodyCellWidth);
|
||||||
var weekHeight = (Blank + WeekHeaderHeight + HeaderCellHeight + 11 * BodyCellHeight);
|
// var weekHeight = (Blank + WeekHeaderHeight + HeaderCellHeight + 11 * BodyCellHeight);
|
||||||
var img = new Bitmap(Blank + weekPerLine * weekWidth, Blank + (weekCount / weekPerLine + (weekCount % weekPerLine == 0 ? 0 : 1)) * weekHeight);
|
// var img = new Bitmap(Blank + weekPerLine * weekWidth, Blank + (weekCount / weekPerLine + (weekCount % weekPerLine == 0 ? 0 : 1)) * weekHeight);
|
||||||
var graphics = Graphics.FromImage(img);
|
// var graphics = Graphics.FromImage(img);
|
||||||
|
|
||||||
//declare graphics value
|
// //declare graphics value
|
||||||
var background = new SolidBrush(Color.White);
|
// var background = new SolidBrush(Color.White);
|
||||||
var headerBrush = new SolidBrush(Color.Gray);
|
// var headerBrush = new SolidBrush(Color.Gray);
|
||||||
var textBrush = new SolidBrush(Color.Black);
|
// var textBrush = new SolidBrush(Color.Black);
|
||||||
Brush cellBrush;
|
// Brush cellBrush;
|
||||||
var textFont = new Font("Microsoft YaHei UI", 12);
|
// var textFont = new Font("Microsoft YaHei UI", 12);
|
||||||
|
|
||||||
var textMargin = graphics.MeasureString("测试字符", textFont).Height;
|
// var textMargin = graphics.MeasureString("测试字符", textFont).Height;
|
||||||
|
|
||||||
//overlay all background
|
// //overlay all background
|
||||||
graphics.FillRectangle(background, 0, 0, Blank + weekPerLine * weekWidth, Blank + (weekCount / weekPerLine + (weekCount % weekPerLine == 0 ? 0 : 1)) * weekHeight);
|
// graphics.FillRectangle(background, 0, 0, Blank + weekPerLine * weekWidth, Blank + (weekCount / weekPerLine + (weekCount % weekPerLine == 0 ? 0 : 1)) * weekHeight);
|
||||||
|
|
||||||
//output each week
|
// //output each week
|
||||||
for (int i = 0; i < weekCount; i++) {
|
// for (int i = 0; i < weekCount; i++) {
|
||||||
//generate week data
|
// //generate week data
|
||||||
var weekData = simuCore.Render(i + 1);
|
// var weekData = simuCore.Render(i + 1);
|
||||||
|
|
||||||
//get start position
|
// //get start position
|
||||||
var top = Blank + (i / weekPerLine) * weekHeight;
|
// var top = Blank + (i / weekPerLine) * weekHeight;
|
||||||
var left = Blank + (i % weekPerLine) * weekWidth;
|
// var left = Blank + (i % weekPerLine) * weekWidth;
|
||||||
graphics.TranslateTransform(left, top);
|
// graphics.TranslateTransform(left, top);
|
||||||
|
|
||||||
//draw week head
|
// //draw week head
|
||||||
graphics.DrawString($"教学周:{weekData.WeekIndex}", textFont, textBrush, 0, 0);
|
// graphics.DrawString($"教学周:{weekData.WeekIndex}", textFont, textBrush, 0, 0);
|
||||||
//move transform
|
// //move transform
|
||||||
graphics.TranslateTransform(0, WeekHeaderHeight);
|
// graphics.TranslateTransform(0, WeekHeaderHeight);
|
||||||
|
|
||||||
|
|
||||||
//draw header
|
// //draw header
|
||||||
graphics.FillRectangle(headerBrush, 0, 0, weekWidth - Blank, HeaderCellHeight);
|
// graphics.FillRectangle(headerBrush, 0, 0, weekWidth - Blank, HeaderCellHeight);
|
||||||
graphics.FillRectangle(headerBrush, 0, 0, LeftCellWidth, weekHeight - WeekHeaderHeight - Blank);
|
// graphics.FillRectangle(headerBrush, 0, 0, LeftCellWidth, weekHeight - WeekHeaderHeight - Blank);
|
||||||
//draw header text
|
// //draw header text
|
||||||
for (int j = 0; j < 7; j++) {
|
// for (int j = 0; j < 7; j++) {
|
||||||
graphics.DrawString(weekDict[j], textFont, textBrush, LeftCellWidth + j * BodyCellWidth, 0);
|
// graphics.DrawString(weekDict[j], textFont, textBrush, LeftCellWidth + j * BodyCellWidth, 0);
|
||||||
graphics.DrawString(weekData.WeekDate[j], textFont, textBrush, LeftCellWidth + j * BodyCellWidth, textMargin);
|
// graphics.DrawString(weekData.WeekDate[j], textFont, textBrush, LeftCellWidth + j * BodyCellWidth, textMargin);
|
||||||
}
|
// }
|
||||||
//draw left text
|
// //draw left text
|
||||||
for (int j = 0; j < 11; j++) {
|
// for (int j = 0; j < 11; j++) {
|
||||||
graphics.DrawString((j + 1).ToString(), textFont, textBrush, 0, HeaderCellHeight + j * BodyCellHeight);
|
// graphics.DrawString((j + 1).ToString(), textFont, textBrush, 0, HeaderCellHeight + j * BodyCellHeight);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//move transform
|
// //move transform
|
||||||
graphics.TranslateTransform(LeftCellWidth, HeaderCellHeight);
|
// graphics.TranslateTransform(LeftCellWidth, HeaderCellHeight);
|
||||||
foreach(var courses in weekData.CourseList) {
|
// foreach(var courses in weekData.CourseList) {
|
||||||
var cellx = courses.Start.week - 1;
|
// var cellx = courses.Start.week - 1;
|
||||||
var celly = courses.Start.index - 1;
|
// var celly = courses.Start.index - 1;
|
||||||
//background
|
// //background
|
||||||
cellBrush = new SolidBrush(Util.ColorTrans.ToWinformColor(courses.BkColor));
|
// cellBrush = new SolidBrush(Util.ColorTrans.ToWinformColor(courses.BkColor));
|
||||||
graphics.FillRectangle(cellBrush, cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, BodyCellHeight * courses.Span);
|
// graphics.FillRectangle(cellBrush, cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, BodyCellHeight * courses.Span);
|
||||||
|
|
||||||
//draw text
|
// //draw text
|
||||||
var rect = new RectangleF(cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, celly * BodyCellHeight);
|
// var rect = new RectangleF(cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, celly * BodyCellHeight);
|
||||||
graphics.DrawString(courses.Name, textFont, textBrush, rect);
|
// graphics.DrawString(courses.Name, textFont, textBrush, rect);
|
||||||
var thisTextMargin = graphics.MeasureString(courses.Name, textFont, BodyCellWidth).Height;
|
// var thisTextMargin = graphics.MeasureString(courses.Name, textFont, BodyCellWidth).Height;
|
||||||
graphics.DrawString(courses.Desc, textFont, textBrush, cellx * BodyCellWidth, celly * BodyCellHeight + thisTextMargin);
|
// graphics.DrawString(courses.Desc, textFont, textBrush, cellx * BodyCellWidth, celly * BodyCellHeight + thisTextMargin);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//reset
|
// //reset
|
||||||
graphics.TranslateTransform(-LeftCellWidth, -HeaderCellHeight);
|
// graphics.TranslateTransform(-LeftCellWidth, -HeaderCellHeight);
|
||||||
graphics.TranslateTransform(0, -WeekHeaderHeight);
|
// graphics.TranslateTransform(0, -WeekHeaderHeight);
|
||||||
graphics.TranslateTransform(-left, -top);
|
// graphics.TranslateTransform(-left, -top);
|
||||||
}
|
// }
|
||||||
|
|
||||||
System.IO.File.Delete(file);
|
// System.IO.File.Delete(file);
|
||||||
img.Save(file, ImageFormat.Png);
|
// img.Save(file, ImageFormat.Png);
|
||||||
img.Dispose();
|
// img.Dispose();
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -187,14 +187,13 @@ namespace HFUTCourseSimulation.Kernel {
|
|||||||
const char DASH = '-';
|
const char DASH = '-';
|
||||||
|
|
||||||
// 分析文本组成,决定其整数集合类型
|
// 分析文本组成,决定其整数集合类型
|
||||||
|
// 如果包含DASH,则肯定是Range,否则按Individual处理
|
||||||
|
// (比如只有一项的Individual是没有COMMA的)
|
||||||
IntegerCollectionKind kind;
|
IntegerCollectionKind kind;
|
||||||
if (s.Contains(COMMA)) {
|
if (s.Contains(DASH)) {
|
||||||
kind = IntegerCollectionKind.Individual;
|
|
||||||
} else if (s.Contains(DASH)) {
|
|
||||||
kind = IntegerCollectionKind.Range;
|
kind = IntegerCollectionKind.Range;
|
||||||
} else {
|
} else {
|
||||||
reporter.Error($"{field_name}的值“{s}”无法被解析");
|
kind = IntegerCollectionKind.Individual;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据整数集合类型,决定分割用字符
|
// 根据整数集合类型,决定分割用字符
|
||||||
@ -322,15 +321,17 @@ namespace HFUTCourseSimulation.Kernel {
|
|||||||
lessons.Add(current_lesson);
|
lessons.Add(current_lesson);
|
||||||
current_lesson = null;
|
current_lesson = null;
|
||||||
}
|
}
|
||||||
// 然后设置当前课程
|
// 然后如果当前有课程,就设置当前课程
|
||||||
var this_course = semester.courses[this_course_index];
|
if (this_course_index >= 0) {
|
||||||
current_lesson = new Data.Presentation.Lesson() {
|
var this_course = semester.courses[this_course_index];
|
||||||
name = this_course.name,
|
current_lesson = new Data.Presentation.Lesson() {
|
||||||
description = this_course.description,
|
name = this_course.name,
|
||||||
color = this_course.color,
|
description = this_course.description,
|
||||||
startIndex = index,
|
color = this_course.color,
|
||||||
indexSpan = 1
|
startIndex = index,
|
||||||
};
|
indexSpan = 1
|
||||||
|
};
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 课程未曾发生改变,如果当前有课程,我们只需要单纯地自增其节次跨度
|
// 课程未曾发生改变,如果当前有课程,我们只需要单纯地自增其节次跨度
|
||||||
if (previous_course_index >= 0) {
|
if (previous_course_index >= 0) {
|
||||||
|
@ -55,7 +55,7 @@ namespace HFUTCourseSimulation.Kernel.Data.Built {
|
|||||||
private int _start, _end;
|
private int _start, _end;
|
||||||
|
|
||||||
public IEnumerator<int> GetEnumerator() {
|
public IEnumerator<int> GetEnumerator() {
|
||||||
return Enumerable.Range(_start, _end).GetEnumerator();
|
return Enumerable.Range(_start, _end - _start + 1).GetEnumerator();
|
||||||
}
|
}
|
||||||
IEnumerator IEnumerable.GetEnumerator() {
|
IEnumerator IEnumerable.GetEnumerator() {
|
||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
<MenuItem x:Name="uiMenuQuit" Header="退出" Click="uiMenuQuit_Click"/>
|
<MenuItem x:Name="uiMenuQuit" Header="退出" Click="uiMenuQuit_Click"/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="输出" Padding="5">
|
<MenuItem Header="输出" Padding="5">
|
||||||
|
<MenuItem x:Name="uiMenuCheck" Header="检查" Click="uiMenuCheck_Click"/>
|
||||||
<MenuItem x:Name="uiMenuSimulator" Header="实时模拟" Click="uiMenuSimulator_Click"/>
|
<MenuItem x:Name="uiMenuSimulator" Header="实时模拟" Click="uiMenuSimulator_Click"/>
|
||||||
<MenuItem x:Name="uiMenuRender" Header="导出为图片" Click="uiMenuRender_Click"/>
|
<MenuItem x:Name="uiMenuRender" Header="导出为图片" Click="uiMenuRender_Click"/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
@ -237,6 +237,12 @@ namespace HFUTCourseSimulation {
|
|||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void uiMenuCheck_Click(object sender, RoutedEventArgs e) {
|
||||||
|
var semester = CurrentSemester.ToStorage();
|
||||||
|
var reporter = new Kernel.Reporter();
|
||||||
|
var rv = Kernel.Arranger.Arrange(semester, reporter);
|
||||||
|
}
|
||||||
|
|
||||||
private void uiMenuSimulator_Click(object sender, RoutedEventArgs e) {
|
private void uiMenuSimulator_Click(object sender, RoutedEventArgs e) {
|
||||||
//var win = new Simulation();
|
//var win = new Simulation();
|
||||||
//win.ShowDialog();
|
//win.ShowDialog();
|
||||||
|
@ -18,44 +18,44 @@ namespace HFUTCourseSimulation {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Simulation : Window {
|
public partial class Simulation : Window {
|
||||||
|
|
||||||
SimulationCore simulationKernel;
|
//SimulationCore simulationKernel;
|
||||||
|
|
||||||
public Simulation() {
|
public Simulation() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
//init colums and rows
|
////init colums and rows
|
||||||
for (int i = 0; i < 11; i++) {
|
//for (int i = 0; i < 11; i++) {
|
||||||
var rows = new RowDefinition();
|
// var rows = new RowDefinition();
|
||||||
rows.Height = new GridLength(1, GridUnitType.Star);
|
// rows.Height = new GridLength(1, GridUnitType.Star);
|
||||||
this.uiArrangeGrid.RowDefinitions.Add(rows);
|
// this.uiArrangeGrid.RowDefinitions.Add(rows);
|
||||||
}
|
//}
|
||||||
|
|
||||||
for (int i = 0; i < 7; i++) {
|
//for (int i = 0; i < 7; i++) {
|
||||||
var colums = new ColumnDefinition();
|
// var colums = new ColumnDefinition();
|
||||||
colums.Width = new GridLength(1, GridUnitType.Star);
|
// colums.Width = new GridLength(1, GridUnitType.Star);
|
||||||
this.uiArrangeGrid.ColumnDefinitions.Add(colums);
|
// this.uiArrangeGrid.ColumnDefinitions.Add(colums);
|
||||||
}
|
//}
|
||||||
|
|
||||||
try {
|
//try {
|
||||||
originDate = DateTime.Parse(General.GeneralSheet.StartDate);
|
// originDate = DateTime.Parse(General.GeneralSheet.StartDate);
|
||||||
weekCount = General.GeneralSheet.WeekCount;
|
// weekCount = General.GeneralSheet.WeekCount;
|
||||||
} catch (Exception) {
|
//} catch (Exception) {
|
||||||
MessageBox.Show("周数或日期转换错误,请关闭窗口", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
// MessageBox.Show("周数或日期转换错误,请关闭窗口", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||||
this.uiArrangeError.IsEnabled = false;
|
// this.uiArrangeError.IsEnabled = false;
|
||||||
this.uiBtnNext.IsEnabled = false;
|
// this.uiBtnNext.IsEnabled = false;
|
||||||
this.uiBtnPre.IsEnabled = false;
|
// this.uiBtnPre.IsEnabled = false;
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
simulationKernel = new SimulationCore(originDate, weekCount);
|
//simulationKernel = new SimulationCore(originDate, weekCount);
|
||||||
simulationKernel.Generate();
|
//simulationKernel.Generate();
|
||||||
//refresh error list
|
////refresh error list
|
||||||
this.uiArrangeError.Items.Clear();
|
//this.uiArrangeError.Items.Clear();
|
||||||
foreach (var item in simulationKernel.ErrorList) {
|
//foreach (var item in simulationKernel.ErrorList) {
|
||||||
this.uiArrangeError.Items.Add(item);
|
// this.uiArrangeError.Items.Add(item);
|
||||||
}
|
//}
|
||||||
currentWeek = 1;
|
//currentWeek = 1;
|
||||||
this.RenderGrid(simulationKernel.Render(currentWeek));
|
//this.RenderGrid(simulationKernel.Render(currentWeek));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,67 +64,67 @@ namespace HFUTCourseSimulation {
|
|||||||
DateTime originDate;
|
DateTime originDate;
|
||||||
|
|
||||||
void RenderGrid(RenderWeek weekRes) {
|
void RenderGrid(RenderWeek weekRes) {
|
||||||
//set date
|
////set date
|
||||||
uiWeek.Text = weekRes.WeekIndex.ToString();
|
//uiWeek.Text = weekRes.WeekIndex.ToString();
|
||||||
uiWeek1.Text = weekRes.WeekDate[0];
|
//uiWeek1.Text = weekRes.WeekDate[0];
|
||||||
uiWeek2.Text = weekRes.WeekDate[1];
|
//uiWeek2.Text = weekRes.WeekDate[1];
|
||||||
uiWeek3.Text = weekRes.WeekDate[2];
|
//uiWeek3.Text = weekRes.WeekDate[2];
|
||||||
uiWeek4.Text = weekRes.WeekDate[3];
|
//uiWeek4.Text = weekRes.WeekDate[3];
|
||||||
uiWeek5.Text = weekRes.WeekDate[4];
|
//uiWeek5.Text = weekRes.WeekDate[4];
|
||||||
uiWeek6.Text = weekRes.WeekDate[5];
|
//uiWeek6.Text = weekRes.WeekDate[5];
|
||||||
uiWeek7.Text = weekRes.WeekDate[6];
|
//uiWeek7.Text = weekRes.WeekDate[6];
|
||||||
|
|
||||||
//remove all old grid
|
////remove all old grid
|
||||||
this.uiArrangeGrid.Children.Clear();
|
//this.uiArrangeGrid.Children.Clear();
|
||||||
|
|
||||||
//generate new
|
////generate new
|
||||||
foreach (var item in weekRes.CourseList) {
|
//foreach (var item in weekRes.CourseList) {
|
||||||
var warp = new Border();
|
// var warp = new Border();
|
||||||
warp.Background = new SolidColorBrush(item.BkColor);
|
// warp.Background = new SolidColorBrush(item.BkColor);
|
||||||
warp.CornerRadius = new CornerRadius(5);
|
// warp.CornerRadius = new CornerRadius(5);
|
||||||
Grid.SetRowSpan(warp, item.Span);
|
// Grid.SetRowSpan(warp, item.Span);
|
||||||
var nGrid = new Grid();
|
// var nGrid = new Grid();
|
||||||
nGrid.ToolTip = item.Desc;
|
// nGrid.ToolTip = item.Desc;
|
||||||
var courseName = new TextBlock();
|
// var courseName = new TextBlock();
|
||||||
courseName.VerticalAlignment = VerticalAlignment.Center;
|
// courseName.VerticalAlignment = VerticalAlignment.Center;
|
||||||
courseName.Text = item.Name;
|
// courseName.Text = item.Name;
|
||||||
nGrid.Children.Add(courseName);
|
// nGrid.Children.Add(courseName);
|
||||||
warp.Child = nGrid;
|
// warp.Child = nGrid;
|
||||||
|
|
||||||
Grid.SetRow(warp, item.Start.index - 1);
|
// Grid.SetRow(warp, item.Start.index - 1);
|
||||||
Grid.SetColumn(warp, item.Start.week - 1);
|
// Grid.SetColumn(warp, item.Start.week - 1);
|
||||||
|
|
||||||
this.uiArrangeGrid.Children.Add(warp);
|
// this.uiArrangeGrid.Children.Add(warp);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uiBtnPre_Click(object sender, RoutedEventArgs e) {
|
private void uiBtnPre_Click(object sender, RoutedEventArgs e) {
|
||||||
if (currentWeek == 1) {
|
//if (currentWeek == 1) {
|
||||||
MessageBox.Show("已经是第一周了", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
// MessageBox.Show("已经是第一周了", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
currentWeek--;
|
//currentWeek--;
|
||||||
this.RenderGrid(simulationKernel.Render(currentWeek));
|
//this.RenderGrid(simulationKernel.Render(currentWeek));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uiBtnNext_Click(object sender, RoutedEventArgs e) {
|
private void uiBtnNext_Click(object sender, RoutedEventArgs e) {
|
||||||
if (currentWeek == weekCount) {
|
//if (currentWeek == weekCount) {
|
||||||
MessageBox.Show("已经是最后一周了", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
// MessageBox.Show("已经是最后一周了", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
currentWeek++;
|
//currentWeek++;
|
||||||
this.RenderGrid(simulationKernel.Render(currentWeek));
|
//this.RenderGrid(simulationKernel.Render(currentWeek));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uiArrangeError_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
private void uiArrangeError_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||||
if (this.uiArrangeError.SelectedIndex < 0) {
|
//if (this.uiArrangeError.SelectedIndex < 0) {
|
||||||
MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
// MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
MessageBox.Show(this.simulationKernel.ErrorList[this.uiArrangeError.SelectedIndex], "错误详情", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
//MessageBox.Show(this.simulationKernel.ErrorList[this.uiArrangeError.SelectedIndex], "错误详情", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,156 +6,156 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace HFUTCourseSimulation {
|
namespace HFUTCourseSimulation {
|
||||||
public class SimulationCore {
|
//public class SimulationCore {
|
||||||
|
|
||||||
public SimulationCore(DateTime startDate, int weekCount) {
|
// public SimulationCore(DateTime startDate, int weekCount) {
|
||||||
this.weekCount = weekCount;
|
// this.weekCount = weekCount;
|
||||||
this.originDate = startDate;
|
// this.originDate = startDate;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Dictionary<Vector3, SimulationItem> itemDict = new Dictionary<Vector3, SimulationItem>();
|
// Dictionary<Vector3, SimulationItem> itemDict = new Dictionary<Vector3, SimulationItem>();
|
||||||
public List<string> ErrorList { get; } = new List<string>();
|
// public List<string> ErrorList { get; } = new List<string>();
|
||||||
|
|
||||||
//List<Grid> uiList = new List<Grid>();
|
// //List<Grid> uiList = new List<Grid>();
|
||||||
|
|
||||||
DateTime originDate;
|
// DateTime originDate;
|
||||||
int weekCount;
|
// int weekCount;
|
||||||
//int currentWeek;
|
// //int currentWeek;
|
||||||
|
|
||||||
public void Generate() {
|
// public void Generate() {
|
||||||
//pre-generate
|
// //pre-generate
|
||||||
foreach (var item in General.GeneralSheet.Courses) {
|
// foreach (var item in General.GeneralSheet.Courses) {
|
||||||
foreach (var inner in item.Schedule) {
|
// foreach (var inner in item.Schedule) {
|
||||||
var weekRes = GetArrange(inner.Week);
|
// var weekRes = GetArrange(inner.Week);
|
||||||
var dayRes = GetArrange(inner.Day);
|
// var dayRes = GetArrange(inner.Day);
|
||||||
var indexRes = GetArrange(inner.Index);
|
// var indexRes = GetArrange(inner.Index);
|
||||||
|
|
||||||
foreach (var weekItem in weekRes) {
|
// foreach (var weekItem in weekRes) {
|
||||||
foreach (var dayItem in dayRes) {
|
// foreach (var dayItem in dayRes) {
|
||||||
foreach (var indexItem in indexRes) {
|
// foreach (var indexItem in indexRes) {
|
||||||
var vectorCache = new Vector3(weekItem, dayItem, indexItem);
|
// var vectorCache = new Vector3(weekItem, dayItem, indexItem);
|
||||||
if (this.itemDict.Keys.Contains(vectorCache)) {
|
// if (this.itemDict.Keys.Contains(vectorCache)) {
|
||||||
ErrorList.Add($"课程冲突:无法将{item.Name}安排到 {weekItem}周,星期{dayItem},第{indexItem}节。因为此处已被{itemDict[vectorCache].Name}占据");
|
// ErrorList.Add($"课程冲突:无法将{item.Name}安排到 {weekItem}周,星期{dayItem},第{indexItem}节。因为此处已被{itemDict[vectorCache].Name}占据");
|
||||||
} else {
|
// } else {
|
||||||
itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWpfColor(item.BkColor) });
|
// itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWpfColor(item.BkColor) });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
List<int> GetArrange(string str) {
|
// List<int> GetArrange(string str) {
|
||||||
var res = new List<int>();
|
// var res = new List<int>();
|
||||||
try {
|
// try {
|
||||||
if (str.Contains('-')) {
|
// if (str.Contains('-')) {
|
||||||
var strSp = str.Split('-');
|
// var strSp = str.Split('-');
|
||||||
int start = int.Parse(strSp[0]), end = int.Parse(strSp[1]);
|
// int start = int.Parse(strSp[0]), end = int.Parse(strSp[1]);
|
||||||
for (int i = start; i <= end; i++) {
|
// for (int i = start; i <= end; i++) {
|
||||||
res.Add(i);
|
// res.Add(i);
|
||||||
}
|
// }
|
||||||
|
|
||||||
} else if (str.Contains(',')) {
|
// } else if (str.Contains(',')) {
|
||||||
var strSp = str.Split(',');
|
// var strSp = str.Split(',');
|
||||||
foreach (var item in strSp) {
|
// foreach (var item in strSp) {
|
||||||
res.Add(int.Parse(item));
|
// res.Add(int.Parse(item));
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
res.Add(int.Parse(str));
|
// res.Add(int.Parse(str));
|
||||||
}
|
// }
|
||||||
} catch (Exception) {
|
// } catch (Exception) {
|
||||||
ErrorList.Add("解析错误:" + str);
|
// ErrorList.Add("解析错误:" + str);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return res;
|
// return res;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public RenderWeek Render(int currentWeek) {
|
// public RenderWeek Render(int currentWeek) {
|
||||||
//remove all old grid
|
// //remove all old grid
|
||||||
var result = new RenderWeek();
|
// var result = new RenderWeek();
|
||||||
result.WeekDate = new List<string>();
|
// result.WeekDate = new List<string>();
|
||||||
|
|
||||||
//update date
|
// //update date
|
||||||
//comput start date
|
// //comput start date
|
||||||
result.WeekIndex = currentWeek;
|
// result.WeekIndex = currentWeek;
|
||||||
var pointer = originDate;
|
// var pointer = originDate;
|
||||||
pointer = pointer.AddDays(7 * (currentWeek - 1));
|
// pointer = pointer.AddDays(7 * (currentWeek - 1));
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
pointer = pointer.AddDays(1);
|
// pointer = pointer.AddDays(1);
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
pointer = pointer.AddDays(1);
|
// pointer = pointer.AddDays(1);
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
pointer = pointer.AddDays(1);
|
// pointer = pointer.AddDays(1);
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
pointer = pointer.AddDays(1);
|
// pointer = pointer.AddDays(1);
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
pointer = pointer.AddDays(1);
|
// pointer = pointer.AddDays(1);
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
pointer = pointer.AddDays(1);
|
// pointer = pointer.AddDays(1);
|
||||||
result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
// result.WeekDate.Add($"{pointer.Month}/{pointer.Day}");
|
||||||
|
|
||||||
result.CourseList = new List<SimulationRenderItem>();
|
// result.CourseList = new List<SimulationRenderItem>();
|
||||||
//create grid
|
// //create grid
|
||||||
var query = (from item in itemDict.Keys
|
// var query = (from item in itemDict.Keys
|
||||||
where item.teachingweek == currentWeek
|
// where item.teachingweek == currentWeek
|
||||||
select item).ToList();
|
// select item).ToList();
|
||||||
|
|
||||||
while (query.Count != 0) {
|
// while (query.Count != 0) {
|
||||||
var core = query[0];
|
// var core = query[0];
|
||||||
var data = itemDict[core];
|
// var data = itemDict[core];
|
||||||
|
|
||||||
int length = 1;
|
// int length = 1;
|
||||||
//check below
|
// //check below
|
||||||
if (core.index != 1 && query.Contains(core + new Vector3(0, 0, -1))) {
|
// if (core.index != 1 && query.Contains(core + new Vector3(0, 0, -1))) {
|
||||||
if (itemDict[core + new Vector3(0, 0, -1)].Name == data.Name) {
|
// if (itemDict[core + new Vector3(0, 0, -1)].Name == data.Name) {
|
||||||
//if below have. jump this->move this to the end
|
// //if below have. jump this->move this to the end
|
||||||
query.RemoveAt(0);
|
// query.RemoveAt(0);
|
||||||
query.Add(core);
|
// query.Add(core);
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//check follow
|
// //check follow
|
||||||
while (true) {
|
// while (true) {
|
||||||
if (query.Contains(core + new Vector3(0, 0, length)) && itemDict[core + new Vector3(0, 0, length)].Name == data.Name) {
|
// if (query.Contains(core + new Vector3(0, 0, length)) && itemDict[core + new Vector3(0, 0, length)].Name == data.Name) {
|
||||||
query.Remove(core + new Vector3(0, 0, length));
|
// query.Remove(core + new Vector3(0, 0, length));
|
||||||
length++;
|
// length++;
|
||||||
} else break;
|
// } else break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
//create
|
// //create
|
||||||
result.CourseList.Add(new SimulationRenderItem() { Name = data.Name, Desc = data.Desc, BkColor = data.BkColor, Start = core, Span = length });
|
// result.CourseList.Add(new SimulationRenderItem() { Name = data.Name, Desc = data.Desc, BkColor = data.BkColor, Start = core, Span = length });
|
||||||
/*
|
// /*
|
||||||
var warp = new Border();
|
// var warp = new Border();
|
||||||
warp.Background = new SolidColorBrush(Colors.LightBlue);
|
// warp.Background = new SolidColorBrush(Colors.LightBlue);
|
||||||
warp.CornerRadius = new CornerRadius(5);
|
// warp.CornerRadius = new CornerRadius(5);
|
||||||
Grid.SetRowSpan(warp, length);
|
// Grid.SetRowSpan(warp, length);
|
||||||
var nGrid = new Grid();
|
// var nGrid = new Grid();
|
||||||
nGrid.ToolTip = data.Desc;
|
// nGrid.ToolTip = data.Desc;
|
||||||
var courseName = new TextBlock();
|
// var courseName = new TextBlock();
|
||||||
courseName.VerticalAlignment = VerticalAlignment.Center;
|
// courseName.VerticalAlignment = VerticalAlignment.Center;
|
||||||
courseName.Text = data.Name;
|
// courseName.Text = data.Name;
|
||||||
nGrid.Children.Add(courseName);
|
// nGrid.Children.Add(courseName);
|
||||||
warp.Child = nGrid;
|
// warp.Child = nGrid;
|
||||||
|
|
||||||
Grid.SetRow(warp, core.index - 1);
|
// Grid.SetRow(warp, core.index - 1);
|
||||||
Grid.SetColumn(warp, core.week - 1);
|
// Grid.SetColumn(warp, core.week - 1);
|
||||||
|
|
||||||
this.uiArrangeGrid.Children.Add(warp);
|
// this.uiArrangeGrid.Children.Add(warp);
|
||||||
*/
|
// */
|
||||||
|
|
||||||
//remove first item
|
// //remove first item
|
||||||
query.RemoveAt(0);
|
// query.RemoveAt(0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user