Commit 8348a92a authored by 潘栩锋's avatar 潘栩锋 🚴

优化 安装完新程序后,只需要到每个程序的服务器,选择对应的plcgroup, 连客户端界面配置也有列表选择。 不需要再手动复制配置文件

parent f429e795
......@@ -65,6 +65,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="WdSetup.xaml.cs">
<DependentUpon>WdSetup.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......@@ -77,6 +80,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="WdSetup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
......
......@@ -4,7 +4,11 @@
ResizeMode="CanMinimize"
Title="MainWindow" Height="184" Width="268">
<Grid>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="80,81,0,0" Name="textBlock1" Text="{Binding CurrRows}" VerticalAlignment="Top" />
<Button Content="加载数据" Height="23" HorizontalAlignment="Left" Margin="80,35,0,0" x:Name="button2" VerticalAlignment="Top" Width="118" Click="button2_Click" />
<StackPanel>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="5" Text="{Binding CurrRows}" VerticalAlignment="Top" />
<Button Content="加载数据" HorizontalAlignment="Left" Padding="20,5" Margin="5" Click="button2_Click" />
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button>
</StackPanel>
</Grid>
</Window>
......@@ -53,5 +53,13 @@ namespace FLY.FeedbackRenZiJia.UI.Server
//mGage.mfeedback.mHeatBuf.LoadData(path);
}
}
private void btnSetupClick(object sender, RoutedEventArgs e)
{
WdSetup w = new WdSetup();
w.Owner = this;
w.Init(mGage.mfeedback);
w.ShowDialog();
}
}
}
<Window x:Class="FLY.FeedbackRenZiJia.UI.Server.WdSetup"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="配置" SizeToContent="WidthAndHeight" >
<Grid>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="5">
<TextBlock Text="PLC适配版本" Margin="2"/>
<ComboBox MinWidth="100" Margin="2" x:Name="comboBox" />
</StackPanel>
<Button Content="确定" Padding="20,5" Margin="5" Click="btnOkClick"/>
</StackPanel>
</Grid>
</Window>
using FLY.FeedbackRenZiJia.Server;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
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.Shapes;
namespace FLY.FeedbackRenZiJia.UI.Server
{
/// <summary>
/// WdSetup.xaml 的交互逻辑
/// </summary>
public partial class WdSetup : Window
{
FeedbackHeat feedback;
public WdSetup()
{
InitializeComponent();
}
public void Init(FeedbackHeat feedback)
{
this.feedback = feedback;
string address = feedback.PLCep.ToString();
Misc.StringConverter.ToIPEndPoint("192.168.50.60:502");
this.comboBox.ItemsSource = new int[] { 1, 2, 3 };
int version = 3;
if (this.feedback.IsClient == false)
{
version = 1;
}
else if (address.CompareTo("192.168.251.20:8000") == 0)
{
version = 2;
}
else// if (address.CompareTo("192.168.50.60:502") == 0)
{
version = 3;
}
this.comboBox.SelectedItem = version;
}
private void btnOkClick(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("需要重启,才能生效", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
int version = (int)this.comboBox.SelectedItem;
switch (version) {
case 1:
{
feedback.IsClient = false;
feedback.Apply();
}
break;
case 2:
{
feedback.IsClient = true;
feedback.PLCep = Misc.StringConverter.ToIPEndPoint("192.168.251.20:8000");
feedback.Apply();
}
break;
default: {
feedback.IsClient = false;
feedback.PLCep = Misc.StringConverter.ToIPEndPoint("192.168.50.60:502");
feedback.Apply();
}
break;
}
Application.Current.Shutdown();
}
}
}
}
......@@ -65,6 +65,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="WdSetup.xaml.cs">
<DependentUpon>WdSetup.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......@@ -77,6 +80,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="WdSetup.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
......
......@@ -6,7 +6,7 @@
<Grid x:Name="grid_plc"/>
<Grid x:Name="grid_plcos"/>
<Grid x:Name="grid_WeightSystem"/>
<StackPanel Orientation="Vertical" Margin="5">
<StackPanel Margin="5">
<ItemsControl x:Name="itemcontrol">
<ItemsControl.ItemTemplate>
<DataTemplate>
......@@ -40,25 +40,7 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="更新速度" />
<TextBlock Text="{Binding ActUpdateInterval}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plcos}">
<TextBlock Text="PLC连接状态" />
<TextBlock Text="{Binding IsRunning}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="寄存器更新数" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DRNeedUpdateCnt}" FontSize="20"/>
<TextBlock Text="/"/>
<TextBlock Text="{Binding DRCnt}" FontSize="20"/>
</StackPanel>
</StackPanel>
</StackPanel>-->
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button>
</StackPanel>
</Grid>
......
......@@ -49,5 +49,12 @@ namespace FLY.Weight.UI.Server
//grid_WeightSystem.DataContext = mTDGage.mData;
this.itemcontrol.ItemsSource = plsos.PLCs;
}
private void btnSetupClick(object sender, RoutedEventArgs e)
{
WdSetup w = new WdSetup();
w.Owner = this;
w.ShowDialog();
}
}
}
<Window x:Class="FLY.Weight.UI.Server.WdSetup"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FLY.Weight.UI.Server"
mc:Ignorable="d"
Title="WdSetup" SizeToContent="WidthAndHeight" >
<Grid>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="5">
<TextBlock Text="plcgroup配置文件" Margin="2"/>
<ComboBox MinWidth="200" Margin="2" x:Name="comboBox" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<Button Content="确定" Padding="20,5" Margin="5" Click="btnOkClick"/>
</StackPanel>
</Grid>
</Window>
using FLY.OBJComponents.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
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.Shapes;
namespace FLY.Weight.UI.Server
{
/// <summary>
/// WdSetup.xaml 的交互逻辑
/// </summary>
public partial class WdSetup : Window
{
public event PropertyChangedEventHandler PropertyChanged;
public WdSetup()
{
InitializeComponent();
Init();
}
private void Init()
{
var items = new List<PlcGroupItem>();
//查找 脚本/称重 下的全部 设备连接变量表_xxx 的文件夹
DirectoryInfo directoryInfo = new DirectoryInfo(@"plcgroups");
if (!directoryInfo.Exists)
{
//异常
return;
}
var dirs = directoryInfo.GetDirectories();
foreach (var dir in dirs)
{
if (dir.Name.StartsWith("设备连接变量表_"))
{
PlcGroupItem item = new PlcGroupItem();
item.Name = dir.Name.Substring("设备连接变量表_".Length);
item.Path = System.IO.Path.Combine(dir.FullName, "Generated", "plcgroup.json");
items.Add(item);
}
}
comboBox.ItemsSource = items;
foreach (var item in items)
{
if (IsSameContent(item.Path, "plcgroup.json"))
{
//找到了
comboBox.SelectedItem = item;
break;
}
}
}
public static bool IsSameContent(string filePath1, string filePath2)
{
//创建一个哈希算法对象
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(filePath1, FileMode.Open), file2 = new FileStream(filePath2, FileMode.Open))
{
byte[] hashByte1 = hash.ComputeHash(file1);//哈希算法根据文本得到哈希码的字节数组
byte[] hashByte2 = hash.ComputeHash(file2);
return Enumerable.SequenceEqual(hashByte1, hashByte2);
//string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串
//string str2 = BitConverter.ToString(hashByte2);
//return (str1 == str2);//比较哈希码
}
}
}
private void btnOkClick(object sender, RoutedEventArgs e)
{
var item = comboBox.SelectedItem as PlcGroupItem;
if (item == null) {
MessageBox.Show("请选择型号!!!");
return;
}
if (MessageBox.Show("需要重启,才能生效", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK) {
File.Copy(item.Path, "plcgroup.json", true);
//System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
}
}
public class PlcGroupItem
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
}
}
......@@ -61,6 +61,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="WdSetup.xaml.cs">
<DependentUpon>WdSetup.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......@@ -73,6 +76,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="WdSetup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
......
......@@ -9,7 +9,7 @@
<Grid>
<Grid x:Name="grid_plc"/>
<Grid x:Name="grid_plcos"/>
<StackPanel Orientation="Vertical">
<StackPanel >
<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="更新速度" />
......@@ -29,6 +29,7 @@
</StackPanel>
</StackPanel>
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button>
</StackPanel>
</Grid>
</Window>
......@@ -42,5 +42,12 @@ namespace FLY.Winder.UI.Server
grid_plc.DataContext = plsos.PLCs[0];
}
private void btnSetupClick(object sender, RoutedEventArgs e)
{
WdSetup w = new WdSetup();
w.Owner = this;
w.ShowDialog();
}
}
}
<Window x:Class="FLY.Winder.UI.Server.WdSetup"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="配置" SizeToContent="WidthAndHeight" >
<Grid>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="5">
<TextBlock Text="plcgroup配置文件" Margin="2"/>
<ComboBox MinWidth="200" Margin="2" x:Name="comboBox" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<Button Content="确定" Padding="20,5" Margin="5" Click="btnOkClick"/>
</StackPanel>
</Grid>
</Window>
using FLY.OBJComponents.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
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.Shapes;
namespace FLY.Winder.UI.Server
{
/// <summary>
/// WdSetup.xaml 的交互逻辑
/// </summary>
public partial class WdSetup : Window
{
public WdSetup()
{
InitializeComponent();
Init();
}
private void Init()
{
var items = new List<PlcGroupItem>();
//查找 脚本/称重 下的全部 设备连接变量表_xxx 的文件夹
DirectoryInfo directoryInfo = new DirectoryInfo(@"plcgroups");
if (!directoryInfo.Exists)
{
//异常
return;
}
var dirs = directoryInfo.GetDirectories();
foreach (var dir in dirs)
{
if (dir.Name.StartsWith("设备连接变量表_"))
{
PlcGroupItem item = new PlcGroupItem();
item.Name = dir.Name.Substring("设备连接变量表_".Length);
item.Path = System.IO.Path.Combine(dir.FullName, "Generated", "plcgroup.json");
items.Add(item);
}
}
comboBox.ItemsSource = items;
foreach (var item in items)
{
if (IsSameContent(item.Path, "plcgroup.json"))
{
//找到了
comboBox.SelectedItem = item;
break;
}
}
}
public static bool IsSameContent(string filePath1, string filePath2)
{
//创建一个哈希算法对象
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(filePath1, FileMode.Open), file2 = new FileStream(filePath2, FileMode.Open))
{
byte[] hashByte1 = hash.ComputeHash(file1);//哈希算法根据文本得到哈希码的字节数组
byte[] hashByte2 = hash.ComputeHash(file2);
return Enumerable.SequenceEqual(hashByte1, hashByte2);
//string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串
//string str2 = BitConverter.ToString(hashByte2);
//return (str1 == str2);//比较哈希码
}
}
}
private void btnOkClick(object sender, RoutedEventArgs e)
{
var item = comboBox.SelectedItem as PlcGroupItem;
if (item == null) {
MessageBox.Show("请选择型号!!!");
return;
}
if (MessageBox.Show("需要重启,才能生效", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK) {
File.Copy(item.Path, "plcgroup.json", true);
//System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
}
}
public class PlcGroupItem
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
}
}
Subproject commit 112766300e4989d39fd3107cf10530d9afa256d8
Subproject commit 5e49ed992e2210e9ec5c5a1397777f248d7182eb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment