|
|
@ -67,6 +67,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|
|
public static DataTable Machines = new DataTable(); //设备表缓存
|
|
|
public static DataTable Machines = new DataTable(); //设备表缓存
|
|
|
|
|
|
public static DataRow MachinesROW; |
|
|
public static DataTable USER_data = new DataTable(); |
|
|
public static DataTable USER_data = new DataTable(); |
|
|
public static UserControls.info[] inf = new UserControls.info[999]; //定义总览信息卡
|
|
|
public static UserControls.info[] inf = new UserControls.info[999]; //定义总览信息卡
|
|
|
public static int ERR_c = 0;//错误计数器
|
|
|
public static int ERR_c = 0;//错误计数器
|
|
|
@ -93,6 +94,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0]; |
|
|
USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0]; |
|
|
SQLiteHelpers.Close(); |
|
|
SQLiteHelpers.Close(); |
|
|
|
|
|
|
|
|
|
|
|
MachinesROW = Machines.NewRow(); |
|
|
|
|
|
|
|
|
USERCapacity(App.USER_Purview);//App.USER_Purview);
|
|
|
USERCapacity(App.USER_Purview);//App.USER_Purview);
|
|
|
CountDown(); |
|
|
CountDown(); |
|
|
TcpClientNEW(); |
|
|
TcpClientNEW(); |
|
|
@ -156,14 +159,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
timer1s.Tick += Tick_Event_1S; |
|
|
timer1s.Tick += Tick_Event_1S; |
|
|
timer1s.Start(); |
|
|
timer1s.Start(); |
|
|
|
|
|
|
|
|
//设置定时器
|
|
|
|
|
|
DispatcherTimer disTimer = new DispatcherTimer |
|
|
|
|
|
{ |
|
|
|
|
|
Interval = TimeSpan.FromMilliseconds(500) //毫秒
|
|
|
|
|
|
}; |
|
|
|
|
|
disTimer.Tick += new EventHandler(DisTimer_500MS);//每一秒执行的方法
|
|
|
|
|
|
disTimer.Start();//计时开始
|
|
|
|
|
|
|
|
|
|
|
|
DispatcherTimer dis50ms = new DispatcherTimer |
|
|
DispatcherTimer dis50ms = new DispatcherTimer |
|
|
{ |
|
|
{ |
|
|
Interval = TimeSpan.FromMilliseconds(50) //毫秒
|
|
|
Interval = TimeSpan.FromMilliseconds(50) //毫秒
|
|
|
@ -171,7 +166,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法
|
|
|
dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法
|
|
|
dis50ms.Start();//计时开始
|
|
|
dis50ms.Start();//计时开始
|
|
|
}//时间周期初始化
|
|
|
}//时间周期初始化
|
|
|
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS
|
|
|
void DisTimer_50MS(object sender, EventArgs e)//Tick_Event周期执行事件50MS
|
|
|
|
|
|
{ |
|
|
|
|
|
if (stringQueue.Count > 0) //信息发送队列
|
|
|
|
|
|
{ |
|
|
|
|
|
QueueString t = stringQueue.Dequeue(); |
|
|
|
|
|
MachiensTcpClient[t.ID].SendAsync(t.DAT); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
|
|
{ |
|
|
{ |
|
|
DATA_view(); |
|
|
DATA_view(); |
|
|
//下传工单信息
|
|
|
//下传工单信息
|
|
|
@ -183,11 +186,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field<object>("Machines").ToString(); |
|
|
string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field<object>("Machines").ToString(); |
|
|
DataTable dataTable = WorkOrderSQL.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" + |
|
|
DataTable dataTable = WorkOrderSQL.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" + |
|
|
WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null).Tables[0]; |
|
|
WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null).Tables[0]; |
|
|
int index = Convert.ToInt16(Machines.Select("NAME='" + WorkOrderdata_m + "'").First().Field<object>("ID")); |
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); |
|
|
stringQueue.Enqueue(new QueueString |
|
|
stringQueue.Enqueue(new QueueString |
|
|
{ |
|
|
{ |
|
|
ID = index, |
|
|
ID = index, |
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", index) + dataTable.ToJsonString() |
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.ToJsonString() |
|
|
}); |
|
|
}); |
|
|
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 112 } }, |
|
|
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 112 } }, |
|
|
"WorkOrder ='" + WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null); |
|
|
"WorkOrder ='" + WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null); |
|
|
@ -197,8 +200,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
for (int k = 0; k < WorkOrderdata.Rows.Count; k++) |
|
|
for (int k = 0; k < WorkOrderdata.Rows.Count; k++) |
|
|
{ |
|
|
{ |
|
|
string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString(); |
|
|
string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString(); |
|
|
string State = Machines.Select("Name='" + WorkOrderdata_m + "'"). |
|
|
string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString(); |
|
|
First().Field<object>("State").ToString(); |
|
|
|
|
|
if ((State == "101") || (State == "201") || (State == "202") || (State == "309")) |
|
|
if ((State == "101") || (State == "201") || (State == "202") || (State == "309")) |
|
|
{ |
|
|
{ |
|
|
DataTable dataTable = WorkOrderdata.Clone(); |
|
|
DataTable dataTable = WorkOrderdata.Clone(); |
|
|
@ -209,45 +212,44 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
dt_temp.EndEdit(); |
|
|
dt_temp.EndEdit(); |
|
|
dataTable.Rows.Add(dt_temp.ItemArray); |
|
|
dataTable.Rows.Add(dt_temp.ItemArray); |
|
|
|
|
|
|
|
|
int index = Convert.ToInt16(Machines.Select("NAME='" + WorkOrderdata_m + "'").First().Field<object>("ID")); |
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); |
|
|
stringQueue.Enqueue(new QueueString |
|
|
stringQueue.Enqueue(new QueueString |
|
|
{ |
|
|
{ |
|
|
ID = index, |
|
|
ID = index, |
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", index) + DataTableToDictionary(dataTable).ToJsonString() |
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() |
|
|
}); |
|
|
}); |
|
|
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } }, |
|
|
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } }, |
|
|
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null); |
|
|
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
WorkOrderSQL.Close(); |
|
|
WorkOrderSQL.Close(); |
|
|
} |
|
|
|
|
|
void DisTimer_50MS(object sender, EventArgs e)//Tick_Event周期执行事件50MS
|
|
|
|
|
|
{ |
|
|
|
|
|
if (stringQueue.Count > 0) //信息发送队列
|
|
|
|
|
|
{ |
|
|
|
|
|
QueueString t = stringQueue.Dequeue(); |
|
|
|
|
|
MachiensTcpClient[t.ID].SendAsync(t.DAT); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
|
|
|
|
|
{ |
|
|
|
|
|
//系统时间
|
|
|
//系统时间
|
|
|
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); |
|
|
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); |
|
|
//更新机台状态与发送指令
|
|
|
//更新机台状态与发送指令
|
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
{ |
|
|
{ |
|
|
if (Selet_Machines(Machines, "State", i).ToString() == "802") |
|
|
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "802") |
|
|
{ |
|
|
{ |
|
|
MachiensTcpClient[i].SendAsync("SC830"+ Selet_Machines(Machines, "SYSKEY", i).ToString()); |
|
|
stringQueue.Enqueue(new QueueString |
|
|
Updata_Machines(Machines, "State", i, "101"); |
|
|
{ |
|
|
|
|
|
ID = i, |
|
|
|
|
|
DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'").ToString() |
|
|
|
|
|
});//信息插入队列
|
|
|
|
|
|
|
|
|
|
|
|
Updata_Machines(Machines, "State", "ID='" + i + "'", "101"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
{ |
|
|
{ |
|
|
string mac_s = Selet_Machines(Machines, "State", i).ToString(); |
|
|
string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString(); |
|
|
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "309"))//获取信息
|
|
|
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "309"))//获取信息
|
|
|
{ |
|
|
{ |
|
|
stringQueue.Enqueue(new QueueString { ID = i, DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", i).ToString() });//信息插入队列
|
|
|
stringQueue.Enqueue(new QueueString |
|
|
|
|
|
{ |
|
|
|
|
|
ID = i, |
|
|
|
|
|
DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'").ToString() |
|
|
|
|
|
});//信息插入队列
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -269,9 +271,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
{ |
|
|
{ |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
{ |
|
|
{ |
|
|
if (Selet_Machines(Machines, "State", i).ToString() == "801") |
|
|
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "801") |
|
|
{ |
|
|
{ |
|
|
MachiensTcpClient[i].SendAsync("SC800:SCCM[" + MachiensTcpClient[i].IP + ";" + MachiensTcpClient[i].Port + "]"); |
|
|
stringQueue.Enqueue(new QueueString |
|
|
|
|
|
{ |
|
|
|
|
|
ID = i, |
|
|
|
|
|
DAT = "SC800:SCCM[" + MachiensTcpClient[i].IP + ";" + MachiensTcpClient[i].Port + "]" |
|
|
|
|
|
});//信息插入队列
|
|
|
} |
|
|
} |
|
|
}//发送800指令
|
|
|
}//发送800指令
|
|
|
} |
|
|
} |
|
|
@ -279,13 +285,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
{ |
|
|
{ |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
for (int i = 0; i < Machinesdata_Count; i++) |
|
|
{ |
|
|
{ |
|
|
if (Selet_Machines(Machines, "State", i).ToString() == "800") |
|
|
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "800") |
|
|
{ |
|
|
{ |
|
|
MachiensTcpClient[i] = new TcpClient(); |
|
|
MachiensTcpClient[i] = new TcpClient(); |
|
|
DataRow dt = machinesdata[i]; |
|
|
DataRow dt = machinesdata[i]; |
|
|
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接
|
|
|
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接
|
|
|
, Selet_Machines(Machines, "IP", Convert.ToInt16(dt["ID"])).ToString() |
|
|
, Selet_Machines(Machines, "IP", "ID='" + Convert.ToInt16(dt["ID"]) + "'" ).ToString() |
|
|
, Selet_Machines(Machines, "PORT", Convert.ToInt16(dt["ID"])).ToString()); |
|
|
, Selet_Machines(Machines, "PORT", "ID='" + Convert.ToInt16(dt["ID"]) + "'").ToString()); |
|
|
} |
|
|
} |
|
|
}//重连
|
|
|
}//重连
|
|
|
} |
|
|
} |
|
|
@ -303,10 +309,10 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
{ |
|
|
{ |
|
|
MachiensTcpClient[i] = new TcpClient(); |
|
|
MachiensTcpClient[i] = new TcpClient(); |
|
|
DataRow dt = machinesdata[i]; |
|
|
DataRow dt = machinesdata[i]; |
|
|
Updata_Machines(Machines, "State", Convert.ToInt16(dt["ID"]), "800"); |
|
|
Updata_Machines(Machines, "State", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "800"); |
|
|
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接
|
|
|
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接
|
|
|
, Selet_Machines(Machines, "IP", Convert.ToInt16(dt["ID"])).ToString() |
|
|
, Selet_Machines(Machines, "IP", "ID='" + Convert.ToInt16(dt["ID"]) + "'").ToString() |
|
|
, Selet_Machines(Machines, "PORT", Convert.ToInt16(dt["ID"])).ToString()); |
|
|
, Selet_Machines(Machines, "PORT", "ID='" + Convert.ToInt16(dt["ID"]) + "'").ToString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -329,13 +335,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
set { sys_machine = value; OnPropertyChanged("Sys_machine"); } |
|
|
set { sys_machine = value; OnPropertyChanged("Sys_machine"); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static object Selet_Machines(DataTable DB, string name, int key)//查询
|
|
|
public static object Selet_Machines(DataTable DB, string name, string key)//查询
|
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
lock (DB) |
|
|
lock (DB) |
|
|
{ |
|
|
{ |
|
|
DataRow drEmployee = DB.Select("ID='" + key + "'").First(); |
|
|
DataRow drEmployee = DB.Select(key).First(); |
|
|
object index = drEmployee.Field<object>(name); |
|
|
object index = drEmployee.Field<object>(name); |
|
|
return index; |
|
|
return index; |
|
|
} |
|
|
} |
|
|
@ -346,13 +352,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
return "ERR"; |
|
|
return "ERR"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
public static void Updata_Machines(DataTable DB, string name, int key, string Value)//更新数据
|
|
|
public static void Updata_Machines(DataTable DB, string name, string key, string Value)//更新数据
|
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
lock (DB) |
|
|
lock (DB) |
|
|
{ |
|
|
{ |
|
|
DataRow drEmployee = DB.Select("ID='" + key + "'").First(); |
|
|
DataRow drEmployee = DB.Select(key).First(); |
|
|
drEmployee.BeginEdit(); |
|
|
drEmployee.BeginEdit(); |
|
|
drEmployee[name] = Value; |
|
|
drEmployee[name] = Value; |
|
|
drEmployee.EndEdit(); |
|
|
drEmployee.EndEdit(); |
|
|
@ -365,6 +371,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
|
|
|
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
public static void UpdataMachines(string key, DataRow Value)//更新数据
|
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
lock (Machines) |
|
|
|
|
|
{ |
|
|
|
|
|
DataRow drEmployee = Machines.Select("IP='" + key + "'").First(); |
|
|
|
|
|
drEmployee.BeginEdit(); |
|
|
|
|
|
|
|
|
|
|
|
if (Value["State"] != null) drEmployee["State"] = Value["State"]; |
|
|
|
|
|
if (Value["WorkOrder"] != null) drEmployee["WorkOrder"] = Value["WorkOrder"]; |
|
|
|
|
|
if (Value["Dyelot"] != null) drEmployee["Dyelot"] = Value["Dyelot"]; |
|
|
|
|
|
if (Value["Temperature"] != null) drEmployee["Temperature"] = Value["WorkOrder"]; |
|
|
|
|
|
if (Value["WaterLevel"] != null) drEmployee["WaterLevel"] = Value["WaterLevel"]; |
|
|
|
|
|
if (Value["Process"] != null) drEmployee["Process"] = Value["Process"]; |
|
|
|
|
|
if (Value["Step"] != null) drEmployee["Step"] = Value["Step"]; |
|
|
|
|
|
if (Value["Message"] != null) drEmployee["Message"] = Value["Message"]; |
|
|
|
|
|
if (Value["SYSKEY"] != null) drEmployee["SYSKEY"] = Value["SYSKEY"]; |
|
|
|
|
|
if (Value["Groups"] != null) drEmployee["Groups"] = Value["Groups"]; |
|
|
|
|
|
|
|
|
|
|
|
drEmployee.EndEdit(); |
|
|
|
|
|
drEmployee.AcceptChanges(); |
|
|
|
|
|
drEmployee.ClearErrors(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
{ |
|
|
|
|
|
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static DataTable dt_d = new DataTable("DIO"); |
|
|
public static DataTable dt_d = new DataTable("DIO"); |
|
|
public static DataTable dt_a = new DataTable("AIO"); |
|
|
public static DataTable dt_a = new DataTable("AIO"); |
|
|
|