|
|
|
@ -2,6 +2,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Data; |
|
|
|
using System.Net.Sockets; |
|
|
|
using System.Security.Cryptography.Pkcs; |
|
|
|
using System.Text; |
|
|
|
using System.Text.Json; |
|
|
|
@ -174,77 +175,212 @@ namespace SunlightAggregationManager.UserClass |
|
|
|
Console.WriteLine("TCP Port:"+ port2.ToString()); |
|
|
|
Console.WriteLine("TCP SERVER:START"); |
|
|
|
} |
|
|
|
|
|
|
|
public static async void Command(string dat,string id , Person person)//
|
|
|
|
|
|
|
|
public static async void Command(string dat, string id, Person person)//
|
|
|
|
{ |
|
|
|
string Command="", ret =""; |
|
|
|
try |
|
|
|
{ |
|
|
|
string Command = "", ret = ""; |
|
|
|
|
|
|
|
Dictionary<string, object> data_ = new Dictionary<string, object>(); |
|
|
|
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(dat)!; |
|
|
|
if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!; |
|
|
|
Dictionary<string, object> data_ = new Dictionary<string, object>(); |
|
|
|
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(dat)!; |
|
|
|
if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!; |
|
|
|
if (Command == "Log")//回复请求的信息
|
|
|
|
{ |
|
|
|
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" + |
|
|
|
person?.User + "' and Password ='" + person?.Password + "'"); |
|
|
|
|
|
|
|
if (Command == "Info")//回复info请求的信息
|
|
|
|
{ |
|
|
|
var t = ToList(MainWindowViewModel._machines).ToJsonString(); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Info", t); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "Query")//回复Query请求的信息
|
|
|
|
{ |
|
|
|
string s_ = deserialized.GetValue("StartTime").ToString()!; |
|
|
|
string e_ = deserialized.GetValue("EndTime").ToString()!; |
|
|
|
string f_ = deserialized.GetValue("Field").ToString()!; |
|
|
|
|
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT "+ |
|
|
|
f_+" FROM [dbo].[Dyelots] " + "WHERE CreationTime>'"+s_+"'and CreationTime<'"+e_+"'"); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "QueryDyelot")//回复QueryDyelot请求的信息
|
|
|
|
{ |
|
|
|
string d_ = deserialized.GetValue("DyelotName").ToString()!; |
|
|
|
string f_ = deserialized.GetValue("Field").ToString()!; |
|
|
|
|
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[Dyelots] " + "WHERE Dyelot LIKE '" + d_ + "%'"); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "QueryDetail")//回复info请求的信息
|
|
|
|
{ |
|
|
|
string d_ = deserialized.GetValue("Dyelot").ToString()!; |
|
|
|
string r_ = deserialized.GetValue("ReDye").ToString()!; |
|
|
|
string f_ = deserialized.GetValue("Field").ToString()!; |
|
|
|
|
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[DyelotsBulkedRecipe] " + "WHERE Dyelot='" + d_ + "'and ReDye='" + r_ + "'"); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("QueryDetail", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "Notification")//回复Notification请求的信息
|
|
|
|
{ |
|
|
|
string s_ = deserialized.GetValue("StartTime").ToString()!; |
|
|
|
string e_ = deserialized.GetValue("EndTime").ToString()!; |
|
|
|
data_.Add("Enterprise", _user?.Field<object>("Enterprise") ?? ""); |
|
|
|
data_.Add("Department", _user?.Field<object>("Department") ?? ""); |
|
|
|
data_.Add("Groups", _user?.Field<object>("Groups") ?? ""); |
|
|
|
data_.Add("UserId", _user?.Field<object>("UserID") ?? ""); |
|
|
|
data_.Add("UserName", _user?.Field<object>("Name") ?? ""); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "SysData")//回复请求的信息
|
|
|
|
{ |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "ChemicalStatistics")//回复请求的信息
|
|
|
|
{ |
|
|
|
data_.Add("ChemicalStatistics", Newtonsoft.Json.JsonConvert.SerializeObject(MainWindowViewModel.ChemicalStatistics)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "Info")//回复info请求的信息
|
|
|
|
{ |
|
|
|
var t = ToList(MainWindowViewModel._machines).ToJsonString(); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Info", t); |
|
|
|
data_.Add("DyeMeasurementNumber", MainWindowViewModel.DyeMeasurementNumber.ToString()); |
|
|
|
data_.Add("ChemicalNumber", MainWindowViewModel.ChemicalNumber.ToString()); |
|
|
|
data_.Add("PowderNumber", MainWindowViewModel.PowderNumber.ToString()); |
|
|
|
data_.Add("DyeDissolveNumber", MainWindowViewModel.DyeDissolveNumber.ToString()); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "Query")//回复Query请求的信息
|
|
|
|
{ |
|
|
|
string s_ = deserialized.GetValue("StartTime").ToString()!; |
|
|
|
string e_ = deserialized.GetValue("EndTime").ToString()!; |
|
|
|
string f_ = deserialized.GetValue("Field").ToString()!; |
|
|
|
|
|
|
|
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData, |
|
|
|
"Groups", "User='" + person?.User + "'"); |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[Dyelots] " + "WHERE CreationTime>'" + s_ + "'and CreationTime<'" + e_ + "'"); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "QueryDyelot")//回复QueryDyelot请求的信息
|
|
|
|
{ |
|
|
|
string d_ = deserialized.GetValue("DyelotName").ToString()!; |
|
|
|
string f_ = deserialized.GetValue("Field").ToString()!; |
|
|
|
|
|
|
|
var resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("" + |
|
|
|
"select * from Notification WHERE Groups='" + groups + "' and Time>'" + |
|
|
|
s_ + "' and Time<'" + e_ + "'", null)?.Tables[0] ?? new DataTable(); |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[Dyelots] " + "WHERE Dyelot LIKE '" + d_ + "%'"); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "QueryDetail")//回复QueryDetail请求的信息
|
|
|
|
{ |
|
|
|
string d_ = deserialized.GetValue("Dyelot").ToString()!; |
|
|
|
string r_ = deserialized.GetValue("ReDye").ToString()!; |
|
|
|
string f_ = deserialized.GetValue("Field").ToString()!; |
|
|
|
|
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Notification", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[DyelotsBulkedRecipe] " + "WHERE Dyelot='" + d_ + "'and ReDye='" + r_ + "'"); |
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("QueryDetail", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "Notification")//回复Notification请求的信息
|
|
|
|
{ |
|
|
|
string s_ = deserialized.GetValue("StartTime").ToString()!; |
|
|
|
string e_ = deserialized.GetValue("EndTime").ToString()!; |
|
|
|
|
|
|
|
person.Dat=ret.ToString(); |
|
|
|
var jsdat = JsonSerializer.Serialize(person); |
|
|
|
await service.SendAsync(id, jsdat); |
|
|
|
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData, |
|
|
|
"Groups", "User='" + person?.User + "'"); |
|
|
|
|
|
|
|
DataTable resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("" + |
|
|
|
"select * from Notification WHERE Groups='" + groups + "' and Id>'" + |
|
|
|
s_ + "'", null)?.Tables[0] ?? new DataTable(); |
|
|
|
if (resultTable.Rows.Count == 0) resultTable.Rows.Add(); |
|
|
|
|
|
|
|
//格式化返回信息
|
|
|
|
data_.Add("Notification", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "InfoMachine")//回复InfoMachine请求的信息
|
|
|
|
{ |
|
|
|
string t_ = deserialized.GetValue("Type").ToString()!; |
|
|
|
string? m_ = null, f_ = "*"; |
|
|
|
|
|
|
|
if (deserialized.TryGetValue("MachinName", out var MachinName) && MachinName != null) m_ = MachinName.ToString(); |
|
|
|
if (deserialized.TryGetValue("Field", out var Field) && Field != null) f_ = Field.ToString(); |
|
|
|
|
|
|
|
if (t_ == "10") |
|
|
|
{ |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[WaitDispenseDyestuff] WHERE DispenseMachine='" + m_ + "'"); |
|
|
|
data_.Add("Type", "10"); |
|
|
|
data_.Add("InfoMachine", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
} |
|
|
|
else if (t_ == "12") |
|
|
|
{ |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[ShelfInfo] "); |
|
|
|
data_.Add("Type", "12"); |
|
|
|
data_.Add("InfoMachine", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
} |
|
|
|
else if (t_ == "20") |
|
|
|
{ |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[WaitChemical] WHERE DispenseMachine='" + m_ + "'"); |
|
|
|
data_.Add("Type", "20"); |
|
|
|
data_.Add("InfoMachine", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
data_.Add("InfoMachine", ""); |
|
|
|
} |
|
|
|
|
|
|
|
//格式化返回信息
|
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "InfoMachineHistory")//回复InfoMachineHistory请求的信息
|
|
|
|
{ |
|
|
|
string t_ = deserialized.GetValue("Type").ToString()!; |
|
|
|
string? m_ = null, f_ = "*"; |
|
|
|
|
|
|
|
if (deserialized.TryGetValue("MachinName", out var MachinName) && MachinName != null) m_ = MachinName.ToString(); |
|
|
|
if (deserialized.TryGetValue("Field", out var Field) && Field != null) f_ = Field.ToString(); |
|
|
|
|
|
|
|
if (t_ == "80") |
|
|
|
{ |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[DyeSolutionHistory] WHERE DispenseStartTime >'" + DateTime.Now.AddDays(-3) + |
|
|
|
"' and DispenseMachine='" + m_ + "'"); |
|
|
|
data_.Add("Type", "80"); |
|
|
|
data_.Add("InfoMachineHistory", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
} |
|
|
|
else if (t_ == "82") |
|
|
|
{ |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[inOutRecords] WHERE Createtime >'" + DateTime.Now.AddDays(-3) + "'"); |
|
|
|
data_.Add("Type", "82"); |
|
|
|
data_.Add("InfoMachineHistory", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
} |
|
|
|
else if (t_ == "90") |
|
|
|
{ |
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[DyeSolutionHistory] WHERE DispenseStartTime >'" + DateTime.Now.AddDays(-3) + |
|
|
|
"' and DispenseMachine='" + m_ + "'"); |
|
|
|
data_.Add("Type", "90"); |
|
|
|
data_.Add("InfoMachineHistory", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
data_.Add("InfoMachineHistory", ""); |
|
|
|
} |
|
|
|
|
|
|
|
//格式化返回信息
|
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "InfoMachinePipes")//回复Notification请求的信息
|
|
|
|
{ |
|
|
|
string? m_ = null, f_ = "*"; |
|
|
|
|
|
|
|
if (deserialized.TryGetValue("MachinName", out var MachinName) && MachinName != null) m_ = MachinName.ToString(); |
|
|
|
if (deserialized.TryGetValue("Field", out var Field) && Field != null) f_ = Field.ToString(); |
|
|
|
|
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT " + |
|
|
|
f_ + " FROM [dbo].[Pipes] WHERE Dispenser='" + m_ + "'"); |
|
|
|
data_.Add("InfoMachinePipes", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
|
|
|
|
|
//格式化返回信息
|
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
if (Command == "SETUSER")//回复Notification请求的信息
|
|
|
|
{ |
|
|
|
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, |
|
|
|
"User='" + deserialized.GetValue("USER").ToString()! + "'", |
|
|
|
deserialized.GetValue("VALUE").ToString(), deserialized.GetValue("KEY").ToString()!); |
|
|
|
data_.Add("USER", deserialized.GetValue("USER").ToString()!); |
|
|
|
data_.Add("VALUE", deserialized.GetValue("VALUE").ToString()!); |
|
|
|
data_.Add("KEY", deserialized.GetValue("KEY").ToString()!); |
|
|
|
data_.Add("SETUSER", "OK"); |
|
|
|
//格式化返回信息
|
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
} |
|
|
|
|
|
|
|
person!.Dat = ret.ToString(); |
|
|
|
var jsdat = JsonSerializer.Serialize(person); |
|
|
|
await service.SendAsync(id, jsdat); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
LogGing.ERRDATA(ex); |
|
|
|
Console.WriteLine(ex.ToString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
|
|
|
|
|