总览信息发布

This commit is contained in:
sc committed 2025-01-10 01:20:08 +08:00
commit 0c6bc3105f
5 files changed
+163 -49

No files matched your search

+76 -21
View File
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using LiveChartsCore.Geo;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenTK.Graphics.ES11;
using SunlightCentralizedControlManagement_SCCM_.Properties;
@@ -17,8 +18,10 @@ using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml.Linq;
using TouchSocket.Core;
using TouchSocket.Sockets;
using static MaterialDesignThemes.Wpf.Theme;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static System.Net.WebRequestMethods;
@@ -56,7 +59,21 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static string SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
public static string SQLPASWORD = Configini.IniReadvalue("SQL_SERVER", "SQL5");
public static SqlConnection conn_SC =new SqlConnection();//数据库
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
public static DataTable Machines = new DataTable(); //设备表缓存
public static UserControls.info[] inf = new UserControls.info[999]; //定义总览信息卡
public MainWindowViewModel()
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
CountDown();
TcpClientNEW();
SQL_LINK();
}
public static async void SQL_LINK()//连接dbc数据库
{
if (conn_SC.State == ConnectionState.Open) conn_SC.Close();
@@ -97,7 +114,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
DispatcherTimer dis50ms = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(100) //毫秒
Interval = TimeSpan.FromMilliseconds(50) //毫秒
};
dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法
dis50ms.Start();//计时开始
@@ -116,6 +133,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{
SQLiteHelper WorkOrderSQL = new SQLiteHelper(DBAddress); //数据库连接路径
WorkOrderSQL.Open(); //打开数据库
DataTable WorkOrderdata = WorkOrderSQL.ExecuteDataSet("select * from WorkOrder where State='100'", null).Tables[0]; //读取表写入缓存
for(int k=0;k<WorkOrderdata.Rows.Count;k++)
{
string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
string State = Machines.Select("Name='" + WorkOrderdata_m + "'").
First().Field<object>("State").ToString();
if ((State == "101") || (State == "201") || (State == "202") || (State == "309"))
{
DataTable dataTable = WorkOrderdata.Clone();
// WorkOrderdata.Columns.Remove("Machines");
DataRow dt_temp = WorkOrderdata.Select()[k];
dt_temp.BeginEdit();
dt_temp["State"] = "101";
dt_temp.EndEdit();
dataTable.Rows.Add(dt_temp.ItemArray);
int index = Convert.ToInt16(Machines.Select("NAME='" + WorkOrderdata_m + "'").First().Field<object>("ID"));
stringQueue.Enqueue(new QueueString
{
ID = index,
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", index) + DataTableToDictionary(dataTable).ToJsonString()
});
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object>{{ "State", 110 }},
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
}
WorkOrderSQL.Close();
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
for (int i = 0; i < Machinesdata_Count; i++)
@@ -157,7 +204,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
MachiensTcpClient[i].SendAsync("SC800:SCCM[" + MachiensTcpClient[i].IP + ";" + MachiensTcpClient[i].Port + "]");
}
}
}//发送800指令
}
void Tick_Event_60S()
{
@@ -171,25 +218,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
, Selet_Machines(Machines, "IP", Convert.ToInt16(dt["ID"])).ToString()
, Selet_Machines(Machines, "PORT", Convert.ToInt16(dt["ID"])).ToString());
}
}
}//重连
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
public static DataTable Machines = new DataTable(); //设备表缓存
public static UserControls.info[] inf = new UserControls.info[999]; //定义总览信息卡
public MainWindowViewModel()
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
CountDown();
TcpClientNEW();
SQL_LINK();
}
public static TcpClient[] MachiensTcpClient = new TcpClient[999];
public static DataRow[] machinesdata = new DataRow[999];
public int Machinesdata_Count;
@@ -540,5 +571,29 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
// 创建一个字符串类型的队列
public static Queue<QueueString> stringQueue = new Queue<QueueString>();
/// <summary>
/// 将 DataTable 转换为 Dictionary 类型数据
/// </summary>
public Dictionary<string, object> DataTableToDictionary(DataTable dataTable)
{
Dictionary<string, object> result = new Dictionary<string, object>();
if (dataTable != null)
{
foreach (DataRow dataRow in dataTable.Rows)
{
foreach (DataColumn dataColumn in dataTable.Columns)
{
result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString());
//result = Console.WriteLine(dataRow[dataColumn].ToString());
//result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString())(new RepeatDictionaryComparer());
}
}
}
else
{
result = null;
}
return result;
}
}
}