This commit is contained in:
sc committed 2025-09-09 00:56:37 +08:00
commit 379db4b738
4 files changed
+780 -102

No files matched your search

+116 -102
View File
@@ -32,10 +32,11 @@ using System.Windows.Media;
using System.Windows.Threading;
using System.Xml.Linq;
using TouchSocket.Core;
using TouchSocket.Sockets;
using TouchSocket.SerialPorts;
using TouchSocket.Sockets;
using static MaterialDesignThemes.Wpf.Theme;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static SunlightCentralizedControlManagement_SCCM_.View.MachinesView;
using static SunlightCentralizedControlManagement_SCCM_.ViewModel.ManualDyelotModel;
using static System.Net.WebRequestMethods;
using static System.Windows.Forms.AxHost;
@@ -120,6 +121,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
UPort();//启动串口
CountDown();
TcpClientNEW();
PortClientNEW();
ClientNEW();
SQL_LINK();
}
public static void USERCapacity(string user) //权限
@@ -361,7 +364,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
"AND EndTime >'" + DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
for (int k = 0; k < WorkOrderstepdata.Rows.Count; k++)
{
if (Selet_Machines(Machines, "Type", "ID='" + k + "'").ToString() == "838")
if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "ID='" + k + "'")))
{
string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field<object>("Machines").ToString();
DataTable dataTable = WorkOrderSQL.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" +
@@ -375,7 +378,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 112 } },
"WorkOrder ='" + WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
else if (Selet_Machines(Machines, "Type", "ID='" + k + "'").ToString() == "828")
else
{
}
@@ -385,7 +388,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
"AND EndTime >'" + DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
for (int k = 0; k < WorkOrderdata.Rows.Count; k++)
{
if (Selet_Machines(Machines, "Type", "ID='" + k + "'").ToString() == "838")
if (Convert.ToBoolean( Selet_Machines(Machines, "Type", "ID='" + k + "'")))
{
string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString();
@@ -410,7 +413,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
}
else if (Selet_Machines(Machines, "Type", "ID='" + k + "'").ToString() == "828")
else
{
string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString();
@@ -442,7 +445,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
"AND EndTime >'" + DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
for (int k = 0; k < WorkOrderset_.Rows.Count; k++)
{
if (Selet_Machines(Machines, "Type", "ID='" + k + "'").ToString() == "838")
if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "ID='" + k + "'")))
{
string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
string WorkOrderset_w = WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString();
@@ -462,7 +465,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
else if (Selet_Machines(Machines, "Type", "ID='" + k + "'").ToString() == "828")
else
{
string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
string WorkOrderset_w = WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString();
@@ -489,27 +492,27 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
//系统时间
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
//更新机台状态与发送指令
for (int i = 0; i < Machinesdata_Count; i++)
{
if (Selet_Machines(Machines, "Type", "ID='" + i + "'").ToString() == "838")
//更新机台状态与发送指令
foreach (DataRow MachinesRow in Machines.Rows)
{
if (Convert.ToBoolean(MachinesRow["Type"]))
{
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "802")
if (MachinesRow["State"].ToString() == "802")
{
stringQueue.Enqueue(new QueueString
{
ID = i,
DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'").ToString()
ID = Convert.ToInt16( MachinesRow["ID"]),
DAT = "SC830" + MachinesRow["SYSKEY"]
});//信息插入队列
bool mode = Machines.Select("ID='" + i + "'").First().Field<bool>("LOCK");//发送锁定状态
bool mode =Convert.ToBoolean( MachinesRow["LOCK"]) ;//发送锁定状态
if (mode)
{
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
dat_829.Clear();
dat_829.Add("NAME", "LOCK");
dat_829.Add("VALUE", "True");
DataRow drEmployee = Machines.Select("ID='" + i + "'").First();
DataRow drEmployee = Machines.Select("ID='" + MachinesRow["ID"] + "'").First();
int index = Convert.ToInt16(drEmployee.Field<object>("ID"));
stringQueue.Enqueue(new QueueString
{
@@ -518,98 +521,93 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
});
}
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");
}
int m_run = (int)Selet_Machines(Machines, "WORK_RUN", "ID='" + i + "'");
int m_run =Convert.ToInt16( MachinesRow["WORK_RUN"]);
if (m_run == 0)
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");//停止状态
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态
}
else if (m_run == 1)
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");//暂停状态
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态
}
else if (m_run == 2)
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "202");//运行
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行
}
if ((bool)Selet_Machines(Machines, "ERR", "ID='" + i + "'"))
if (Convert.ToBoolean(MachinesRow["ERR"]))
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "309");//错误
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误
}
string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString();
string mac_s = MachinesRow["State"].ToString();
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
{
stringQueueinf.Enqueue(new QueueString
{
ID = i,
DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'").ToString()
ID = Convert.ToInt16( MachinesRow["ID"]),
DAT = "SC830" + MachinesRow["SYSKEY"]
});//信息插入队列
}
}
else if (Selet_Machines(Machines, "Type", "ID='" + i + "'").ToString() == "828")
else
{
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "800")
if (MachinesRow["State"].ToString() == "800")
{//串口发送
string POR = Selet_Machines(Machines, "Serial", "ID='" + i + "'").ToString();
string POR = MachinesRow["Serial"].ToString();
stringQueueSerial.Enqueue(new QueueSerial
{
ID = POR,
DAT = "SC830[" +
Selet_Machines(Machines, "Station", "ID='" + i + "'") + "]"
DAT = "SC830[" + MachinesRow["Station"] + "]"
});
bool mode = Machines.Select("ID='" + i + "'").First().Field<bool>("LOCK");//发送锁定状态
bool mode =Convert.ToBoolean( MachinesRow["LOCK"]);//发送锁定状态
if (mode)
{
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
dat_829.Clear();
dat_829.Add("NAME", "LOCK");
dat_829.Add("VALUE", "True");
DataRow drEmployee = Machines.Select("ID='" + i + "'").First();
dat_829.Add("VALUE", "True");
stringQueueSerial.Enqueue(new QueueSerial
{
ID = POR,
DAT = "SC829[" +
Selet_Machines(Machines, "Station", "ID='" + i + "'") + "]" +
dat_829.ToJsonString()
DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString()
});
}
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");
}
int m_run = (int)Selet_Machines(Machines, "WORK_RUN", "ID='" + i + "'");
int m_run =Convert.ToInt16( MachinesRow["WORK_RUN"]);
if (m_run == 0)
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");//停止状态
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态
}
else if (m_run == 1)
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");//暂停状态
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态
}
else if (m_run == 2)
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "202");//运行
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行
}
if ((bool)Selet_Machines(Machines, "ERR", "ID='" + i + "'"))
if (Convert.ToBoolean(MachinesRow["ERR"]))
{
Updata_Machines(Machines, "State", "ID='" + i + "'", "309");//错误
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误
}
string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString();
string mac_s = MachinesRow["State"].ToString();
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
{
string POR = Selet_Machines(Machines, "Serial", "ID='" + i + "'").ToString();
string POR = MachinesRow["Serial"].ToString();
stringQueueSerial.Enqueue(new QueueSerial
{
ID = POR,
DAT = "SC830[" +
Selet_Machines(Machines, "Station", "ID='" + i + "'") + "]"
DAT = "SC830[" + MachinesRow["Station"] + "]"
});
}
}
@@ -630,66 +628,65 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
async void Tick_Event_5S()//Tick_Event周期执行事件5S
{
for (int i = 0; i < Machinesdata_Count; i++)
{/**发送800指令**/
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "801")
foreach (DataRow MachinesRow in Machines.Rows)
{
/**发送800指令**/
if (MachinesRow["State"].ToString() == "801")
{
stringQueue.Enqueue(new QueueString
{
ID = i,
DAT = "SC800:SCCM[" + Selet_Machines(Machines, "IP", "ID='" + i + "'") + ";" +
Selet_Machines(Machines, "Prot", "ID='" + i + "'") + "]"
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC800:SCCM[" + MachinesRow["IP"] + ";" + MachinesRow["Prot"] + "]"
});//信息插入队列
}
/**染机用户信息**/
try
{
if ((int)Selet_Machines(Machines, "UserInfoStart", "ID='" + i + "'") == 901)//打开用户提示信息
if (MachinesRow["UserInfoStart"].ToString() == "901")//打开用户提示信息
{
MainWindow.InfData.Rows.Add(new object[] {
Selet_Machines(Machines, "Name", "ID='" + i + "'"),
Properties.Resources.Pequest + Selet_Machines(Machines, "UserInfo", "ID='" + i + "'"),
Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'"),
Selet_Machines(Machines, "ID", "ID='" + i + "'")});
Updata_Machines(Machines, "UserInfoStart", "ID='" + i + "'", "900");
MachinesRow["Name"],Properties.Resources.Pequest + MachinesRow["UserInfo"],
MachinesRow["SYSKEY"],MachinesRow["ID"]});
Updata_Machines(Machines, "UserInfoStart", "ID='" + MachinesRow["ID"] + "'", "900");
}
if (Selet_Machines(Machines, "UserInfoStart", "ID='" + i + "'").ToString() == "902")//删除用户提示信息
if (MachinesRow["UserInfoStart"].ToString() == "902")//删除用户提示信息
{
MainWindow.InfData.Select("ID='" + i + "'").First().Delete();
MainWindow.InfData.Select("ID='" + MachinesRow["ID"] + "'").First().Delete();
}
}
catch (Exception EX) { LogGing.ERRDATA(EX); }
/**染机呼叫状态**/
try
{
if ((bool)Selet_Machines(Machines, "CALL", "ID='" + i + "'"))
if (Convert.ToBoolean(MachinesRow["CALL"]))
{
if (Selet_Machines(Machines, "Type", "ID='" + i + "'").ToString() == "828")
if (Convert.ToBoolean(MachinesRow["Type"]))
{
string POR = Selet_Machines(Machines, "Serial", "ID='" + i + "'").ToString();
stringQueue.Enqueue(new QueueString
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827" + MachinesRow["SYSKEY"]
});
}
else
{
string POR = MachinesRow["Serial"].ToString();
stringQueueSerial.Enqueue(new QueueSerial
{
ID = POR,
DAT = "SC827[" +
Selet_Machines(Machines, "Station", "ID='" + i + "'") + "]"
});
}
else if (Selet_Machines(Machines, "Type", "ID='" + i + "'").ToString() == "838")
{
stringQueue.Enqueue(new QueueString
{
ID = i,
DAT = "SC827" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'")
DAT = "SC827[" + MachinesRow["Station"]
});
}
}
}
catch (Exception EX) { LogGing.ERRDATA(EX); }
try
{//处理呼叫请求列表完成发送后(202》203)
if (Dyelot_CALL.Select("State='202'").Count() > 0)
if (Dyelot_CALL.Select("State='202'").Count() > 0)
{
DataRow row = Dyelot_CALL.Select("State='202'").First();
var r = await bDCSqlHelper.UPDATA("Machines", "Name = '" + row.Field<string>("Machine") + "'", row);
@@ -719,10 +716,10 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
catch (Exception EX) { LogGing.ERRDATA(EX); }
try
{//检查呼叫回复列表确认是否完成(203=>301)
if (Dyelot_CALL.Select("State='203'").Count() > 0)
if (Dyelot_CALL.Select("State='203'").Count() > 0)
{
DataTable dt = new DataTable();
// DataRow[] dataRows = Dyelot_CALL.Select("State='203'");
// DataRow[] dataRows = Dyelot_CALL.Select("State='203'");
foreach (DataRow dataRow in Dyelot_CALL.Select("State='203'"))
{
if ((dataRow["State"].ToString() != "301") && (dataRow["State"].ToString() != "309"))
@@ -736,15 +733,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
if (dt.Select("DyeState = 301").Count() > 0)
{
// Dyelot_CALL.Rows.Remove(dataRow);
// Dyelot_CALL.Rows.Remove(dataRow);
DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe",
"Dyelot = '" + dataRow.Field<string>("Dyelot") +
"' AND ReDye = " + dataRow.Field<int>("ReDye") +
" AND StepNumber = " + dataRow.Field<int>("Step"));
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='"+ dataRow["Dyelot"]+ "' and Redye ='"+
dataRow["Redye"]+ "' AND Step = '"+ dataRow["Step"] + "'"))
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
{
if (dr.Rows.Count > 0)
{
@@ -766,7 +763,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
else if(dt.Select("DyeState = 309").Count() > 0)
else if (dt.Select("DyeState = 309").Count() > 0)
{
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
@@ -795,7 +792,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
if (dt.Select("PowderState = 301").Count() > 0)
{
// Dyelot_CALL.Rows.Remove(dataRow);
// Dyelot_CALL.Rows.Remove(dataRow);
DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe",
"Dyelot = '" + dataRow.Field<string>("Dyelot") +
"' AND ReDye = " + dataRow.Field<int>("ReDye") +
@@ -846,7 +843,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
if (dt.Select("ChemicalState = 301").Count() > 0)
{
// Dyelot_CALL.Rows.Remove(dataRow);
// Dyelot_CALL.Rows.Remove(dataRow);
DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe",
"Dyelot = '" + dataRow.Field<string>("Dyelot") +
"' AND ReDye = " + dataRow.Field<int>("ReDye") +
@@ -865,7 +862,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
Row["DispenseEndTime"] = data.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
Row.EndEdit();
}
else
else
{
Row.BeginEdit();
Row["State"] = 301;
@@ -898,7 +895,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
try
{//301列表发送完成至染机(203=>301)
foreach (DataRow row in Dyelot_CALL.Select("State='301' OR State='309'"))
{
{
Dictionary<string, object> Product_ = new Dictionary<string, object>();//缓存函数
Product_.Add("State", row.Field<int>("State"));
Product_.Add("Step", row.Field<int>("Step"));
@@ -915,10 +912,10 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
"SYSKEY", "Name='" + row.Field<string>("Machine") + "'") + Product_.ToJsonString()
});
if (row["State"].ToString() == "309")
{
MainWindow.InfData.Rows.Add(new object[] { row["Machine"],
Resources.Step + row["Step"]+ Resources.DispenseException,
Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"),
{
MainWindow.InfData.Rows.Add(new object[] { row["Machine"],
Resources.Step + row["Step"]+ Resources.DispenseException,
Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"),
Selet_Machines(Machines, "ID", "Name='" + row["Machine"] + "'")});
}
Dyelot_CALL.Rows.Remove(row);
@@ -927,11 +924,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
catch (Exception EX) { LogGing.ERRDATA(EX); }
}
}
void Tick_Event_30S()
{
for (int i = 0; i < Machines.Rows.Count; i++)
/*曲线图*/
for (int i = 0; i < Machines.Rows.Count; i++)//曲线图
{
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() !="800")
{
@@ -946,14 +945,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static TcpClient[] MachiensTcpClient = new TcpClient[999];
public static DataRow[] machinesdata = new DataRow[999];
public int Machinesdata_Count;
public void TcpClientNEW()
public void ClientNEW()
{
// bool Machine_ ;
machinesdata = Machines.Select("PORT>0 AND IP<>''", "id asc");//获取连接有效的组
Machinesdata_Count = machinesdata.Count();
foreach (DataRow dataRow in Machines.Rows)
foreach (DataRow dataRow in Machines.Rows)
{
dataRow.BeginEdit();
dataRow["State"] = 800;
@@ -967,10 +961,30 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
dataRow["UserInfoStart"] = 900;
dataRow.EndEdit();
dataRow.AcceptChanges();
MachiensTcpClient[Convert.ToInt16(dataRow["ID"])]= new TcpClient();
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接
, dataRow["IP"].ToString(), dataRow["PORT"].ToString());
}
}
public void TcpClientNEW()
{
foreach (DataRow dataRow in Machines.Rows)
{
if (Convert.ToBoolean(dataRow["Type"]))
{
MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] = new TcpClient();
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接
, dataRow["IP"].ToString(), dataRow["PORT"].ToString());
}
}
}
public void PortClientNEW()
{
foreach (DataRow dataRow in Machines.Rows)
{
if (!Convert.ToBoolean(dataRow["Type"]))
{
// MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] = new TcpClient();
// _ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接
// , dataRow["IP"].ToString(), dataRow["PORT"].ToString());
}
}
}