Selaa lähdekoodia

本地数据修改

样式分支
pry 2 vuotta sitten
vanhempi
commit
e96b439331
7 muutettua tiedostoa jossa 154 lisäystä ja 44 poistoa
  1. +3
    -3
      BPASmart.ConfigurationSoftware/MainWindow.xaml
  2. +34
    -18
      BPASmart.ConfigurationSoftware/MainWindowViewModel.cs
  3. +10
    -4
      BPASmart.ConfigurationSoftware/NewPageView.xaml.cs
  4. +40
    -0
      BPASmart.ConfigurationSoftware/ProjectDataServer.cs
  5. +35
    -0
      BPASmart.ConfigurationSoftware/ProjectModel.cs
  6. +31
    -19
      BPASmart.VariableManager/App.xaml.cs
  7. +1
    -0
      BPASmart.VariableManager/BPASmart.VariableManager.csproj

+ 3
- 3
BPASmart.ConfigurationSoftware/MainWindow.xaml Näytä tiedosto

@@ -115,13 +115,13 @@
<Button
Width="60"
Margin="5"
Command="{Binding NewCommand}"
Command="{Binding NewProjectCommand}"
Content="新建" />

<Button
Width="60"
Margin="5"
Command="{Binding SaveCommand}"
Command="{Binding SaveProjectCommand}"
Content="保存" />

<Button
@@ -175,7 +175,7 @@
<DataTemplate>
<Grid>
<RadioButton
Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
Command="{Binding DataContext.SelectedPageCommand, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
CommandParameter="{Binding}"
Content="{Binding}"
GroupName="All"


+ 34
- 18
BPASmart.ConfigurationSoftware/MainWindowViewModel.cs Näytä tiedosto

