|
|
|
using LiveChartsCore;
|
|
|
|
using SunlightCentralizedControlManagement_SCCM_.UserClass;
|
|
|
|
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data;
|
|
|
|
using System.Data.Entity;
|
|
|
|
using System.Data.SQLite;
|
|
|
|
using System.Diagnostics.Eventing.Reader;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Controls;
|
|
|
|
using System.Windows.Controls.Primitives;
|
|
|
|
using System.Windows.Data;
|
|
|
|
using System.Windows.Documents;
|
|
|
|
using System.Windows.Input;
|
|
|
|
using System.Windows.Media;
|
|
|
|
using System.Windows.Media.Animation;
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using System.Drawing;
|
|
|
|
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
|
|
|
using static SunlightCentralizedControlManagement_SCCM_.WindowsView.ViewStep;
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
|
|
|
|
using LiveChartsCore.SkiaSharpView.WPF;
|
|
|
|
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
|
|
|
|
using nGantt.GanttChart;
|
|
|
|
using nGantt;
|
|
|
|
using nGantt.PeriodSplitter;
|
|
|
|
using ScottPlot.TickGenerators.TimeUnits;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Windows.Markup;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SunlightCentralizedControlManagement_SCCM_.View
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// ProgramgroupView.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class ProductionPlanningView : UserControl
|
|
|
|
{
|
|
|
|
public ProductionPlanningView()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
DataContext = new ProductionPlanningModel();
|
|
|
|
Sdatepicker.Language = XmlLanguage.GetLanguage(Configini.IniReadvalue("SYS", "Language"));
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
|
|
|
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|
|
|
DataTable WorkOrder;
|
|
|
|
private DateTime minDate;
|
|
|
|
private DateTime maxDate;
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
|
|
|
|
{
|
|
|
|
Sdatepicker.Text = DateTime.Now.ToString("yyyy/MM/dd");
|
|
|
|
minDate = DateTime.Now.Date;
|
|
|
|
maxDate = minDate.AddDays(1);
|
|
|
|
//添加表右键功能
|
|
|
|
ganttTaskContextMenuItems.Add(new ContextMenuItem(ViewClicked, Properties.Resources.View + "..."));
|
|
|
|
ganttTaskContextMenuItems.Add(new ContextMenuItem(ViewClicked, Properties.Resources.Advance + "..."));
|
|
|
|
ganttTaskContextMenuItems.Add(new ContextMenuItem(ViewClicked, Properties.Resources.Delayed + "..."));
|
|
|
|
ganttTaskContextMenuItems.Add(new ContextMenuItem(EditClicked, Properties.Resources.edit + "..."));
|
|
|
|
ganttTaskContextMenuItems.Add(new ContextMenuItem(DeleteClicked, Properties.Resources.Delete + "..."));
|
|
|
|
GanttChart.GanttTaskContextMenuItems = ganttTaskContextMenuItems;
|
|
|
|
|
|
|
|
GanttChartNEW();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ObservableCollection<ContextMenuItem> ganttTaskContextMenuItems = new ObservableCollection<ContextMenuItem>();
|
|
|
|
private void GanttChartNEW()
|
|
|
|
{
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
WorkOrder = SQLiteHelpers.ExecuteDataSet(
|
|
|
|
"select * from WorkOrder where StartTime>'" + Sdatepicker.Text
|
|
|
|
+ "'or EndTime>'" + Sdatepicker.Text + "'Order by StartTime", null).Tables[0]; //读取表写入缓存
|
|
|
|
SQLiteHelpers.Close();
|
|
|
|
|
|
|
|
//生成表
|
|
|
|
GanttChart.ClearGantt();
|
|
|
|
GanttChart.Initialize(minDate, maxDate);
|
|
|
|
var gridLineTimeLine = GanttChart.CreateTimeLine(new PeriodDaySplitter(minDate, maxDate), FormatDay);
|
|
|
|
GanttChart.CreateTimeLine(new PeriodHourSplitter(minDate, maxDate), FormatHour);
|
|
|
|
|
|
|
|
// Set the timeline to atatch gridlines to
|
|
|
|
GanttChart.SetGridLinesTimeline(gridLineTimeLine, DetermineBackground);
|
|
|
|
var rowgroup = GanttChart.CreateGanttRowGroup();
|
|
|
|
|
|
|
|
//生成表信息
|
|
|
|
List<string> Chart_machines = MainWindowViewModel.Machines.AsEnumerable().Select(rowdata => rowdata.Field<string>("name")).ToList();//转换列名为机台
|
|
|
|
for (int i= 0; i<Chart_machines.Count(); i++)//列表机台号
|
|
|
|
{
|
|
|
|
var row = GanttChart.CreateGanttRow(rowgroup, Chart_machines[i]);
|
|
|
|
DataRow[] dataRows = WorkOrder.Select("Machines='"+ Chart_machines[i]+"'");
|
|
|
|
|
|
|
|
for (int j = 0; j < dataRows.Count(); j++) //列表排程
|
|
|
|
{
|
|
|
|
// if(string.IsNullOrEmpty(dataRows[j].Field<string>("color")))
|
|
|
|
|
|
|
|
GanttChart.AddGanttTask(row, new GanttTask() {
|
|
|
|
Start = DateTime.Parse(dataRows[j].Field<string>("StartTime")),
|
|
|
|
End = DateTime.Parse(dataRows[j].Field<string>("EndTime")),
|
|
|
|
Name = Properties.Resources.ProcessName +";"+ dataRows[j].Field<string>("ProgramName"),
|
|
|
|
TaskProgressVisibility = System.Windows.Visibility.Hidden });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}//创建日程图
|
|
|
|
private void ViewClicked(GanttTask ganttTask)
|
|
|
|
{
|
|
|
|
MessageBox.Show("New clicked for task " + ganttTask.Name);
|
|
|
|
}
|
|
|
|
private void EditClicked(GanttTask ganttTask)
|
|
|
|
{
|
|
|
|
MessageBox.Show("Edit clicked for task " + ganttTask.Name);
|
|
|
|
}
|
|
|
|
private void DeleteClicked(GanttTask ganttTask)//删除
|
|
|
|
{
|
|
|
|
if (System.Windows.Forms.MessageBox.Show(Properties.Resources.Confirm + Properties.Resources.Delete + ganttTask.Name, "Delete ",
|
|
|
|
System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
|
|
|
|
{
|
|
|
|
///执行删除
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
SQLiteHelpers.Delete(
|
|
|
|
"WorkOrder", "StartTime='" + ganttTask.Start + "'and EndTime='" + ganttTask.End + "'", null);
|
|
|
|
SQLiteHelpers.Close();
|
|
|
|
GanttChartNEW();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private string FormatYear(Period period)
|
|
|
|
{
|
|
|
|
return period.Start.Year.ToString();
|
|
|
|
}
|
|
|
|
private string FormatMonth(Period period)
|
|
|
|
{
|
|
|
|
return period.Start.Month.ToString();
|
|
|
|
}
|
|
|
|
private string FormatDay(Period period)
|
|
|
|
{
|
|
|
|
return period.Start.Day.ToString();
|
|
|
|
}
|
|
|
|
private string FormatDayName(Period period)
|
|
|
|
{
|
|
|
|
return period.Start.DayOfWeek.ToString();
|
|
|
|
}
|
|
|
|
private string FormatHour(Period period)
|
|
|
|
{
|
|
|
|
return period.Start.Hour.ToString();
|
|
|
|
}
|
|
|
|
private System.Windows.Media.Brush DetermineBackground(TimeLineItem timeLineItem)
|
|
|
|
{
|
|
|
|
if (timeLineItem.End.Date.DayOfWeek == DayOfWeek.Saturday || timeLineItem.End.Date.DayOfWeek == DayOfWeek.Sunday)
|
|
|
|
return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.LightBlue);
|
|
|
|
else
|
|
|
|
return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent);
|
|
|
|
}
|
|
|
|
private void ListViewItem_New(object sender, System.Windows.Input.MouseButtonEventArgs e)//新建事件
|
|
|
|
{
|
|
|
|
Picture.Width = 600;
|
|
|
|
Picture.Content = new ProductionPlanningEdit();
|
|
|
|
}
|
|
|
|
private void WorkOrderNumder_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
// Select_WorkOrderNumder.Text;
|
|
|
|
}
|
|
|
|
private void ListViewItem_Before(object sender, MouseButtonEventArgs e)//前一天
|
|
|
|
{
|
|
|
|
Sdatepicker.Text = DateTime.Parse(Sdatepicker.Text).AddDays(-1).ToString("yyyy/MM/dd");
|
|
|
|
}
|
|
|
|
private void ListViewItem_Today(object sender, MouseButtonEventArgs e)//今天
|
|
|
|
{
|
|
|
|
Sdatepicker.Text = DateTime.Now.ToString("yyyy/MM/dd");
|
|
|
|
}
|
|
|
|
private void ListViewItem_DayAfter(object sender, MouseButtonEventArgs e)//后一天
|
|
|
|
{
|
|
|
|
Sdatepicker.Text = DateTime.Parse(Sdatepicker.Text).AddDays(1).ToString("yyyy/MM/dd");
|
|
|
|
}
|
|
|
|
private void Sdatepicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)//时间控件
|
|
|
|
{
|
|
|
|
minDate = DateTime.Parse(sender.ToString());
|
|
|
|
maxDate = DateTime.Parse(sender.ToString()).AddDays(1);
|
|
|
|
GanttChartNEW();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|