|
|
|
using DyeingComputer.UserClass;
|
|
|
|
using DyeingComputer.ViewModel;
|
|
|
|
using DyeingComputer.Windows;
|
|
|
|
using ScottPlot;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
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.Animation;
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
using System.Windows.Threading;
|
|
|
|
using static DyeingComputer.UserClass.SqliteHelper;
|
|
|
|
using static DyeingComputer.ViewModel.MainWindowViewModel;
|
|
|
|
using static DyeingComputer.Windows.ViewStep;
|
|
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
|
|
|
|
namespace DyeingComputer.View
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// TechnologicalProcessView.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class TechnologicalProcessView : UserControl
|
|
|
|
{
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName)
|
|
|
|
{
|
|
|
|
if (PropertyChanged != null)
|
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
}
|
|
|
|
public void RaisePropertyChanged(string propertyName)
|
|
|
|
{
|
|
|
|
if (PropertyChanged != null)
|
|
|
|
{
|
|
|
|
if (propertyName != null)
|
|
|
|
{
|
|
|
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public TechnologicalProcessView()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
//Grid.DataContext = new MainWindowViewModel();
|
|
|
|
// FocusManager.SetFocusedElement(Grid, Grid);
|
|
|
|
// if (workName != null)
|
|
|
|
// {
|
|
|
|
// TechnologicalProcess_Import();
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
TechnologicalProcess_sql();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ProgramgroupView_edit.IsEnabled = false;
|
|
|
|
// ProgramgroupView_del.IsEnabled = false;
|
|
|
|
// ProgramgroupView_Insert.IsEnabled = false;
|
|
|
|
tblDatas.Columns.Add("Name", Type.GetType("System.String"));
|
|
|
|
tblDatas.Columns.Add("Value", Type.GetType("System.Double"));
|
|
|
|
tblDatas.Columns.Add("ID", Type.GetType("System.String"));
|
|
|
|
|
|
|
|
DataRow newRow;
|
|
|
|
newRow = tblDatas.NewRow();
|
|
|
|
newRow["Name"] = Properties.Resources.PumpSpeed;//
|
|
|
|
newRow["Value"] = MainWindowViewModel.Selet_dtm("1020");
|
|
|
|
newRow["ID"] = "1020";
|
|
|
|
tblDatas.Rows.Add(newRow);
|
|
|
|
}
|
|
|
|
DataTable tblDatas = new DataTable("Datas");
|
|
|
|
public static object workName;
|
|
|
|
public static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
|
|
public static readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
|
|
|
public static DataSet sql; //内存数据缓存
|
|
|
|
private void TechnologicalProcess_Import()
|
|
|
|
{
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
int r = 0;
|
|
|
|
string sql_script = "select * from WorkorderSteps where ProgramID = '" + workName + "'";
|
|
|
|
if (sql != null) sql.Clear(); //清空缓存
|
|
|
|
sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取表写入缓存
|
|
|
|
MainWindowViewModel.ProgramName = SQLiteHelpers.ExecuteScalar("select ProgramName from WorkOrder where ProgramID = '" + workName + "'", null).ToString();
|
|
|
|
if (sql != null) dt_TP = sql.Tables[0]; //转换显示计划表
|
|
|
|
|
|
|
|
SQLiteHelpers.Delete("RUN", null, null); //删除run信息
|
|
|
|
DataTable data_t = new DataTable();
|
|
|
|
data_t = sql.Tables[0].Clone();
|
|
|
|
data_t.Columns.Add("DYELOT", typeof(string)); //添加列
|
|
|
|
int a = sql.Tables[0].Rows.Count;
|
|
|
|
for (int i = 0; i < a; i++)
|
|
|
|
{
|
|
|
|
data_t.Clear();//清空
|
|
|
|
DataRow dt = sql.Tables[0].Rows[i];//行转
|
|
|
|
DataRow dr = data_t.NewRow();
|
|
|
|
dr.ItemArray = dt.ItemArray;
|
|
|
|
dr.BeginEdit(); //添加订单号
|
|
|
|
dr["DYELOT"] = MainWindowViewModel.WorkNumder;
|
|
|
|
dr.EndEdit();
|
|
|
|
data_t.Rows.InsertAt(dr, 0); //行转换
|
|
|
|
|
|
|
|
r = SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
|
|
}
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TechnologicalProcess_sql()
|
|
|
|
{
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
string sql_script = "select * from RUN";
|
|
|
|
if (sql != null) sql.Clear(); //清空缓存
|
|
|
|
sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取表写入缓存
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MainWindowViewModel.ProgramName = SQLiteHelpers.ExecuteScalar("select Program from RUN where Step = '1'", null).ToString();
|
|
|
|
MainWindowViewModel.WorkNumder = SQLiteHelpers.ExecuteScalar("select WorkOrder from RUN where Step = '1'", null).ToString();
|
|
|
|
}
|
|
|
|
catch (Exception) { }
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
|
|
|
|
if (sql != null) dt_TP = sql.Tables[0]; //转换显示计划表
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
// FocusManager.SetFocusedElement(Grid, Grid);
|
|
|
|
// Grid.DataContext = new MainWindowViewModel();
|
|
|
|
if (workName != null)
|
|
|
|
{
|
|
|
|
GridSTEP.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (MainWindowViewModel.WORK_RUN != 0) GridSTEP.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
|
|
|
|
}
|
|
|
|
CountDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UserControl_KeyDown(object sender, KeyEventArgs e) //键盘监控
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(MainWindowViewModel.Name_err.ToString()))//无错误信息
|
|
|
|
{
|
|
|
|
if ((MainWindowViewModel.WORK_RUN == 1) || (MainWindowViewModel.WORK_RUN == 0))//停止暂停时可以启用开始
|
|
|
|
{
|
|
|
|
if (e.Key == Key.Y) //按键y
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(Numder))
|
|
|
|
{
|
|
|
|
MainWindowViewModel.WORK_RUN = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MainWindowViewModel.RUN_DATATABLE = sql.Tables[0];//缓存表
|
|
|
|
MainWindowViewModel.RUN_STEPID = Convert.ToInt16(ID);//插入步骤号
|
|
|
|
MainWindowViewModel.STEP_START(Numder, Convert.ToDouble(P1), Convert.ToDouble(P2), Convert.ToDouble(P3), Convert.ToDouble(P4), Convert.ToDouble(P5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ProgramgroupView_edit_Click(object sender, RoutedEventArgs e)//编辑按钮
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; }
|
|
|
|
if (ID == null) ID = sql.Tables[0].Rows.Count.ToString();
|
|
|
|
ViewStep viewstop = new ViewStep(Numder, P1, P2, P3, P4, P5);
|
|
|
|
viewstop.data = ID;
|
|
|
|
viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked);
|
|
|
|
viewstop.ShowDialog();
|
|
|
|
}
|
|
|
|
private void Address_ButtonClicked(object sender, AddressUpdateEventArgs e)//编辑返回结果
|
|
|
|
{
|
|
|
|
int n = Convert.ToInt16(ID);
|
|
|
|
ID = null;
|
|
|
|
DataRow dr = sql.Tables[0].Rows[n - 1];
|
|
|
|
dr.BeginEdit();
|
|
|
|
dr["StepID"] = e.StepID;
|
|
|
|
dr["StepName"] = e.StepNAME;
|
|
|
|
dr["ParameterName"] = e.PNAME;
|
|
|
|
dr["Parameter1"] = e.P1;
|
|
|
|
dr["Parameter2"] = e.P2;
|
|
|
|
dr["Parameter3"] = e.P3;
|
|
|
|
dr["Parameter4"] = e.P4;
|
|
|
|
dr["Parameter5"] = e.P5;
|
|
|
|
dr.EndEdit();
|
|
|
|
|
|
|
|
dt_TP = sql.Tables[0];
|
|
|
|
GridSTEP.SelectedIndex = -1;
|
|
|
|
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
SQLiteHelpers.Delete("RUN", null, null);
|
|
|
|
DataTable data_t = dt_TP.Clone();
|
|
|
|
for (int i = 0; i < dt_TP.Rows.Count; i++)
|
|
|
|
{
|
|
|
|
data_t.Clear();//清空
|
|
|
|
|
|
|
|
DataRow dt = dt_TP.Rows[i];//行转换
|
|
|
|
DataRow drT = data_t.NewRow();
|
|
|
|
drT.ItemArray = dt.ItemArray;
|
|
|
|
data_t.Rows.InsertAt(drT, 0);
|
|
|
|
drT.BeginEdit(); //添加订单号
|
|
|
|
drT["DYELOT"] = MainWindowViewModel.WorkNumder;
|
|
|
|
drT.EndEdit();
|
|
|
|
|
|
|
|
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
|
|
}
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
}
|
|
|
|
public static void Dat()//行号刷新
|
|
|
|
{
|
|
|
|
int a = dt_TP.Rows.Count;
|
|
|
|
for (int i = 0; i < a; i++)
|
|
|
|
{
|
|
|
|
DataRow dr = dt_TP.Rows[i];
|
|
|
|
dr.BeginEdit();
|
|
|
|
dr["Step"] = i + 1;
|
|
|
|
dr.EndEdit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void ProgramgroupView_del_Click(object sender, RoutedEventArgs e)//删除
|
|
|
|
{
|
|
|
|
int d = 0;
|
|
|
|
int a = dt_TP.Rows.Count;
|
|
|
|
|
|
|
|
if (ID != null) { d = Convert.ToInt16(ID); } else { return; }
|
|
|
|
dt_TP.Rows.RemoveAt(d - 1);
|
|
|
|
|
|
|
|
Dat();
|
|
|
|
GridSTEP.SelectedIndex = -1;
|
|
|
|
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
SQLiteHelpers.Delete("RUN", null, null);
|
|
|
|
DataTable data_t = dt_TP.Clone();
|
|
|
|
a = dt_TP.Rows.Count;
|
|
|
|
for (int i = 0; i < a; i++)
|
|
|
|
{
|
|
|
|
data_t.Clear();//清空
|
|
|
|
|
|
|
|
DataRow dt = dt_TP.Rows[i];//行转换
|
|
|
|
DataRow drT = data_t.NewRow();
|
|
|
|
drT.ItemArray = dt.ItemArray;
|
|
|
|
data_t.Rows.InsertAt(drT, 0);
|
|
|
|
drT.BeginEdit(); //添加订单号
|
|
|
|
drT["DYELOT"] = MainWindowViewModel.WorkNumder;
|
|
|
|
drT.EndEdit();
|
|
|
|
|
|
|
|
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
|
|
}
|
|
|
|
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ProgramgroupView_Insert_Click(object sender, RoutedEventArgs e)//插入
|
|
|
|
{
|
|
|
|
int d = 0;
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
|
|
|
|
string ProgramID = SQLiteHelpers.ExecuteScalar("select ProgramID from RUN where Step = '1'", null).ToString();
|
|
|
|
string ProgramNAME = SQLiteHelpers.ExecuteScalar("select Program from RUN where Step = '1'", null).ToString();
|
|
|
|
|
|
|
|
SQLiteHelpers.Close();
|
|
|
|
|
|
|
|
if (ID != null) { d = Convert.ToInt16(ID); } else { return; }
|
|
|
|
DataRow dr = sql.Tables[0].NewRow();//添加表数据
|
|
|
|
dr["ProgramID"] = ProgramID;
|
|
|
|
dr["Program"] = ProgramNAME;
|
|
|
|
|
|
|
|
sql.Tables[0].Rows.InsertAt(dr, d - 1);
|
|
|
|
// ID = null;
|
|
|
|
|
|
|
|
Dat();
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; }
|
|
|
|
if (ID == null) ID = sql.Tables[0].Rows.Count.ToString();
|
|
|
|
ViewStep viewstop = new ViewStep(null, "0", "0", "0", "0", "0");
|
|
|
|
viewstop.data = ID;
|
|
|
|
viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked);
|
|
|
|
viewstop.ShowDialog();
|
|
|
|
//Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
|
|
}
|
|
|
|
|
|
|
|
string Numder = null;
|
|
|
|
string ID = null;
|
|
|
|
string P1 = "0", P2 = "0", P3 = "0", P4 = "0", P5 = "0";
|
|
|
|
|
|
|
|
private void DyeingMachine_Click(object sender, RoutedEventArgs e)//染色剂
|
|
|
|
{
|
|
|
|
Receip.Visibility = Visibility.Collapsed;
|
|
|
|
// Parameter_Scroll.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
private void Receipt_Click(object sender, RoutedEventArgs e)//领料单
|
|
|
|
{
|
|
|
|
Receip.Visibility = Visibility.Visible;
|
|
|
|
// Parameter_Scroll.Visibility = Visibility.Collapsed;
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
string sql_script = "select * from Dyelot where WorkOrder = '" + MainWindowViewModel.WorkNumder + "'";
|
|
|
|
Receip.ItemsSource = SQLiteHelpers.ExecuteDataSet(sql_script, null).Tables[0].DefaultView; //转换显示
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
}
|
|
|
|
private void ParameterSet_Click(object sender, RoutedEventArgs e)//参数
|
|
|
|
{
|
|
|
|
// Parameter_Scroll.Visibility = Visibility.Visible;
|
|
|
|
Receip.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ProgramgroupView_run_Click(object sender, RoutedEventArgs e)//运行/暂停
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ProgramgroupView_stop_Click(object sender, RoutedEventArgs e)//结束工艺
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (MainWindowViewModel.WORK_RUN == 2) GridSTEP.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
|
|
|
|
int rownum = GridSTEP.SelectedIndex;//获取鼠标选中行并定义变量
|
|
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
|
|
{
|
|
|
|
ID = (GridSTEP.Columns[2].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第0列,
|
|
|
|
Numder = (GridSTEP.Columns[3].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
|
|
P1 = (GridSTEP.Columns[6].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第6列,
|
|
|
|
P2 = (GridSTEP.Columns[7].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第7列,
|
|
|
|
P3 = (GridSTEP.Columns[8].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第8列,
|
|
|
|
P4 = (GridSTEP.Columns[9].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第9列,
|
|
|
|
P5 = (GridSTEP.Columns[10].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第10列,
|
|
|
|
|
|
|
|
ProgramgroupView_edit.IsEnabled = true;
|
|
|
|
ProgramgroupView_del.IsEnabled = true;
|
|
|
|
ProgramgroupView_Insert.IsEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CountDown()
|
|
|
|
{
|
|
|
|
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
|
|
|
{
|
|
|
|
Interval = TimeSpan.FromSeconds(3)//秒
|
|
|
|
};
|
|
|
|
timer1s.Tick += Tick_Event_1S;
|
|
|
|
timer1s.Start();
|
|
|
|
}
|
|
|
|
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
|
|
|
{
|
|
|
|
if (MainWindowViewModel.WORK_RUN == 2) GridSTEP.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
|
|
|
|
if (sql != null)
|
|
|
|
{
|
|
|
|
dt_TP = sql.Tables[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|