@@ -19,19 +19,19 @@ namespace BPASmart.ConfigurationSoftware
{
public class MainWindowViewModel : NoticeBase
{

public MainWindowViewModel()
{

ActionManage.GetInstance.Register(new Action<object>((o) =>
{
Pages.Add(o.ToString());
string path = $"{Global.ProjectPath}\\{Global.PageDirectoryName}";
string path = $"{ Json<ProjectModel>.Data.ProjectPath}\\{Global.PageDirectoryName}";
Directory.CreateDirectory(path);
File.WriteAllText($"{path}\\{o.ToString()}.lay", null, Encoding.Unicode);
Json<ProjectModel>.Data.Pages.TryAdd(o.ToString(), $"{path}\\{o.ToString()}.lay");
}), "AddPage");

NewCommand = new RelayCommand(() =>
NewProjectCommand = new RelayCommand(() =>
{
NewProjectView newProjectView = new NewProjectView();
bool? result = newProjectView.ShowDialog();
@@ -41,9 +41,13 @@ namespace BPASmart.ConfigurationSoftware
{
string path = $"{objModel.ProjectPath}\\{objModel.ProjectName}";
Directory.CreateDirectory(path);
Global.ProjectPath = path;
Json<ProjectModel>.Data.ProjectPath = path;
Json<ProjectModel>.Data.ProjectName = objModel.ProjectName;

//Global.ProjectPath = path;
Head = objModel.ProjectName;
Global.ProjectName = objModel.ProjectName;
//Global.ProjectName = objModel.ProjectName;
Save();
}
}
});
@@ -56,17 +60,21 @@ namespace BPASmart.ConfigurationSoftware

OpenVarManagerCommand = new RelayCommand(() =>
{
if (File.Exists(Global.VarManagerPath))
{
Process[] pro = Process.GetProcesses();
if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null)
{
Process.Start(Global.VarManagerPath);
}
}
//if (File.Exists(Global.VarManagerPath))
//{
// Process[] pro = Process.GetProcesses();
// if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null)
// {
// Process.Start(Global.VarManagerPath);
// }
//}

VariableManager.App.Start(Json<ProjectModel>.Data.ProjectPath);


});

SelectedCommand = new RelayCommand<object>((o) =>
SelectedPageCommand = new RelayCommand<object>((o) =>
{
string path = $"{Global.ProjectPath}\\{Global.PageDirectoryName}\\{o.ToString()}.lay";
mainCanvasPanels.Add(new MainCanvasPageModel()
@@ -82,22 +90,30 @@ namespace BPASmart.ConfigurationSoftware
}
});

SaveCommand = new RelayCommand(() =>
SaveProjectCommand = new RelayCommand(() =>
{
for (int i = 0; i < mainCanvasPanels.Count; i++)
{
mainCanvasPanels.ElementAt(i).MainCanvasPanelModel.FileSave();
}
Save();
});
}

public RelayCommand NewCommand { get; set; }
public void Save()
{
string path = Json<ProjectModel>.Data.ProjectPath;
string name = Json<ProjectModel>.Data.ProjectName;
Json<ProjectModel>.Save($"{path}\\{name}.project");
}

public RelayCommand NewProjectCommand { get; set; }

public RelayCommand OpenVarManagerCommand { get; set; }

public RelayCommand<object> SelectedCommand { get; set; }
public RelayCommand<object> SelectedPageCommand { get; set; }

public RelayCommand SaveCommand { get; set; }
public RelayCommand SaveProjectCommand { get; set; }

public RelayCommand NewPageCommand { get; set; }



+ 10
- 4
BPASmart.ConfigurationSoftware/NewPageView.xaml.cs Näytä tiedosto

@@ -35,10 +35,16 @@ namespace BPASmart.ConfigurationSoftware
{
if (this.pageName.Text.Trim().Length > 0)
{

this.DialogResult = true;
ActionManage.GetInstance.Send("AddPage", this.pageName.Text);
this.Close();
if (!Json<ProjectModel>.Data.Pages.ContainsKey(this.pageName.Text.Trim()))
{
this.DialogResult = true;
ActionManage.GetInstance.Send("AddPage", this.pageName.Text);
this.Close();
}
else
{
ErrorInfo.Text = "该页面已存在";
}
}
else
{


+ 40
- 0
BPASmart.ConfigurationSoftware/ProjectDataServer.cs Näytä tiedosto

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.ConfigurationSoftware
{
public class ProjectDataServer<TClass> where TClass : class, new()
{
public static TClass Data { get; set; } = new TClass();

/// <summary>
/// 保存数据
/// </summary>
public static void Save(string path)
{
FileStream fs = new FileStream(path, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();//创建一个二进制格式化器
bf?.Serialize(fs, Data);
fs.Close();
}

/// <summary>
/// 获取保存的数据
/// </summary>
public static void Read(string path)
{
if (File.Exists(path))
{
FileStream fs = new FileStream(path, FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
var res = (TClass)bf.Deserialize(fs);
fs.Close();
}
}
}
}

+ 35
- 0
BPASmart.ConfigurationSoftware/ProjectModel.cs Näytä tiedosto

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Runtime.Serialization;

namespace BPASmart.ConfigurationSoftware
{
public class ProjectModel
{
/// <summary>
/// 项目名称
/// </summary>
public string ProjectName { get; set; }

/// <summary>
/// 项目路径
/// </summary>
public string ProjectPath { get; set; }

/// <summary>
/// 页面集合
/// key 是页面名称
/// value 是页面路径
/// </summary>
public ConcurrentDictionary<string, string> Pages { get; set; } = new ConcurrentDictionary<string, string>();

/// <summary>
/// 变量表配置路径
/// </summary>
public string VariableTabPath { get; set; }
}
}

+ 31
- 19
BPASmart.VariableManager/App.xaml.cs Näytä tiedosto

@@ -1,7 +1,6 @@
using BPASmartClient.CustomResource.Pages.Enums;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.CustomResource.Pages.View;
using BPASmartClient.Helper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -11,6 +10,8 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using BPASmart.Model;
using BPA.Helper;
using System.IO;

namespace BPASmart.VariableManager
{
@@ -19,6 +20,7 @@ namespace BPASmart.VariableManager
/// </summary>
public partial class App : Application
{
public static string ConstPath = string.Empty;
public static Window MainWindow;
protected override void OnStartup(StartupEventArgs e)
{
@@ -33,7 +35,19 @@ namespace BPASmart.VariableManager

}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
public static void Start(string path)
{
ConstPath = path;
DataRead();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
MenuInit();
MainView mv = new MainView();
mv.WindowState = WindowState.Normal;
MainWindow = mv;
mv.Show();
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
DataSave();
}
@@ -44,7 +58,7 @@ namespace BPASmart.VariableManager
DataSave();
}

private void MenuInit()
private static void MenuInit()
{
#region 设备管理
ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
@@ -99,7 +113,7 @@ namespace BPASmart.VariableManager

}

private SubMenumodel AddSubMenuModel(string s)
private static SubMenumodel AddSubMenuModel(string s)
{
return new SubMenumodel()
{
@@ -110,26 +124,24 @@ namespace BPASmart.VariableManager
};
}

private void DataSave()
static string path
{
//for (int i = 0; i < Json<CommunicationPar>.Data.CommunicationDevices.Count; i++)
//{
// for (int m = 0; m < Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.Count; m++)
// {
// var deviceType = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).CommDevice;
// var deviceValue = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).Address;
// string RealAddress = AddressConvert.GetInstance.PlcConverter(deviceType, deviceValue);
// Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).RealAddress = RealAddress;
// }
//}

Json<CommunicationPar>.Save();
get
{
string path = $"{ConstPath}\\AccessFile\\JSON";
Directory.CreateDirectory(path);
return $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json";
}
}

private static void DataSave()
{
Json<CommunicationPar>.Save(path);
}

private void DataRead()
private static void DataRead()
{
Json<CommunicationPar>.Read();
Json<CommunicationPar>.Read(path);
}
}



+ 1
- 0
BPASmart.VariableManager/BPASmart.VariableManager.csproj Näytä tiedosto

@@ -30,6 +30,7 @@

<ItemGroup>
<PackageReference Include="BPA.Communication" Version="1.0.13" />
<PackageReference Include="BPA.Helper" Version="1.0.8" />
</ItemGroup>

<ItemGroup>


Ladataan…
Peruuta
Tallenna