You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
9.4 KiB
212 lines
9.4 KiB
using DyeingComputer.UserClass;
|
|
using DyeingComputer.ViewModel;
|
|
using DyeingComputer.Windows;
|
|
using ScottPlot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
using System.Xml.Linq;
|
|
using static DyeingComputer.UserClass.SqliteHelper;
|
|
using static DyeingComputer.Windows.ViewProgram;
|
|
using static System.Collections.Specialized.BitVector32;
|
|
|
|
namespace DyeingComputer.View
|
|
{
|
|
/// <summary>
|
|
/// WorkOrder.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class WorkOrderView : UserControl
|
|
{
|
|
public WorkOrderView()
|
|
{
|
|
DataContext = new WorkOrderViewModel();
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
string S09 = SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'S09'", null).ToString(); //读取
|
|
string S10 = SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'S10'", null).ToString();
|
|
string S11 = SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'S11'", null).ToString();
|
|
SQLiteHelpers.Close();
|
|
if (S09 == "0") WorkOrderView_new.IsEnabled = false;//禁止用户新建
|
|
if (S10 == "0") WorkOrderView_del.IsEnabled = false;
|
|
if (S11 == "0") WorkOrderView_redy.IsEnabled = false;
|
|
|
|
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
|
{
|
|
Interval = TimeSpan.FromSeconds(1)//秒
|
|
};
|
|
timer1s.Tick += Tick_Event_1S;
|
|
timer1s.Start();
|
|
}
|
|
void Tick_Event_1S(object sender, EventArgs e)
|
|
{
|
|
Workorder_sql();
|
|
}
|
|
|
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
|
DataSet sql; //内存数据缓存
|
|
Dictionary<string, object> updata_temp = new Dictionary<string, object>();//缓存函数
|
|
|
|
string WorkOrder_Numder;
|
|
string Process_Name;
|
|
string Process_id;
|
|
string _lock;
|
|
|
|
public void Workorder_sql()
|
|
{
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
string sql_script = "select * from WorkOrder where StartTime > '" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "'";
|
|
|
|
if (sql != null) sql.Clear(); //清空缓存
|
|
sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取计划表写入缓存
|
|
if (sql != null) Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
WorkOrder_Numder = null;
|
|
Process_Name = null;
|
|
Process_id = null;
|
|
_lock = null;
|
|
//sql.Clear(); //清除缓存
|
|
//System.GC.Collect();
|
|
}
|
|
|
|
|
|
private void WorkOrderView_lock_Click(object sender, RoutedEventArgs e)//锁定按钮
|
|
{
|
|
if (WorkOrder_Numder == null) return;
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
updata_temp.Clear();//使用前清理缓存
|
|
if (_lock == "0") //改变lock的状态
|
|
{
|
|
updata_temp.Add("lock", 1);
|
|
SQLiteHelpers.Update("WorkOrder", updata_temp, "WorkOrder='" + WorkOrder_Numder + "'", null);
|
|
}
|
|
else
|
|
{
|
|
updata_temp.Add("lock", 0);
|
|
SQLiteHelpers.Update("WorkOrder", updata_temp, "WorkOrder='" + WorkOrder_Numder + "'", null);
|
|
}
|
|
SQLiteHelpers.Close();
|
|
Workorder_sql();
|
|
}
|
|
|
|
private void WorkOrderView_new_Click(object sender, RoutedEventArgs e)//新建按钮
|
|
{
|
|
ViewProgram viewProgram = new ViewProgram();
|
|
viewProgram.AddressUpdated += new ViewProgram.AddressUpdateHandler(Address_ButtonClicked);
|
|
viewProgram.ShowDialog();
|
|
}
|
|
private void Address_ButtonClicked(object sender, AddressUpdateEventArgs e)//编辑返回结果
|
|
{
|
|
MainWindowViewModel.WorkNumder = DateTime.Now.ToString("yyMMddHHmmss");
|
|
TechnologicalProcessView.workName = e.ID;
|
|
|
|
var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;//跨页面
|
|
_mainWindow.container.Content = new TechnologicalProcessView();//获取控件
|
|
}
|
|
private void WorkOrderView_del_Click(object sender, RoutedEventArgs e)//删除按钮
|
|
{
|
|
if (WorkOrder_Numder == null) return;
|
|
///弹窗提示确认删除
|
|
if (System.Windows.Forms.MessageBox.Show(Properties.Resources.Confirm + Properties.Resources.Delete + WorkOrder_Numder, "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", "WorkOrder='" + WorkOrder_Numder + "'", null);
|
|
SQLiteHelpers.Close();
|
|
Workorder_sql();
|
|
}
|
|
}
|
|
|
|
private void WorkOrderView_redy_Click(object sender, RoutedEventArgs e)//重染按钮
|
|
{
|
|
string WorkNum = MainWindowViewModel.WorkNumder.ToString();
|
|
if (WorkNum != null)
|
|
{
|
|
if (System.Windows.Forms.MessageBox.Show(Properties.Resources.Confirm + Properties.Resources.Redye + WorkNum, "Redye ",
|
|
System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
///执行重染
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)//表格选择事件
|
|
{
|
|
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
{
|
|
WorkOrder_Numder = (Grid.Columns[0].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
|
Process_Name = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
Process_id = (Grid.Columns[2].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
|
_lock = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
}
|
|
}
|
|
|
|
private void UserControl_KeyDown(object sender, KeyEventArgs e) //键盘监控
|
|
{
|
|
if (e.Key == Key.Y) //按键y
|
|
{
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
string sql_script = "select * from ProgramName where ProgramID = '" + Process_id + "'";
|
|
int i = SQLiteHelpers.ExecuteDataSet(sql_script, null).Tables[0].Rows.Count; //读取工艺表返回0工艺不存在
|
|
|
|
if (i == 0) //工艺不存在提示
|
|
{
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
WorkOrder_Numder = null;
|
|
Process_id = null;
|
|
if (System.Windows.Forms.MessageBox.Show("["+Process_Name+"] "+ Properties.Resources.process_not, "800 ",
|
|
System.Windows.Forms.MessageBoxButtons.OK) == System.Windows.Forms.DialogResult.OK) return;
|
|
}
|
|
else //否则修改工艺执行状态
|
|
{
|
|
updata_temp.Clear(); //使用前清缓存
|
|
updata_temp.Add("State", 101);
|
|
SQLiteHelpers.Update("WorkOrder", updata_temp, "ProgramID='" + Process_id + "'", null);
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
}
|
|
|
|
if (Process_id != null) //选定工艺有效跳转准备
|
|
{
|
|
MainWindowViewModel.WorkNumder = WorkOrder_Numder;
|
|
TechnologicalProcessView.workName = Process_id;
|
|
MainWindowViewModel.SYS_REDYE = 0;
|
|
|
|
MainWindowViewModel.ViewID = 1;
|
|
var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;//跨页面
|
|
_mainWindow.container.Content = new TechnologicalProcessView();//获取控件
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|