@@ -55,7 +55,11 @@ namespace BPASmartClient.Business | |||
var MqttServerConfig = Plugin.GetInstance().GetPlugin<ConfigMgr>().MQTT_Config; | |||
var MqttServerAccount = Plugin.GetInstance().GetPlugin<ConfigMgr>().Mqtt_Account; | |||
var deviceConfig = Plugin.GetInstance().GetPlugin<ConfigMgr>().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<ConfigMgr>().ClientId; | |||
//MQTT 初始化 | |||
mqttProxy.Connect(new BPA.Communication.Base.ConfigurationOptions() | |||
@@ -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<List<DeviceTable>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<DeviceTable>>>(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; | |||
@@ -6,6 +6,10 @@ | |||
<UseWPF>true</UseWPF> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="SqlSugarCore" Version="5.1.4.84" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.Business\BPASmartClient.Business.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.CustomResource\BPASmartClient.CustomResource.csproj" /> | |||
@@ -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 | |||
{ | |||
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 辅料数据表 | |||
/// </summary> | |||
public class AccessoriesTB : MaterialBase | |||
{ | |||
} | |||
} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 主料数据表 | |||
/// </summary> | |||
public class IngredientsTB : MaterialBase | |||
{ | |||
} | |||
} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 物料数据表 | |||
/// </summary> | |||
public class MaterialBase | |||
{ | |||
[SugarColumn(IsPrimaryKey = true)]//设置主键 | |||
public string Id { get; set; } | |||
/// <summary> | |||
/// 名称 | |||
/// </summary> | |||
public string Name { get; set; } | |||
/// <summary> | |||
/// 描述 | |||
/// </summary> | |||
public string Description { get; set; } | |||
/// <summary> | |||
/// 物料位置 | |||
/// </summary> | |||
public int Loc { get; set; } | |||
} | |||
} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 调料数据表 | |||
/// </summary> | |||
public class SeasoningTB : MaterialBase | |||
{ | |||
} | |||
} |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.Model | |||
namespace BPASmartClient.MorkCL.Model.DataInfo | |||
{ | |||
/// <summary> | |||
/// 辅料信息 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.Model | |||
namespace BPASmartClient.MorkCL.Model.DataInfo | |||
{ | |||
/// <summary> | |||
/// 主料信息 |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 原料ID | |||
/// ID | |||
/// </summary> | |||
public string Id { get; set; } | |||
/// <summary> | |||
/// 原料名称 | |||
/// 名称 | |||
/// </summary> | |||
public string Name { get; set; } | |||
} |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.Model | |||
namespace BPASmartClient.MorkCL.Model.DataInfo | |||
{ | |||
/// <summary> | |||
/// 调料信息 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.Model | |||
namespace BPASmartClient.MorkCL.Model.Func | |||
{ | |||
/// <summary> | |||
/// 功能枚举列表 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.Model | |||
namespace BPASmartClient.MorkCL.Model.Func | |||
{ | |||
/// <summary> | |||
/// 功能参数信息 |
@@ -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 | |||
{ |
@@ -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<IngredientsTB> GetIngredients(); | |||
//辅料 | |||
bool AddAccessories(AccessoriesTB mb); | |||
bool EditAccessories(AccessoriesTB req); | |||
bool DelAccessories(string id); | |||
AccessoriesTB GetAccessoriesInfo(string id); | |||
List<AccessoriesTB> GetAccessories(); | |||
//调料 | |||
bool AddSeasoning(SeasoningTB mb); | |||
bool EditSeasoning(SeasoningTB req); | |||
bool DelSeasoning(string id); | |||
SeasoningTB GetSeasoningInfo(string id); | |||
List<SeasoningTB> GetSeasoning(); | |||
} | |||
} |
@@ -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,//设置自动关闭连接 | |||
}); | |||
/// <summary> | |||
/// 初始化 | |||
/// </summary> | |||
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 主料数据操作 | |||
/// <summary> | |||
/// 添加主料 | |||
/// </summary> | |||
/// <param name="mb"></param> | |||
/// <returns></returns> | |||
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<IngredientsTB>().Any(p => p.Name == mb.Name)) return false; | |||
return Db.Insertable(tempMB).ExecuteCommand() > 0; | |||
} | |||
/// <summary> | |||
/// 编辑主料 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public bool EditIngredients(IngredientsTB req) | |||
{ | |||
IngredientsTB tempMB = Db.Queryable<IngredientsTB>().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; | |||
} | |||
/// <summary> | |||
/// 删除主料 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public bool DelIngredients(string id) | |||
{ | |||
return Db.Ado.ExecuteCommand($"DELETE [IngredientsTB] WHERE Id IN({id})") > 0; | |||
} | |||
/// <summary> | |||
/// 获取所有主料 | |||
/// </summary> | |||
/// <returns></returns> | |||
public List<IngredientsTB> GetIngredients() | |||
{ | |||
return Db.Queryable<IngredientsTB>().ToList(); | |||
} | |||
/// <summary> | |||
/// 获取指定主料信息 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public IngredientsTB GetIngredientsInfo(string id) | |||
{ | |||
return Db.Queryable<IngredientsTB>().First(p => p.Id == id); | |||
} | |||
#endregion | |||
#region 辅料数据操作 | |||
/// <summary> | |||
/// 添加辅料 | |||
/// </summary> | |||
/// <param name="mb"></param> | |||
/// <returns></returns> | |||
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<AccessoriesTB>().Any(p => p.Name == mb.Name)) return false; | |||
return Db.Insertable(tempMB).ExecuteCommand() > 0; | |||
} | |||
/// <summary> | |||
/// 编辑辅料 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public bool EditAccessories(AccessoriesTB req) | |||
{ | |||
AccessoriesTB tempMB = Db.Queryable<AccessoriesTB>().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; | |||
} | |||
/// <summary> | |||
/// 删除辅料 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public bool DelAccessories(string id) | |||
{ | |||
return Db.Ado.ExecuteCommand($"DELETE [AccessoriesTB] WHERE Id IN({id})") > 0; | |||
} | |||
/// <summary> | |||
/// 获取所有辅料 | |||
/// </summary> | |||
/// <returns></returns> | |||
public List<AccessoriesTB> GetAccessories() | |||
{ | |||
return Db.Queryable<AccessoriesTB>().ToList(); | |||
} | |||
/// <summary> | |||
/// 获取指定的辅料 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public AccessoriesTB GetAccessoriesInfo(string id) | |||
{ | |||
return Db.Queryable<AccessoriesTB>().First(p => p.Id == id); | |||
} | |||
#endregion | |||
#region 调料数据操作 | |||
/// <summary> | |||
/// 添加调料 | |||
/// </summary> | |||
/// <param name="mb"></param> | |||
/// <returns></returns> | |||
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<SeasoningTB>().Any(p => p.Name == mb.Name)) return false; | |||
return Db.Insertable(tempMB).ExecuteCommand() > 0; | |||
} | |||
/// <summary> | |||
/// 编辑调料 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public bool EditSeasoning(SeasoningTB req) | |||
{ | |||
SeasoningTB tempMB = Db.Queryable<SeasoningTB>().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; | |||
} | |||
/// <summary> | |||
/// 删除调料 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public bool DelSeasoning(string id) | |||
{ | |||
return Db.Ado.ExecuteCommand($"DELETE [SeasoningTB] WHERE Id IN({id})") > 0; | |||
} | |||
/// <summary> | |||
/// 获取所有调料 | |||
/// </summary> | |||
/// <returns></returns> | |||
public List<SeasoningTB> GetSeasoning() | |||
{ | |||
return Db.Queryable<SeasoningTB>().ToList(); | |||
} | |||
/// <summary> | |||
/// 获取指定的调料信息 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
public SeasoningTB GetSeasoningInfo(string id) | |||
{ | |||
return Db.Queryable<SeasoningTB>().First(p => p.Id == id); | |||
} | |||
#endregion | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
<UserControl | |||
x:Class="BPASmartClient.MorkCL.View.Test" | |||
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:local="clr-namespace:BPASmartClient.MorkCL.View" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:vm="clr-namespace:BPASmartClient.MorkCL.ViewModel" | |||
Name="测试" | |||
d:DesignHeight="450" | |||
d:DesignWidth="800" | |||
mc:Ignorable="d"> | |||
<UserControl.DataContext> | |||
<vm:testViewModel /> | |||
</UserControl.DataContext> | |||
<Grid> | |||
<Button | |||
Width="100" | |||
Height="30" | |||
Command="{Binding testCommand}" | |||
Content="Init" /> | |||
</Grid> | |||
</UserControl> |
@@ -0,0 +1,28 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
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 BPASmartClient.MorkCL.View | |||
{ | |||
/// <summary> | |||
/// Test.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class Test : UserControl | |||
{ | |||
public Test() | |||
{ | |||
InitializeComponent(); | |||
} | |||
} | |||
} |
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPASmartClient.MorkCL.Model.DataInfo; | |||
namespace BPASmartClient.MorkCL.ViewModel | |||
{ | |||
@@ -0,0 +1,90 @@ | |||
using BPASmartClient.MorkCL.Model.DB; | |||
using BPASmartClient.MorkCL.Server; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.ViewModel | |||
{ | |||
public class testViewModel : NotifyBase | |||
{ | |||
public testViewModel() | |||
{ | |||
testCommand = new BPARelayCommand(() => | |||
{ | |||
SqliteHelper.GetInstance.Init(); | |||
for (int i = 0; i < 10; i++) | |||
{ | |||
SqliteHelper.GetInstance.AddAccessories(new Model.DB.AccessoriesTB() | |||
{ | |||
Description = "AccessoriesTB", | |||
Loc = 1, | |||
Name = $"AccessoriesTB{i}" | |||
}); | |||
SqliteHelper.GetInstance.AddIngredients(new Model.DB.IngredientsTB() | |||
{ | |||
Description = "IngredientsTB", | |||
Loc = 1, | |||
Name = $"IngredientsTB{i}" | |||
}); | |||
SqliteHelper.GetInstance.AddSeasoning(new Model.DB.SeasoningTB() | |||
{ | |||
Description = "SeasoningTB", | |||
Loc = 1, | |||
Name = $"SeasoningTB{i}" | |||
}); | |||
} | |||
var Accessories = SqliteHelper.GetInstance.GetAccessories(); | |||
var Ingredients = SqliteHelper.GetInstance.GetIngredients(); | |||
var Seasoning = SqliteHelper.GetInstance.GetSeasoning(); | |||
Accessories?.ForEach(x => | |||
{ | |||
SqliteHelper.GetInstance.EditAccessories(new Model.DB.AccessoriesTB() | |||
{ | |||
Description = "AccessoriesTB1111", | |||
Loc = x.Loc, | |||
Name = x.Name, | |||
Id = x.Id | |||
}); | |||
}); | |||
Ingredients?.ForEach(x => | |||
{ | |||
SqliteHelper.GetInstance.EditIngredients(new Model.DB.IngredientsTB() | |||
{ | |||
Description = "IngredientsTB1111", | |||
Loc = x.Loc, | |||
Name = x.Name, | |||
Id = x.Id | |||
}); | |||
}); | |||
Seasoning?.ForEach(x => | |||
{ | |||
SqliteHelper.GetInstance.EditSeasoning(new Model.DB.SeasoningTB() | |||
{ | |||
Description = "SeasoningTB1111", | |||
Loc = x.Loc, | |||
Name = x.Name, | |||
Id = x.Id | |||
}); | |||
}); | |||
var Accessories1 = SqliteHelper.GetInstance.GetAccessories(); | |||
var Ingredients1 = SqliteHelper.GetInstance.GetIngredients(); | |||
var Seasoning1 = SqliteHelper.GetInstance.GetSeasoning(); | |||
}); | |||
} | |||
public BPARelayCommand testCommand { get; set; } | |||
} | |||
} |