|
|
|
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;
|
|
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if(!SQL_UPDATE) 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;
|
|
|
|
bool SQL_UPDATE = false;
|
|
|
|
|
|
|
|
public void Workorder_sql()
|
|
|
|
{
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
|
|
|
|
string sql_script = "select * from WorkOrder where EndTime > '" + 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
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列,
|
|
|
|
|
|
|
|
SQL_UPDATE = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UserControl_KeyDown(object sender, KeyEventArgs e) //键盘监控
|
|
|
|
{
|
|
|
|
if (e.Key == Key.Y) //按键
|
|
|
|
{
|
|
|
|
if(string.IsNullOrEmpty(WorkOrder_Numder)) return;
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
|
|
|
|
updata_temp.Clear(); //使用前清缓存
|
|
|
|
updata_temp.Add("State", 101);
|
|
|
|
SQLiteHelpers.Update("WorkOrder", updata_temp, "WorkOrder='" + WorkOrder_Numder + "'", null);
|
|
|
|
|
|
|
|
DataTable WorkorderSteps = SQLiteHelpers.ExecuteDataSet(
|
|
|
|
"select * from WorkorderSteps where WorkOrder='" + WorkOrder_Numder + "'", null).Tables[0]; //读取表写入缓存
|
|
|
|
MainWindowViewModel.ProgramName = Process_Name;
|
|
|
|
SQLiteHelpers.Delete("RUN", null, null); //删除run信息
|
|
|
|
DataTable data_t = new DataTable();
|
|
|
|
data_t = WorkorderSteps.Clone();
|
|
|
|
int a = WorkorderSteps.Rows.Count;
|
|
|
|
for (int i = 0; i < a; i++)
|
|
|
|
{
|
|
|
|
data_t.Clear();//清空
|
|
|
|
DataRow dt = WorkorderSteps.Rows[i];//行转
|
|
|
|
DataRow dr = data_t.NewRow();
|
|
|
|
dr.ItemArray = dt.ItemArray;
|
|
|
|
dr.BeginEdit(); //添加订单号
|
|
|
|
dr["ProgramID"] = Process_id;
|
|
|
|
dr["Program"] = MainWindowViewModel.ProgramName;
|
|
|
|
dr.EndEdit();
|
|
|
|
data_t.Rows.InsertAt(dr, 0); //行转换
|
|
|
|
|
|
|
|
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
|
|
}
|
|
|
|
|
|
|
|
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();//获取控件
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void start_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|