diff --git a/MainWindow.xaml b/MainWindow.xaml index b9331b9..aad2e04 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -2,10 +2,14 @@ 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:SunlightCentralizedControlManagement_SCCM_" - mc:Ignorable="d" - Title="MainWindow" Height="1080" Width="1920"> + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" + xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel" + xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_" + + mc:Ignorable="d" + Title="SUNLIGHT SCCM b0.0.1 (2024/08/10)" + Height="1080" Width="1920"> diff --git a/SunlightCentralizedControlManagement(SCCM).csproj b/SunlightCentralizedControlManagement(SCCM).csproj index 7169dcd..561901b 100644 --- a/SunlightCentralizedControlManagement(SCCM).csproj +++ b/SunlightCentralizedControlManagement(SCCM).csproj @@ -34,9 +34,16 @@ prompt 4 + + SunlightCentralizedControlManagement_SCCM_.App + + + sunlight_logo.ico + + @@ -55,7 +62,6 @@ MSBuild:Compile Designer - @@ -64,17 +70,15 @@ - - - - + + MSBuild:Compile Designer @@ -156,6 +160,9 @@ + + 2.0.7 + 8.3.2 @@ -168,15 +175,21 @@ 3.0.81 + + 5.0.41 + + + 2.1.10 + - + @@ -184,6 +197,17 @@ + + + {58FBCF7C-E7A9-467C-80B3-FC65E8FCCA08} + 1 + 0 + 0 + tlbimp + False + True + + diff --git a/UserClass/AsyncTcpServer.cs b/UserClass/AsyncTcpServer.cs deleted file mode 100644 index e93b626..0000000 --- a/UserClass/AsyncTcpServer.cs +++ /dev/null @@ -1,344 +0,0 @@ -using DyeingComputer.UserClass; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Sockets; -using System.Reflection.Emit; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Diagnostics; -using TouchSocket.Core; -using TouchSocket.Sockets; -using DyeingComputer.ViewModel; -using System.Runtime.InteropServices; -using ScottPlot.Colormaps; -using static System.Windows.Forms.AxHost; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; -using Newtonsoft.Json; -using static DyeingComputer.UserClass.SqliteHelper; -using DyeingComputer.View; - -namespace DyeingComputer.UserClass -{/// - /// 异步TCP服务器 - /// - public class AsyncTcpServer - { - //设置系统时间的API函数 - [DllImport("kernel32.dll")] - private static extern bool SetLocalTime(ref SYSTEMTIME time); - [StructLayout(LayoutKind.Sequential)] - private struct SYSTEMTIME - { - public short year; - public short month; - public short dayOfWeek; - public short day; - public short hour; - public short minute; - public short second; - public short milliseconds; - } - /// - /// 设置系统时间 - /// - /// 需要设置的时间 - /// 返回系统时间设置状态,true为成功,false为失败 - private static bool SetLocalDateTime(DateTime dt) - { - SYSTEMTIME st; - st.year = (short)dt.Year; - st.month = (short)dt.Month; - st.dayOfWeek = (short)dt.DayOfWeek; - st.day = (short)dt.Day; - st.hour = (short)dt.Hour; - st.minute = (short)dt.Minute; - st.second = (short)dt.Second; - st.milliseconds = (short)dt.Millisecond; - bool rt = SetLocalTime(ref st); - return rt; - } - - public static async Task Main() - { - NetFwManger.AllowPort(7790,"TCP");//开放7790端口 - TcpService service = new TcpService(); - service.Connecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在连接 - service.Connected = (client, e) => { return EasyTask.CompletedTask; };//有客户端成功连接 - service.Closing = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在断开连接,只有当主动断开时才有效。 - service.Closed = (client, e) => { return EasyTask.CompletedTask; };//有客户端断开连接 - service.Received = (client, e) => - { - string SYSAPI = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(0,5); - string DAT = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(5); - string SYSDAT ="";// = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(5); - string SYSKEY =""; - if(DAT.Length>=16) SYSKEY = DAT.Substring(0,16); - if (DAT.Length > 16) SYSDAT = DAT.Substring(16); - //LogGing.LogSQLDATA("800", "TcpServer", "API:"+ SYSAPI); - if (SYSAPI == "SC800") - { - Dictionary Chart_new = new Dictionary();//缓存函数 - Chart_new.Add("MACHINE", MainWindowViewModel.S01); - Chart_new.Add("GROUP", MainWindowViewModel.S05); - Chart_new.Add("SYSKEY", MainWindowViewModel.SYSKEY); - Chart_new.Add("TIME", MainWindowViewModel.SYSTime); - client.SendAsync("[" + MainWindowViewModel.S01 + "]" + Chart_new.ToJsonString()); - } - else if (SYSAPI == "SC810") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - try - { - Dictionary WorkOrder_dat; - WorkOrder_dat = SerializeConvert.JsonDeserializeFromString>(SYSDAT); - //WorkOrder_dat.GetValue("WorkOrder"); - bool dat_w= SQLDATA.WorkOrder( - WorkOrder_dat.GetValue("WorkOrder").ToString(), - WorkOrder_dat.GetValue("ProcessName").ToString(), - WorkOrder_dat.GetValue("StartTime").ToString(), - WorkOrder_dat.GetValue("EndTime").ToString(), - WorkOrder_dat.GetValue("Time").ToString(), - WorkOrder_dat.GetValue("Remark").ToString(), - WorkOrder_dat.GetValue("lock").ToString(), - WorkOrder_dat.GetValue("State").ToString(), - WorkOrder_dat.GetValue("ProcessID").ToString()); - if (!dat_w) { client.SendAsync("SC910"); } - else { client.SendAsync("SC810"+SYSKEY+SYSDAT); } - } - catch - { - client.SendAsync("SC990"); - } - } - else { client.SendAsync("SC999"); } - }//WorkOrder表信息检查写入 - else if (SYSAPI == "SC811") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - try - { - DataTable WorkOrder_dat; - WorkOrder_dat = SerializeConvert.JsonDeserializeFromString(SYSDAT); - bool dat_w = SQLDATA.WorkOderStep(WorkOrder_dat); - if (!dat_w) { client.SendAsync("SC911"); } - else { client.SendAsync("SC811" + SYSKEY + SYSDAT); } - } - catch - { - client.SendAsync("SC991"); - } - } - else { client.SendAsync("SC999"); } - }//WorkOrderstep表信息检查写入 - else if (SYSAPI == "SC820") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - try - { - if (SYSDAT.Length == 21) - { - SYSDAT = SYSDAT.Substring(1, 19); - DateTime dt; - if (DateTime.TryParse(SYSDAT, out dt)) - SetLocalDateTime(dt); - } - client.SendAsync("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "]"); - } - catch { client.SendAsync("SC920"); } - } - else { client.SendAsync("SC999"); } - }//设置系统时间 - else if (SYSAPI == "SC821") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - try - { - Dictionary dat_821; - dat_821 = SerializeConvert.JsonDeserializeFromString>(SYSDAT); - if (dat_821.GetValue("INSTRUCTION").ToString() == "START") - { - SQLDATA.TechnologicalProcess_START(dat_821.GetValue("ProgramID").ToString()); - } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "STOP") - { - MainWindowViewModel.WORK_RUN = 0;//停止 - MainWindowViewModel.DIDETime = 0; - } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "PAUSE") - { - MainWindowViewModel.WORK_RUN = 1;//暂停 - } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "CONTINUE") - { - MainWindowViewModel.WORK_RUN = 2;//暂停 - } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "JUMP") - { - MainWindowViewModel.RUN_DATATABLE = TechnologicalProcessView.sql.Tables[0];//缓存表 - MainWindowViewModel.RUN_STEPID = Convert.ToInt16(dat_821.GetValue("ID").ToString());//插入步骤号 - MainWindowViewModel.STEP_START(dat_821.GetValue("Numder").ToString(), Convert.ToDouble(dat_821.GetValue("P1")), - Convert.ToDouble(dat_821.GetValue("P2")), Convert.ToDouble(dat_821.GetValue("P3")), - Convert.ToDouble(dat_821.GetValue("P4")), Convert.ToDouble(dat_821.GetValue("P5"))); - } - client.SendAsync("SC821" + SYSKEY + SYSDAT); - } - catch { client.SendAsync("SC921"); } - } - else { client.SendAsync("SC999"); } - }//启停跳步指令 - else if (SYSAPI == "SC830") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - Dictionary Chart_new = new Dictionary();//缓存函数 - Chart_new.Add("DYELOT", MainWindowViewModel.WorkNumder); - Chart_new.Add("Time", MainWindowViewModel.SYSTime); - Chart_new.Add("MST", MainWindowViewModel.TEMP_co); - Chart_new.Add("MTT", MainWindowViewModel.Selet_dtm("1010")); - Chart_new.Add("MTL", MainWindowViewModel.Selet_dtm("1015")); - Chart_new.Add("MTH", MainWindowViewModel.Selet_dtm("1009")); - Chart_new.Add("MUT", MainWindowViewModel.Selet_dtm("1011")); - Chart_new.Add("STTA", MainWindowViewModel.Selet_dtm("1012")); - Chart_new.Add("STLA", MainWindowViewModel.Selet_dtm("1017")); - Chart_new.Add("STTB", MainWindowViewModel.Selet_dtm("1013")); - Chart_new.Add("STLB", MainWindowViewModel.Selet_dtm("1018")); - Chart_new.Add("STTC", MainWindowViewModel.Selet_dtm("1014")); - Chart_new.Add("STLC", MainWindowViewModel.Selet_dtm("1019")); - client.SendAsync("[" + MainWindowViewModel.S01 + "]" + Chart_new.ToJsonString()); - } - else { client.SendAsync("SC999"); } - }//当前信息 - else if (SYSAPI == "SC831") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - - client.SendAsync("[" + MainWindowViewModel.S01 + "]" +TechnologicalProcessView.sql.Tables[0].ToJsonString()); - } - else { client.SendAsync("SC999"); } - }//当前工作表 - else if (SYSAPI == "SC832") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - - client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.SYSlog); - } - else { client.SendAsync("SC999"); } - }//当前细节信息 - else if (SYSAPI == "SC851") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_d.ToJsonString());//数字开关信息 - } - else { client.SendAsync("SC999"); } - }//数字开关表 - else if (SYSAPI == "SC852") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_a.ToJsonString());//寄存器信息 - } - else { client.SendAsync("SC999"); } - }//寄存器表 - else if (SYSAPI == "SC853") - { - if (SYSKEY == MainWindowViewModel.SYSKEY) - { - client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_m.ToJsonString());//缓存信息 - } - else { client.SendAsync("SC999"); } - }//缓存表 - - return EasyTask.CompletedTask; - }; - - await service.SetupAsync(new TouchSocketConfig()//载入配置 - .SetListenIPHosts(new IPHost[] { new IPHost("tcp://127.0.0.1:7789"), new IPHost(7790) })//同时监听两个地址 - .ConfigureContainer(a =>//容器的配置顺序应该在最前面 - { - //a.AddConsoleLogger();//添加一个控制台日志注入(注意:在maui中控制台日志不可用) - }) - .ConfigurePlugins(a => - { - //a.Add(); - }) - ); - await service.StartAsync();//启动 - - LogGing.LogGingDATA("800SREVER:START"); - } - } - - class MyTcpService : TcpService - { - protected override MyTcpSessionClient NewClient() - { - return new MyTcpSessionClient(); - } - } - - class MyTcpSessionClient : TcpSessionClient - { - internal void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter) - { - base.SetAdapter(adapter); - } - } - - /// - /// 此插件实现,按照不同端口,使用不同适配器。 - /// - /// 7789端口:使用"**"结尾的数据 - /// 7790端口:使用"##"结尾的数据 - /// - /// - internal class DifferentProtocolPlugin : PluginBase, ITcpConnectingPlugin, ITcpReceivedPlugin - { - public async Task OnTcpConnecting(ITcpSession client, ConnectingEventArgs e) - { - if (client is MyTcpSessionClient sessionClient) - { - if (sessionClient.ServicePort == 7789) - { - sessionClient.SetDataHandlingAdapter(new TerminatorPackageAdapter("**")); - } - else - { - sessionClient.SetDataHandlingAdapter(new TerminatorPackageAdapter("##")); - } - } - - await e.InvokeNext(); - } - - public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e) - { - //如果是自定义适配器,此处解析时,可以判断e.RequestInfo的类型 - - if (client is ITcpSessionClient sessionClient) - { - sessionClient.Logger.Info($"{sessionClient.GetIPPort()}收到数据,服务器端口:{sessionClient.ServicePort},数据:{e.ByteBlock}"); - } - - await e.InvokeNext(); - } - } -} - - - - - - diff --git a/UserClass/Json.cs b/UserClass/Json.cs deleted file mode 100644 index 452f846..0000000 --- a/UserClass/Json.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Remoting.Metadata.W3cXsd2001; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; - - -namespace DyeingComputer.UserClass -{ - public class Json - { - - } - - public class ProgramSteps_ - { - public string Program { get; set; } - public int Step { get; set; } - public string StepID { get; set; } - public string StepName { get; set; } - public string ParameterName { get; set; } - public double Parameter1 { get; set; } - public double Parameter2 { get; set; } - public double Parameter3 { get; set; } - public double Parameter4 { get; set; } - public double Parameter5 { get; set; } - public double Parameter6 { get; set; } - public double Parameter7 { get; set; } - public double Parameter8 { get; set; } - public double Parameter9 { get; set; } - public double Parameter10 { get; set; } - public string Remark { get; set; } - } - public class WorkorderSteps_ - { - public string Program { get; set; } - public int Step { get; set; } - public string StepID { get; set; } - public string StepName { get; set; } - public string ParameterName { get; set; } - public double Parameter1 { get; set; } - public double Parameter2 { get; set; } - public double Parameter3 { get; set; } - public double Parameter4 { get; set; } - public double Parameter5 { get; set; } - public string Remark { get; set; } - } - public class WorkOrder_ - { - public string WorkOrder { get; set; } - public string ProcessName { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public DateTime Time { get; set; } - public string Remark { get; set; } - public string ProcessID { get; set; } - public int State { get; set; } - public int lock_ { get; set; } - } - public class RUN_ - { - public string Program { get; set; } - public int Step { get; set; } - public string StepID { get; set; } - public string StepName { get; set; } - public string ParameterName { get; set; } - public double Parameter1 { get; set; } - public double Parameter2 { get; set; } - public double Parameter3 { get; set; } - public double Parameter4 { get; set; } - public double Parameter5 { get; set; } - public double Parameter6 { get; set; } - public double Parameter7 { get; set; } - public double Parameter8 { get; set; } - public double Parameter9 { get; set; } - public double Parameter10 { get; set; } - public string Remark { get; set; } - public int Run { get; set; } - public string Ryelot { get; set; } - } - public class DyelotHistory_ - { - public DateTime TIME { get; set;} - public string WorkOrder { get; set; } - public string Dyelot { get; set; } - public int Tank { get; set; } - public int Step { get; set; } - public int State { get; set; } - public int Redye { get; set; } - public int Type { get; set; } - public string Machine { get; set; } - } - -} diff --git a/UserClass/LogDataRead.cs b/UserClass/LogDataRead.cs deleted file mode 100644 index 076bbf7..0000000 --- a/UserClass/LogDataRead.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Text; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Media; - -namespace DyeingComputer.UserClass -{ - public static class LogDataRead - { - private const int MaxCount = 1000; - private static int Count = 0; - private static RichTextBox textControl; - private static InlineCollection inlines; - - //设置主控件 - public static void SetTextControl(RichTextBox _textBox) - { - textControl = _textBox; - Paragraph graph = new Paragraph(); - inlines = graph.Inlines; - textControl.Document.Blocks.Add(graph); - } - - //输出黑色消息 - public static void Info(string format, params object[] args) - { - AppendText(Brushes.Black, format, args); - } - - //输出绿色消息 - public static void Suc(string format, params object[] args) - { - AppendText(Brushes.DarkGreen, format, args); - } - - //输出黄色消息 - public static void Warning(string format, params object[] args) - { - AppendText(Brushes.DarkOrange, format, args); - } - - //输出红色消息 - public static void Error(string format, params object[] args) - { - AppendText(Brushes.Red, format, args); - } - - //清除日志 - public static void Clear() - { - Count = 0; - inlines.Clear(); - textControl.ScrollToEnd(); - } - - private static void AppendText(Brush color, string format, params object[] args) - { - textControl.BeginChange(); - StringBuilder builder = new StringBuilder(); - builder.Append("["); - builder.Append(Count++); - builder.Append("] : "); - builder.Append(string.Format(format, (object[])args)); - builder.Append("\n"); - string str = builder.ToString(); - inlines.Add(new Run(str) { Foreground = color }); - if (inlines.Count > MaxCount) - { - inlines.Remove(inlines.FirstInline); - } - textControl.ScrollToEnd(); - textControl.EndChange(); - } - - } -} diff --git a/UserClass/PressKey.cs b/UserClass/PressKey.cs index 427c3b1..4712be2 100644 --- a/UserClass/PressKey.cs +++ b/UserClass/PressKey.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; using System.Windows.Forms; -namespace DyeingComputer.UserClass +namespace SunlightCentralizedControlManagement_SCCM_.UserClass { internal class PressKey { diff --git a/UserClass/SQLDATA.cs b/UserClass/SQLDATA.cs deleted file mode 100644 index 06edd9f..0000000 --- a/UserClass/SQLDATA.cs +++ /dev/null @@ -1,114 +0,0 @@ -using DyeingComputer.View; -using DyeingComputer.ViewModel; -using ScottPlot.Colormaps; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Documents; -using System.Xml.Linq; -using static DyeingComputer.UserClass.SqliteHelper; - -namespace DyeingComputer.UserClass -{ - public class SQLDATA - { - private static SQLiteHelper SQLiteHelpers = null; //定义数据库 - private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 - //WorkOrder表检查写入 - public static bool WorkOrder(string WorkOrder, string ProcessName,string StartTime, string EndTime, string Time, string Remark,string lock_,string state,string ProcessID) - { - SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 - SQLiteHelpers.Open(); //打开数据库 - object i = SQLiteHelpers.ExecuteScalar("select * from WorkOrder where WorkOrder = "+ WorkOrder,null); - if (i!=null) - { - SQLiteHelpers.Close(); - return false; - } - Dictionary WorkOrder_new = new Dictionary();//缓存函数 - WorkOrder_new.Add("WorkOrder", WorkOrder); - WorkOrder_new.Add("ProcessName", ProcessName); - WorkOrder_new.Add("StartTime", StartTime); - WorkOrder_new.Add("EndTime", EndTime); - WorkOrder_new.Add("Time", Time); - WorkOrder_new.Add("Remark", Remark); - WorkOrder_new.Add("lock", Convert.ToInt16(lock_)); - WorkOrder_new.Add("state", Convert.ToInt16(state)); - WorkOrder_new.Add("ProcessID", ProcessID); - SQLiteHelpers.InsertData("WorkOrder", WorkOrder_new); - SQLiteHelpers.Close(); - return true; - } - - public static bool WorkOderStep(DataTable WorkOrderStep_) - { - SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 - SQLiteHelpers.Open(); //打开数据库 - DataTable data_t = WorkOrderStep_.Clone(); - int a = WorkOrderStep_.Rows.Count; - if (a < 1) - { - SQLiteHelpers.Close(); - return false; - } - string Program = WorkOrderStep_.Rows[0][0].ToString(); - object n = SQLiteHelpers.ExecuteScalar("select * from WorkorderSteps where Program = " + Program, null); - if (n != null)//如id存在着返回错误状态 - { - SQLiteHelpers.Close(); - return false; - } - for (int i = 0; i < a; i++) - { - data_t.Clear();//清空 - DataRow dr = data_t.NewRow(); - dr.ItemArray = WorkOrderStep_.Rows[i].ItemArray; - data_t.Rows.InsertAt(dr, 0); - SQLiteHelpers.InsertData("WorkorderSteps", SQLiteHelpers.DataTableToDictionary(data_t));//行插入 - } - SQLiteHelpers.Close(); //关闭连接 - return true; - } - - public static void TechnologicalProcess_START(string workName) - { - SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 - SQLiteHelpers.Open(); //打开数据库 - int r = 0; - string sql_script = "select * from WorkorderSteps where ProgramID = '" + workName + "'"; - if (TechnologicalProcessView.sql != null) TechnologicalProcessView.sql.Clear(); //清空缓存 - TechnologicalProcessView.sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取表写入缓存 - TechnologicalProcessView.Program_Name = SQLiteHelpers.ExecuteScalar("select ProgramName from Workorder where ProgramID = '" + workName + "'", null).ToString(); - - SQLiteHelpers.Delete("RUN", null, null); //删除run信息 - DataTable data_t = new DataTable(); - data_t = TechnologicalProcessView.sql.Tables[0].Clone(); - data_t.Columns.Add("DYELOT", typeof(string)); //添加列 - int a = TechnologicalProcessView.sql.Tables[0].Rows.Count; - for (int i = 0; i < a; i++) - { - data_t.Clear();//清空 - DataRow dt = TechnologicalProcessView.sql.Tables[0].Rows[i];//行转 - DataRow dr = data_t.NewRow(); - dr.ItemArray = dt.ItemArray; - dr.BeginEdit(); //添加订单号 - dr["DYELOT"] = MainWindowViewModel.WorkNumder; - dr.EndEdit(); - data_t.Rows.InsertAt(dr, 0); //行转换 - - r = SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入 - } - //数据插入 - MainWindowViewModel.WorkNumder = SQLiteHelpers.ExecuteDataSet("select WorkOrder from Workorder where ProgramID = '" + workName + "'", null);; - TechnologicalProcessView.workName = workName; - MainWindowViewModel.SYS_REDYE = 0; - MainWindowViewModel.ViewID = 1; - - SQLiteHelpers.Close(); //关闭连接 - } - - } -} diff --git a/UserClass/SqliteHelper.cs b/UserClass/SqliteHelper.cs deleted file mode 100644 index e057a50..0000000 --- a/UserClass/SqliteHelper.cs +++ /dev/null @@ -1,686 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Data; -using System.IO; -using System.Data.Common; -using System.Windows.Media.Animation; -using System.Data.SQLite; -using System.Windows.Shapes; -using System.Drawing; - - -namespace DyeingComputer.UserClass -{ - public class SqliteHelper - { - - public class SQLiteHelper - { - #region 字段 - - /// - /// 事务的基类 - /// - private DbTransaction DBtrans; - /// - /// 使用静态变量字典解决多线程实例本类,实现一个数据库对应一个clslock - /// - private static readonly Dictionary RWL = new Dictionary(); - /// - /// 数据库地址 - /// - private readonly string mdataFile; - /// - /// 数据库密码 - /// - private readonly string mPassWord; - private readonly string LockName = null; - /// - /// 数据库连接定义 - /// - private SQLiteConnection mConn; - - #endregion - - #region 构造函数 - - /// - /// 根据数据库地址初始化 - /// - /// 数据库地址 - public SQLiteHelper(string dataFile) - { - this.mdataFile = dataFile ?? throw new ArgumentNullException("dataFile=null"); - //this.mdataFile = AppDomain.CurrentDomain.BaseDirectory + dataFile; - this.mdataFile = dataFile; - if (!RWL.ContainsKey(dataFile)) - { - LockName = dataFile; - RWL.Add(dataFile, new ClsLock()); - } - } - - /// - /// 使用密码打开数据库 - /// - /// 数据库地址 - /// 数据库密码 - public SQLiteHelper(string dataFile, string PassWord) - { - this.mdataFile = dataFile ?? throw new ArgumentNullException("dataFile is null"); - this.mPassWord = PassWord ?? throw new ArgumentNullException("PassWord is null"); - //this.mdataFile = AppDomain.CurrentDomain.BaseDirectory + dataFile; - this.mdataFile = dataFile; - if (!RWL.ContainsKey(dataFile)) - { - LockName = dataFile; - RWL.Add(dataFile, new ClsLock()); - } - } - - #endregion - - #region 打开/关闭 数据库 - - /// - /// 打开 SQLiteManager 使用的数据库连接 - /// - public void Open() - { - if (string.IsNullOrWhiteSpace(mPassWord)) - { - mConn = OpenConnection(this.mdataFile); - } - else - { - mConn = OpenConnection(this.mdataFile, mPassWord); - } - Console.WriteLine("The database was opened successfully"); - } - - /// - /// 关闭连接 - /// - public void Close() - { - if (this.mConn != null) - { - try - { - this.mConn.Close(); - if (RWL.ContainsKey(LockName)) - { - RWL.Remove(LockName); - } - } - catch - { - Console.WriteLine("Shutdown failed"); - } - } - Console.WriteLine("The database was shut down successfully"); - } - - #endregion - - #region 事务 - - /// - /// 开始事务 - /// - public void BeginTrain() - { - EnsureConnection(); - DBtrans = mConn.BeginTransaction(); - } - - /// - /// 提交事务 - /// - public void DBCommit() - { - try - { - DBtrans.Commit(); - } - catch (Exception) - { - DBtrans.Rollback(); - } - } - - #endregion - - #region 工具 - - /// - /// 打开一个SQLite数据库文件,如果文件不存在,则创建(无密码) - /// - /// - /// SQLiteConnection 类 - private SQLiteConnection OpenConnection(string dataFile) - { - if (dataFile == null) - { - throw new ArgumentNullException("dataFiledataFile=null"); - } - if (!File.Exists(dataFile)) - { - SQLiteConnection.CreateFile(dataFile); - } - SQLiteConnection conn = new SQLiteConnection(); - SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder - { - DataSource = dataFile - }; - conn.ConnectionString = conStr.ToString(); - conn.Open(); - return conn; - } - - /// - /// 打开一个SQLite数据库文件,如果文件不存在,则创建(有密码) - /// - /// - /// - /// SQLiteConnection 类 - private SQLiteConnection OpenConnection(string dataFile, string Password) - { - if (dataFile == null) - { - throw new ArgumentNullException("dataFile=null"); - } - if (!File.Exists(Convert.ToString(dataFile))) - { - SQLiteConnection.CreateFile(dataFile); - } - try - { - SQLiteConnection conn = new SQLiteConnection(); - SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder - { - DataSource = dataFile, - Password = Password - }; - conn.ConnectionString = conStr.ToString(); - conn.Open(); - return conn; - } - catch (Exception) - { - return null; - } - } - - /// - /// 读取 或 设置 SQLiteManager 使用的数据库连接 - /// - public SQLiteConnection Connection - { - get - { - return mConn; - } - private set - { - mConn = value ?? throw new ArgumentNullException(); - } - } - - /// - /// 确保数据库是连接状态 - /// - /// - protected void EnsureConnection() - { - if (this.mConn == null) - { - throw new Exception("SQLiteManager.Connection=null"); - } - if (mConn.State != ConnectionState.Open) - { - mConn.Open(); - } - } - - /// - /// 获取数据库文件的路径 - /// - /// - public string GetDataFile() - { - return this.mdataFile; - } - - /// - /// 判断表 table 是否存在 - /// - /// - /// 存在返回true,否则返回false - public bool TableExists(string table) - { - if (table == null) - { - throw new ArgumentNullException("table=null"); - } - EnsureConnection(); - SQLiteDataReader reader = ExecuteReader("SELECT count(*) as c FROM sqlite_master WHERE type='table' AND name=@tableName ", new SQLiteParameter[] { new SQLiteParameter("tableName", table) }); - if (reader == null) - { - return false; - } - reader.Read(); - int c = reader.GetInt32(0); - reader.Close(); - reader.Dispose(); - //return false; - return c == 1; - } - - /// - /// VACUUM 命令(通过复制主数据库中的内容到一个临时数据库文件,然后清空主数据库,并从副本中重新载入原始的数据库文件) - /// - /// - public bool Vacuum() - { - try - { - using (SQLiteCommand Command = new SQLiteCommand("VACUUM", Connection)) - { - Command.ExecuteNonQuery(); - } - return true; - } - catch (System.Data.SQLite.SQLiteException) - { - return false; - } - } - - #endregion - - #region 执行SQL - - /// - /// 执行SQL, 并返回 SQLiteDataReader 对象结果 - /// - /// - /// null 表示无参数 - /// - public SQLiteDataReader ExecuteReader(string sql, SQLiteParameter[] paramArr) - { - if (sql == null) - { - throw new ArgumentNullException("sql=null"); - } - EnsureConnection(); - using (RWL[LockName].Read()) - { - using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection)) - { - if (paramArr != null) - { - cmd.Parameters.AddRange(paramArr); - } - try - { - SQLiteDataReader reader = cmd.ExecuteReader(); - cmd.Parameters.Clear(); - return reader; - } - catch (Exception) - { - return null; - } - } - } - } - - /// - /// 执行查询,并返回dataset对象 - /// - /// SQL查询语句 - /// 参数数组 - /// - public DataSet ExecuteDataSet(string sql, SQLiteParameter[] paramArr) - { - if (sql == null) - { - throw new ArgumentNullException("sql=null"); - } - this.EnsureConnection(); - using (RWL[LockName].Read()) - { - using (SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection)) - { - if (paramArr != null) - { - cmd.Parameters.AddRange(paramArr); - } - try - { - SQLiteDataAdapter da = new SQLiteDataAdapter(); - DataSet ds = new DataSet(); - da.SelectCommand = cmd; - da.Fill(ds); - cmd.Parameters.Clear(); - da.Dispose(); - return ds; - } - catch (Exception) - { - return null; - } - } - } - } - - /// - /// 执行SQL查询,并返回dataset对象。 - /// - /// 映射源表的名称 - /// SQL语句 - /// SQL参数数组 - /// - public DataSet ExecuteDataSet(string strTable, string sql, SQLiteParameter[] paramArr) - { - if (sql == null) - { - throw new ArgumentNullException("sql=null"); - } - this.EnsureConnection(); - using (RWL[LockName].Read()) - { - using (SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection)) - { - if (paramArr != null) - { - cmd.Parameters.AddRange(paramArr); - } - try - { - SQLiteDataAdapter da = new SQLiteDataAdapter(); - DataSet ds = new DataSet(); - da.SelectCommand = cmd; - da.Fill(ds, strTable); - cmd.Parameters.Clear(); - da.Dispose(); - return ds; - } - catch (Exception) - { - return null; - } - } - } - } - - /// - /// 执行SQL,返回受影响的行数,可用于执行表创建语句,paramArr == null 表示无参数 - /// - /// - /// - public int ExecuteNonQuery(string sql, SQLiteParameter[] paramArr) - { - if (sql == null) - { - throw new ArgumentNullException("sql=null"); - } - this.EnsureConnection(); - using (RWL[LockName].Read()) - { - try - { - using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection)) - { - if (paramArr != null) - { - foreach (SQLiteParameter p in paramArr) - { - cmd.Parameters.Add(p); - } - } - int c = cmd.ExecuteNonQuery(); - cmd.Parameters.Clear(); - return c; - } - } - catch (SQLiteException) - { - return 0; - } - } - } - - /// - /// 执行SQL,返回结果集第一行,如果结果集为空,那么返回空 List(List.Count=0), - /// rowWrapper = null 时,使用 WrapRowToDictionary - /// - /// - /// - /// - public object ExecuteScalar(string sql, SQLiteParameter[] paramArr) - { - if (sql == null) - { - throw new ArgumentNullException("sql=null"); - } - this.EnsureConnection(); - using (RWL[LockName].Read()) - { - using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection)) - { - if (paramArr != null) - { - cmd.Parameters.AddRange(paramArr); - } - try - { - object reader = cmd.ExecuteScalar(); - cmd.Parameters.Clear(); - cmd.Dispose(); - return reader; - } - catch (Exception) - { - return null; - } - } - } - } - - /// - /// 查询一行记录,无结果时返回 null,conditionCol = null 时将忽略条件,直接执行 select * from table - /// - /// 表名 - /// - /// - /// - public object QueryOne(string table, string conditionCol, object conditionVal) - { - if (table == null) - { - throw new ArgumentNullException("table=null"); - } - this.EnsureConnection(); - string sql = "select * from " + table; - if (conditionCol != null) - { - sql += " where " + conditionCol + "=@" + conditionCol; - } - object result = ExecuteScalar(sql, new SQLiteParameter[] { new SQLiteParameter(conditionCol, conditionVal) }); - return result; - } - - #endregion - - #region 增 删 改 - - /// - /// 执行 insert into 语句 - /// - /// - /// - /// - public int InsertData(string table, Dictionary entity) - { - if (table == null) - { - throw new ArgumentNullException("table=null"); - } - this.EnsureConnection(); - string sql = BuildInsert(table, entity); - return this.ExecuteNonQuery(sql, BuildParamArray(entity)); - } - - /// - /// 执行 update 语句,注意:如果 where = null,那么 whereParams 也为 null, - /// - /// 表名 - /// 要修改的列名和列名的值 - /// 查找符合条件的列 - /// where条件中参数的值 - /// - public int Update(string table, Dictionary entity, string where, SQLiteParameter[] whereParams) - { - if (table == null) - { - throw new ArgumentNullException("table=null"); - } - this.EnsureConnection(); - string sql = BuildUpdate(table, entity); - SQLiteParameter[] parameter = BuildParamArray(entity); - if (where != null) - { - sql += " where " + where; - if (whereParams != null) - { - SQLiteParameter[] newArr = new SQLiteParameter[(parameter.Length + whereParams.Length)]; - Array.Copy(parameter, newArr, parameter.Length); - Array.Copy(whereParams, 0, newArr, parameter.Length, whereParams.Length); - parameter = newArr; - } - } - return this.ExecuteNonQuery(sql, parameter); - } - - /// - /// 执行 delete from table 语句,where不必包含'where'关键字,where = null 时将忽略 whereParams - /// - /// - /// - /// - /// - public int Delete(string table, string where, SQLiteParameter[] whereParams) - { - if (table == null) - { - throw new ArgumentNullException("table=null"); - } - this.EnsureConnection(); - string sql = "delete from " + table + " "; - if (where != null) - { - sql += "where " + where; - } - return ExecuteNonQuery(sql, whereParams); - } - - /// - /// 将 Dictionary 类型数据 转换为 SQLiteParameter[] 类型 - /// - /// - /// - private SQLiteParameter[] BuildParamArray(Dictionary entity) - { - List list = new List(); - foreach (string key in entity.Keys) - { - list.Add(new SQLiteParameter(key, entity[key])); - } - if (list.Count == 0) - { - return null; - } - return list.ToArray(); - } - - /// - /// 将 Dictionary 类型数据 转换为 插入数据 的 SQL语句 - /// - /// 表名 - /// 字典 - /// - private string BuildInsert(string table, Dictionary entity) - { - StringBuilder buf = new StringBuilder(); - buf.Append("insert into ").Append(table); - buf.Append(" ("); - foreach (string key in entity.Keys) - { - buf.Append(key).Append(","); - } - buf.Remove(buf.Length - 1, 1); // 移除最后一个, - buf.Append(") "); - buf.Append("values("); - foreach (string key in entity.Keys) - { - buf.Append("@").Append(key).Append(","); // 创建一个参数 - } - buf.Remove(buf.Length - 1, 1); - buf.Append(") "); - - return buf.ToString(); - } - - /// - /// 将 Dictionary 类型数据 转换为 修改数据 的 SQL语句 - /// - /// 表名 - /// 字典 - /// - private string BuildUpdate(string table, Dictionary entity) - { - StringBuilder buf = new StringBuilder(); - buf.Append("update ").Append(table).Append(" set "); - foreach (string key in entity.Keys) - { - buf.Append(key).Append("=").Append("@").Append(key).Append(","); - } - buf.Remove(buf.Length - 1, 1); - buf.Append(" "); - return buf.ToString(); - } - - /// - /// 将 DataTable 转换为 Dictionary 类型数据 - /// - public Dictionary DataTableToDictionary(DataTable dataTable) - { - Dictionary result = new Dictionary(); - if (dataTable != null) - { - foreach (DataRow dataRow in dataTable.Rows) - { - foreach (DataColumn dataColumn in dataTable.Columns) - { - result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString()); - //result = Console.WriteLine(dataRow[dataColumn].ToString()); - //result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString())(new RepeatDictionaryComparer()); - } - } - } - else - { - result = null; - } - return result; - } - - } - #endregion - } -} diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs new file mode 100644 index 0000000..2cb9323 --- /dev/null +++ b/ViewModel/MainWindowViewModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SunlightCentralizedControlManagement_SCCM_.ViewModel +{ + /// + /// 变量传递至ui + /// + public class ViewModelBase : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + public void RaisePropertyChanged(string propertyName) + { + if (PropertyChanged != null) + { + if (propertyName != null) + { + PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } + } + } + public class MainWindowViewModel : ViewModelBase + { + } +} diff --git a/ViewModel/ViewModelLocator.cs b/ViewModel/ViewModelLocator.cs new file mode 100644 index 0000000..802b519 --- /dev/null +++ b/ViewModel/ViewModelLocator.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.ComponentModel; +using CommonServiceLocator; + +namespace SunlightCentralizedControlManagement_SCCM_.ViewModel +{ + public class ViewModelLocator + { + public ViewModelLocator() + { + + + } + + public MainWindowViewModel Main + { + get + { + return ServiceLocator.Current.GetInstance(); + } + } + } +} diff --git a/sunlight_logo.ico b/sunlight_logo.ico new file mode 100644 index 0000000..2fe6131 Binary files /dev/null and b/sunlight_logo.ico differ