sc 11 months ago
parent
commit
102e07dbe2
  1. 106
      UserClass/AsyncTcpServer.cs
  2. 34
      View/TechnologicalProcessView.xaml.cs
  3. 8
      ViewModel/MainWindowViewModel.cs

106
UserClass/AsyncTcpServer.cs

@ -24,6 +24,7 @@ using static DyeingComputer.UserClass.SqliteHelper;
using DyeingComputer.View; using DyeingComputer.View;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using static System.Net.WebRequestMethods;
namespace DyeingComputer.UserClass namespace DyeingComputer.UserClass
{/// <summary> {/// <summary>
@ -66,6 +67,8 @@ namespace DyeingComputer.UserClass
return rt; return rt;
} }
public static SQLiteHelper SQLiteHelpers = null; //定义数据库
public static readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
public static async Task Main() public static async Task Main()
{ {
NetFwManger.AllowPort(7790,"TCP");//开放7790端口 NetFwManger.AllowPort(7790,"TCP");//开放7790端口
@ -186,7 +189,7 @@ namespace DyeingComputer.UserClass
} }
else if (dat_821.GetValue("INSTRUCTION").ToString() == "JUMP") else if (dat_821.GetValue("INSTRUCTION").ToString() == "JUMP")
{ {
MainWindowViewModel.RUN_DATATABLE = TechnologicalProcessView.sql.Tables[0];//缓存表 MainWindowViewModel.RUN_DATATABLE = MainWindowViewModel.dt_TP;//缓存表
MainWindowViewModel.RUN_STEPID = Convert.ToInt16(dat_821.GetValue("ID").ToString());//插入步骤号 MainWindowViewModel.RUN_STEPID = Convert.ToInt16(dat_821.GetValue("ID").ToString());//插入步骤号
MainWindowViewModel.STEP_START(dat_821.GetValue("Numder").ToString(), Convert.ToDouble(dat_821.GetValue("P1")), MainWindowViewModel.STEP_START(dat_821.GetValue("Numder").ToString(), Convert.ToDouble(dat_821.GetValue("P1")),
Convert.ToDouble(dat_821.GetValue("P2")), Convert.ToDouble(dat_821.GetValue("P3")), Convert.ToDouble(dat_821.GetValue("P2")), Convert.ToDouble(dat_821.GetValue("P3")),
@ -195,27 +198,20 @@ namespace DyeingComputer.UserClass
else if (dat_821.GetValue("INSTRUCTION").ToString() == "INSERT") else if (dat_821.GetValue("INSTRUCTION").ToString() == "INSERT")
{ {
int d = Convert.ToInt16(dat_821.GetValue("ID")); int d = Convert.ToInt16(dat_821.GetValue("ID"));
TechnologicalProcessView.SQLiteHelpers = new SQLiteHelper(TechnologicalProcessView.DBAddress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
TechnologicalProcessView.SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
/**插入行**/ /**插入行**/
string ProgramID = TechnologicalProcessView.SQLiteHelpers.ExecuteScalar("select ProgramID from RUN where Step = '1'", null).ToString(); string ProgramID = SQLiteHelpers.ExecuteScalar("select ProgramID from RUN where Step = '1'", null).ToString();
string ProgramNAME = TechnologicalProcessView.SQLiteHelpers.ExecuteScalar("select Program from RUN where Step = '1'", null).ToString(); string ProgramNAME = SQLiteHelpers.ExecuteScalar("select Program from RUN where Step = '1'", null).ToString();
// TechnologicalProcessView.SQLiteHelpers.Close(); // TechnologicalProcessView.SQLiteHelpers.Close();
DataRow dr = TechnologicalProcessView.sql.Tables[0].NewRow();//添加表数据 DataRow dr = MainWindowViewModel.dt_TP.NewRow();//添加表数据
dr["ProgramID"] = ProgramID; dr["ProgramID"] = ProgramID;
dr["Program"] = ProgramNAME; dr["Program"] = ProgramNAME;
TechnologicalProcessView.sql.Tables[0].Rows.InsertAt(dr, d - 1); MainWindowViewModel.dt_TP.Rows.InsertAt(dr, d - 1);
/**编辑行号**/ /**编辑行号**/
int a = TechnologicalProcessView.sql.Tables[0].Rows.Count; TechnologicalProcessView.Dat();
for (int i = 0; i < a; i++)
{
DataRow drt = TechnologicalProcessView.sql.Tables[0].Rows[i];
drt.BeginEdit();
drt["Step"] = i + 1;
drt.EndEdit();
}
/**编辑行信息**/ /**编辑行信息**/
DataRow drtt = TechnologicalProcessView.sql.Tables[0].Rows[d - 1]; DataRow drtt = MainWindowViewModel.dt_TP.Rows[d - 1];
drtt.BeginEdit(); drtt.BeginEdit();
drtt["StepID"] = dat_821.GetValue("StepID").ToString(); drtt["StepID"] = dat_821.GetValue("StepID").ToString();
drtt["StepName"] = dat_821.GetValue("StepName").ToString(); drtt["StepName"] = dat_821.GetValue("StepName").ToString();
@ -234,23 +230,26 @@ namespace DyeingComputer.UserClass
// _TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView; // _TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView;
//_TechnologicalProcessView.Grid.SelectedIndex = -1; //_TechnologicalProcessView.Grid.SelectedIndex = -1;
/**存入信息**/ /**存入信息**/
TechnologicalProcessView.SQLiteHelpers.Delete("RUN", null, null); /**存入信息**/
DataTable data_t = new DataTable(); SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
data_t.Columns.Add("DYELOT", typeof(string)); //添加列 SQLiteHelpers.Open(); //打开数据库
data_t = TechnologicalProcessView.sql.Tables[0].Clone(); SQLiteHelpers.Delete("RUN", null, null);
a = TechnologicalProcessView.sql.Tables[0].Rows.Count; DataTable data_t = MainWindowViewModel.dt_TP.Clone();
for (int i = 0; i < a; i++) for (int i = 0; i < MainWindowViewModel.dt_TP.Rows.Count; i++)
{ {
data_t.Clear();//清空 data_t.Clear();//清空
DataRow dt = TechnologicalProcessView.sql.Tables[0].Rows[i];//行转换 DataRow dt = MainWindowViewModel.dt_TP.Rows[i];//行转换
DataRow drT = data_t.NewRow(); DataRow drT = data_t.NewRow();
drT.ItemArray = dt.ItemArray; drT.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(drT, 0); data_t.Rows.InsertAt(drT, 0);
drT.BeginEdit(); //添加订单号
drT["DYELOT"] = MainWindowViewModel.WorkNumder;
drT.EndEdit();
TechnologicalProcessView.SQLiteHelpers.InsertData("RUN", TechnologicalProcessView.SQLiteHelpers.DataTableToDictionary(data_t));//行插入 SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
} }
TechnologicalProcessView.SQLiteHelpers.Close(); //关闭连接 SQLiteHelpers.Close(); //关闭连接
client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString()); client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString());
}//插入 }//插入
@ -258,7 +257,7 @@ namespace DyeingComputer.UserClass
{ {
int n = Convert.ToInt16(dat_821.GetValue("ID").ToString()); int n = Convert.ToInt16(dat_821.GetValue("ID").ToString());
/**编辑行信息**/ /**编辑行信息**/
DataRow dr = TechnologicalProcessView.sql.Tables[0].Rows[n - 1]; DataRow dr =MainWindowViewModel.dt_TP.Rows[n - 1];
dr.BeginEdit(); dr.BeginEdit();
dr["StepID"] = dat_821.GetValue("StepID").ToString(); dr["StepID"] = dat_821.GetValue("StepID").ToString();
dr["StepName"] = dat_821.GetValue("StepName").ToString(); dr["StepName"] = dat_821.GetValue("StepName").ToString();
@ -271,21 +270,18 @@ namespace DyeingComputer.UserClass
dr.EndEdit(); dr.EndEdit();
var _TechnologicalProcessView = Application.Current.Windows.Cast<UserControl>().FirstOrDefault(window => window is TechnologicalProcessView) as TechnologicalProcessView;//跨页面 var _TechnologicalProcessView = Application.Current.Windows.Cast<UserControl>().FirstOrDefault(window => window is TechnologicalProcessView) as TechnologicalProcessView;//跨页面
_TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView; // _TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView;
_TechnologicalProcessView.Grid.SelectedIndex = -1; _TechnologicalProcessView.Grid.SelectedIndex = -1;
/**存入信息**/ /**存入信息**/
TechnologicalProcessView.SQLiteHelpers = new SQLiteHelper(TechnologicalProcessView.DBAddress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
TechnologicalProcessView.SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
TechnologicalProcessView.SQLiteHelpers.Delete("RUN", null, null); SQLiteHelpers.Delete("RUN", null, null);
DataTable data_t = new DataTable(); DataTable data_t = MainWindowViewModel.dt_TP.Clone();
data_t.Columns.Add("DYELOT", typeof(string)); //添加列 for (int i = 0; i < MainWindowViewModel.dt_TP.Rows.Count; i++)
data_t = TechnologicalProcessView.sql.Tables[0].Clone();
int a = TechnologicalProcessView.sql.Tables[0].Rows.Count;
for (int i = 0; i < a; i++)
{ {
data_t.Clear();//清空 data_t.Clear();//清空
DataRow dt = TechnologicalProcessView.sql.Tables[0].Rows[i];//行转换 DataRow dt = MainWindowViewModel.dt_TP.Rows[i];//行转换
DataRow drT = data_t.NewRow(); DataRow drT = data_t.NewRow();
drT.ItemArray = dt.ItemArray; drT.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(drT, 0); data_t.Rows.InsertAt(drT, 0);
@ -293,31 +289,37 @@ namespace DyeingComputer.UserClass
drT["DYELOT"] = MainWindowViewModel.WorkNumder; drT["DYELOT"] = MainWindowViewModel.WorkNumder;
drT.EndEdit(); drT.EndEdit();
TechnologicalProcessView.SQLiteHelpers.InsertData("RUN", TechnologicalProcessView.SQLiteHelpers.DataTableToDictionary(data_t));//行插入 SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
} }
TechnologicalProcessView.SQLiteHelpers.Close(); //关闭连接 SQLiteHelpers.Close(); //关闭连接
client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString()); client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString());
}//编辑 }//编辑
else if (dat_821.GetValue("INSTRUCTION").ToString() == "DELETE") else if (dat_821.GetValue("INSTRUCTION").ToString() == "DELETE")
{ {
int d = Convert.ToInt16(dat_821.GetValue("ID")); int d = Convert.ToInt16(dat_821.GetValue("ID"));
MainWindowViewModel.dt_TP.Rows.RemoveAt(d - 1);
int a = TechnologicalProcessView.sql.Tables[0].Rows.Count; TechnologicalProcessView.Dat();
if (a != d)//如果删除不是最后一行执行 /**存入信息**/
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("RUN", null, null);
DataTable data_t = MainWindowViewModel.dt_TP.Clone();
for (int i = 0; i < MainWindowViewModel.dt_TP.Rows.Count; i++)
{ {
TechnologicalProcessView.sql.Tables[0].Rows.RemoveAt(d - 1); data_t.Clear();//清空
for (int i = 0; i < a; i++) DataRow dt = MainWindowViewModel.dt_TP.Rows[i];//行转换
{ DataRow drT = data_t.NewRow();
DataRow drt = TechnologicalProcessView.sql.Tables[0].Rows[i]; drT.ItemArray = dt.ItemArray;
drt.BeginEdit(); data_t.Rows.InsertAt(drT, 0);
drt["Step"] = i + 1; drT.BeginEdit(); //添加订单号
drt.EndEdit(); drT["DYELOT"] = MainWindowViewModel.WorkNumder;
} drT.EndEdit();
var _TechnologicalProcessView = Application.Current.Windows.Cast<UserControl>().FirstOrDefault(window => window is TechnologicalProcessView) as TechnologicalProcessView;//跨页面
_TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView; //转换显示计划表 SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
} }
SQLiteHelpers.Close(); //关闭连接
client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString()); client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString());
} }

34
View/TechnologicalProcessView.xaml.cs

@ -167,15 +167,12 @@ namespace DyeingComputer.View
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("RUN", null, null); SQLiteHelpers.Delete("RUN", null, null);
DataTable data_t = new DataTable(); DataTable data_t = dt_TP.Clone();
data_t.Columns.Add("DYELOT", typeof(string)); //添加列 for (int i = 0; i < dt_TP.Rows.Count; i++)
data_t = sql.Tables[0].Clone();
int a = sql.Tables[0].Rows.Count;
for (int i = 0; i < a; i++)
{ {
data_t.Clear();//清空 data_t.Clear();//清空
DataRow dt = sql.Tables[0].Rows[i];//行转换 DataRow dt = dt_TP.Rows[i];//行转换
DataRow drT = data_t.NewRow(); DataRow drT = data_t.NewRow();
drT.ItemArray = dt.ItemArray; drT.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(drT, 0); data_t.Rows.InsertAt(drT, 0);
@ -185,15 +182,14 @@ namespace DyeingComputer.View
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入 SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
} }
SQLiteHelpers.Close(); //关闭连接 SQLiteHelpers.Close(); //关闭连接
} }
public void Dat()//行号刷新 public static void Dat()//行号刷新
{ {
int a = sql.Tables[0].Rows.Count; int a = dt_TP.Rows.Count;
for (int i = 0; i < a; i++) for (int i = 0; i < a; i++)
{ {
DataRow dr = sql.Tables[0].Rows[i]; DataRow dr = dt_TP.Rows[i];
dr.BeginEdit(); dr.BeginEdit();
dr["Step"] = i + 1; dr["Step"] = i + 1;
dr.EndEdit(); dr.EndEdit();
@ -202,12 +198,10 @@ namespace DyeingComputer.View
private void ProgramgroupView_del_Click(object sender, RoutedEventArgs e)//删除 private void ProgramgroupView_del_Click(object sender, RoutedEventArgs e)//删除
{ {
int d = 0; int d = 0;
int a = sql.Tables[0].Rows.Count; int a = dt_TP.Rows.Count;
if (ID != null) { d = Convert.ToInt16(ID); } else { return; } if (ID != null) { d = Convert.ToInt16(ID); } else { return; }
if (a != d)//如果删除不是最后一行执行 dt_TP.Rows.RemoveAt(d - 1);
{
sql.Tables[0].Rows.RemoveAt(d - 1);
Dat(); Dat();
Grid.SelectedIndex = -1; Grid.SelectedIndex = -1;
@ -215,15 +209,13 @@ namespace DyeingComputer.View
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("RUN", null, null); SQLiteHelpers.Delete("RUN", null, null);
DataTable data_t = new DataTable(); DataTable data_t = dt_TP.Clone();
data_t.Columns.Add("DYELOT", typeof(string)); //添加列 a = dt_TP.Rows.Count;
data_t = sql.Tables[0].Clone();
a = sql.Tables[0].Rows.Count;
for (int i = 0; i < a; i++) for (int i = 0; i < a; i++)
{ {
data_t.Clear();//清空 data_t.Clear();//清空
DataRow dt = sql.Tables[0].Rows[i];//行转换 DataRow dt = dt_TP.Rows[i];//行转换
DataRow drT = data_t.NewRow(); DataRow drT = data_t.NewRow();
drT.ItemArray = dt.ItemArray; drT.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(drT, 0); data_t.Rows.InsertAt(drT, 0);
@ -235,8 +227,8 @@ namespace DyeingComputer.View
} }
SQLiteHelpers.Close(); //关闭连接 SQLiteHelpers.Close(); //关闭连接
dt_TP = sql.Tables[0]; //转换显示计划表 // dt_TP = sql.Tables[0]; //转换显示计划表
}
} }
private void ProgramgroupView_Insert_Click(object sender, RoutedEventArgs e)//插入 private void ProgramgroupView_Insert_Click(object sender, RoutedEventArgs e)//插入

8
ViewModel/MainWindowViewModel.cs

@ -187,7 +187,7 @@ namespace DyeingComputer.ViewModel
get { return work_Numder; } get { return work_Numder; }
set { work_Numder = value; OnPropertyChanged("Work_Numder"); } set { work_Numder = value; OnPropertyChanged("Work_Numder"); }
} }
public string status_Str; //显示状态 public string status_Str ="-"; //显示状态
public string Status_Str //通知UI控件参数改变 public string Status_Str //通知UI控件参数改变
{ {
get { return status_Str; } get { return status_Str; }
@ -220,9 +220,9 @@ namespace DyeingComputer.ViewModel
public static int ViewID = 0;//页面id public static int ViewID = 0;//页面id
public static object Name_err = ""; public static object Name_err = "";
public static object SYSTime; public static object SYSTime = "-----";
public static object WorkNumder; public static object WorkNumder ="-----";
public static object StatusStr; public static object StatusStr = "-----";
public static object Process_step = "-----"; public static object Process_step = "-----";
public static string ProgramName = "-----";//工艺名 public static string ProgramName = "-----";//工艺名
public static Int32 DIDETime; //空闲计时器 public static Int32 DIDETime; //空闲计时器

Loading…
Cancel
Save