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.
228 lines
9.3 KiB
228 lines
9.3 KiB
using DyeingComputer.UserClass;
|
|
using DyeingComputer.ViewModel;
|
|
using DyeingComputer.Windows;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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 static DyeingComputer.UserClass.SqliteHelper;
|
|
using static DyeingComputer.Windows.ViewStep;
|
|
|
|
namespace DyeingComputer.View
|
|
{
|
|
/// <summary>
|
|
/// TechnologicalProcessView.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class TechnologicalProcessView : UserControl
|
|
{
|
|
public TechnologicalProcessView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public static object workName;
|
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
|
DataSet sql; //内存数据缓存
|
|
|
|
private void TechnologicalProcess_Import()
|
|
{
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
int r = 0;
|
|
string sql_script = "select * from ProgramSteps where ProgramID = '" + workName + "'";
|
|
if (sql != null) sql.Clear(); //清空缓存
|
|
sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取表写入缓存
|
|
name.Text = SQLiteHelpers.ExecuteScalar("select ProgramName from ProgramName where ProgramID = '" + workName + "'", null).ToString();
|
|
if (sql != null) Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
|
|
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); //读取表写入缓存
|
|
name.Text = SQLiteHelpers.ExecuteScalar("select Program from RUN where Step = '1'", null).ToString();
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
if (sql != null) Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
}
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
FocusManager.SetFocusedElement(Grid, Grid);
|
|
if (workName != null)
|
|
{
|
|
TechnologicalProcess_Import();
|
|
//Grid.SelectedIndex = 0;
|
|
//MainWindowViewModel.Process_step = 0;
|
|
}
|
|
else
|
|
{
|
|
TechnologicalProcess_sql();
|
|
// Grid.SelectedIndex = Convert.ToInt16(MainWindowViewModel.Process_step);
|
|
}
|
|
}
|
|
|
|
private void UserControl_KeyDown(object sender, KeyEventArgs e) //键盘监控
|
|
{
|
|
if (e.Key == Key.Y) //按键y
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
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 = StrToInt.To16Convert10(ID);
|
|
|
|
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();
|
|
|
|
Grid.ItemsSource = sql.Tables[0].DefaultView;
|
|
Grid.SelectedIndex = -1;
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
SQLiteHelpers.Delete("RUN", null, null);
|
|
DataTable data_t = new DataTable();
|
|
data_t.Columns.Add("DYELOT", typeof(string)); //添加列
|
|
data_t = sql.Tables[0].Clone();
|
|
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 drT = data_t.NewRow();
|
|
drT.ItemArray = dt.ItemArray;
|
|
data_t.Rows.InsertAt(drT, 0);
|
|
dr.BeginEdit(); //添加订单号
|
|
dr["DYELOT"] = MainWindowViewModel.WorkNumder;
|
|
dr.EndEdit();
|
|
|
|
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
}
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
}
|
|
public void Dat()//行号刷新
|
|
{
|
|
int a = sql.Tables[0].Rows.Count;
|
|
for (int i = 0; i < a; i++)
|
|
{
|
|
DataRow dr = sql.Tables[0].Rows[i];
|
|
dr.BeginEdit();
|
|
dr["Step"] = i + 1;
|
|
dr.EndEdit();
|
|
}
|
|
}
|
|
private void ProgramgroupView_del_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
int d = 0;
|
|
int a = sql.Tables[0].Rows.Count;
|
|
|
|
if (ID != null) { d = StrToInt.To16Convert10(ID); } else { return; }
|
|
if (a != d)//如果删除不是最后一行执行
|
|
{
|
|
sql.Tables[0].Rows.RemoveAt(d - 1);
|
|
|
|
Dat();
|
|
Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
}
|
|
}
|
|
|
|
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 = StrToInt.To16Convert10(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();
|
|
Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
}
|
|
|
|
string Numder = null;
|
|
string ID = null;
|
|
string P1, P2, P3, P4, P5;
|
|
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
{
|
|
ID = (Grid.Columns[2].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
|
Numder = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
P1 = (Grid.Columns[6].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第6列,
|
|
P2 = (Grid.Columns[7].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第7列,
|
|
P3 = (Grid.Columns[8].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第8列,
|
|
P4 = (Grid.Columns[9].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第9列,
|
|
P5 = (Grid.Columns[10].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第10列,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|