diff --git a/EX/Exchange/BDC_SQL.cs b/EX/Exchange/BDC_SQL.cs new file mode 100644 index 0000000..1baac82 --- /dev/null +++ b/EX/Exchange/BDC_SQL.cs @@ -0,0 +1,123 @@ +using LiveChartsCore.Kernel; +using SunlightCentralizedControlManagement_SCCM_.UserClass; +using SunlightCentralizedControlManagement_SCCM_.ViewModel; +using SunlightCentralizedControlManagement_SCCM_.WindowsView; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.IO; +using System.Runtime.Remoting; +using System.Runtime.Remoting.Contexts; +using System.Security.Principal; +using System.Threading.Tasks; +using TouchSocket.Core; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; + +namespace SunlightCentralizedControlManagement_SCCM_.EX.Exchange +{ + public class BDC_SQL + { + public class BDCSqlHelper + { + // SqlConnection conn_SC = new SqlConnection();//数据库 + string db; + public void Config(string IP, string DATABASE, string USER, string PAWSSD, bool MODE)//连接dbc数据库 + { + if (MODE) //连接数据库测试 + { + db="server=" + IP + ";database=" + DATABASE + ";Trusted_Connection=SSPI"; + } + else + { + db="server=" + IP + ";database=" + DATABASE + ";User ID=" + USER + ";Password=" + PAWSSD; + } + } + + public async Task UPDATA(string name,string where,DataRow entity)//dbc数据库 + { + string DAT = null; + int rowsAffected = 0; + int type = 0; + try { type = entity.Field("Type"); } catch { } + try + { + + DAT = "DispenseDyelot='" + entity.Field("Dyelot") + "',DispenseReDye='" + entity.Field("Redye")+"',"; + if (type == 2) + { + DAT = DAT+"DyeCallOff=" + entity.Field("Step") + ",DyeState = 201,DyeTank=" + + entity.Field("Tank"); + } + else if (type == 3) + { + DAT = DAT+"PowderCallOff=" + entity.Field("Step") +",PowderState=201,PowderTank=" + + entity.Field("Tank"); + } + else + { + DAT = DAT+"ChemicalCallOff=" + entity.Field("Step") +",ChemicalState=201,ChemicalTank=" + + entity.Field("Tank"); + } + + using (var connection = new SqlConnection(db)) + { + await connection.OpenAsync(); + var command = connection.CreateCommand(); + command.CommandText = "UPDATE "+ name + " SET "+ DAT + " WHERE "+ where; + // command.Parameters.AddWithValue("@table", name); + // command.Parameters.AddWithValue("@Id", where); + // command.Parameters.AddWithValue("@data", DAT); + rowsAffected = await command.ExecuteNonQueryAsync(); + + LogGing.ExchangeDATA( command.CommandText.ToString()); + } + } + catch (Exception ex) + { + LogGing.ERRDATA(ex); + } + return rowsAffected; + } + + public async Task SELECT(string name, string where)//dbc数据库 + { + DataTable rowsAffected = new DataTable(); + try + { + using (var connection = new SqlConnection(db)) + { + await connection.OpenAsync(); + var command = connection.CreateCommand(); + command.CommandText = "SELECT * FROM " + name + " WHERE " + where; + var dat = await command.ExecuteReaderAsync(); + rowsAffected.Load(dat); + + LogGing.ExchangeDATA(command.CommandText.ToString()); + } + } + catch (Exception ex) + { + LogGing.ERRDATA(ex); + } + return rowsAffected; + } + + + + + + + + + + + + + + + + } + } +} diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 14f35ce..689ef94 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -699,6 +699,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.Properties { } } + /// + /// 查找类似 DispenseException 的本地化字符串。 + /// + public static string DispenseException { + get { + return ResourceManager.GetString("DispenseException", resourceCulture); + } + } + /// /// 查找类似 DispenseGrams 的本地化字符串。 /// diff --git a/Properties/Resources.en-US.resx b/Properties/Resources.en-US.resx index d35b39a..cdeda62 100644 --- a/Properties/Resources.en-US.resx +++ b/Properties/Resources.en-US.resx @@ -1074,4 +1074,7 @@ Subroutine + + Dispense Exception + \ No newline at end of file diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 910d697..5808cb1 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -1074,4 +1074,7 @@ Subroutine + + DispenseException + \ No newline at end of file diff --git a/Properties/Resources.zh-CN.resx b/Properties/Resources.zh-CN.resx index bd2225e..bb8b9f2 100644 --- a/Properties/Resources.zh-CN.resx +++ b/Properties/Resources.zh-CN.resx @@ -1074,4 +1074,7 @@ 副功能 + + 输送异常 + \ No newline at end of file diff --git a/Properties/Resources.zh-TW.resx b/Properties/Resources.zh-TW.resx index 09c24df..a97b9ed 100644 --- a/Properties/Resources.zh-TW.resx +++ b/Properties/Resources.zh-TW.resx @@ -1074,4 +1074,7 @@ + + + \ No newline at end of file diff --git a/SunlightCentralizedControlManagement_SCCM_.csproj b/SunlightCentralizedControlManagement_SCCM_.csproj index a542ba4..f37aacf 100644 --- a/SunlightCentralizedControlManagement_SCCM_.csproj +++ b/SunlightCentralizedControlManagement_SCCM_.csproj @@ -109,6 +109,7 @@ DispenseState.xaml + ManualDyelot.xaml diff --git a/View/EngineerSetView.xaml.cs b/View/EngineerSetView.xaml.cs index ed74f62..659bab3 100644 --- a/View/EngineerSetView.xaml.cs +++ b/View/EngineerSetView.xaml.cs @@ -114,7 +114,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.View MainWindowViewModel.SQMOD = TEXT_SQMOD.Text; MainWindowViewModel.SQLUSER = TEXT_SQLUSER.Text; MainWindowViewModel.SQLPASWORD = TEXT_SQLPASWORD.Text; - MainWindowViewModel.SQL_LINK();//更新设定 } } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 6ebcd1e..30c3e51 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -3,6 +3,8 @@ using LiveChartsCore.Geo; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OpenTK.Graphics.ES11; +using ScottPlot.Palettes; +using SunlightCentralizedControlManagement_SCCM_.EX.Exchange; using SunlightCentralizedControlManagement_SCCM_.Properties; using SunlightCentralizedControlManagement_SCCM_.UserClass; using SunlightCentralizedControlManagement_SCCM_.WindowsView; @@ -11,10 +13,12 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; +using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; using System.Data.SqlClient; using System.Diagnostics.Eventing.Reader; using System.Linq; using System.Reflection; +using System.Speech.Synthesis; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -26,10 +30,11 @@ using System.Windows.Threading; using System.Xml.Linq; using TouchSocket.Core; using TouchSocket.Sockets; -using System.Speech.Synthesis; using static MaterialDesignThemes.Wpf.Theme; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; +using static SunlightCentralizedControlManagement_SCCM_.ViewModel.ManualDyelotModel; using static System.Net.WebRequestMethods; +using static System.Windows.Forms.AxHost; namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { @@ -69,6 +74,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel public static bool DyelotsDispenser; public static SqlConnection conn_SC =new SqlConnection();//数据库 private SQLiteHelper SQLiteHelpers = null; //定义数据库 + private BDC_SQL.BDCSqlHelper bDCSqlHelper = new BDC_SQL.BDCSqlHelper(); private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径 public static DataTable Machines = new DataTable(); //设备表缓存 // public static DataRow MachinesROW; @@ -99,7 +105,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0]; Dyelot_CALL = SQLiteHelpers.ExecuteDataSet("select * from Dyelot", null).Tables[0].Clone(); SQLiteHelpers.Close(); - + USERCapacity(App.USER_Purview);//App.USER_Purview); CountDown(); TcpClientNEW(); @@ -131,7 +137,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } } - public static async void SQL_LINK()//连接dbc数据库 + public async void SQL_LINK()//连接dbc数据库 { if (conn_SC.State == ConnectionState.Open) conn_SC.Close(); try @@ -152,6 +158,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel LogGing.LogGingDATA("[Database='" + ex + "']=SQLSERVER"); ERR_c++; } + + if (SQMOD == "Windows Authentication") //连接数据库测试 + { + bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, true); + } + else + { + bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, false); + } } public void CountDown() @@ -304,7 +319,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else { Time60++; } } - void Tick_Event_5S()//Tick_Event周期执行事件5S + async void Tick_Event_5S()//Tick_Event周期执行事件5S { for (int i = 0; i < Machinesdata_Count; i++) {/**发送800指令**/ @@ -348,7 +363,158 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } } catch (Exception) { } + try + {//处理呼叫请求列表 + if (Dyelot_CALL.Select("State='202'").Count() > 0) + { + DataRow row = Dyelot_CALL.Select("State='202'").First(); + var r = await bDCSqlHelper.UPDATA("Machines", "Name = '" + row.Field("Machine") + "'", row); + if (r > 0) + { + DataRow[] dataRows = Dyelot_CALL.Select("Dyelot='" + row.Field("Dyelot") + + "' and Redye='" + row.Field("Redye") + + "' and Step='" + row.Field("Step") + "'"); + foreach (DataRow dataRow in dataRows) + { + dataRow.BeginEdit(); + dataRow["State"] = 203; + dataRow.EndEdit(); + } + Dictionary dat_ = new Dictionary();//缓存函数 + dat_.Add("State", 203); + SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 + SQLiteHelpers.Open(); //打开数据库 + SQLiteHelpers.Update("DyelotHistory", dat_, + "Dyelot='" + row.Field("Dyelot") + + "' and Redye='" + row.Field("Redye") + + "' and Step='" + row.Field("Step") + "'", null);// 执行插入 + SQLiteHelpers.Close(); + } + } + } + catch (Exception) { } + try + {//检查呼叫回复列表 + if (Dyelot_CALL.Select("State='203'").Count() > 0) + { + DataTable dt = new DataTable(); + int ri = 0; + // DataRow[] dataRows = Dyelot_CALL.Select("State='203'"); + foreach (DataRow dataRow in Dyelot_CALL.Select("State='203'")) + { + ri++; + if ((dataRow["State"].ToString() != "301") && (dataRow["State"].ToString() != "309")) + { + if (dataRow.Field("Type") == 2) + { + dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + + "' AND (DyeState = 301 OR DyeState = 309)"); + + if (dt.Rows.Count > 0) + { + if (dt.Select("DyeState = 301").Count() > 0) + { + Dyelot_CALL.Rows.Remove(dataRow); + + DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", + "Dyelot = '" + dataRow.Field("Dyelot") + + "' AND ReDye = " + dataRow.Field("ReDye") + + " AND StepNumber = " + dataRow.Field("StepNumber")); + + foreach (DataRow Row in dr.Rows) + { + DataRow data = Dyelot_CALL.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); + data.BeginEdit(); + data["Amount"] = Row.Field("Amount"); + data["DispenseEndTime"] = Row.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); + data.EndEdit(); + } + } + else + { + MainWindow.InfData.Rows.Add(new object[] { dataRow["Machine"], + Resources.Dyelot + dataRow["Dyelot"] + Resources.Step + dataRow["Step"]+ + Resources.DispenseException, + Selet_Machines(Machines, "SYSKEY", "Name='" + dataRow["Machine"] + "'"), + Selet_Machines(Machines, "ID", "Name='" + dataRow["Machine"] + "'")}); + + } + } + } + else if (dataRow.Field("Type") == 3) + { + dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + + "' AND (PowderState = 301 OR PowderState = 309)"); + if (dt.Rows.Count > 0) + { + if (dt.Select("PowderState = 301").Count() > 0) + { + Dyelot_CALL.Rows.Remove(dataRow); + DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", + "Dyelot = '" + dataRow.Field("Dyelot") + + "' AND ReDye = " + dataRow.Field("ReDye") + + " AND StepNumber = " + dataRow.Field("StepNumber")); + foreach (DataRow Row in dr.Rows) + { + DataRow data = Dyelot_CALL.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); + data.BeginEdit(); + data["Amount"] = Row.Field("Amount"); + data["DispenseEndTime"] = Row.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); + data.EndEdit(); + } + } + else + { + MainWindow.InfData.Rows.Add(new object[] { dataRow["Machine"], + Resources.Dyelot + dataRow["Dyelot"] + Resources.Step + dataRow["Step"]+ + Resources.DispenseException, + Selet_Machines(Machines, "SYSKEY", "Name='" + dataRow["Machine"] + "'"), + Selet_Machines(Machines, "ID", "Name='" + dataRow["Machine"] + "'")}); + + } + } + } + else + { + dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + + "' AND (ChemicalState = 301 OR ChemicalState = 309)"); + if (dt.Rows.Count > 0) + { + if (dt.Select("PowderState = 301").Count() > 0) + { + Dyelot_CALL.Rows.Remove(dataRow); + DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", + "Dyelot = '" + dataRow.Field("Dyelot") + + "' AND ReDye = " + dataRow.Field("ReDye") + + " AND StepNumber = " + dataRow.Field("StepNumber")); + + foreach (DataRow Row in dr.Rows) + { + DataRow data = Dyelot_CALL.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); + data.BeginEdit(); + data["Amount"] = Row.Field("Amount"); + data["DispenseEndTime"] = Row.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); + data.EndEdit(); + } + } + else + { + MainWindow.InfData.Rows.Add(new object[] { dataRow["Machine"], + Resources.Dyelot + dataRow["Dyelot"] + Resources.Step + dataRow["Step"]+ + Resources.DispenseException, + Selet_Machines(Machines, "SYSKEY", "Name='" + dataRow["Machine"] + "'"), + Selet_Machines(Machines, "ID", "Name='" + dataRow["Machine"] + "'")}); + + } + } + } + + } + } + } + } + catch (Exception) { } }