This commit is contained in:
sc committed 2025-08-25 00:25:50 +08:00
commit d13edd4070
9 files changed
+315 -5

No files matched your search

+170 -4
View File
@@ -3,6 +3,8 @@ using LiveChartsCore.Geo;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenTK.Graphics.ES11;
using ScottPlot.Palettes;
using SunlightCentralizedControlManagement_SCCM_.EX.Exchange;
using SunlightCentralizedControlManagement_SCCM_.Properties;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
@@ -11,10 +13,12 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Data.SqlClient;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Reflection;
using System.Speech.Synthesis;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -26,10 +30,11 @@ using System.Windows.Threading;
using System.Xml.Linq;
using TouchSocket.Core;
using TouchSocket.Sockets;
using System.Speech.Synthesis;
using static MaterialDesignThemes.Wpf.Theme;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static SunlightCentralizedControlManagement_SCCM_.ViewModel.ManualDyelotModel;
using static System.Net.WebRequestMethods;
using static System.Windows.Forms.AxHost;
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
@@ -69,6 +74,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static bool DyelotsDispenser;
public static SqlConnection conn_SC =new SqlConnection();//数据库
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private BDC_SQL.BDCSqlHelper bDCSqlHelper = new BDC_SQL.BDCSqlHelper();
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
public static DataTable Machines = new DataTable(); //设备表缓存
// public static DataRow MachinesROW;
@@ -99,7 +105,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0];
Dyelot_CALL = SQLiteHelpers.ExecuteDataSet("select * from Dyelot", null).Tables[0].Clone();
SQLiteHelpers.Close();
USERCapacity(App.USER_Purview);//App.USER_Purview);
CountDown();
TcpClientNEW();
@@ -131,7 +137,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
public static async void SQL_LINK()//连接dbc数据库
public async void SQL_LINK()//连接dbc数据库
{
if (conn_SC.State == ConnectionState.Open) conn_SC.Close();
try
@@ -152,6 +158,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
LogGing.LogGingDATA("[Database='" + ex + "']=SQLSERVER");
ERR_c++;
}
if (SQMOD == "Windows Authentication") //连接数据库测试
{
bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, true);
}
else
{
bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, false);
}
}
public void CountDown()
@@ -304,7 +319,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
else { Time60++; }
}
void Tick_Event_5S()//Tick_Event周期执行事件5S
async void Tick_Event_5S()//Tick_Event周期执行事件5S
{
for (int i = 0; i < Machinesdata_Count; i++)
{/**发送800指令**/
@@ -348,7 +363,158 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
catch (Exception) { }
try
{//处理呼叫请求列表
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);
if (r > 0)
{
DataRow[] dataRows = Dyelot_CALL.Select("Dyelot='" + row.Field<string>("Dyelot") +
"' and Redye='" + row.Field<int>("Redye") +
"' and Step='" + row.Field<int>("Step") + "'");
foreach (DataRow dataRow in dataRows)
{
dataRow.BeginEdit();
dataRow["State"] = 203;
dataRow.EndEdit();
}
Dictionary<string, object> dat_ = new Dictionary<string, object>();//缓存函数
dat_.Add("State", 203);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Update("DyelotHistory", dat_,
"Dyelot='" + row.Field<string>("Dyelot") +
"' and Redye='" + row.Field<int>("Redye") +
"' and Step='" + row.Field<int>("Step") + "'", null);// 执行插入
SQLiteHelpers.Close();
}
}
}
catch (Exception) { }
try
{//检查呼叫回复列表
if (Dyelot_CALL.Select("State='203'").Count() > 0)
{
DataTable dt = new DataTable();
int ri = 0;
// DataRow[] dataRows = Dyelot_CALL.Select("State='203'");
foreach (DataRow dataRow in Dyelot_CALL.Select("State='203'"))
{
ri++;
if ((dataRow["State"].ToString() != "301") && (dataRow["State"].ToString() != "309"))
{
if (dataRow.Field<int>("Type") == 2)
{
dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field<string>("Machine") +
"' AND (DyeState = 301 OR DyeState = 309)");
if (dt.Rows.Count > 0)
{
if (dt.Select("DyeState = 301").Count() > 0)
{
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>("StepNumber"));
foreach (DataRow Row in dr.Rows)
{
DataRow data = Dyelot_CALL.Select("ProductCode='" + Row.Field<string>("ProductCode") + "'").First();
data.BeginEdit();
data["Amount"] = Row.Field<float>("Amount");
data["DispenseEndTime"] = Row.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
data.EndEdit();
}
}
else
{
MainWindow.InfData.Rows.Add(new object[] { dataRow["Machine"],
Resources.Dyelot + dataRow["Dyelot"] + Resources.Step + dataRow["Step"]+
Resources.DispenseException,
Selet_Machines(Machines, "SYSKEY", "Name='" + dataRow["Machine"] + "'"),
Selet_Machines(Machines, "ID", "Name='" + dataRow["Machine"] + "'")});
}
}
}
else if (dataRow.Field<int>("Type") == 3)
{
dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field<string>("Machine") +
"' AND (PowderState = 301 OR PowderState = 309)");
if (dt.Rows.Count > 0)
{
if (dt.Select("PowderState = 301").Count() > 0)
{
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>("StepNumber"));
foreach (DataRow Row in dr.Rows)
{
DataRow data = Dyelot_CALL.Select("ProductCode='" + Row.Field<string>("ProductCode") + "'").First();
data.BeginEdit();
data["Amount"] = Row.Field<float>("Amount");
data["DispenseEndTime"] = Row.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
data.EndEdit();
}
}
else
{
MainWindow.InfData.Rows.Add(new object[] { dataRow["Machine"],
Resources.Dyelot + dataRow["Dyelot"] + Resources.Step + dataRow["Step"]+
Resources.DispenseException,
Selet_Machines(Machines, "SYSKEY", "Name='" + dataRow["Machine"] + "'"),
Selet_Machines(Machines, "ID", "Name='" + dataRow["Machine"] + "'")});
}
}
}
else
{
dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field<string>("Machine") +
"' AND (ChemicalState = 301 OR ChemicalState = 309)");
if (dt.Rows.Count > 0)
{
if (dt.Select("PowderState = 301").Count() > 0)
{
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>("StepNumber"));
foreach (DataRow Row in dr.Rows)
{
DataRow data = Dyelot_CALL.Select("ProductCode='" + Row.Field<string>("ProductCode") + "'").First();
data.BeginEdit();
data["Amount"] = Row.Field<float>("Amount");
data["DispenseEndTime"] = Row.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
data.EndEdit();
}
}
else
{
MainWindow.InfData.Rows.Add(new object[] { dataRow["Machine"],
Resources.Dyelot + dataRow["Dyelot"] + Resources.Step + dataRow["Step"]+
Resources.DispenseException,
Selet_Machines(Machines, "SYSKEY", "Name='" + dataRow["Machine"] + "'"),
Selet_Machines(Machines, "ID", "Name='" + dataRow["Machine"] + "'")});
}
}
}
}
}
}
}
catch (Exception) { }
}