@@ -61,12 +61,12 @@ namespace HBLConsole.Business.MessageServer | |||
string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt(); | |||
string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo"; | |||
result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST); | |||
Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result); | |||
} | |||
catch (Exception ex) | |||
{ | |||
MessageLog.GetInstance.Show(ex.ToString()); | |||
} | |||
Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result); | |||
MessageLog.GetInstance.Show("【物料信息】"); | |||
Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x => | |||
@@ -66,7 +66,7 @@ namespace HBLConsole.Factory | |||
return Activator.CreateInstance(type) as AbstractMessageServer; | |||
} | |||
IControl business; | |||
IControl control; | |||
/// <summary> | |||
/// 设备初始化 | |||
/// </summary> | |||
@@ -83,19 +83,19 @@ namespace HBLConsole.Factory | |||
string NameSpace = $"HBLConsole.{DeviceType}";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类 | |||
Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{DeviceType}"); | |||
business = Activator.CreateInstance(type) as IControl; | |||
control = Activator.CreateInstance(type) as IControl; | |||
//IControl business = (IControl)type?.GetProperty("GetInstance").GetValue(null); | |||
GetBatchingInfo(); | |||
business?.Init(); | |||
ActionManagerment.GetInstance.Register(new Action<object>((o) => { business?.DataParse(o); }), "DataParse"); | |||
ActionManagerment.GetInstance.Register(new Action(() => { business?.ConnectOk(); }), "ConnectOk"); | |||
ActionManagerment.GetInstance.Register(new Action<object>((o) => { business?.SimOrder(o); }), "SimOrder"); | |||
control?.Init(); | |||
ActionManagerment.GetInstance.Register(new Action<object>((o) => { control?.DataParse(o); }), "DataParse"); | |||
ActionManagerment.GetInstance.Register(new Action(() => { control?.ConnectOk(); }), "ConnectOk"); | |||
ActionManagerment.GetInstance.Register(new Action<object>((o) => { control?.SimOrder(o); }), "SimOrder"); | |||
ConnectHelper.GetInstance.Init(); | |||
} | |||
public IGvl GetGvl() | |||
{ | |||
Type type = business?.GetType(); | |||
Type type = control?.GetType(); | |||
foreach (var item in type?.GetProperties()) | |||
{ | |||
var interfaces = item.PropertyType.GetInterfaces(); | |||
@@ -105,7 +105,7 @@ namespace HBLConsole.Factory | |||
{ | |||
if (inters.Name.Equals("IGvl")) | |||
{ | |||
return (type?.GetProperty(item.Name).GetValue(business, null)) as IGvl; | |||
return (type?.GetProperty(item.Name).GetValue(control, null)) as IGvl; | |||
} | |||
} | |||
} | |||
@@ -12,6 +12,7 @@ | |||
<ItemGroup> | |||
<ProjectReference Include="..\HBLConsole.Interface\HBLConsole.Interface.csproj" /> | |||
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -7,6 +7,7 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Newtonsoft.Json; | |||
using HBLConsole.Service; | |||
namespace HBLConsole.Model | |||
{ | |||
@@ -31,9 +32,7 @@ namespace HBLConsole.Model | |||
{ | |||
_mVarName = value; | |||
OnPropertyChanged(); | |||
//if (DelegationNotifi.GetInstance.VarNameChanged != null) | |||
// DelegationNotifi.GetInstance.VarNameChanged(_mID); | |||
ActionManagerment.GetInstance.Send("VarNameChanged", _mID); | |||
} | |||
} | |||
private string _mVarName; | |||
@@ -26,7 +26,6 @@ namespace HBLConsole | |||
protected override void OnStartup(StartupEventArgs e) | |||
{ | |||
base.OnStartup(e); | |||
SystemHelper.GetInstance.AutoStart(false); | |||
SystemHelper.GetInstance.CreateDesktopShortcut(); | |||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | |||
@@ -77,6 +77,7 @@ | |||
<None Remove="Resources\Images\表格\表格顶右.png" /> | |||
<None Remove="Resources\Images\表格\表格顶左.png" /> | |||
<None Remove="Resources\Images\表格标题背景2.png" /> | |||
<None Remove="Resources\Images\边框1.png" /> | |||
<None Remove="Resources\Images\边框效果2.png" /> | |||
<None Remove="Resources\Images\边角.png" /> | |||
<None Remove="Resources\Images\退出.png" /> | |||
@@ -180,6 +181,7 @@ | |||
<Resource Include="Resources\Images\表格\表格顶右.png" /> | |||
<Resource Include="Resources\Images\表格\表格顶左.png" /> | |||
<Resource Include="Resources\Images\表格标题背景2.png" /> | |||
<Resource Include="Resources\Images\边框1.png" /> | |||
<Resource Include="Resources\Images\边框效果2.png" /> | |||
<Resource Include="Resources\Images\边角.png" /> | |||
<Resource Include="Resources\Images\退出.png" /> | |||
@@ -5,13 +5,14 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using Microsoft.EntityFrameworkCore; | |||
using System.IO; | |||
using HBLConsole.Model; | |||
namespace HBLConsole.Service | |||
namespace HBLConsole | |||
{ | |||
public class SqlHelper<T> : DbContext where T : class, new() | |||
public class SqlHelper : DbContext | |||
{ | |||
private volatile static SqlHelper<T> _Instance; | |||
public static SqlHelper<T> GetInstance => _Instance ?? (_Instance = new SqlHelper<T>()); | |||
private volatile static SqlHelper _Instance; | |||
public static SqlHelper GetInstance => _Instance ?? (_Instance = new SqlHelper()); | |||
private SqlHelper() { } | |||
private string path | |||
@@ -19,11 +20,11 @@ namespace HBLConsole.Service | |||
get | |||
{ | |||
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile")); | |||
return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\{typeof(T).Name}.db"; | |||
return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\{GVL.GeneralConfig.DeviceType.ToString()}_{typeof(VariableInfo).Name}.db"; | |||
} | |||
} | |||
Dictionary<T, bool> IsEnsureCreated = new Dictionary<T, bool>(); | |||
//Dictionary<T, bool> IsEnsureCreated = new Dictionary<T, bool>(); | |||
private static readonly object addLock = new object(); | |||
@@ -32,19 +33,19 @@ namespace HBLConsole.Service | |||
optionsBuilder.UseSqlite($"FileName={path}"); | |||
} | |||
public DbSet<T> DbObj { get; set; } | |||
public DbSet<VariableInfo> DbObj { get; set; } | |||
protected override void OnModelCreating(ModelBuilder modelBuilder) | |||
{ | |||
//一对一关系映射 | |||
//modelBuilder.Entity<VariableInfo>().HasOne(p => p.AlarmSetProp).WithOne(p => p.VariableInfo).HasForeignKey<AlarmSet>(p => p.VariableInfoId); | |||
//modelBuilder.Entity<AlarmSet>().HasOne(P => P.DiscreteAlarmInfoSet).WithOne(P => P.AlarmSet).HasForeignKey<DiscreteAlarmInfo>(P => P.AlarmSetId); | |||
modelBuilder.Entity<VariableInfo>().HasOne(p => p.AlarmSetProp).WithOne(p => p.VariableInfo).HasForeignKey<AlarmSet>(p => p.VariableInfoId); | |||
modelBuilder.Entity<AlarmSet>().HasOne(P => P.DiscreteAlarmInfoSet).WithOne(P => P.AlarmSet).HasForeignKey<DiscreteAlarmInfo>(P => P.AlarmSetId); | |||
////一对多关系映射 | |||
//modelBuilder.Entity<AnalogAlarmModel>().HasOne(p => p.AlarmSet).WithMany(p => p.AnalogAlarmModels).HasForeignKey(p => p.AlarmSetId); | |||
modelBuilder.Entity<AnalogAlarmModel>().HasOne(p => p.AlarmSet).WithMany(p => p.AnalogAlarmModels).HasForeignKey(p => p.AlarmSetId); | |||
} | |||
public List<T> GetData() | |||
public List<VariableInfo> GetData() | |||
{ | |||
Database.EnsureCreated(); | |||
return DbObj.ToList(); | |||
@@ -64,7 +65,7 @@ namespace HBLConsole.Service | |||
} | |||
public void Add(T data) | |||
public void Add(VariableInfo data) | |||
{ | |||
//lock (addLock) | |||
//{ |
@@ -224,6 +224,14 @@ | |||
Content="设备管理" | |||
Style="{StaticResource ParallelogramRadioButtonStyle}" /> | |||
<RadioButton | |||
Margin="-10,0,0,0" | |||
Command="{Binding NavChangedCommand}" | |||
CommandParameter="VariableConfig" | |||
Content="变量管理" | |||
Style="{StaticResource ParallelogramRadioButtonStyle}" /> | |||
<RadioButton | |||
Margin="-10,0,0,0" | |||
Command="{Binding NavChangedCommand}" | |||
@@ -250,7 +250,7 @@ | |||
<Border Background="#081424" ClipToBounds="True"> | |||
<Grid Margin="0"> | |||
<Grid.Background> | |||
<ImageBrush ImageSource="../Resource/Images/边框1.png" /> | |||
<ImageBrush ImageSource="../Resources/Images/边框1.png" /> | |||
</Grid.Background> | |||
<Grid.RowDefinitions> | |||
<RowDefinition /> | |||
@@ -13,6 +13,7 @@ using System.Windows.Media; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
using HBLConsole.Service; | |||
namespace HBLConsole.View | |||
{ | |||
@@ -32,6 +33,7 @@ namespace HBLConsole.View | |||
var obj = (VariableConfig)sender; | |||
if (!obj.IsVisible) | |||
{ | |||
ActionManagerment.GetInstance.Send("VariableSave"); | |||
//if (DelegationNotifi.GetInstance.VariableSave != null) | |||
//{ | |||
// DelegationNotifi.GetInstance.VariableSave(); | |||
@@ -17,24 +17,26 @@ namespace HBLConsole.ViewModel | |||
{ | |||
public VariableConfig() | |||
{ | |||
//DelegationNotifi.GetInstance.VariableSave = new Action(() => { SaveDataAsync(); }); | |||
//DelegationNotifi.GetInstance.VarNameChanged = new Action<int>((p) => | |||
//{ | |||
// if ((p - 1) >= 0) | |||
// { | |||
// if (varialeInfos?.Count >= p) | |||
// { | |||
// if (varialeInfos.ElementAt(p - 1).VarName != null) | |||
// { | |||
// if (varialeInfos.ElementAt(p - 1).VarName.Length > 0) | |||
// { | |||
// if (varialeInfos.Count == p) AddRow(); | |||
// } | |||
// } | |||
// } | |||
// } | |||
//}); | |||
ActionManagerment.GetInstance.Register(new Action(() => { SaveDataAsync(); }), "VariableSave"); | |||
ActionManagerment.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
if (o is int p) | |||
{ | |||
if ((p - 1) >= 0) | |||
{ | |||
if (varialeInfos?.Count >= p) | |||
{ | |||
if (varialeInfos.ElementAt(p - 1).VarName != null) | |||
{ | |||
if (varialeInfos.ElementAt(p - 1).VarName.Length > 0) | |||
{ | |||
if (varialeInfos.Count == p) AddRow(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
}), "VarNameChanged"); | |||
GetLocalDataAsync(); | |||
} | |||
@@ -43,9 +45,9 @@ namespace HBLConsole.ViewModel | |||
/// </summary> | |||
private Task<bool> GetLocalDataAsync() | |||
{ | |||
//SqlHelper<VariableInfo>.GetInstance.Database.EnsureCreated(); | |||
////多表查询 | |||
var DataList = SqlHelper<VariableInfo>.GetInstance.DbObj.ToList(); | |||
SqlHelper.GetInstance.Database.EnsureCreated(); | |||
//多表查询 | |||
var DataList = SqlHelper.GetInstance.DbObj.ToList(); | |||
App.Current.Dispatcher.Invoke(new Action(() => { varialeInfos.Clear(); })); | |||
foreach (var item in DataList) | |||
{ | |||
@@ -73,10 +75,10 @@ namespace HBLConsole.ViewModel | |||
/// <returns></returns> | |||
private Task<bool> SaveDataAsync() | |||
{ | |||
SqlHelper<VariableInfo>.GetInstance.DbObj.RemoveRange(SqlHelper<VariableInfo>.GetInstance.DbObj.ToArray()); | |||
SqlHelper.GetInstance.DbObj.RemoveRange(SqlHelper.GetInstance.DbObj.ToArray()); | |||
foreach (var item in varialeInfos) | |||
{ | |||
SqlHelper<VariableInfo>.GetInstance.Add(new VariableInfo() | |||
SqlHelper.GetInstance.Add(new VariableInfo() | |||
{ | |||
ID = item.ID, | |||
VarName = item.VarName, | |||
@@ -88,7 +90,7 @@ namespace HBLConsole.ViewModel | |||
}); | |||
} | |||
SqlHelper<VariableInfo>.GetInstance.Save(); | |||
SqlHelper.GetInstance.Save(); | |||
return Task.FromResult(true); | |||
} | |||