Commit 80e25321 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 称重服务器寄存器原始地址查看

parent 3504da74
......@@ -51,6 +51,6 @@ using System.Windows;
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.0.1.0")]
[assembly: AssemblyFileVersion("7.0.1.0")]
[assembly: AssemblyVersion("7.0.2.0")]
[assembly: AssemblyFileVersion("7.0.2.0")]
[assembly: Guid("AC4FFE57-FF42-4B4D-9E23-FF583D78187D")]
......@@ -6,9 +6,41 @@
xmlns:local="clr-namespace:FLY.Weight.UI.Server"
mc:Ignorable="d"
Title="DRList" Height="450" Width="800">
<Window.Resources>
<Style TargetType="DataGridCell" x:Key="gridCellStyle">
<!--文字居中-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<!--被选中时,背景色改变-->
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="Gray" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<DataGrid x:Name="dataGrid" AutoGenerateColumns="True" IsReadOnly="True"/>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding SearchText}" MinWidth="200" Margin="2"/>
<Button Content="向下搜索" Padding="20,5" Margin="2" Click="btnSearchDownClick"/>
<Button Content="向上搜索" Padding="20,5" Margin="2" Click="btnSearchUpClick"/>
<TextBlock>
当前查找结果序号=<Run Text="{Binding SearchIndex,Mode=OneWay}"/>
</TextBlock>
</StackPanel>
<DataGrid Grid.Row="1" x:Name="dataGrid" AutoGenerateColumns="True" IsReadOnly="True"
AlternationCount ="5" AlternatingRowBackground="LightGray"
CellStyle="{StaticResource gridCellStyle}" CanUserSortColumns="False"/>
</Grid>
</Window>
......@@ -20,13 +20,17 @@ namespace FLY.Weight.UI.Server
/// <summary>
/// DRList.xaml 的交互逻辑
/// </summary>
public partial class WdDRList : Window
public partial class WdDRList : Window,INotifyPropertyChanged
{
ObservableCollection<DataToRegsView> dataToRegsViews = new ObservableCollection<DataToRegsView>();
Modbus.WithThread.ModbusMapper_Client plc;
public event PropertyChangedEventHandler PropertyChanged;
public WdDRList()
{
InitializeComponent();
}
public void Init(Modbus.WithThread.ModbusMapper_Client plc)
{
......@@ -49,19 +53,23 @@ namespace FLY.Weight.UI.Server
dataToRegsViews.Add(new DataToRegsView()
{
Index = i,
dr = dr,
Addr = dr.addr,
RegAddr = dr.regAddr,
DataArea = dr.dataArea,
OwnerName = dr.ownerName,
IsNeedUpdate = dr.isNeedUpdate,
PropertyName = dr.propertyName,
Description = description,
Value = dr.value
});
}); ;
}
plc.PropertyChanged += Plc_PropertyChanged;
plc.NameDataChanged += Plc_NameDataChanged;
dataGrid.ItemsSource = dataToRegsViews;
this.DataContext = this;
}
private void Plc_NameDataChanged(object sender, DataToRegs dr)
......@@ -88,6 +96,113 @@ namespace FLY.Weight.UI.Server
}
}
}
public int SearchIndex { get; private set; } = -1;
public string SearchText { get; set; }
private void btnSearchDownClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(SearchText))
{
MessageBox.Show("输入为空", "异常", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
int newSearchIndex = -1;
for (int i = SearchIndex + 1; i < dataToRegsViews.Count(); i++)
{
if (dataToRegsViews[i].OwnerName.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
if (dataToRegsViews[i].PropertyName.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
if (dataToRegsViews[i].Description.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
if (dataToRegsViews[i].RegAddr.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
}
if (newSearchIndex != -1)
{
SearchIndex = newSearchIndex;
dataGrid.SelectedItem = dataToRegsViews[newSearchIndex];
dataGrid.ScrollIntoView(dataGrid.SelectedItem);
return;
}
else
{
SearchIndex = -1;
MessageBox.Show("不能找到更多", "异常", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
}
private void btnSearchUpClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(SearchText))
{
MessageBox.Show("输入为空", "异常", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
int newSearchIndex = -1;
for (int i = SearchIndex - 1; i >= 0 && i < dataToRegsViews.Count(); i--)
{
if (dataToRegsViews[i].OwnerName.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
if (dataToRegsViews[i].PropertyName.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
if (dataToRegsViews[i].Description.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
if (dataToRegsViews[i].RegAddr.Contains(SearchText))
{
//找到了
newSearchIndex = i;
break;
}
}
if (newSearchIndex != -1)
{
SearchIndex = newSearchIndex;
dataGrid.SelectedItem = dataToRegsViews[newSearchIndex];
return;
}
else
{
SearchIndex = -1;
MessageBox.Show("不能找到更多", "异常", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
}
}
/// <summary>
/// 数据映射的类;
......@@ -96,6 +211,7 @@ namespace FLY.Weight.UI.Server
/// </summary>
public class DataToRegsView : INotifyPropertyChanged
{
public int Index { get; set; }
public DataToRegs dr;
/// <summary>
/// 对应 PLC寄存器区 coil or register
......@@ -103,10 +219,16 @@ namespace FLY.Weight.UI.Server
public PLCAddressArea DataArea { get; set; }
/// <summary>
/// PLC 首地址
/// PLC寄存器 首地址
/// </summary>
public int Addr { get; set; }
/// <summary>
/// 寄存器 原始地址字符串
/// </summary>
public string RegAddr { get; set; }
public string OwnerName { get; set; }
/// <summary>
/// object 的 property 名称, 只能是 数字类型都是double, 剩下就是 bool
/// </summary>
......
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