diff --git a/BPASmartClient.Business/Plugin/MQTTMgr.cs b/BPASmartClient.Business/Plugin/MQTTMgr.cs index 7fedd3f7..3856f2bb 100644 --- a/BPASmartClient.Business/Plugin/MQTTMgr.cs +++ b/BPASmartClient.Business/Plugin/MQTTMgr.cs @@ -55,7 +55,11 @@ namespace BPASmartClient.Business var MqttServerConfig = Plugin.GetInstance().GetPlugin().MQTT_Config; var MqttServerAccount = Plugin.GetInstance().GetPlugin().Mqtt_Account; var deviceConfig = Plugin.GetInstance().GetPlugin().deviceConfigModelJsons; - string deviceId = deviceConfig[0].deviceModels[0].DeviceId; + string deviceId = ""; + if (deviceConfig.Count > 0 && deviceConfig[0].deviceModels.Count > 0) + { + deviceId = deviceConfig[0].deviceModels[0].DeviceId; + } clientId = Plugin.GetInstance().GetPlugin().ClientId; //MQTT 初始化 mqttProxy.Connect(new BPA.Communication.Base.ConfigurationOptions() diff --git a/BPASmartClient.IoT/Model/DataVReport.cs b/BPASmartClient.IoT/Model/DataVReport.cs index 543696c9..517c1671 100644 --- a/BPASmartClient.IoT/Model/DataVReport.cs +++ b/BPASmartClient.IoT/Model/DataVReport.cs @@ -199,7 +199,7 @@ namespace BPASmartDatavDeviceClient.IoT //json = APIHelper.GetInstance.GetRequest($"{url}/api/Device/Query?clientId={clientId}&deviceId={deviceId}"); json = APIHelper.GetInstance.GetRequest($"{url}/api/Device/Query?clientId={clientId}&deviceId={deviceId}"); JsonMsg> jsonMsg = Tools.JsonToObjectTools>>(json); - if (jsonMsg.obj != null && jsonMsg.obj.data != null) + if (jsonMsg != null && jsonMsg.obj != null && jsonMsg.obj.data != null) { device = jsonMsg.obj.data.FirstOrDefault(); if (device == null) return false; diff --git a/BPASmartClient.Tourism/BPASmartClient.MorkCL.csproj b/BPASmartClient.Tourism/BPASmartClient.MorkCL.csproj index ad6abcf2..5cf2eeff 100644 --- a/BPASmartClient.Tourism/BPASmartClient.MorkCL.csproj +++ b/BPASmartClient.Tourism/BPASmartClient.MorkCL.csproj @@ -6,6 +6,10 @@ true + + + + diff --git a/BPASmartClient.Tourism/Model/ControlData.cs b/BPASmartClient.Tourism/Model/ControlData.cs index a2eff3fc..e521bab4 100644 --- a/BPASmartClient.Tourism/Model/ControlData.cs +++ b/BPASmartClient.Tourism/Model/ControlData.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BPASmartClient.MorkCL.Model.Func; namespace BPASmartClient.MorkCL.Model { diff --git a/BPASmartClient.Tourism/Model/DB/AccessoriesTB.cs b/BPASmartClient.Tourism/Model/DB/AccessoriesTB.cs new file mode 100644 index 00000000..9f80ee22 --- /dev/null +++ b/BPASmartClient.Tourism/Model/DB/AccessoriesTB.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model.DB +{ + /// + /// 辅料数据表 + /// + public class AccessoriesTB : MaterialBase + { + } +} diff --git a/BPASmartClient.Tourism/Model/DB/IngredientsTB.cs b/BPASmartClient.Tourism/Model/DB/IngredientsTB.cs new file mode 100644 index 00000000..c3bbd053 --- /dev/null +++ b/BPASmartClient.Tourism/Model/DB/IngredientsTB.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model.DB +{ + /// + /// 主料数据表 + /// + public class IngredientsTB : MaterialBase + { + } +} diff --git a/BPASmartClient.Tourism/Model/DB/MaterialBase.cs b/BPASmartClient.Tourism/Model/DB/MaterialBase.cs new file mode 100644 index 00000000..e3ce51d7 --- /dev/null +++ b/BPASmartClient.Tourism/Model/DB/MaterialBase.cs @@ -0,0 +1,33 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model +{ + /// + /// 物料数据表 + /// + public class MaterialBase + { + [SugarColumn(IsPrimaryKey = true)]//设置主键 + public string Id { get; set; } + + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 描述 + /// + public string Description { get; set; } + + /// + /// 物料位置 + /// + public int Loc { get; set; } + } +} diff --git a/BPASmartClient.Tourism/Model/DB/SeasoningTB.cs b/BPASmartClient.Tourism/Model/DB/SeasoningTB.cs new file mode 100644 index 00000000..10456122 --- /dev/null +++ b/BPASmartClient.Tourism/Model/DB/SeasoningTB.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model.DB +{ + /// + /// 调料数据表 + /// + public class SeasoningTB : MaterialBase + { + } +} diff --git a/BPASmartClient.Tourism/Model/AccessoriesInfo.cs b/BPASmartClient.Tourism/Model/DataInfo/AccessoriesInfo.cs similarity index 88% rename from BPASmartClient.Tourism/Model/AccessoriesInfo.cs rename to BPASmartClient.Tourism/Model/DataInfo/AccessoriesInfo.cs index 93e6ef5a..36e81ca0 100644 --- a/BPASmartClient.Tourism/Model/AccessoriesInfo.cs +++ b/BPASmartClient.Tourism/Model/DataInfo/AccessoriesInfo.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.DataInfo { /// /// 辅料信息 diff --git a/BPASmartClient.Tourism/Model/IngredientsInfo.cs b/BPASmartClient.Tourism/Model/DataInfo/IngredientsInfo.cs similarity index 83% rename from BPASmartClient.Tourism/Model/IngredientsInfo.cs rename to BPASmartClient.Tourism/Model/DataInfo/IngredientsInfo.cs index 2b0d4e98..2e4ea128 100644 --- a/BPASmartClient.Tourism/Model/IngredientsInfo.cs +++ b/BPASmartClient.Tourism/Model/DataInfo/IngredientsInfo.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.DataInfo { /// /// 主料信息 diff --git a/BPASmartClient.Tourism/Model/RawMaterial.cs b/BPASmartClient.Tourism/Model/DataInfo/RawMaterial.cs similarity index 80% rename from BPASmartClient.Tourism/Model/RawMaterial.cs rename to BPASmartClient.Tourism/Model/DataInfo/RawMaterial.cs index ed4d274c..2fbcb5fb 100644 --- a/BPASmartClient.Tourism/Model/RawMaterial.cs +++ b/BPASmartClient.Tourism/Model/DataInfo/RawMaterial.cs @@ -4,17 +4,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.DataInfo { public class RawMaterial : NotifyBase { /// - /// 原料ID + /// ID /// public string Id { get; set; } /// - /// 原料名称 + /// 名称 /// public string Name { get; set; } } diff --git a/BPASmartClient.Tourism/Model/SeasoningInfo.cs b/BPASmartClient.Tourism/Model/DataInfo/SeasoningInfo.cs similarity index 88% rename from BPASmartClient.Tourism/Model/SeasoningInfo.cs rename to BPASmartClient.Tourism/Model/DataInfo/SeasoningInfo.cs index eff800e7..ac30c6b8 100644 --- a/BPASmartClient.Tourism/Model/SeasoningInfo.cs +++ b/BPASmartClient.Tourism/Model/DataInfo/SeasoningInfo.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.DataInfo { /// /// 调料信息 diff --git a/BPASmartClient.Tourism/Model/EFunc.cs b/BPASmartClient.Tourism/Model/Func/EFunc.cs similarity index 92% rename from BPASmartClient.Tourism/Model/EFunc.cs rename to BPASmartClient.Tourism/Model/Func/EFunc.cs index 8d6219e9..af7616a3 100644 --- a/BPASmartClient.Tourism/Model/EFunc.cs +++ b/BPASmartClient.Tourism/Model/Func/EFunc.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.Func { /// /// 功能枚举列表 diff --git a/BPASmartClient.Tourism/Model/FuncPar.cs b/BPASmartClient.Tourism/Model/Func/FuncPar.cs similarity index 94% rename from BPASmartClient.Tourism/Model/FuncPar.cs rename to BPASmartClient.Tourism/Model/Func/FuncPar.cs index 73498edf..7886a43d 100644 --- a/BPASmartClient.Tourism/Model/FuncPar.cs +++ b/BPASmartClient.Tourism/Model/Func/FuncPar.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.Func { /// /// 功能参数信息 diff --git a/BPASmartClient.Tourism/Model/InitData.cs b/BPASmartClient.Tourism/Model/Func/InitData.cs similarity index 97% rename from BPASmartClient.Tourism/Model/InitData.cs rename to BPASmartClient.Tourism/Model/Func/InitData.cs index 0bcb6931..57d23e5b 100644 --- a/BPASmartClient.Tourism/Model/InitData.cs +++ b/BPASmartClient.Tourism/Model/Func/InitData.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.Func { public class InitData { diff --git a/BPASmartClient.Tourism/Server/ISqlLIte.cs b/BPASmartClient.Tourism/Server/ISqlLIte.cs new file mode 100644 index 00000000..0aba62c9 --- /dev/null +++ b/BPASmartClient.Tourism/Server/ISqlLIte.cs @@ -0,0 +1,34 @@ +using BPASmartClient.MorkCL.Model.DB; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Server +{ + internal interface ISqlLIte : IServer + { + //主料 + bool AddIngredients(IngredientsTB mb); + bool EditIngredients(IngredientsTB req); + bool DelIngredients(string id); + IngredientsTB GetIngredientsInfo(string id); + List GetIngredients(); + + //辅料 + bool AddAccessories(AccessoriesTB mb); + bool EditAccessories(AccessoriesTB req); + bool DelAccessories(string id); + AccessoriesTB GetAccessoriesInfo(string id); + List GetAccessories(); + + + //调料 + bool AddSeasoning(SeasoningTB mb); + bool EditSeasoning(SeasoningTB req); + bool DelSeasoning(string id); + SeasoningTB GetSeasoningInfo(string id); + List GetSeasoning(); + } +} diff --git a/BPASmartClient.Tourism/Server/SqliteHelper.cs b/BPASmartClient.Tourism/Server/SqliteHelper.cs new file mode 100644 index 00000000..ecdc6023 --- /dev/null +++ b/BPASmartClient.Tourism/Server/SqliteHelper.cs @@ -0,0 +1,262 @@ +using BPASmartClient.MorkCL.Model.DB; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Server +{ + internal class SqliteHelper : ISqlLIte + { + + private volatile static SqliteHelper _Instance; + public static SqliteHelper GetInstance => _Instance ?? (_Instance = new SqliteHelper()); + private SqliteHelper() { } + + static string path + { + get + { + Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory); + return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB\\Material.db"); + } + } + + public SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig() + { + ConnectionString = $"Data Source={path}", + DbType = DbType.Sqlite, + IsAutoCloseConnection = true,//设置自动关闭连接 + }); + + /// + /// 初始化 + /// + public void Init() + { + try + { + if (!File.Exists(path)) + { + //创建数据库 + Db.DbMaintenance.CreateDatabase(); + + //创建数据表 + string spnaName = "BPASmartClient.MorkCL.Model.DB";//实体类的命名空间 + Type[] ass = Assembly.LoadFrom(AppContext.BaseDirectory + "BPASmartClient.MorkCL.dll").GetTypes().Where(p => p.Namespace == spnaName).ToArray(); + Db.CodeFirst.SetStringDefaultLength(200).InitTables(ass); + //Db.Insertable(new IngredientsTB()).ExecuteCommand(); + //Db.Insertable(new AccessoriesTB()).ExecuteCommand(); + //Db.Insertable(new SeasoningTB()).ExecuteCommand(); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + } + } + + #region 主料数据操作 + /// + /// 添加主料 + /// + /// + /// + public bool AddIngredients(IngredientsTB mb) + { + IngredientsTB tempMB = new IngredientsTB() + { + Id = Guid.NewGuid().ToString(), + Name = mb.Name, + Description = mb.Description, + Loc = mb.Loc, + }; + if (Db.Queryable().Any(p => p.Name == mb.Name)) return false; + return Db.Insertable(tempMB).ExecuteCommand() > 0; + } + + /// + /// 编辑主料 + /// + /// + /// + public bool EditIngredients(IngredientsTB req) + { + IngredientsTB tempMB = Db.Queryable().First(p => p.Id == req.Id); + if (tempMB == null) return false; + tempMB.Name = req.Name; + tempMB.Loc = req.Loc; + tempMB.Description = req.Description; + return Db.Updateable(tempMB).ExecuteCommand() > 0; + } + + /// + /// 删除主料 + /// + /// + /// + public bool DelIngredients(string id) + { + return Db.Ado.ExecuteCommand($"DELETE [IngredientsTB] WHERE Id IN({id})") > 0; + } + + /// + /// 获取所有主料 + /// + /// + public List GetIngredients() + { + return Db.Queryable().ToList(); + } + + /// + /// 获取指定主料信息 + /// + /// + /// + public IngredientsTB GetIngredientsInfo(string id) + { + return Db.Queryable().First(p => p.Id == id); + } + + #endregion + + + #region 辅料数据操作 + /// + /// 添加辅料 + /// + /// + /// + public bool AddAccessories(AccessoriesTB mb) + { + AccessoriesTB tempMB = new AccessoriesTB() + { + Id = Guid.NewGuid().ToString(), + Name = mb.Name, + Description = mb.Description, + Loc = mb.Loc, + }; + if (Db.Queryable().Any(p => p.Name == mb.Name)) return false; + return Db.Insertable(tempMB).ExecuteCommand() > 0; + } + + /// + /// 编辑辅料 + /// + /// + /// + public bool EditAccessories(AccessoriesTB req) + { + AccessoriesTB tempMB = Db.Queryable().First(p => p.Id == req.Id); + if (tempMB == null) return false; + tempMB.Name = req.Name; + tempMB.Loc = req.Loc; + tempMB.Description = req.Description; + return Db.Updateable(tempMB).ExecuteCommand() > 0; + } + + /// + /// 删除辅料 + /// + /// + /// + public bool DelAccessories(string id) + { + return Db.Ado.ExecuteCommand($"DELETE [AccessoriesTB] WHERE Id IN({id})") > 0; + } + + /// + /// 获取所有辅料 + /// + /// + public List GetAccessories() + { + return Db.Queryable().ToList(); + } + + /// + /// 获取指定的辅料 + /// + /// + /// + public AccessoriesTB GetAccessoriesInfo(string id) + { + return Db.Queryable().First(p => p.Id == id); + } + + #endregion + + #region 调料数据操作 + /// + /// 添加调料 + /// + /// + /// + public bool AddSeasoning(SeasoningTB mb) + { + SeasoningTB tempMB = new SeasoningTB() + { + Id = Guid.NewGuid().ToString(), + Name = mb.Name, + Description = mb.Description, + Loc = mb.Loc, + }; + if (Db.Queryable().Any(p => p.Name == mb.Name)) return false; + return Db.Insertable(tempMB).ExecuteCommand() > 0; + } + + /// + /// 编辑调料 + /// + /// + /// + public bool EditSeasoning(SeasoningTB req) + { + SeasoningTB tempMB = Db.Queryable().First(p => p.Id == req.Id); + if (tempMB == null) return false; + tempMB.Name = req.Name; + tempMB.Loc = req.Loc; + tempMB.Description = req.Description; + return Db.Updateable(tempMB).ExecuteCommand() > 0; + } + + /// + /// 删除调料 + /// + /// + /// + public bool DelSeasoning(string id) + { + return Db.Ado.ExecuteCommand($"DELETE [SeasoningTB] WHERE Id IN({id})") > 0; + } + + /// + /// 获取所有调料 + /// + /// + public List GetSeasoning() + { + return Db.Queryable().ToList(); + } + + /// + /// 获取指定的调料信息 + /// + /// + /// + public SeasoningTB GetSeasoningInfo(string id) + { + return Db.Queryable().First(p => p.Id == id); + } + #endregion + + + + + } +} diff --git a/BPASmartClient.Tourism/View/Test.xaml b/BPASmartClient.Tourism/View/Test.xaml new file mode 100644 index 00000000..93311873 --- /dev/null +++ b/BPASmartClient.Tourism/View/Test.xaml @@ -0,0 +1,25 @@ + + + + + + + +