Compare commits
67
Commits
a5151aa64a
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9afd362de6 | ||
|
|
5b9cf5a538 | ||
|
|
db203d01e1 | ||
|
|
8690824663 | ||
|
|
5ca8148c42 | ||
|
|
e54cafd16b | ||
|
|
c21504993f | ||
|
|
8e90c904ee | ||
|
|
85e60c01bc | ||
|
|
0ce1a57a53 | ||
|
|
c2451be4a2 | ||
|
|
8aa79a46e3 | ||
|
|
654f73aca8 | ||
|
|
a0eeb9c8c4 | ||
|
|
ebbb44b132 | ||
|
|
c94fe5c62f | ||
|
|
ffc9b3d425 | ||
|
|
d9d00cc9fa | ||
|
|
e28be80856 | ||
|
|
db73d606e8 | ||
|
|
7fb76a9d12 | ||
|
|
7437355573 | ||
|
|
65cfef8d02 | ||
|
|
ea2e55787c | ||
|
|
85a4630020 | ||
|
|
5aca5ad39f | ||
|
|
fd88cca4c6 | ||
|
|
cb1e7a2e65 | ||
|
|
ee65be0f93 | ||
|
|
59e1272cdb | ||
|
|
474093d2f2 | ||
|
|
d39aadc98d | ||
|
|
eb3e13c63a | ||
|
|
610c9c31ac | ||
|
|
e38418500d | ||
|
|
b70596cf31 | ||
|
|
5c8071f1f4 | ||
|
|
3bbfe20f84 | ||
|
|
9a5195cb0a | ||
|
|
683f8ac880 | ||
|
|
0b444636a4 | ||
|
|
710672bfc0 | ||
|
|
a92610c2f4 | ||
|
|
c43531c206 | ||
|
|
f1085c0291 | ||
|
|
7860fe088b | ||
|
|
dbcdc02d91 | ||
|
|
d35420bed1 | ||
|
|
7039c1d5eb | ||
|
|
919e0b662b | ||
|
|
498f65dae9 | ||
|
|
797738c240 | ||
|
|
c5c8c536be | ||
|
|
aee911cc20 | ||
|
|
8213e51756 | ||
|
|
751bbe5199 | ||
|
|
a58132e6d8 | ||
|
|
c362d9177f | ||
|
|
e06aeb054c | ||
|
|
ea0077a3e7 | ||
|
|
7ec9c22520 | ||
|
|
5d9ab90ed3 | ||
|
|
f2a3b697d2 | ||
|
|
10611241d1 | ||
|
|
6c27d7c0e5 | ||
|
|
b079f6556c | ||
|
|
6b16bc838c |
No files matched your search
+53
-1
@@ -3,6 +3,7 @@ using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace SunlightAggregationManager
|
||||
{
|
||||
@@ -11,7 +12,58 @@ namespace SunlightAggregationManager
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
RegisterGlobalExceptionHandlers();
|
||||
}
|
||||
|
||||
private void RegisterGlobalExceptionHandlers()
|
||||
{
|
||||
// 1. 捕获 UI 主线程的未处理异常
|
||||
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
|
||||
|
||||
// 2. 捕获非 UI 线程(后台线程)的未处理异常
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
// 3. 捕获 Task 异步任务中的未观察到的异常
|
||||
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
|
||||
}
|
||||
|
||||
// UI线程异常处理
|
||||
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
LogAndShowError("UI线程发生异常", e.Exception);
|
||||
|
||||
// 【关键】将 Handled 设为 true,告诉 WPF 该异常已被处理,阻止程序自动闪退
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
// 非UI线程异常处理
|
||||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
var exception = e.ExceptionObject as Exception;
|
||||
bool isTerminating = e.IsTerminating;
|
||||
|
||||
LogAndShowError($"非UI线程异常 (即将终止: {isTerminating})", exception);
|
||||
|
||||
// 注意:此事件不允许设置 Handled=true,默认情况下致命异常仍会导致程序退出
|
||||
}
|
||||
|
||||
// Task线程异常处理
|
||||
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
|
||||
{
|
||||
LogAndShowError("Task异步任务异常", e.Exception);
|
||||
|
||||
// 标记异常已被观察,防止它被重新抛出导致进程终止
|
||||
e.SetObserved();
|
||||
}
|
||||
|
||||
private void LogAndShowError(string context, Exception ex)
|
||||
{
|
||||
// 在这里记录日志或弹出友好的自定义错误提示窗口
|
||||
MessageBox.Show($"{context}:\n{ex?.Message}", "程序遇到错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
[SYS]
|
||||
Language=zh-CN
|
||||
Name=YZ
|
||||
Enterprise=YONGZHAO
|
||||
[SQL_SERVER]
|
||||
SQL1=192.168.15.248
|
||||
SQL2=BatchDyeingCentral
|
||||
SQL3=SQL SERVER
|
||||
SQL4=sa
|
||||
SQL5=yf888999
|
||||
[NETWORK]
|
||||
TCP=1
|
||||
HTTP=1
|
||||
TLS=0
|
||||
TCP_PORT1=7789
|
||||
TCP_PORT2=7790
|
||||
HTTP_PORT=7791
|
||||
[SERVER]
|
||||
SERVERIP=www.scserverddns.top:7795
|
||||
SERVERNAME=SUNLIGHT
|
||||
SERVERUSER=SUNLIGHT
|
||||
SERRVERPASWORD=SUNLIGHT
|
||||
|
||||
Binary file not shown.
+4
-1
@@ -24,7 +24,7 @@ namespace SunlightAggregationManager
|
||||
}
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GlobalLogManager.RegisterTarget(LOG);
|
||||
GlobalLogManager.RegisterTarget(LOG,LogGing.LogGingDATA);
|
||||
|
||||
DataContext = new MainWindowViewModel();
|
||||
}
|
||||
@@ -80,11 +80,13 @@ namespace SunlightAggregationManager
|
||||
{
|
||||
state.Visibility = Visibility.Collapsed;
|
||||
Picture.Visibility = Visibility.Visible;
|
||||
Picture.Content = new View.MachinePage();
|
||||
}
|
||||
private void ListViewItem_MouseLeftButtonUp_extend(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
state.Visibility = Visibility.Collapsed;
|
||||
Picture.Visibility = Visibility.Visible;
|
||||
Picture.Content = new View.ExtendPage();
|
||||
}
|
||||
private void ListViewItem_MouseLeftButtonUp_user(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
@@ -96,6 +98,7 @@ namespace SunlightAggregationManager
|
||||
{
|
||||
state.Visibility = Visibility.Collapsed;
|
||||
Picture.Visibility = Visibility.Visible;
|
||||
Picture.Content = new View.ActionPage();
|
||||
}
|
||||
|
||||
private void ListViewItem_MouseLeftButtonUp_set(object sender, MouseButtonEventArgs e)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
public class AES
|
||||
{
|
||||
public static string AesEncipher(string Key, string dat) //加密
|
||||
{
|
||||
//压缩
|
||||
byte[] plainBytes = Compress( Encoding.UTF8.GetBytes(dat));
|
||||
|
||||
using var sha256 = System.Security.Cryptography.SHA256.Create();
|
||||
using var aes = System.Security.Cryptography.Aes.Create();
|
||||
|
||||
aes.Key = sha256.ComputeHash(Encoding.UTF8.GetBytes(Key));
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
aes.GenerateIV(); // 生成随机 IV
|
||||
|
||||
using var enc = aes.CreateEncryptor();
|
||||
byte[] cipherBytes = enc.TransformFinalBlock(plainBytes, 0, plainBytes.Length);
|
||||
|
||||
//将 IV (16字节) 和 密文 拼接成一个完整的字节数组
|
||||
byte[] combinedBytes = new byte[aes.IV.Length + cipherBytes.Length];
|
||||
Buffer.BlockCopy(aes.IV, 0, combinedBytes, 0, aes.IV.Length);
|
||||
Buffer.BlockCopy(cipherBytes, 0, combinedBytes, aes.IV.Length, cipherBytes.Length);
|
||||
|
||||
return Convert.ToBase64String(combinedBytes);
|
||||
}
|
||||
|
||||
public static string AesDecrypt(string Key, string dat)//解密
|
||||
{
|
||||
// 解码Base64
|
||||
byte[] cipherBytes = Convert.FromBase64String(dat);
|
||||
|
||||
using var sha256 = System.Security.Cryptography.SHA256.Create();
|
||||
using var aes = System.Security.Cryptography.Aes.Create();
|
||||
|
||||
aes.Key = sha256.ComputeHash(Encoding.UTF8.GetBytes(Key));
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
// 从字节数组中提取前 16 字节作为 IV
|
||||
aes.IV = cipherBytes.AsSpan(0, 16).ToArray();
|
||||
using var dec = aes.CreateDecryptor();
|
||||
|
||||
// 解密
|
||||
byte[] bytes = dec.TransformFinalBlock(cipherBytes, 16, cipherBytes.Length - 16);
|
||||
//解压缩并返回
|
||||
return Encoding.UTF8.GetString(Decompress(bytes));
|
||||
}
|
||||
|
||||
// 3. Brotli 压缩辅助方法
|
||||
private static byte[] Compress(byte[] data)
|
||||
{
|
||||
using var output = new MemoryStream();
|
||||
using (var brotli = new BrotliStream(output, CompressionLevel.Optimal))
|
||||
{
|
||||
brotli.Write(data, 0, data.Length);
|
||||
}
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
// 4. Brotli 解压辅助方法
|
||||
private static byte[] Decompress(byte[] data)
|
||||
{
|
||||
using var input = new MemoryStream(data);
|
||||
using var brotli = new BrotliStream(input, CompressionMode.Decompress);
|
||||
using var output = new MemoryStream();
|
||||
brotli.CopyTo(output);
|
||||
return output.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using TouchSocket.Core;
|
||||
@@ -16,7 +17,10 @@ namespace SunlightAggregationManager.UserClass
|
||||
public class AsyncHttpServer
|
||||
{
|
||||
public static HttpService httpservice = new HttpService();
|
||||
|
||||
public static async void Configuration(int P1)
|
||||
{
|
||||
await HttpMain(P1);
|
||||
}
|
||||
public static async Task HttpMain(int port1)
|
||||
{
|
||||
NetFwManger.AllowPort(port1, "TCP");//开放端口
|
||||
@@ -97,6 +101,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("Http:" + ex.ToString());
|
||||
//client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
}
|
||||
@@ -131,18 +136,31 @@ namespace SunlightAggregationManager.UserClass
|
||||
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" +
|
||||
deserializedPerson?.User + "' and Password ='" + deserializedPerson?.Password + "'");
|
||||
|
||||
data_.Add("Enterprise", _user?.Field<object>("Enterprise") ?? "");
|
||||
data_.Add("Enterprise",MainWindowViewModel.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请求的信息
|
||||
@@ -168,7 +186,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
if (Command == "QueryDetail")//回复info请求的信息
|
||||
if (Command == "QueryDetail")//回复QueryDetail请求的信息
|
||||
{
|
||||
string d_ = deserialized.GetValue("Dyelot").ToString()!;
|
||||
string r_ = deserialized.GetValue("ReDye").ToString()!;
|
||||
@@ -180,8 +198,127 @@ namespace SunlightAggregationManager.UserClass
|
||||
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()!;
|
||||
|
||||
return ret;
|
||||
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData,
|
||||
"Groups", "User='" + deserializedPerson?.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_);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
|
||||
|
||||
+335
-90
@@ -1,9 +1,12 @@
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using SunlightAggregationManager.UserWindow;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
using static SunlightAggregationManager.UserClass.AsyncTcpServer;
|
||||
@@ -34,11 +37,15 @@ namespace SunlightAggregationManager.UserClass
|
||||
|
||||
public static async Task TcpClient(TouchSocket.Sockets.TcpClient tcpClient, string ip)
|
||||
{
|
||||
|
||||
// 自定义心跳首次延迟60秒开始,之后每30秒执行一次
|
||||
Timer timer = new Timer(TimerCallback, null, TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(30));
|
||||
|
||||
tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp
|
||||
tcpClient.Connected = (client, e) =>
|
||||
{
|
||||
//设定显示状态
|
||||
System.Data.DataRow targetRow =ViewModel.MainWindowViewModel._service.Select("ID = 1").FirstOrDefault()!;
|
||||
System.Data.DataRow targetRow =ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
|
||||
if (targetRow != null)
|
||||
{
|
||||
targetRow.BeginEdit();
|
||||
@@ -58,9 +65,18 @@ namespace SunlightAggregationManager.UserClass
|
||||
Console.WriteLine("Sunlight_Server_Connected");
|
||||
return EasyTask.CompletedTask;
|
||||
};//成功连接到服务器
|
||||
tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
|
||||
tcpClient.Closing = (client, e) => {
|
||||
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
|
||||
if (targetRow != null)
|
||||
{
|
||||
targetRow.BeginEdit();
|
||||
targetRow["Status"] = "Disconnect";
|
||||
targetRow.EndEdit();
|
||||
}
|
||||
Console.WriteLine("Sunlight_Server_Disconnect");
|
||||
return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
|
||||
tcpClient.Closed = (client, e) => {
|
||||
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("ID = 1").FirstOrDefault()!;
|
||||
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
|
||||
if (targetRow != null)
|
||||
{
|
||||
targetRow.BeginEdit();
|
||||
@@ -74,139 +90,368 @@ namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
|
||||
var mes = e.Memory.Span.ToString(Encoding.UTF8);
|
||||
//信息处理暂停心跳定时
|
||||
timer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
|
||||
try
|
||||
{
|
||||
Person? deserializedPerson = JsonSerializer.Deserialize<Person>(mes);
|
||||
Person? deserializedPerson = JsonSerializer.Deserialize<Person>(mes);
|
||||
string password= AES.AesDecrypt(deserializedPerson?.Terminal!, deserializedPerson?.Password!);
|
||||
|
||||
var _user = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData, "State", "User='" +
|
||||
deserializedPerson?.User + "' and Password ='" + deserializedPerson?.Password + "'");
|
||||
deserializedPerson?.User + "' and Password ='" + password + "'");
|
||||
if (_user != null)
|
||||
{
|
||||
string _dat = _user?.ToString() ?? "0";
|
||||
if (_dat != "99")
|
||||
{
|
||||
//行为
|
||||
Dictionary<string, object> myDict = new Dictionary<string, object>();
|
||||
//myDict.Add("LinkID", client.Id);
|
||||
myDict.Add("LastLoginIP", deserializedPerson?.IP ?? client.IP);
|
||||
myDict.Add("LastActionTime", DateTime.Now);
|
||||
myDict.Add("Note", deserializedPerson?.Dat ?? "unknown");
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict);
|
||||
Dictionary<string, object> myDict = new Dictionary<string, object>();
|
||||
//myDict.Add("LinkID", client.Id);
|
||||
|
||||
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]");
|
||||
CommandC(deserializedPerson?.Dat ?? "NOT", deserializedPerson!);
|
||||
|
||||
//AES解密
|
||||
string dataAES = AES.AesDecrypt(deserializedPerson!.Terminal, deserializedPerson.Dat);
|
||||
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]COMMAND[" +
|
||||
Regex.Replace(dataAES, @"\\u[0-9A-Fa-f]{4}", match =>
|
||||
{ return Regex.Unescape(match.Value); }) + "]");
|
||||
|
||||
//记录
|
||||
myDict.Add("LastLoginIP", deserializedPerson?.IP ?? client.IP);
|
||||
myDict.Add("LastActionTime", DateTime.Now);
|
||||
myDict.Add("Note", dataAES ?? "unknown");
|
||||
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" +
|
||||
deserializedPerson?.User + "'", myDict);
|
||||
|
||||
CommandC(dataAES ?? "NOT", deserializedPerson!);
|
||||
}
|
||||
else
|
||||
{//停用账号关闭连接
|
||||
client.SendAsync("Account Deactivated");
|
||||
|
||||
}
|
||||
}
|
||||
else if (password== MainWindowViewModel.SERRVERPASWORD && deserializedPerson?.User== MainWindowViewModel.SERVERUSER)
|
||||
{
|
||||
//行为
|
||||
Dictionary<string, object> myDict = new Dictionary<string, object>();
|
||||
//myDict.Add("LinkID", client.Id);
|
||||
|
||||
//AES解密
|
||||
string dataAES = AES.AesDecrypt(deserializedPerson!.Terminal, deserializedPerson.Dat);
|
||||
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]COMMAND[" +
|
||||
Regex.Replace(dataAES, @"\\u[0-9A-Fa-f]{4}", match =>
|
||||
{ return Regex.Unescape(match.Value); }) + "]");
|
||||
|
||||
//记录
|
||||
myDict.Add("LastLoginIP", deserializedPerson?.IP ?? client.IP);
|
||||
myDict.Add("LastActionTime", DateTime.Now);
|
||||
myDict.Add("Note", dataAES ?? "unknown");
|
||||
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" +
|
||||
deserializedPerson?.User + "'", myDict);
|
||||
|
||||
CommandC(dataAES ?? "NOT", deserializedPerson!);
|
||||
}
|
||||
else
|
||||
{ //无效账号关闭连接
|
||||
client.SendAsync("Invalid Account");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
}
|
||||
finally
|
||||
{//继续心跳定时
|
||||
timer.Change(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));
|
||||
}
|
||||
|
||||
return EasyTask.CompletedTask;
|
||||
};
|
||||
#endregion
|
||||
|
||||
// while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
await tcpClient.SetupAsync(new TouchSocketConfig()
|
||||
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
|
||||
.SetRemoteIPHost(ip)
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
|
||||
{
|
||||
options.PollingInterval = TimeSpan.FromSeconds(5);
|
||||
});
|
||||
|
||||
})
|
||||
.ConfigureContainer(a =>
|
||||
{
|
||||
|
||||
}));
|
||||
|
||||
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
|
||||
// break;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// tcpClient.Dispose();//清
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
// await Task.Delay(TimeSpan.FromMinutes(1));
|
||||
// Console.WriteLine("Tcp:重试连接...");
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void TimerCallback(object? state)
|
||||
{
|
||||
try
|
||||
{
|
||||
await tcpClient.SetupAsync(new TouchSocketConfig()
|
||||
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
|
||||
.SetRemoteIPHost(ip)
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
|
||||
{
|
||||
options.PollingInterval = TimeSpan.FromSeconds(5);
|
||||
});
|
||||
}));
|
||||
|
||||
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
|
||||
if (tcpClient.Online)
|
||||
{
|
||||
tcpClient.SendAsync("SUNLIGHT");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
Console.WriteLine(ex.ToString());
|
||||
LogGing.ERRDATA(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static async void CommandC(string dat, Person person)//
|
||||
{
|
||||
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()!;
|
||||
if (Command == "Log")//回复请求的信息
|
||||
try
|
||||
{
|
||||
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" +
|
||||
person?.User + "' and Password ='" + person?.Password + "'");
|
||||
string Command = "", ret = "";
|
||||
|
||||
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_);
|
||||
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 == "SysCom")//回复指令的信息
|
||||
{
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
else if (Command == "Log")//回复请求的信息
|
||||
{
|
||||
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" +
|
||||
person?.User + "'");
|
||||
|
||||
data_.Add("Enterprise", MainWindowViewModel.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_);
|
||||
}
|
||||
else if (Command == "SysData")//特殊指令数据库查询
|
||||
{
|
||||
string com_ = deserialized.GetValue("Comm").ToString()!;
|
||||
string da_ = deserialized.GetValue("Data").ToString()!;
|
||||
if (com_ == "SYSDB")//本机sqlite数据库
|
||||
{
|
||||
DataTable resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet(da_, null)?.Tables[0] ?? new DataTable();
|
||||
data_.Add("DB", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
data_.Add("Comm", "SYSDB");
|
||||
data_.Add("Enterprise", MainWindowViewModel.Enterprise);
|
||||
}
|
||||
else if (com_ == "DBCDB")//系统dbc数据库
|
||||
{
|
||||
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync(da_);
|
||||
data_.Add("DB", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable));
|
||||
data_.Add("Comm", "DBCDB");
|
||||
data_.Add("Enterprise", MainWindowViewModel.Enterprise);
|
||||
}
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
else if (Command == "ChemicalStatistics")//回复请求的信息
|
||||
{
|
||||
data_.Add("ChemicalStatistics", Newtonsoft.Json.JsonConvert.SerializeObject(MainWindowViewModel.ChemicalStatistics));
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
}
|
||||
else 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_);
|
||||
}
|
||||
else 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_);
|
||||
}
|
||||
else 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_);
|
||||
}
|
||||
else if (Command == "QueryDetail")//回复QueryDetail请求的信息
|
||||
{
|
||||
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_);
|
||||
}
|
||||
else if (Command == "Notification")//回复Notification请求的信息
|
||||
{
|
||||
string s_; try { s_ = deserialized.GetValue("StartTime").ToString()!; } catch(Exception) { s_ = "0"; }
|
||||
string e_ = deserialized.GetValue("EndTime").ToString()!;
|
||||
|
||||
var groups = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData,
|
||||
"Groups", "User='" + person?.User + "'");
|
||||
var department = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData,
|
||||
"Department", "User='" + person?.User + "'");
|
||||
|
||||
DataTable resultTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("" +
|
||||
"select * from Notification WHERE Groups='" + groups + "'and Department='" +
|
||||
department + "' 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_);
|
||||
}
|
||||
else 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_);
|
||||
}
|
||||
else 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_);
|
||||
}
|
||||
else 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_);
|
||||
}
|
||||
else if (Command == "SETUSER")//回复请求的信息
|
||||
{
|
||||
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_);
|
||||
}
|
||||
//加密回传
|
||||
/*Console.WriteLine("[Log on]User[" + person?.User + "]REPLY[" +
|
||||
Regex.Replace(ret, @"\\u[0-9A-Fa-f]{4}", match =>
|
||||
{ return Regex.Unescape(match.Value); }) + "]");*/
|
||||
|
||||
person!.Dat =AES.AesEncipher( person.Terminal, ret);
|
||||
var jsdat = JsonSerializer.Serialize(person);
|
||||
await tcpClient.SendAsync(jsdat);
|
||||
}
|
||||
if (Command == "Info")//回复info请求的信息
|
||||
catch (Exception ex)
|
||||
{
|
||||
var t = ToList(MainWindowViewModel._machines).ToJsonString();
|
||||
//格式化返回信息
|
||||
data_.Add("Info", t);
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
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_);
|
||||
}
|
||||
|
||||
person!.Dat = ret.ToString();
|
||||
var jsdat = JsonSerializer.Serialize(person);
|
||||
await tcpClient.SendAsync(jsdat);
|
||||
}
|
||||
}
|
||||
}
|
||||
+210
-50
@@ -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;
|
||||
@@ -24,7 +25,14 @@ namespace SunlightAggregationManager.UserClass
|
||||
public required string Terminal { get; set; }
|
||||
public required string Dat { get; set; }
|
||||
}
|
||||
|
||||
public static async void Configuration(int P1, int P2)
|
||||
{
|
||||
await TcpMain(P1, P2);
|
||||
}
|
||||
|
||||
public static TcpService service = new TcpService();
|
||||
|
||||
public static async Task TcpMain(int port1 ,int port2)
|
||||
{
|
||||
NetFwManger.AllowPort(port1, "TCP");//开放7790端口
|
||||
@@ -132,6 +140,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
foreach (var item in AsyncTcpServer.service.Clients)
|
||||
@@ -166,61 +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 ="";
|
||||
|
||||
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 == "Info")//回复info请求的信息
|
||||
try
|
||||
{
|
||||
var t = ToList(MainWindowViewModel._machines).ToJsonString();
|
||||
//格式化返回信息
|
||||
data_.Add("Info", t);
|
||||
ret = JsonSerializer.Serialize(data_);
|
||||
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()!;
|
||||
if (Command == "Log")//回复请求的信息
|
||||
{
|
||||
DataRow? _user = MainWindowViewModel.Selet_Row(MainWindowViewModel._userData, "User='" +
|
||||
person?.User + "' and Password ='" + person?.Password + "'");
|
||||
|
||||
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()!;
|
||||
|
||||
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")//回复QueryDetail请求的信息
|
||||
{
|
||||
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()!;
|
||||
|
||||
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);
|
||||
}
|
||||
if (Command == "Query")//回复Query请求的信息
|
||||
catch (Exception ex)
|
||||
{
|
||||
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_);
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
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_);
|
||||
}
|
||||
|
||||
person.Dat=ret.ToString();
|
||||
var jsdat = JsonSerializer.Serialize(person);
|
||||
await service.SendAsync(id, jsdat);
|
||||
}
|
||||
|
||||
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
|
||||
|
||||
+52
-7
@@ -18,7 +18,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
private string DB_IP = null!;
|
||||
private string DB_PASSWORD = null!;
|
||||
|
||||
public void Config(string ip, string name, string type, string id, string password)
|
||||
public async void Config(string ip, string name, string type, string id, string password)
|
||||
{
|
||||
DB_IP = ip;
|
||||
DB_ID = id;
|
||||
@@ -26,7 +26,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
DB_TYPE = type;
|
||||
DB_PASSWORD = password;
|
||||
|
||||
_= ConfigAsync();
|
||||
await ConfigAsync();
|
||||
|
||||
}
|
||||
public async Task ConfigAsync()
|
||||
@@ -63,7 +63,8 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("DataBase Link timeout\n"+ex.ToString());
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("DataBase Link timeout\n"+ ex.Message.ToString());
|
||||
// 失败处理
|
||||
return; // 直接返回,不执行后续代码
|
||||
}
|
||||
@@ -76,7 +77,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
// 创建一个空的 DataTable 用于存放查询结果
|
||||
DataTable dataTable = new DataTable();
|
||||
|
||||
// 沿用你原有的数据库连接字符串构建逻辑
|
||||
// 数据库连接字符串构建逻辑
|
||||
var builder = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = DB_IP,
|
||||
@@ -109,14 +110,58 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("DataBase Query failed\n" + ex.ToString());
|
||||
// 这里可以选择将异常抛出给调用方,或者返回一个空的 DataTable
|
||||
throw;
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("DataBase Query failed\n" + ex.Message.ToString());
|
||||
}
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
public async Task<int> ExecuteQueryAsyncCount(string sql)
|
||||
{
|
||||
// 创建一个空的 DataTable 用于存放查询结果
|
||||
DataTable dataTable = new DataTable();
|
||||
|
||||
// 数据库连接字符串构建逻辑
|
||||
var builder = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = DB_IP,
|
||||
InitialCatalog = DB_NAME,
|
||||
IntegratedSecurity = DB_TYPE == "Windows Authentication",
|
||||
TrustServerCertificate = true,
|
||||
ConnectTimeout = 5
|
||||
};
|
||||
|
||||
if (!builder.IntegratedSecurity)
|
||||
{
|
||||
builder.UserID = DB_ID;
|
||||
builder.Password = DB_PASSWORD;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var conn = new SqlConnection(builder.ConnectionString);
|
||||
await conn.OpenAsync(); // 使用异步方式打开连接<websource>source_group_web_2</websource>
|
||||
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
// 执行查询并将结果直接加载到 DataTable 中
|
||||
using (var reader = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
dataTable.Load(reader);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("DataBase Query failed\n" + ex.Message.ToString());
|
||||
}
|
||||
|
||||
return dataTable.Rows.Count;
|
||||
}
|
||||
|
||||
public void Database(string dat)
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
using SunlightAggregationManager.View;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
public class LogGing
|
||||
{
|
||||
public class LOGinf
|
||||
{
|
||||
public required string Logpath { get; set; }
|
||||
public required string LogPath { get; set; }
|
||||
public required string Log_time { get; set; }
|
||||
public required object DAT { get; set; }
|
||||
}
|
||||
static Queue<LOGinf> LogGingQueue = new Queue<LOGinf>();
|
||||
static Queue<LOGinf> ERRQueue = new Queue<LOGinf>();
|
||||
static Queue<LOGinf> ExchangeQueue = new Queue<LOGinf>();
|
||||
public static void LogGingDATA(string dat)
|
||||
{
|
||||
LOGinf ginf = new LOGinf
|
||||
{
|
||||
Logpath = System.Environment.CurrentDirectory + "\\Log",//日志文件目录
|
||||
LogPath = "" + System.Environment.CurrentDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt",//日志文件
|
||||
Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:",
|
||||
DAT = dat
|
||||
};
|
||||
LogGingQueue.Enqueue(ginf);
|
||||
|
||||
if(LogGingQueue.Count==1) LogGingQueueW();
|
||||
}
|
||||
public static async void LogGingQueueW()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
LOGinf inf = LogGingQueue.Dequeue();
|
||||
|
||||
if (Directory.Exists(inf.Logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(inf.LogPath))//检查日志文件并写入启动日志
|
||||
{
|
||||
FileStream fs = new FileStream(inf.LogPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(inf.Log_time + inf.DAT);
|
||||
wr.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(inf.LogPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(inf.Log_time + inf.DAT);
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(inf.Logpath);
|
||||
directoryInfo.Create();//创建日志路径
|
||||
}
|
||||
}
|
||||
catch (Exception ) { }
|
||||
if (LogGingQueue.Count == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ERRDATA(System.Exception dat)
|
||||
{
|
||||
LOGinf ginf = new LOGinf
|
||||
{
|
||||
Logpath = System.Environment.CurrentDirectory + "\\ERR",//日志文件目录
|
||||
LogPath = "" + System.Environment.CurrentDirectory + "\\ERR\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt",//日志文件
|
||||
Log_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
DAT = dat
|
||||
};
|
||||
ERRQueue.Enqueue(ginf);
|
||||
|
||||
if (ERRQueue.Count == 1) ERRQueueW();
|
||||
}
|
||||
public static async void ERRQueueW()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
LOGinf inf = ERRQueue.Dequeue();
|
||||
Exception dat = (Exception)inf.DAT;
|
||||
|
||||
if (Directory.Exists(inf.Logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(inf.LogPath))//检查文件并写入
|
||||
{
|
||||
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.Close();
|
||||
FileStream fil = new FileStream(inf.LogPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error source] ||" + dat.Source.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error area] ||" + dat.StackTrace.ToString());
|
||||
wfil.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(inf.LogPath, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error source] ||" + dat.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error area] ||" + dat.ToString());
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(inf.Logpath);
|
||||
directoryInfo.Create();
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
if (ERRQueue.Count == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExchangeDATA(string dat)
|
||||
{
|
||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
string logpath = System.Environment.CurrentDirectory + "\\Exchange";//日志文件目录
|
||||
// string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
||||
string log_path = logpath + "\\Exchange" + Log_time + ".txt";
|
||||
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
if (Directory.Exists(logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(log_path))//检查文件并写入
|
||||
{
|
||||
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.Close();
|
||||
FileStream fil = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Exchange] ||" + dat);
|
||||
wfil.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + Log_timehms + "];[Exchange] ||" + dat);
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||
directoryInfo.Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
-41
@@ -15,61 +15,75 @@ namespace SunlightAggregationManager.UserClass
|
||||
|
||||
public static void AllowPort(int port, string protocol)
|
||||
{
|
||||
|
||||
DelPort(port, protocol);
|
||||
//创建一个INetFwRule对象
|
||||
Type type = Type.GetTypeFromProgID("HNetCfg.FwRule") ?? throw new
|
||||
InvalidOperationException("Failed to retrieve HNetCfg.FwRule type. Ensure the COM component is registered.");
|
||||
INetFwRule? rule = (INetFwRule?)Activator.CreateInstance(type);
|
||||
|
||||
//设置规则的属性
|
||||
rule?.Action = NET_FW_ACTION_.NET_FW_ACTION_ALLOW; //允许连接
|
||||
rule?.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN; //入站规则
|
||||
rule?.Enabled = true; //启用规则
|
||||
rule?.InterfaceTypes = "All"; //适用于所有网络接口
|
||||
rule?.Name = GetName(port, protocol); //规则名称
|
||||
if (protocol.ToLower() == "tcp")
|
||||
try
|
||||
{
|
||||
rule?.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP; //TCP协议
|
||||
DelPort(port, protocol);
|
||||
//创建一个INetFwRule对象
|
||||
Type type = Type.GetTypeFromProgID("HNetCfg.FwRule") ?? throw new
|
||||
InvalidOperationException("Failed to retrieve HNetCfg.FwRule type. Ensure the COM component is registered.");
|
||||
INetFwRule? rule = (INetFwRule?)Activator.CreateInstance(type);
|
||||
|
||||
//设置规则的属性
|
||||
rule?.Action = NET_FW_ACTION_.NET_FW_ACTION_ALLOW; //允许连接
|
||||
rule?.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN; //入站规则
|
||||
rule?.Enabled = true; //启用规则
|
||||
rule?.InterfaceTypes = "All"; //适用于所有网络接口
|
||||
rule?.Name = GetName(port, protocol); //规则名称
|
||||
if (protocol.ToLower() == "tcp")
|
||||
{
|
||||
rule?.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP; //TCP协议
|
||||
}
|
||||
else
|
||||
{
|
||||
rule?.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP; //UDP协议
|
||||
}
|
||||
|
||||
rule?.LocalPorts = "" + port; //本地端口号
|
||||
|
||||
//获取FirewallPolicy对象
|
||||
Type policyType = Type.GetTypeFromProgID("HNetCfg.FwPolicy2") ?? throw new
|
||||
InvalidOperationException("Failed to retrieve HNetCfg.FwRule type. Ensure the COM component is registered.");
|
||||
INetFwPolicy2? policy = (INetFwPolicy2?)Activator.CreateInstance(policyType);
|
||||
|
||||
//将规则添加到防火墙策略中
|
||||
policy?.Rules.Add(rule);
|
||||
Console.WriteLine("Add firewall port:" + port);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
rule?.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP; //UDP协议
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
rule?.LocalPorts = "" + port; //本地端口号
|
||||
|
||||
//获取FirewallPolicy对象
|
||||
Type policyType = Type.GetTypeFromProgID("HNetCfg.FwPolicy2") ?? throw new
|
||||
InvalidOperationException("Failed to retrieve HNetCfg.FwRule type. Ensure the COM component is registered.");
|
||||
INetFwPolicy2? policy = (INetFwPolicy2?)Activator.CreateInstance(policyType);
|
||||
|
||||
//将规则添加到防火墙策略中
|
||||
policy?.Rules.Add(rule);
|
||||
}
|
||||
|
||||
public static void DelPort(int port, string protocol)
|
||||
{
|
||||
//获取FirewallPolicy对象
|
||||
Type policyType = Type.GetTypeFromProgID("HNetCfg.FwPolicy2") ?? throw new
|
||||
InvalidOperationException("Failed to retrieve HNetCfg.FwRule type. Ensure the COM component is registered.");
|
||||
INetFwPolicy2? policy = (INetFwPolicy2?)Activator.CreateInstance(policyType);
|
||||
|
||||
//获取现有的规则集合
|
||||
INetFwRules? rules = policy?.Rules;
|
||||
if (rules != null)
|
||||
try
|
||||
{
|
||||
//查找名称的规则并删除它
|
||||
foreach (INetFwRule rule in rules)
|
||||
//获取FirewallPolicy对象
|
||||
Type policyType = Type.GetTypeFromProgID("HNetCfg.FwPolicy2") ?? throw new
|
||||
InvalidOperationException("Failed to retrieve HNetCfg.FwRule type. Ensure the COM component is registered.");
|
||||
INetFwPolicy2? policy = (INetFwPolicy2?)Activator.CreateInstance(policyType);
|
||||
|
||||
//获取现有的规则集合
|
||||
INetFwRules? rules = policy?.Rules;
|
||||
if (rules != null)
|
||||
{
|
||||
if (rule.Name == GetName(port, protocol))
|
||||
//查找名称的规则并删除它
|
||||
foreach (INetFwRule rule in rules)
|
||||
{
|
||||
rules.Remove(rule.Name);
|
||||
Console.WriteLine(@"Firewall rule deleted successfully.");
|
||||
break;
|
||||
if (rule.Name == GetName(port, protocol))
|
||||
{
|
||||
rules.Remove(rule.Name);
|
||||
//Console.WriteLine(@"Firewall rule deleted successfully.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-8
@@ -10,25 +10,32 @@ namespace SunlightAggregationManager.UserClass
|
||||
public class ControlWriter : TextWriter
|
||||
{
|
||||
private readonly TextBox _textbox;
|
||||
private readonly Action<string> _logGingDataAction;
|
||||
|
||||
public ControlWriter(TextBox textbox)
|
||||
public ControlWriter(TextBox textbox,Action<string> logGingDataAction)
|
||||
{
|
||||
_textbox = textbox;
|
||||
_logGingDataAction = logGingDataAction;
|
||||
}
|
||||
|
||||
public override void Write(char value) => AppendText(DateTime.Now + ": " + value.ToString());
|
||||
public override void Write(string? value) => AppendText(DateTime.Now + ": " + value);
|
||||
public override void WriteLine(string? value) => AppendText(DateTime.Now + ": "+value + Environment.NewLine);
|
||||
public override void Write(char value) => AppendText(DateTime.Now + ": " + value.ToString(), true);
|
||||
public override void Write(string? value) => AppendText(DateTime.Now + ": " + value, true);
|
||||
public override void WriteLine(string? value) => AppendText(DateTime.Now + ": "+value + Environment.NewLine, true);
|
||||
|
||||
private void AppendText(string text)
|
||||
private void AppendText(string text, bool invokeExternalLog)
|
||||
{
|
||||
if (!_textbox.Dispatcher.CheckAccess())
|
||||
{
|
||||
_textbox.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => AppendText(text)));
|
||||
_textbox.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => AppendText(text, true)));
|
||||
return;
|
||||
}
|
||||
_textbox.AppendText(text);
|
||||
_textbox.ScrollToEnd();
|
||||
|
||||
if (invokeExternalLog)
|
||||
{
|
||||
_logGingDataAction?.Invoke(text);
|
||||
}
|
||||
}
|
||||
|
||||
public override Encoding Encoding => Encoding.UTF8;
|
||||
@@ -41,10 +48,10 @@ namespace SunlightAggregationManager.UserClass
|
||||
|
||||
// 【核心功能】注册目标 TextBox
|
||||
// 子页面加载时调用这个方法
|
||||
public static void RegisterTarget(TextBox logBox)
|
||||
public static void RegisterTarget(TextBox logBox ,Action<string> logGingDataAction)
|
||||
{
|
||||
// 创建新的 Writer
|
||||
_currentWriter = new ControlWriter(logBox);
|
||||
_currentWriter = new ControlWriter(logBox, logGingDataAction);
|
||||
|
||||
// 【关键】将 Console 的输出重定向到这个 Writer
|
||||
// 这样 Console.WriteLine("...") 就会自动写入到 logBox 中
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
<Window x:Class="SunlightAggregationManager.UserWindow.MachineSet"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.UserWindow"
|
||||
xmlns:ConvertMoels="clr-namespace:SunlightAggregationManager.ConvertMoels"
|
||||
xmlns:lang="clr-namespace:SunlightAggregationManager"
|
||||
xmlns:viewmodel="clr-namespace:SunlightAggregationManager.ViewModel"
|
||||
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
|
||||
mc:Ignorable="d"
|
||||
Title="MachineSet"
|
||||
Loaded="Window_Loaded"
|
||||
ResizeMode="NoResize"
|
||||
Height="900" Width="1440" MinHeight="900" MinWidth="1440">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="100"/>
|
||||
</Grid.RowDefinitions>
|
||||
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Background="#FFCECECE"/>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="500"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FFCECECE"/>
|
||||
<Grid Grid.Column="0">
|
||||
<!--用户-->
|
||||
<TextBox x:Name="_Name" Height="30" Margin="105,10,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,10,0,100" TextWrapping="Wrap"
|
||||
Text="归属信息" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<TextBox x:Name="_Machine" Height="30" Margin="105,55,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,55,0,100" TextWrapping="Wrap"
|
||||
Text="设备名称" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<ComboBox x:Name="GROUP" Height="30" Margin="105,100,10,100" VerticalAlignment="Top" FontSize="16" IsReadOnly="True">
|
||||
<ComboBoxItem Content="200"></ComboBoxItem>
|
||||
<ComboBoxItem Content="202"></ComboBoxItem>
|
||||
<ComboBoxItem Content="242W"></ComboBoxItem>
|
||||
<ComboBoxItem Content="252"></ComboBoxItem>
|
||||
<ComboBoxItem Content="252-2T"></ComboBoxItem>
|
||||
<ComboBoxItem Content="252RB"></ComboBoxItem>
|
||||
<ComboBoxItem Content="252RDRM"></ComboBoxItem>
|
||||
<ComboBoxItem Content="252-2T"></ComboBoxItem>
|
||||
<ComboBoxItem Content="301"></ComboBoxItem>
|
||||
<ComboBoxItem Content="301P"></ComboBoxItem>
|
||||
<ComboBoxItem Content="302"></ComboBoxItem>
|
||||
<ComboBoxItem Content="303"></ComboBoxItem>
|
||||
<ComboBoxItem Content="303PDW"></ComboBoxItem>
|
||||
</ComboBox>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,100,0,50" TextWrapping="Wrap"
|
||||
Text="系列型号" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
<TextBox x:Name="_IP" Height="30" Margin="105,145,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,145,0,100" TextWrapping="Wrap"
|
||||
Text="连接IP" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<TextBox x:Name="_MachineUser" Height="30" Margin="105,190,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,190,0,100" TextWrapping="Wrap"
|
||||
Text="连接用户" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<TextBox x:Name="_MachinePassword" Height="30" Margin="105,235,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,235,0,100" TextWrapping="Wrap"
|
||||
Text="连接密码" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<TextBox x:Name="_inf" Height="90" Margin="105,280,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1"/>
|
||||
|
||||
</Grid>
|
||||
<Grid Grid.Column="2" Margin="0">
|
||||
<ScrollViewer Margin="0" VerticalScrollBarVisibility="Auto">
|
||||
<WrapPanel Orientation="Horizontal" x:Name="Capacity" >
|
||||
</WrapPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<!--表-->
|
||||
<DataGrid Grid.Row="2" x:Name="DataGridm" MouseDoubleClick="DataGridm_MouseDoubleClick"
|
||||
SelectionMode="Single" AlternationCount="2" IsReadOnly="True"
|
||||
ItemsSource="{Binding Machines.DefaultView}"
|
||||
AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9"
|
||||
GridLinesVisibility="All" BorderBrush="{x:Null}"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40"
|
||||
HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
|
||||
CanUserResizeRows="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False" CanUserSortColumns="False"
|
||||
HeadersVisibility ="Column" Background="{x:Null}">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="0" FontSize="26" Binding="{Binding ID}" MaxWidth="0" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="200" FontSize="26"
|
||||
Binding="{Binding Name}" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.machine}" Width="200" FontSize="26"
|
||||
Binding="{Binding Machine}" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.state}" Width="150" FontSize="26"
|
||||
Binding="{Binding State}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Mode}" Width="150" FontSize="26"
|
||||
Binding="{Binding Model}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="IP" Width="150" FontSize="26"
|
||||
Binding="{Binding IP}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="用户" Width="150" FontSize="26"
|
||||
Binding="{Binding MachineUser}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="密码" Width="150" FontSize="26"
|
||||
Binding="{Binding MachinePassword}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="*" FontSize="26"
|
||||
Binding="{Binding Information}" MinWidth="200" CanUserReorder="False"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!--存储按钮-->
|
||||
<Button Grid.Row="3" Content="存储" HorizontalAlignment="Right" Height="50" VerticalAlignment="Center" Width="100" FontSize="30"
|
||||
Click="Button_Preservation" Margin="0,0,200,0">
|
||||
</Button>
|
||||
<!--删除按钮-->
|
||||
<Button Grid.Row="3" Content="删除" HorizontalAlignment="Right" Height="50" VerticalAlignment="Center" Width="100" FontSize="30"
|
||||
Click="Button_Delete" Margin="0,0,50,0">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,96 @@
|
||||
using Microsoft.VisualBasic;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Xml.Linq;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SunlightAggregationManager.UserWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// MachineSet.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MachineSet : Window
|
||||
{
|
||||
private string _id = "";
|
||||
public MachineSet()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Button_Preservation(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Dictionary<string, object> _new = new Dictionary<string, object>();//缓存函数
|
||||
_new.Add("Name", _Name.Text);
|
||||
_new.Add("Machine", _Machine.Text);
|
||||
_new.Add("Model", GROUP.Text);
|
||||
_new.Add("IP", _IP.Text);
|
||||
_new.Add("MachineUser", _MachineUser.Text);
|
||||
_new.Add("MachinePassword", _MachinePassword.Text);
|
||||
_new.Add("Information", _inf.Text);
|
||||
_new.Add("State", 0);
|
||||
|
||||
var rowdata = MainWindowViewModel.Selet_Memory(MainWindowViewModel._machines, "ID", "ID='" + _id + "'");
|
||||
if (rowdata != null)
|
||||
{
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._machines, "ID='" + _id + "'", _new);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindowViewModel.Insert_Memory(MainWindowViewModel._machines, _new);// 执行插入
|
||||
}
|
||||
DataGridm.ItemsSource = MainWindowViewModel._machines.DefaultView;
|
||||
_Name.Text = null;
|
||||
_Machine.Text = null;
|
||||
_id = "";
|
||||
}
|
||||
|
||||
private void Button_Delete(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
MainWindowViewModel.Delete_Memory(MainWindowViewModel._machines, "ID='" + _id + "'");
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
{
|
||||
DataGridm.ItemsSource = MainWindowViewModel._machines.DefaultView;
|
||||
_Name.Text = null;
|
||||
_Machine.Text = null;
|
||||
_id = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void DataGridm_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
int rownum = DataGridm.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
/*定位选中行及指定列单元格文本信息*/
|
||||
_id = (DataGridm.Columns[0].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
_Name.Text = (DataGridm.Columns[1].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
_Machine.Text = (DataGridm.Columns[2].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
GROUP.Text = (DataGridm.Columns[4].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
_IP.Text = (DataGridm.Columns[5].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
_MachineUser.Text = (DataGridm.Columns[6].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
_MachinePassword.Text = (DataGridm.Columns[7].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
_inf.Text = (DataGridm.Columns[8].GetCellContent(DataGridm.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DataGridm.ItemsSource = MainWindowViewModel._machines.DefaultView;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<Window x:Class="SunlightAggregationManager.UserWindow.User"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.UserWindow"
|
||||
xmlns:viewmodel="clr-namespace:SunlightAggregationManager.ViewModel"
|
||||
xmlns:lang="clr-namespace:SunlightAggregationManager"
|
||||
mc:Ignorable="d"
|
||||
Loaded="user_Loaded"
|
||||
ResizeMode="NoResize"
|
||||
Title="MAC_SET"
|
||||
Height="900" Width="1440" MinHeight="900" MinWidth="1440"
|
||||
BorderBrush="White" Background="White">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="100"/>
|
||||
</Grid.RowDefinitions>
|
||||
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Background="#FFCECECE"/>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="200" MaxWidth="500"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FFCECECE"/>
|
||||
<Grid Grid.Column="0">
|
||||
<!--用户-->
|
||||
<TextBox x:Name="_User" Height="30" Margin="105,10,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1" InputMethod.IsInputMethodEnabled="False" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,10,0,100" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.user}" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<!--名-->
|
||||
<TextBox x:Name="_Name" Height="30" Margin="105,55,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,55,0,100" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Name}" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<!--密码-->
|
||||
<TextBox x:Name="Pasword" Height="30" Margin="105,100,10,50" VerticalAlignment="Top" FontSize="16" MaxLines="1" InputMethod.IsInputMethodEnabled="False" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,100,0,50" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Password}" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
<!--部门-->
|
||||
<TextBox x:Name="_Department" Height="30" Margin="105,145,10,50" VerticalAlignment="Top" FontSize="16" MaxLines="1" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,145,0,50" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Department}" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
<!--组-->
|
||||
<ComboBox x:Name="GROUP" Height="30" Margin="105,190,10,100" VerticalAlignment="Top" FontSize="16" IsReadOnly="True">
|
||||
<ComboBoxItem Content="CHIEF"></ComboBoxItem>
|
||||
<ComboBoxItem Content="ENGINEER"></ComboBoxItem>
|
||||
<ComboBoxItem Content="POWERUSER"></ComboBoxItem>
|
||||
<ComboBoxItem Content="USER"></ComboBoxItem>
|
||||
</ComboBox>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,190,0,50" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Groups}" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
</Grid>
|
||||
<Grid Grid.Column="2" Margin="0">
|
||||
<ScrollViewer Margin="0" VerticalScrollBarVisibility="Auto">
|
||||
<WrapPanel Orientation="Horizontal" x:Name="Capacity" >
|
||||
</WrapPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<!--表-->
|
||||
<DataGrid Grid.Row="2" x:Name="DataGriduser" MouseDoubleClick="DataGridMac_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True"
|
||||
d:ItemsSource="{d:SampleData ItemCount=999}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="{x:Null}"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
|
||||
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False" CanUserSortColumns="False" HeadersVisibility ="Column" Background="{x:Null}">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.user}" Binding="{Binding User}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Name}" Binding="{Binding Name}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Password}" Binding="{Binding Password}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Department}" Binding="{Binding Department}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Groups}" Binding="{Binding Groups}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Binding="{Binding Capacity}" Width="0" MaxWidth="0" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.LastLoginIP}" Binding="{Binding LastLoginIP}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.LastLoginTime}" Binding="{Binding LastLoginTime}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!--存储按钮-->
|
||||
<Button Grid.Row="3" Content="存储" HorizontalAlignment="Right" Height="50" VerticalAlignment="Center" Width="100" FontSize="30"
|
||||
Click="Button_Preservation" Margin="0,0,200,0">
|
||||
</Button>
|
||||
<!--删除按钮-->
|
||||
<Button Grid.Row="3" Content="删除" HorizontalAlignment="Right" Height="50" VerticalAlignment="Center" Width="100" FontSize="30"
|
||||
Click="Button_Delete" Margin="0,0,50,0">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,152 @@
|
||||
using SunlightAggregationManager.View;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SunlightAggregationManager.UserWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Machine.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class User : Window
|
||||
{
|
||||
CheckBox[] checkBoxes = new CheckBox[99];
|
||||
string[] strings = new string[8] {"修改系统设置", "修改用户设置",
|
||||
"设备监控","设备控制","远程设置","远程查询","输送信息","历史查询"};
|
||||
public User()
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void user_Loaded(object sender, RoutedEventArgs e)//打开页面执行
|
||||
{
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
checkBoxes[i] = new CheckBox();
|
||||
checkBoxes[i].Content = strings[i].ToString();
|
||||
checkBoxes[i].FontSize = 20;
|
||||
checkBoxes[i].Width = 200;
|
||||
checkBoxes[i].Height = 50;
|
||||
Capacity.Children.Add(checkBoxes[i]);
|
||||
}
|
||||
DataGriduser.ItemsSource = MainWindowViewModel._userData.DefaultView;
|
||||
}
|
||||
|
||||
private void Tb_KeyFloating(object sender, TextCompositionEventArgs e)//输入事件
|
||||
{
|
||||
//Regex re = new Regex("[^0-9.-]+");
|
||||
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
|
||||
e.Handled = !re.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void DataGridMac_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
{
|
||||
string Capacity_;
|
||||
int rownum = DataGriduser.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
/*定位选中行及指定列单元格文本信息*/
|
||||
_Name.Text = (DataGriduser.Columns[1].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
_User.Text = (DataGriduser.Columns[0].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
GROUP.Text = (DataGriduser.Columns[4].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
Capacity_ = (DataGriduser.Columns[5].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
_Department.Text = (DataGriduser.Columns[3].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
Pasword.Text = (DataGriduser.Columns[2].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
|
||||
if (strings.Length > Capacity_.Length)
|
||||
{
|
||||
for (int i = 0; i < Capacity_.Length; i++)
|
||||
{
|
||||
if (Capacity_.Substring(i, 1) == "1")
|
||||
{
|
||||
checkBoxes[i].IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBoxes[i].IsChecked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
if (Capacity_.Substring(i, 1) == "1")
|
||||
{
|
||||
checkBoxes[i].IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBoxes[i].IsChecked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
|
||||
{
|
||||
Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数
|
||||
Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串
|
||||
|
||||
string user = _User.Text;
|
||||
string name = _Name.Text;
|
||||
string password = Pasword.Text;
|
||||
string Group = GROUP.Text;
|
||||
string Cap = "";
|
||||
string department = _Department.Text;
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
if ((bool)checkBoxes[i].IsChecked!)
|
||||
{
|
||||
Cap = Cap + "1";
|
||||
}
|
||||
else { Cap = Cap + "0"; }
|
||||
}
|
||||
Dictionary<string, object> USER_new = new Dictionary<string, object>();//缓存函数
|
||||
USER_new.Add("User", user);
|
||||
USER_new.Add("Name", name);
|
||||
USER_new.Add("Password", password);
|
||||
USER_new.Add("Groups", Group);
|
||||
USER_new.Add("Capacity", Cap);
|
||||
USER_new.Add("Department", department);
|
||||
USER_new.Add("State", 0);
|
||||
USER_new.Add("Enterprise", MainWindowViewModel.Enterprise);
|
||||
|
||||
var rowdata = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData, "UserID", "User='" + user + "'");
|
||||
if (rowdata != null)
|
||||
{
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + user + "'", USER_new);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindowViewModel.Insert_Memory(MainWindowViewModel._userData, USER_new);// 执行插入
|
||||
}
|
||||
DataGriduser.ItemsSource = MainWindowViewModel._userData.DefaultView;
|
||||
_Name.Text = null;
|
||||
|
||||
}
|
||||
|
||||
private void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
try
|
||||
{
|
||||
MainWindowViewModel.Delete_Memory(MainWindowViewModel._userData, "User='" + _User.Text + "'");
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
{
|
||||
DataGriduser.ItemsSource = MainWindowViewModel._userData.DefaultView;
|
||||
_Name.Text = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace SunlightAggregationManager.UserWindow
|
||||
/// </summary>
|
||||
public partial class UserSet : Window
|
||||
{
|
||||
public UserSet()
|
||||
public UserSet(string id)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<UserControl x:Class="SunlightAggregationManager.View.ActionPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.View"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
d:DesignHeight="720" d:DesignWidth="1080">
|
||||
<Grid>
|
||||
<DataGrid x:Name="CurrentData"
|
||||
IsReadOnly="True"
|
||||
AutoGenerateColumns="True"
|
||||
EnableRowVirtualization="True"
|
||||
EnableColumnVirtualization="True"
|
||||
VirtualizingPanel.IsVirtualizing="True"
|
||||
VirtualizingPanel.VirtualizationMode="Recycling"
|
||||
VirtualizingPanel.ScrollUnit="Pixel" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,36 @@
|
||||
using SunlightAggregationManager.UserClass;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SunlightAggregationManager.View
|
||||
{
|
||||
/// <summary>
|
||||
/// ActionPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ActionPage : UserControl
|
||||
{
|
||||
public ActionPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var data =MainWindowViewModel.SQLiteHelpers.ExecuteDataSet(
|
||||
"select * from ActionLog order by Time DESC", null)?.Tables[0] ?? new DataTable();
|
||||
CurrentData.ItemsSource=data.AsDataView();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="SunlightAggregationManager.View.ExtendPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.View"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SunlightAggregationManager.View
|
||||
{
|
||||
/// <summary>
|
||||
/// ExtendPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ExtendPage : UserControl
|
||||
{
|
||||
public ExtendPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<UserControl x:Class="SunlightAggregationManager.View.MachinePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.View"
|
||||
xmlns:ConvertMoels="clr-namespace:SunlightAggregationManager.ConvertMoels"
|
||||
xmlns:lang="clr-namespace:SunlightAggregationManager"
|
||||
xmlns:viewmodel="clr-namespace:SunlightAggregationManager.ViewModel"
|
||||
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="720" d:DesignWidth="1080">
|
||||
<Grid>
|
||||
<DataGrid x:Name="DataGridmachines"
|
||||
ItemsSource="{Binding Machines.DefaultView}"
|
||||
SelectionChanged="DataGridmachines_SelectionChanged"
|
||||
SelectionMode="Single"
|
||||
AlternationCount="2"
|
||||
IsReadOnly="True"
|
||||
FontSize="26"
|
||||
Margin="5,5,5,5"
|
||||
AutoGenerateColumns="False"
|
||||
MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9"
|
||||
VerticalGridLinesBrush="#FFC9C9C9"
|
||||
GridLinesVisibility="All"
|
||||
BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1"
|
||||
ColumnHeaderHeight="40"
|
||||
HorizontalContentAlignment="Right"
|
||||
CanUserReorderColumns="False"
|
||||
VerticalContentAlignment="Center">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
<Setter Property="Height" Value="40" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
<Setter Property="Height" Value="40" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="{x:Static lang:ResourceLanguage.information}" Click="MenuItem_information"/>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="200" FontSize="26"
|
||||
Binding="{Binding Name}" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.machine}" Width="200" FontSize="26"
|
||||
Binding="{Binding Machine}" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.state}" Width="150" FontSize="26"
|
||||
Binding="{Binding State}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Mode}" Width="150" FontSize="26"
|
||||
Binding="{Binding Model}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="A" Width="150" FontSize="26"
|
||||
Binding="{Binding ModelA}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="B" Width="150" FontSize="26"
|
||||
Binding="{Binding ModelB}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="C" Width="150" FontSize="26"
|
||||
Binding="{Binding ModelC}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="D" Width="150" FontSize="26"
|
||||
Binding="{Binding ModelD}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="E" Width="150" FontSize="26"
|
||||
Binding="{Binding ModelE}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="F" Width="150" FontSize="26"
|
||||
Binding="{Binding ModelF}" MinWidth="150" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="*" FontSize="26"
|
||||
Binding="{Binding Information}" MinWidth="200" CanUserReorder="False"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using SunlightAggregationManager.UserWindow;
|
||||
|
||||
namespace SunlightAggregationManager.View
|
||||
{
|
||||
/// <summary>
|
||||
/// MachinePage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MachinePage : UserControl
|
||||
{
|
||||
public MachinePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private string id = "";
|
||||
private void DataGridmachines_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
int rownum = DataGridmachines.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
var row_ = DataGridmachines.Columns[0].GetCellContent(DataGridmachines.Items[rownum]);
|
||||
if (row_ is TextBlock textBlock)
|
||||
{
|
||||
id = textBlock.Text;//定位第0列,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuItem_information(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MachineSet machineSet = new MachineSet();
|
||||
machineSet.Show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@
|
||||
<Button Content="{x:Static lang:ResourceLanguage.Test}" HorizontalAlignment="Left" Height="35" Margin="370,335,0,0" VerticalAlignment="Top" Width="80" Click="test_Click"/>
|
||||
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,335,0,0" x:Name="textlog" TextWrapping="Wrap" Text="------------" VerticalAlignment="Top" Width="140" FontSize="20"/>
|
||||
|
||||
|
||||
<CheckBox x:Name="EnableTCP" Content="{x:Static lang:ResourceLanguage.EnableTCP}" HorizontalAlignment="Left" Margin="600,10,0,0" VerticalAlignment="Top" Height="40" Width="300" FontSize="24"
|
||||
Checked="EnableTCP_Checked" Unchecked="EnableTCP_Unchecked"/>
|
||||
<CheckBox x:Name="EnableHTTP" Content="{x:Static lang:ResourceLanguage.EnableHTTP}" HorizontalAlignment="Left" Margin="600,60,0,0" VerticalAlignment="Top" Height="40" Width="300" FontSize="24"
|
||||
|
||||
@@ -39,6 +39,35 @@ namespace SunlightAggregationManager.View
|
||||
TEXT_SQMOD.Text = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
||||
TEXT_SQLUSER.Text = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
||||
TEXT_SQLPASWORD.Text = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
||||
|
||||
|
||||
var tcp = Configini.IniReadvalue("NETWORK", "TCP");
|
||||
if (tcp == "1")
|
||||
{
|
||||
EnableTCP.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableTCP.IsChecked = false;
|
||||
}
|
||||
var http = Configini.IniReadvalue("NETWORK", "HTTP");
|
||||
if (http == "1")
|
||||
{
|
||||
EnableHTTP.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableHTTP.IsChecked = false;
|
||||
}
|
||||
var tls = Configini.IniReadvalue("NETWORK", "TLS");
|
||||
if (tls == "1")
|
||||
{
|
||||
EnableTLS.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableTLS.IsChecked = false;
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@
|
||||
Binding="{Binding LastOfflineTime}" MinWidth="300" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Groups}" Width="200" FontSize="26"
|
||||
Binding="{Binding Groups}" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="*" FontSize="26"
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="auto" FontSize="26"
|
||||
Binding="{Binding Note}" MinWidth="200" CanUserReorder="False"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
|
||||
+6
-10
@@ -1,4 +1,5 @@
|
||||
using SunlightAggregationManager.UserClass;
|
||||
using SunlightAggregationManager.UserWindow;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -40,17 +41,15 @@ namespace SunlightAggregationManager.View
|
||||
if (row_ is TextBlock textBlock)
|
||||
{
|
||||
user_id = textBlock.Text;//定位第0列,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuItem_Information(object sender, RoutedEventArgs e)//信息
|
||||
{
|
||||
|
||||
User userSet =new User();
|
||||
userSet.Show();
|
||||
}
|
||||
|
||||
private async void MenuItem_Offine(object sender, RoutedEventArgs e)//下线
|
||||
@@ -82,9 +81,6 @@ namespace SunlightAggregationManager.View
|
||||
{
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + user_id + "'", "99", "State");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -1,8 +1,10 @@
|
||||
using Net.Codecrete.QrCodeGenerator;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -94,9 +96,11 @@ namespace SunlightAggregationManager.View
|
||||
}
|
||||
|
||||
private void imgQR_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string text_APP = "TEST"; // 要生成二维码的内容
|
||||
string text_LINK = Configini.IniReadvalue("SYS", "LINK"); // 要生成二维码的内容
|
||||
{
|
||||
string text_APP = "TEST"; //
|
||||
string text_LINK = MainWindowViewModel.MachineIP + ":"+ MainWindowViewModel.MachineIPP1 +
|
||||
"," + MainWindowViewModel.SERVERIP + ":7791/"+ MainWindowViewModel.Enterprise;
|
||||
// 要生成二维码的内容
|
||||
|
||||
imgQR_CREATE(text_APP, imgQR_app);
|
||||
imgQR_CREATE(text_LINK, imgQR_link);
|
||||
|
||||
@@ -28,6 +28,10 @@ namespace SunlightAggregationManager.ViewModel
|
||||
public static string SQLPASWORD = "";
|
||||
public static string MachineName = "SERVER";
|
||||
public static string MachineVer = "1.0.0";
|
||||
public static string MachineIP = "";
|
||||
public static int MachineIPP1 = 7789;
|
||||
public static int MachineIPP2 = 7790;
|
||||
public static int MachineHTTPP = 7791;
|
||||
public static string Enterprise = "";
|
||||
public static string TCP_E = "0";
|
||||
public static string HTTP_E = "0";
|
||||
@@ -36,12 +40,15 @@ namespace SunlightAggregationManager.ViewModel
|
||||
public static string SERVERNAME = "";
|
||||
public static string SERVERUSER = "";
|
||||
public static string SERRVERPASWORD = "";
|
||||
public static int ChemicalNumber, DyeMeasurementNumber, DyeDissolveNumber, PowderNumber;
|
||||
|
||||
private static Timer? _timer;
|
||||
public static DataTable ChemicalStatistics = new DataTable();
|
||||
public static DataTable DBC_Machines = new DataTable();
|
||||
public static DataBase dataBase = new DataBase();
|
||||
public static UserClass.SqliteHelper SQLiteHelpers = null!; //定义数据库
|
||||
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SunlightAggregationManager.db"; //数据库路径
|
||||
|
||||
public static DataTable ActionLog = new DataTable();
|
||||
|
||||
[ObservableProperty]
|
||||
public static DataTable _machines = new DataTable(); //设备表缓存
|
||||
[ObservableProperty]
|
||||
@@ -81,8 +88,11 @@ namespace SunlightAggregationManager.ViewModel
|
||||
row["State"] = 0;
|
||||
row["LinkID"] = 0;
|
||||
}
|
||||
|
||||
Machines.RowChanged += Machines_Updata;
|
||||
Machines.RowDeleting += Machines_Updata;
|
||||
UserData.RowChanged += UserData_Updata;//注册userdata表更新事件
|
||||
UserData.RowDeleting += UserData_Updata;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -99,56 +109,105 @@ namespace SunlightAggregationManager.ViewModel
|
||||
//运行数据库
|
||||
Service.Rows.Add(0, "RUN", "SQL_DataBase_Link");
|
||||
dataBase.Config(SQLIP, SQLNAME, SQMOD, SQLUSER, SQLPASWORD);
|
||||
Service.Rows.Add(1, "RUN", "Sunlight_Server_Link");
|
||||
AsyncTcpClient.Configuration(SERVERIP, SERVERNAME, SERVERUSER, SERRVERPASWORD);//连接sunlight服务器
|
||||
|
||||
Console.WriteLine(GetLocalIP.GetLocalIPv4Address().ToString());
|
||||
|
||||
|
||||
if (TCP_E == "1")//启动tcp(内网直连)
|
||||
{
|
||||
int P1, P2;
|
||||
try
|
||||
{
|
||||
P1 = int.Parse(Configini.IniReadvalue("NETWORK", "TCP_PORT1"));
|
||||
MachineIPP1 = int.Parse(Configini.IniReadvalue("NETWORK", "TCP_PORT1"));
|
||||
}
|
||||
catch (Exception) { P1 = 7789; }
|
||||
catch (Exception) { MachineIPP1 = 7789; }
|
||||
try
|
||||
{
|
||||
P2 = int.Parse(Configini.IniReadvalue("NETWORK", "TCP_PORT2"));
|
||||
MachineIPP2 = int.Parse(Configini.IniReadvalue("NETWORK", "TCP_PORT2"));
|
||||
}
|
||||
catch (Exception) { P2 = 7790; }
|
||||
catch (Exception) { MachineIPP2 = 7790; }
|
||||
|
||||
Service.Rows.Add(2, "RUN", "TCP");
|
||||
_ = AsyncTcpServer.TcpMain(P1, P2);
|
||||
Service.Rows.Add(1, "RUN", "TCP");
|
||||
AsyncTcpServer.Configuration(MachineIPP1, MachineIPP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Service.Rows.Add(2, "STOP", "TCP");
|
||||
Service.Rows.Add(1, "STOP", "TCP");
|
||||
}
|
||||
if (HTTP_E == "1")//启动tcp(内网直连)
|
||||
{
|
||||
int P1;
|
||||
try
|
||||
{
|
||||
P1 = int.Parse(Configini.IniReadvalue("NETWORK", "HTTP_PORT"));
|
||||
MachineHTTPP = int.Parse(Configini.IniReadvalue("NETWORK", "HTTP_PORT"));
|
||||
}
|
||||
catch (Exception) { P1 = 7791; }
|
||||
catch (Exception) { MachineHTTPP = 7791; }
|
||||
|
||||
Service.Rows.Add(3, "RUN", "HTTP");
|
||||
_ = AsyncHttpServer.HttpMain(P1);
|
||||
Service.Rows.Add(2, "RUN", "HTTP");
|
||||
AsyncHttpServer.Configuration(MachineHTTPP);
|
||||
}
|
||||
else
|
||||
{
|
||||
Service.Rows.Add(3, "STOP", "HTTP");
|
||||
Service.Rows.Add(2, "STOP", "HTTP");
|
||||
}
|
||||
|
||||
//获取当前IP
|
||||
MachineIP = GetLocalIP.GetLocalIPv4Address().ToString();
|
||||
Console.WriteLine(MachineIP);
|
||||
//连接sunlight服务器
|
||||
Service.Rows.Add(3, "RUN", "Sunlight_Server_Link");
|
||||
AsyncTcpClient.Configuration(SERVERIP + ":7795", SERVERNAME, SERVERUSER, SERRVERPASWORD);
|
||||
|
||||
Service.EndInit();
|
||||
|
||||
|
||||
_timer = new Timer(TimeTask, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30));
|
||||
}
|
||||
|
||||
//Machines操作数据库
|
||||
private void Machines_Updata(object sender, DataRowChangeEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
Dictionary<string, object> row_entity = new Dictionary<string, object>();
|
||||
Dictionary<string, object> userlog = new Dictionary<string, object>();
|
||||
|
||||
if (e.Action == DataRowAction.Change)
|
||||
{
|
||||
//修改的行回传
|
||||
foreach (DataColumn col in Machines.Columns)
|
||||
{
|
||||
row_entity.Add(col.ColumnName, e.Row.Field<object>(col.ColumnName) ?? DBNull.Value);//传入字段和值(值允许为空)
|
||||
|
||||
if (ActionLog.Columns.Contains(col.ColumnName))//添加到行为记录表
|
||||
{
|
||||
userlog.Add(col.ColumnName, e.Row.Field<object>(col.ColumnName) ?? DBNull.Value);//传入字段和值(值允许为空)
|
||||
}
|
||||
}
|
||||
SQLiteHelpers.Update("Machines", row_entity, "ID='" + e.Row.Field<object>("ID") + "'", null);
|
||||
userlog.Add("Action", "Command");
|
||||
userlog.Add("Time", DateTime.Now.ToString("yyyy-MM-dd dd:HH:mm:ss:fff"));
|
||||
userlog.Add("Note", "Machine = " + e.Row.Field<object>("Machine"));
|
||||
SQLiteHelpers.InsertData("ActionLog", userlog);
|
||||
|
||||
}
|
||||
if (e.Action == DataRowAction.Add)
|
||||
{
|
||||
//添加的行回传
|
||||
foreach (DataColumn col in Machines.Columns)
|
||||
{
|
||||
row_entity.Add(col.ColumnName, e.Row.Field<object>(col.ColumnName) ?? DBNull.Value);//传入字段和值(值允许为空)
|
||||
}
|
||||
SQLiteHelpers.InsertData("Machines", row_entity);
|
||||
userlog.Add("Time", DateTime.Now.ToString("yyyy-MM-dd dd:HH:mm:ss:fff"));
|
||||
userlog.Add("Action", "New Account");
|
||||
userlog.Add("Note", "Machine = " + e.Row.Field<object>("Machine"));
|
||||
SQLiteHelpers.InsertData("ActionLog", userlog);
|
||||
}
|
||||
if (e.Action == DataRowAction.Delete)
|
||||
{
|
||||
//删除的行回传
|
||||
SQLiteHelpers.Delete("Machines", "ID='" + e.Row.Field<object>("ID") + "'", null);
|
||||
userlog.Add("Time", DateTime.Now.ToString("yyyy-MM-dd dd:HH:mm:ss:fff"));
|
||||
userlog.Add("Action", "Delete Account");
|
||||
userlog.Add("Note", "Machine = " + e.Row.Field<object>("Machine"));
|
||||
SQLiteHelpers.InsertData("ActionLog", userlog);
|
||||
}
|
||||
}
|
||||
//UserData操作数据库
|
||||
private void UserData_Updata(object sender, DataRowChangeEventArgs e)
|
||||
{
|
||||
Dictionary<string, object> row_entity = new Dictionary<string, object>();
|
||||
@@ -202,7 +261,47 @@ namespace SunlightAggregationManager.ViewModel
|
||||
SQLiteHelpers.InsertData("ActionLog", userlog);
|
||||
}
|
||||
}
|
||||
|
||||
//数据表操作
|
||||
public static void Insert_Memory(DataTable DB, Dictionary<string, object> Value)//插入数据
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (DB)
|
||||
{
|
||||
DataRow drEmployee = DB.NewRow();
|
||||
drEmployee.BeginEdit();
|
||||
|
||||
foreach (KeyValuePair<string, object> kvp in Value)
|
||||
{
|
||||
drEmployee[kvp.Key] = kvp.Value;
|
||||
}
|
||||
drEmployee.EndEdit();
|
||||
DB.Rows.Add(drEmployee);
|
||||
drEmployee.AcceptChanges();
|
||||
// drEmployee.ClearErrors();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Insert_Row:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
public static void Delete_Memory(DataTable DB, string? key)//删除数据
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (DB)
|
||||
{
|
||||
DataRow drEmployee = DB.Select(key).First();
|
||||
drEmployee.Delete();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Delete_Row:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
public static DataRow? Selet_Row(DataTable DB, string? key)//查询
|
||||
{
|
||||
try
|
||||
@@ -225,9 +324,14 @@ namespace SunlightAggregationManager.ViewModel
|
||||
{
|
||||
lock (DB)
|
||||
{
|
||||
DataRow drEmployee = DB.Select(key).First();
|
||||
object? index = drEmployee.Field<object>(name);
|
||||
return index;
|
||||
DataRow[] dataRows = DB.Select(key);
|
||||
if (dataRows.Count() > 0)
|
||||
{
|
||||
DataRow drEmployee = dataRows.First();
|
||||
object? index = drEmployee.Field<object>(name);
|
||||
return index;
|
||||
}
|
||||
else { return null; }
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -286,5 +390,68 @@ namespace SunlightAggregationManager.ViewModel
|
||||
Console.WriteLine("SDTD:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static int EXTime = 120;
|
||||
private static async void TimeTask(object? state)
|
||||
{
|
||||
if (EXTime == 120)//1小时
|
||||
{
|
||||
EXTask();//统计配送消息
|
||||
EXTime = 0;
|
||||
}
|
||||
|
||||
|
||||
DBC_Machines = await dataBase.ExecuteQueryAsync("SELECT *FROM [BatchDyeingCentral].[dbo].[Machines]");
|
||||
|
||||
EXTime++;
|
||||
|
||||
}
|
||||
private static async void EXTask()
|
||||
{
|
||||
try
|
||||
{
|
||||
string DyelotsBulkedRecipe_sql = "SELECT [ProductCode],[ProductName],SUM(DispenseGrams)" +
|
||||
"as TotalDispenseGrams FROM [BatchDyeingCentral].[dbo].[DyelotsBulkedRecipe] " +
|
||||
"where DispenseEndTime > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND DispenseEndTime < '" +
|
||||
DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "' GROUP BY [ProductCode],[ProductName] " +
|
||||
"ORDER BY TotalDispenseGrams DESC ";
|
||||
string Dye_sql =
|
||||
"SELECT [Dyelot],[ReDye],[StepNumber] FROM [BatchDyeingCentral].[dbo].[DyelotsBulkedRecipe] " +
|
||||
"where ((DispenseEndTime >= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND DispenseEndTime < '" +
|
||||
DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "') OR (DispenseTime >= '" + DateTime.Now.ToString("yyyy-MM-dd") +
|
||||
"' AND DispenseTime < '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "')) " +
|
||||
"AND ProductType = 1 GROUP BY [Dyelot],[ReDye],[StepNumber];";
|
||||
string Chemical_sql =
|
||||
"SELECT [Dyelot],[ReDye],[StepNumber] FROM [BatchDyeingCentral].[dbo].[DyelotsBulkedRecipe] " +
|
||||
"where ((DispenseEndTime >= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND DispenseEndTime < '" +
|
||||
DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "') OR (DispenseTime >= '" + DateTime.Now.ToString("yyyy-MM-dd") +
|
||||
"' AND DispenseTime < '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "')) " +
|
||||
"AND ProductType = 2 GROUP BY [Dyelot],[ReDye],[StepNumber];";
|
||||
string Powder_sql =
|
||||
"SELECT [Dyelot],[ReDye],[StepNumber] FROM [BatchDyeingCentral].[dbo].[DyelotsBulkedRecipe] " +
|
||||
"where ((DispenseEndTime >= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND DispenseEndTime < '" +
|
||||
DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "') OR (DispenseTime >= '" + DateTime.Now.ToString("yyyy-MM-dd") +
|
||||
"' AND DispenseTime < '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "')) " +
|
||||
"AND ProductType = 3 GROUP BY [Dyelot],[ReDye],[StepNumber];";
|
||||
string DyeDissolve =
|
||||
"SELECT *FROM [BatchDyeingCentral].[dbo].[DyeSolutionHistory] " + "where DispenseEndTime >= '" +
|
||||
DateTime.Now.ToString("yyyy-MM-dd") + "' AND DispenseEndTime < '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "'";
|
||||
|
||||
ChemicalStatistics = await dataBase.ExecuteQueryAsync(DyelotsBulkedRecipe_sql);
|
||||
DyeMeasurementNumber = await dataBase.ExecuteQueryAsyncCount(Dye_sql);
|
||||
ChemicalNumber = await dataBase.ExecuteQueryAsyncCount(Chemical_sql);
|
||||
PowderNumber = await dataBase.ExecuteQueryAsyncCount(Powder_sql);
|
||||
DyeDissolveNumber = await dataBase.ExecuteQueryAsyncCount(DyeDissolve);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误处理
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
finally {
|
||||
Console.WriteLine("当日染料称量["+ DyeMeasurementNumber+ "]染料输送["+ DyeDissolveNumber + "]" +
|
||||
"助剂输送["+ ChemicalNumber + "]粉体输送["+ PowderNumber + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user