Compare commits

...
12 Commits
Author SHA1 Message Date
sc eb2828aab0 Merge branch 'master' of http://192.168.0.12:13000/sc/SunlightCentralizedControlManagement 2026-01-04 23:26:01 +08:00
sc 33b970eff9 Merge branch 'master' of http://192.168.0.12:13000/sc/SunlightCentralizedControlManagement 2026-01-04 23:26:00 +08:00
sc 5caf92be59 Merge branch 'master' of http://192.168.0.12:13000/sc/SunlightCentralizedControlManagement 2026-01-04 23:24:46 +08:00
sc 437b8957ce Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2026-01-04 23:24:44 +08:00
sc a68fb9ae01 Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-27 22:10:41 +08:00
sc 68b98ac7e4 Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-27 22:10:39 +08:00
sc 2329ac9abc Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-26 01:35:33 +08:00
sc b062420be1 Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-26 01:35:30 +08:00
sc a248c41163 Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-25 20:18:34 +08:00
sc 2b676adbba 修正错误 2025-10-25 20:18:31 +08:00
sc 00a5cd3ec7 Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-15 22:14:27 +08:00
sc abfcf6e36a Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement 2025-10-15 22:14:26 +08:00
3 changed files with 143 additions and 315 deletions

No files matched your search

+34 -194
View File
@@ -2,7 +2,6 @@
using ScottPlot.Plottables;
using SunlightCentralizedControlManagement_SCCM_.View;
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
using System;
using System.Collections.Generic;
using System.Data;
@@ -16,10 +15,8 @@ using System.Windows;
using TouchSocket.Core;
using TouchSocket.SerialPorts;
using TouchSocket.Sockets;
using static OpenTK.Graphics.OpenGL.GL;
using static SkiaSharp.HarfBuzz.SKShaper;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static SunlightCentralizedControlManagement_SCCM_.ViewModel.MainWindowViewModel;
using static System.Net.Mime.MediaTypeNames;
namespace SunlightCentralizedControlManagement_SCCM_.UserClass
@@ -47,7 +44,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
int contentLength = endIndex - startIndex - 1;
return contentLength > 0 ? source.Substring(contentStart, contentLength) : string.Empty;
}
}//获取字符串指定字符的范围的值
}
public static string PortCOM1 { get; set; }
public static string PortCOM2 { get; set; }
@@ -63,17 +60,19 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
portclient.Closed = (client, e) => { return EasyTask.CompletedTask; };//从端口断开连接,当连接不成功时不会触发。
portclient.Received = (client, e) =>
{
//接受重置事件状态
_responseEvent.Set();
string[] sArray = Regex.Split(e.ByteBlock.Span.ToString(Encoding.UTF8),
@"\n", RegexOptions.IgnoreCase);
for (int i = 0; i < sArray.Length; i++)
{
if (sArray[i].Length>5)
{
if (sArray[i].Length > 5)
{
string SYSAPI = sArray[i].Substring(0, 5);
string Station = ClipBetween(sArray[i], '[', ']');
string DAT = sArray[i].Substring(sArray[i].IndexOf("]") + 1);
if (SYSAPI == "SC800")
{
try
@@ -98,10 +97,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 111 } },
"WorkOrder ='" + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
"WorkOrder ='" + _dat.GetValue("Work") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
}
catch (Exception ex)
{
@@ -112,18 +112,19 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MainWindowViewModel.SQLiteHelpers.Update("WorkorderSteps", new Dictionary<string, object> { { "Mode", 1 } },
"WorkOrder ='" + _dat.GetValue("Order") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "' AND Step ='" +
"WorkOrder ='" + _dat.GetValue("Work") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "' AND Step ='" +
_dat.GetValue("Step") + "'", null);
int x = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='"+
_dat.GetValue("Order") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "' AND Mode <> '1'", null).Tables[0].Rows.Count;
int x = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" +
_dat.GetValue("Work") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "' AND Mode <> '1'", null).Tables[0].Rows.Count;
if (x == 0)
{
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 113 } },
"WorkOrder ='" + _dat.GetValue("Order") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
"WorkOrder ='" + _dat.GetValue("Work") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
}
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
@@ -132,10 +133,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 101 } },
"WorkOrder ='" + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
"WorkOrder ='" + _dat.GetValue("Work") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//回复的工单设置状态后就位101
@@ -143,79 +145,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
DataTable dataTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Dyelot where WorkOrder='" +
_dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "' AND Step = '"+ _dat.GetValue("Step") + "'", null).Tables[0];
foreach (DataRow sourceRow in dataTable.Rows)
{
lock (MainWindowViewModel.Dyelot_CALL.Rows.SyncRoot)
{
// 创建新行(基于目标表结构)
DataRow newRow = MainWindowViewModel.Dyelot_CALL.NewRow();
// 复制源表中存在的列数据
foreach (DataColumn column in dataTable.Columns)
{
if (MainWindowViewModel.Dyelot_CALL.Columns.Contains(column.ColumnName))
{
newRow[column.ColumnName] = sourceRow[column.ColumnName];
}
}
MainWindowViewModel.Dyelot_CALL.Rows.Add(newRow);
Dictionary<string, object> Product_ = new Dictionary<string, object>();//缓存函数
Product_.Add("State", 202);
Product_.Add("Dyelot", newRow.Field<string>("Dyelot"));
Product_.Add("Step", newRow.Field<int>("Step"));
newRow.BeginEdit();
newRow["State"] = 202;
newRow.EndEdit();
MainWindowViewModel.SQLiteHelpers.InsertData("DyelotHistory", MainWindowViewModel.SQLiteHelpers.ToDictionary(newRow));// 执行插入
int index = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Machines where Serial='PORT1' AND Station ='" +
Station + "' ", null).Tables[0].Rows[0].Field<int>("ID");
string dat_ = "SC828[" + Station + "]" + Product_.ToJsonString();
bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
{
stringQueueSerial_1.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
}
}
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//获取呼叫领料单
else if (SYSAPI == "SC822")
{
try
{
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(DAT).Copy();//反序列化
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
UserWorkOrder userWorkOrder = new UserWorkOrder();
userWorkOrder.WorkOrderTable = dataTable;
userWorkOrder.Show();
});
}
catch (Exception)
{
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
UserInf userInf = new UserInf();
userInf.Inf_DAT = "没有等待中的工艺";
userInf.Show();
userInf.Activate();
});
// LogGing.LogGingDATA("[ERR='" + ex + "']=Exception");
MainWindowViewModel.ERR_c++;
}
}//可用工单
else if (SYSAPI == "SC830")
{
try
@@ -236,7 +168,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee["WaterLevel"] = _new.GetValue("MTL");
drEmployee["Process"] = _new.GetValue("Process");
drEmployee["Step"] = _new.GetValue("Step");
drEmployee["UserButton"] = _new.GetValue("User");
drEmployee["UserButton"] = _new.GetValue("UserB");
if (_new.GetValue("InfoS").ToString() != "900")
{ drEmployee["UserInfoStart"] = _new.GetValue("InfoS"); }
drEmployee["UserInfo"] = _new.GetValue("Info");
@@ -246,13 +178,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee.EndEdit();
drEmployee.AcceptChanges();
}
if (_new.GetValue("Status").ToString() != "----------")
{
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
Chart_new.Add("WorkOrder", _new.GetValue("Work"));
Chart_new.Add("Machine", mac);
Chart_new.Add("Time", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
//Chart_new.Add("Machine", mac);
//Chart_new.Add("Time", _new.GetValue("Time"));
Chart_new.Add("MST", _new.GetValue("MST"));
Chart_new.Add("MTT", _new.GetValue("MTT"));
Chart_new.Add("MTL", _new.GetValue("MTL"));
@@ -268,20 +200,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
MainWindowViewModel.SQLiteChartAdress.InsertData("Chart", Chart_new);// 执行插入
}
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++;
catch (Exception ex)
{
LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++;
}
}//当前信息
else if (SYSAPI == "SC831")
{
try
{
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MainWindowViewModel.dt_TP = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * WorkorderSteps Dyelot where WorkOrder='" +
_dat.GetValue("Work") + "' AND ReDye ='" + _dat.GetValue("Re") + "'", null).Tables[0];
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//当前步骤信息
}
else if (SYSAPI == "SC832")
{
try
@@ -294,11 +224,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MonitorView.Product_DAT = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Dyelot where WorkOrder='" +
_dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null).Tables[0];
MonitorView.Product_bool = true;
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//当前领料单信息
@@ -306,34 +231,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
string[] DO = _dat.GetValue("DO").ToString().Split(',');
string[] DQ = _dat.GetValue("DQ").ToString().Split(',');
DataTable dataTable = new DataTable();
dataTable.Columns.Add("ID", Type.GetType("System.String"));
dataTable.Columns.Add("type", Type.GetType("System.String"));
dataTable.Columns.Add("DIO", Type.GetType("System.Bool"));
dataTable.Columns.Add("PLC", Type.GetType("System.String"));
for (int DOi = 0; DOi < DO.Length; DOi++)
{
DataRow newRow = dataTable.NewRow();
newRow["ID"] = DOi+2001;
newRow["type"] = "DO";
newRow["DIO"] = DO[DOi];
newRow["PLC"] = DOi + 2001;
dataTable.Rows.Add(newRow);
}
for (int DQi = 0; DQi < DO.Length; DQi++)
{
DataRow newRow = dataTable.NewRow();
newRow["ID"] = DQi + 3001;
newRow["type"] = "DQ";
newRow["DIO"] = DQ[DQi];
newRow["PLC"] = DQi + 3001;
dataTable.Rows.Add(newRow);
}
MainWindowViewModel.dt_d = dataTable;
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//数字开关表
@@ -341,34 +238,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
string[] AI = _dat.GetValue("DO").ToString().Split(',');
string[] AO = _dat.GetValue("DQ").ToString().Split(',');
DataTable dataTable = new DataTable();
dataTable.Columns.Add("ID", Type.GetType("System.String"));
dataTable.Columns.Add("type", Type.GetType("System.String"));
dataTable.Columns.Add("AIO", Type.GetType("System.Int"));
dataTable.Columns.Add("PLC", Type.GetType("System.String"));
for (int AIi = 0; AIi < AI.Length; AIi++)
{
DataRow newRow = dataTable.NewRow();
newRow["ID"] = AIi + 4001;
newRow["type"] = "DO";
newRow["AIO"] = AI[AIi];
newRow["PLC"] = AIi + 4001;
dataTable.Rows.Add(newRow);
}
for (int AOi = 0; AOi < AO.Length; AOi++)
{
DataRow newRow = dataTable.NewRow();
newRow["ID"] = AOi + 5001;
newRow["type"] = "DQ";
newRow["AIO"] = AO[AOi];
newRow["PLC"] = AOi + 5001;
dataTable.Rows.Add(newRow);
}
MainWindowViewModel.dt_a = dataTable;
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//寄存器表
@@ -376,23 +245,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
string[] M = _dat.GetValue("M").ToString().Split(',');
DataTable dataTable = new DataTable();
dataTable.Columns.Add("ID", Type.GetType("System.String"));
dataTable.Columns.Add("type", Type.GetType("System.String"));
dataTable.Columns.Add("Value", Type.GetType("System.Double"));
dataTable.Columns.Add("PLC", Type.GetType("System.String"));
for (int Mi = 0; Mi < M.Length; Mi++)
{
DataRow newRow = dataTable.NewRow();
newRow["ID"] = Mi + 1001;
newRow["type"] = "M";
newRow["Value"] = M[Mi];
newRow["PLC"] = Mi + 1001;
dataTable.Rows.Add(newRow);
}
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
@@ -425,8 +277,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 109 } },
"WorkOrder ='" + DAT + "'", null);
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//发布失败
@@ -434,21 +285,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 119 } },
"WorkOrder ='" + DAT + "'", null);
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//细节错误
else if (SYSAPI == "SC921")
{
try
{
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}//错误
else if (SYSAPI == "SC980")
{
MessageBox.Show(DAT, "SCCM", MessageBoxButton.OK, MessageBoxImage.Question);
}
}
}
@@ -564,8 +407,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
string[] sArray = Regex.Split(e.ByteBlock.Span.ToString(Encoding.UTF8),
@"\n", RegexOptions.IgnoreCase);
return EasyTask.CompletedTask; ;
};
await portclient.SetupAsync(new TouchSocketConfig()
@@ -577,7 +418,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
PortName = com,//COM
StopBits = System.IO.Ports.StopBits.One,//停止位
})
.SetSerialDataHandlingAdapter(() => new PeriodPackageAdapter() { CacheTimeout = TimeSpan.FromMilliseconds(100) })
.SetSerialDataHandlingAdapter(() => new PeriodPackageAdapter() { CacheTimeout = TimeSpan.FromMilliseconds(500) })
.ConfigurePlugins(a =>
{
//a.Add<MyPlugin>();
@@ -602,14 +443,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
try
{
// var t = CRCcheck16.ToCRC16(command);
var t = CRCcheck16.ToCRC16(command);
_responseEvent.Reset();
serialPortClients.Send(command); // 发送指令
// 等待500毫秒或直到收到响应
_responseEvent.Wait(TimeSpan.FromMilliseconds(1000));
if (!_responseEvent.IsSet)
{
//清机台状态
// 等待500毫秒或直到收到响应
if (!_responseEvent.Wait(TimeSpan.FromMilliseconds(1000)))
{
_responseEvent.Set();
//清楚了解状态
string Station = ClipBetween(command, '[', ']');
lock (MainWindowViewModel.Machines.Rows.SyncRoot)
{
@@ -634,8 +476,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
}
}
}
// 重置事件状态
_responseEvent.Set();
}
catch (Exception) { }
}
+13 -7
View File
@@ -160,10 +160,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
try
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 111 } },
"WorkOrder ='" + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
"WorkOrder ='" + DAT + "'", null);
// Dictionary<string, object> _dat;
// _dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
// MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 111 } },
// "WorkOrder ='" + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null);
}
catch (Exception ex)
{
@@ -175,10 +178,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
try
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
Dictionary<string, object> _dat;
_dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 113 } },
"WorkOrder ='" + _dat.GetValue("WorkOrder") + "' AND ReDye ='"+ _dat.GetValue("ReDye") + "'", null);
MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 111 } },
"WorkOrder ='" + DAT + "'", null);
// Dictionary<string, object> _dat;
// _dat = SerializeConvert.JsonDeserializeFromString<Dictionary<string, object>>(DAT);
// MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 113 } },
// "WorkOrder ='" + _dat.GetValue("WorkOrder") + "' AND ReDye ='"+ _dat.GetValue("ReDye") + "'", null);
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}
+96 -114
View File
@@ -79,7 +79,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static string SN_ID;
public static string SN_KEY;
public static bool DyelotsDispenser;
public static SqlConnection conn_SC =new SqlConnection();//数据库
public static SqlConnection conn_SC = new SqlConnection();//数据库
public static SQLiteHelper SQLiteHelpers = null; //定义数据库
private BDC_SQL.BDCSqlHelper bDCSqlHelper = new BDC_SQL.BDCSqlHelper();
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
@@ -95,7 +95,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static int ERR_c = 0;//错误计数器
public bool UPort1, UPort2, UPort3;
public static bool[] USER_Capacity { set; get; } = new bool[99];
public MainWindowViewModel()
{
try
@@ -150,15 +150,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
else
else
{
for (int i = 0; i < 99; i++)
{
USER_Capacity[i] = true;
{
USER_Capacity[i] = true;
}
}
}
public async void SQL_LINK()//连接dbc数据库
{
if (conn_SC.State == ConnectionState.Open) conn_SC.Close();
@@ -180,7 +180,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
LogGing.LogGingDATA("[Database='" + ex + "']=SQLSERVER");
ERR_c++;
}
if (SQMOD == "Windows Authentication") //连接数据库测试
{
bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, true);
@@ -254,7 +254,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
foreach (DataRow dataRow in dataTable.Select("Mode<>'1'"))
{
Dictionary<string, object> dat_ = new Dictionary<string, object>();
dat_.Add("Order", dataRow["WorkOrder"].ToString());
dat_.Add("Work", dataRow["WorkOrder"].ToString());
dat_.Add("Dye", dataRow["DYELOT"].ToString());
dat_.Add("Time", dataRow["StepTime"].ToString());
dat_.Add("ReDye", dataRow["ReDye"].ToString());
@@ -314,7 +314,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
ID = index,
DAT = "SC811[" + Selet_Machines(Machines, "Station", "ID='" + index + "'") + "]" + dat_.ToJsonString()
});
} }
}
}
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT3")
{ // 检查队列中是否已存在相同项
bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat);
@@ -337,11 +338,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
ID = index,
DAT = "SC811[" + Selet_Machines(Machines, "Station", "ID='" + index + "'") + "]" + dat_.ToJsonString()
});
} }
}
}
}
}
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 112 } },
if (WorkOrderstepdata.Select()[k].Field<object>("State").ToString() == "111")
{
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 112 } },
"WorkOrder ='" + WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
}
}
/*下传工单总览*/
@@ -391,9 +396,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
dt_temp.EndEdit();
dataTable.Rows.Add(dt_temp.ItemArray);
Dictionary<string, object> dat_ = new Dictionary<string, object>();
dat_.Add("Work", dt_temp["WorkOrder"].ToString());
dat_.Add("Dye", dt_temp["DYELOT"].ToString());
dat_.Add("STime", dt_temp["StartTime"].ToString());
dat_.Add("Time", dt_temp["Time"].ToString());
dat_.Add("ReDye", 0);
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString());
string dat = "SC810[" + Selet_Machines(Machines, "Station", "ID='" + index + "'") + "]" +
DataTableToDictionary(dataTable).ToJsonString();
string dat = "SC810[" + Selet_Machines(Machines, "Station", "ID='" + index + "'") + "]" + dat_.ToJsonString();
if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT1")
{ // 检查队列中是否已存在相同项
bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat);
@@ -444,8 +455,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
if (WorkOrderdata.Select()[k].Field<object>("State").ToString() == "110")
{
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
}
}
/*下传工单设置*/
@@ -472,7 +486,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
ID = index,
DAT = "SC812" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(WorkOrder_set).ToJsonString()
});
}
}
}
else
{//串口
@@ -534,10 +548,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
});
}
}
}
}
}
if (WorkOrderset_.Select()[k].Field<object>("State").ToString() == "113")
{
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 114 } },
"WorkOrder ='" + WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 114 } },
"WorkOrder ='" + WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
}
@@ -633,6 +650,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
});
}
}
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");
}
else if (MachinesRow["Serial"].ToString() == "PORT2")
{
@@ -771,7 +789,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309")|| (mac_s == "802"))//获取信息
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
{
if (MachinesRow["Serial"].ToString() == "PORT1")
{
@@ -870,7 +888,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
else { Time30++; }
}
async void Tick_Event_5S()//Tick_Event周期执行事件5S
{
{
try
{//处理呼叫请求列表完成发送后(202》203)
if (Dyelot_CALL.Select("State='202'").Count() > 0)
@@ -1114,55 +1132,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
else
{//串口
int index = Convert.ToInt16(MachinesRow["ID"]);
string dat_ = "SC827[" + MachinesRow["Station"] + "]";
if (MachinesRow["Serial"].ToString() == "PORT1")
{
bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_1.Enqueue(new QueueSerial
{
stringQueueSerial_1.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
else if (MachinesRow["Serial"].ToString() == "PORT2")
{
bool exists = stringQueueSerial_2.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_2.Enqueue(new QueueSerial
{
stringQueueSerial_2.Enqueue(new QueueSerial
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
else if (MachinesRow["Serial"].ToString() == "PORT3")
{
bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_3.Enqueue(new QueueSerial
{
stringQueueSerial_3.Enqueue(new QueueSerial
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
else if (MachinesRow["Serial"].ToString() == "PORT4")
{
bool exists = stringQueueSerial_4.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_4.Enqueue(new QueueSerial
{
stringQueueSerial_4.Enqueue(new QueueSerial
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
}
}
@@ -1193,55 +1193,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
else
{//串口
int index = Convert.ToInt16(MachinesRow["ID"]);
string dat_ = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString();
if (MachinesRow["Serial"].ToString() == "PORT1")
{
bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_1.Enqueue(new QueueSerial
{
stringQueueSerial_1.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
else if (MachinesRow["Serial"].ToString() == "PORT2")
{
bool exists = stringQueueSerial_2.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_2.Enqueue(new QueueSerial
{
stringQueueSerial_2.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
else if (MachinesRow["Serial"].ToString() == "PORT3")
{
bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_3.Enqueue(new QueueSerial
{
stringQueueSerial_3.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
else if (MachinesRow["Serial"].ToString() == "PORT4")
{
bool exists = stringQueueSerial_4.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_4.Enqueue(new QueueSerial
{
stringQueueSerial_4.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
}
@@ -1282,7 +1264,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
catch (Exception EX) { LogGing.ERRDATA(EX); }
}
public static TcpClient[] MachiensTcpClient = new TcpClient[99];
public static SerialPortClient[] MachiensPortClient = new SerialPortClient[4];
//public static DataRow[] machinesdata = new DataRow[999];
@@ -1334,7 +1316,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1")));
AsyncSerialPortClient._responseEvent.Set();
Port1_link();
Port1_link();
}
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0)
{
@@ -1377,7 +1359,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
await Task.Run(() =>
{
while (MachiensPortClient[0].Online )
while (MachiensPortClient[0].Online)
{
try
{
@@ -1423,7 +1405,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
private async void Port2_link()
{
@@ -1475,7 +1457,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
private async void Port3_link()
{
@@ -1527,7 +1509,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
private async void Port4_link()
{
@@ -1579,7 +1561,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
public static string SYS_WorkNumder; //工单号
@@ -1594,12 +1576,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
}
public static string MachineLOG;
/* public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变
{
get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
}*/
/* public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变
{
get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
}*/
public static object Selet_Machines(DataTable DB, string name, string key)//查询
{
@@ -1613,7 +1595,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
catch (Exception ex)
{
{
LogGing.LogGingDATA("SDTD:" + ex.ToString());
return "ERR";
}
@@ -1629,14 +1611,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
drEmployee[name] = Value;
drEmployee.EndEdit();
drEmployee.AcceptChanges();
// drEmployee.ClearErrors();
// drEmployee.ClearErrors();
}
}
catch (Exception ex)
{
LogGing.LogGingDATA("SDTD:" + ex.ToString());
{
LogGing.LogGingDATA("SDTD:" + ex.ToString());
}
}
}
public static DataTable dt_d = new DataTable("DIO");
public static DataTable dt_a = new DataTable("AIO");
@@ -1645,20 +1627,20 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static DataTable dt_TP = new DataTable();
public static DataTable dt_ParameterSet = new DataTable();
public static DataTable dt_SysSet = new DataTable();
public static bool TechnologicalProcess_bool =true;
// public static bool A_view =true;
// public static bool D_view =true;
public static bool TechnologicalProcess_bool = true;
// public static bool A_view =true;
// public static bool D_view =true;
public static bool IO_view;
// public static bool ParameterSet_view=true;
// public static bool SysSet_view=true;
// public static bool ParameterSet_view=true;
// public static bool SysSet_view=true;
public static string machine;
public static string workOrder;
public static string dyelot;
public static string machin_LOG;
//通讯队列
public static UInt32 RX=0;
public static UInt32 TX=0;
public static UInt32 RX = 0;
public static UInt32 TX = 0;
public class QueueSerial
{
public int ID { get; set; }