Преглед на файлове

变量配置管理修改

master
pry преди 2 години
родител
ревизия
89d17d6ffe
променени са 12 файла, в които са добавени 64 реда и са изтрити 50 реда
  1. +1
    -1
      HBLConsole.Business/MessageServer/Base.cs
  2. +8
    -8
      HBLConsole.Factory/SimpleFactory.cs
  3. +1
    -0
      HBLConsole.Model/HBLConsole.Model.csproj
  4. +2
    -3
      HBLConsole.Model/VariableInfo.cs
  5. +0
    -1
      HBLConsole/App.xaml.cs
  6. +2
    -0
      HBLConsole/HBLConsole.csproj
  7. Двоични данни
     
  8. +13
    -12
      HBLConsole/SqlHelper.cs
  9. +8
    -0
      HBLConsole/View/MainView.xaml
  10. +1
    -1
      HBLConsole/View/VariableConfig.xaml
  11. +2
    -0
      HBLConsole/View/VariableConfig.xaml.cs
  12. +26
    -24
      HBLConsole/ViewModel/VariableConfig.cs

+ 1
- 1
HBLConsole.Business/MessageServer/Base.cs Целия файл

@@ -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 =>


+ 8
- 8
HBLConsole.Factory/SimpleFactory.cs Целия файл

@@ -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;
}
}
}


+ 1
- 0
HBLConsole.Model/HBLConsole.Model.csproj Целия файл

@@ -12,6 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Interface\HBLConsole.Interface.csproj" />
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
</ItemGroup>

<ItemGroup>


+ 2
- 3
HBLConsole.Model/VariableInfo.cs Целия файл

@@ -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;


+ 0
- 1
HBLConsole/App.xaml.cs Целия файл

@@ -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;


+ 2
- 0
HBLConsole/HBLConsole.csproj Целия файл

@@ -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" />


Двоични данни
Целия файл


HBLConsole.Service/SqlHelper.cs → HBLConsole/SqlHelper.cs Целия файл

@@ -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)
//{

+ 8
- 0
HBLConsole/View/MainView.xaml Целия файл

@@ -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}"


+ 1
- 1
HBLConsole/View/VariableConfig.xaml Целия файл

@@ -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 />


+ 2
- 0
HBLConsole/View/VariableConfig.xaml.cs Целия файл

@@ -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();


+ 26
- 24
HBLConsole/ViewModel/VariableConfig.cs Целия файл

@@ -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);
}



Зареждане…
Отказ
Запис