Commit cf066b8e authored by 潘栩锋's avatar 潘栩锋 🚴

添加 称重单组分/设备连接变量表_5

parent 4ea25e8b
......@@ -62,6 +62,9 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="WdSetup.xaml.cs">
<DependentUpon>WdSetup.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="MainWindow.xaml.cs">
......@@ -141,6 +144,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="WdSetup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Resource Include="hourglass.ico" />
......
......@@ -53,6 +53,7 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnSetupClick"></Button>
<!--<StackPanel Orientation="Horizontal" >
<StackPanel Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="更新速度" />
......
......@@ -34,5 +34,12 @@ namespace FLY.Weight2.UI.Server
this.itemcontrol.ItemsSource = plsos.PLCs;
spBDetect.DataContext = gage.mBDetect;
}
private void btnSetupClick(object sender, RoutedEventArgs e)
{
WdSetup w = new WdSetup();
w.Owner = this;
w.ShowDialog();
}
}
}
<Window x:Class="FLY.Weight2.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.Weight2.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.Weight2.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; }
}
}
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