一:Device窗口布局和功能实现
< UserControl x: Class= "Zhaoxi.HostComputer.Views.DeviceView"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns: x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns: mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns: d= "http://schemas.microsoft.com/expression/blend/2008"
xmlns: local= "clr-namespace:Zhaoxi.HostComputer.Views"
xmlns: lvc= "clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns: sys= "clr-namespace:System;assembly=System.Runtime"
xmlns: base= "clr-namespace:Zhaoxi.HostComputer.Base"
mc: Ignorable= "d" UseLayoutRounding= "True"
d: DesignHeight= "450" d: DesignWidth= "800" >
< UserControl. Resources>
< ControlTemplate TargetType= "ToggleButton" x: Key= "StateButtonTemplate" >
< Border BorderBrush= "#99EEEEEE" BorderThickness= "0" CornerRadius= "3"
Background= "#EEE" Height= "20" Width= "50" Name= "back" >
< Grid>
< TextBlock Text= "停机" VerticalAlignment= "Center" HorizontalAlignment= "Left" Margin= "4,0" FontSize= "9" Foreground= "#888" / >
< TextBlock Text= "运行" VerticalAlignment= "Center" HorizontalAlignment= "Right" Margin= "4,0" FontSize= "9" Foreground= "White" / >
< Border Margin= "2,2" HorizontalAlignment= "Left" Width= "23" Background= "#DDD" CornerRadius= "2" >
< TextBlock Text= "||" VerticalAlignment= "Center" HorizontalAlignment= "Center" FontSize= "8" / >
< Border. RenderTransform>
< TranslateTransform X= "22" x: Name= "tt" / >
< / Border. RenderTransform>
< / Border>
< / Grid>
< / Border>
< ControlTemplate. Triggers>
< Trigger Property= "IsChecked" Value= "True" >
< Trigger. EnterActions>
< BeginStoryboard>
< Storyboard>
< DoubleAnimation Duration= "0:0:0.2" To= "0" Storyboard. TargetName= "tt" Storyboard. TargetProperty= "X" / >
< ColorAnimation Duration= "0:0:0.2" To= "#38baec" Storyboard. TargetName= "back" Storyboard. TargetProperty= "Background.(SolidColorBrush.Color)" / >
< / Storyboard>
< / BeginStoryboard>
< / Trigger. EnterActions>
< Trigger. ExitActions>
< BeginStoryboard>
< Storyboard>
< DoubleAnimation Duration= "0:0:0.2" Storyboard. TargetName= "tt" Storyboard. TargetProperty= "X" / >
< ColorAnimation Duration= "0:0:0.2" Storyboard. TargetName= "back" Storyboard. TargetProperty= "Background.(SolidColorBrush.Color)" / >
< / Storyboard>
< / BeginStoryboard>
< / Trigger. ExitActions>
< / Trigger>
< / ControlTemplate. Triggers>
< / ControlTemplate>
< Style TargetType= "RadioButton" x: Key= "DeviceItemButtonStyle" >
< Setter Property= "Margin" Value= "5" / >
< Setter Property= "Background" Value= "#DDD" / >
< Setter Property= "Template" >
< Setter. Value>
< ControlTemplate TargetType= "RadioButton" >
< Border Background= "Transparent" BorderBrush= "{TemplateBinding Background}" BorderThickness= "1" CornerRadius= "5" >
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "auto" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< StackPanel Orientation= "Horizontal" VerticalAlignment= "Center" HorizontalAlignment= "Center" Margin= "0,15" >
< TextBlock Text= "" FontFamily= "{StaticResource iconfont}"
VerticalAlignment= "Center" HorizontalAlignment= "Center"
FontSize= "40" Foreground= "#888" Name= "device_icon" / >
< StackPanel VerticalAlignment= "Center" Margin= "20,0" >
< TextBlock Text= "{Binding Name}" FontSize= "13" HorizontalAlignment= "Center" / >
< TextBlock Text= "8937-45834659" FontSize= "10" Margin= "0,5,0,0" HorizontalAlignment= "Center" / >
< / StackPanel>
< / StackPanel>
< Grid Grid. Row= "1" >
< UniformGrid Columns= "4" Grid. Column= "1" TextBlock. FontSize= "10" TextBlock. Foreground= "#888" >
< TextBlock Text= "正在运行" VerticalAlignment= "Top" HorizontalAlignment= "Center" Grid. Row= "1" Foreground= "#333" FontSize= "11" / >
< TextBlock>
< Run Text= "电压:" / >
< Run Text= "220V" / >
< / TextBlock>
< TextBlock>
< Run Text= "电流:" / >
< Run Text= "220A" / >
< / TextBlock>
< TextBlock>
< Run Text= "温度:" / >
< Run Text= "220℃" / >
< / TextBlock>
< Border/ >
< TextBlock Text= "流量:220" / >
< TextBlock Text= "温度:220" / >
< TextBlock Text= "时长:220" / >
< / UniformGrid>
< / Grid>
< / Grid>
< / Border>
< ControlTemplate. Triggers>
< Trigger Property= "IsChecked" Value= "True" >
< Setter Property= "Foreground" Value= "#14AAE6" TargetName= "device_icon" / >
< / Trigger>
< / ControlTemplate. Triggers>
< / ControlTemplate>
< / Setter. Value>
< / Setter>
< Style. Triggers>
< Trigger Property= "IsChecked" Value= "True" >
< Setter Property= "Background" Value= "#14AAE6" / >
< / Trigger>
< / Style. Triggers>
< / Style>
< ControlTemplate TargetType= "Button" x: Key= "FlipButtonTemplate" >
< Grid Background= "Transparent" Name= "back" >
< TextBlock Text= "{Binding Content,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Button}}" VerticalAlignment= "Center" HorizontalAlignment= "Center"
FontSize= "20" FontFamily= "{StaticResource iconfont}" / >
< / Grid>
< ControlTemplate. Triggers>
< Trigger Property= "IsMouseOver" Value= "True" >
< Setter Property= "Background" Value= "#11000000" TargetName= "back" / >
< / Trigger>
< / ControlTemplate. Triggers>
< / ControlTemplate>
< ControlTemplate TargetType= "Button" x: Key= "AddButtonTemplate" >
< Border Background= "#FF3269DE" Name= "back" CornerRadius= "3" >
< ContentPresenter VerticalAlignment= "Center" HorizontalAlignment= "Center"
Content= "{TemplateBinding Content}" TextBlock. Foreground= "White" / >
< / Border>
< ControlTemplate. Triggers>
< Trigger Property= "IsMouseOver" Value= "True" >
< Setter Property= "Background" Value= "#CC3269DE" TargetName= "back" / >
< / Trigger>
< / ControlTemplate. Triggers>
< / ControlTemplate>
< x: Array Type= "sys:String" x: Key= "datas" >
< sys: String>
< sys: String>
< sys: String>
< sys: String>
< / x: Array>
< Style TargetType= "ListViewItem" >
< Setter Property= "Margin" Value= "0" / >
< Setter Property= "Padding" Value= "0" / >
< Setter Property= "VerticalContentAlignment" Value= "Stretch" / >
< Setter Property= "HorizontalContentAlignment" Value= "Stretch" / >
< / Style>
< / UserControl. Resources>
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "60" / >
< RowDefinition/ >
< RowDefinition Height= "180" / >
< / Grid. RowDefinitions>
< Button Content= "注册新设备" VerticalAlignment= "Center" Height= "30" Width= "90" HorizontalAlignment= "Right"
Template= "{StaticResource AddButtonTemplate}" Margin= "10,0" / >
< Grid Grid. Row= "1" Margin= "20,0" DataContext= "{Binding ElementName=lvDeviceList,Path=SelectedItem}" >
< Grid. ColumnDefinitions>
< ColumnDefinition/ >
< ColumnDefinition Width= "2*" / >
< ColumnDefinition Width= "0.7*" / >
< / Grid. ColumnDefinitions>
< Border BorderBrush= "#EEE" BorderThickness= "0,0,1,0" / >
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "30" / >
< RowDefinition/ >
< RowDefinition Height= "40" / >
< / Grid. RowDefinitions>
< TextBlock Text= "设备详情" VerticalAlignment= "Center" FontSize= "14" / >
< Grid Grid. Row= "1" >
< Grid. RowDefinitions>
< RowDefinition Height= "40" / >
< RowDefinition/ >
< RowDefinition/ >
< / Grid. RowDefinitions>
< TextBlock Text= "[设备基本参数]" VerticalAlignment= "Center" Foreground= "#888" / >
< Border Background= "#FFF" Grid. Row= "1" Margin= "30,10" BorderThickness= "0,2,0,2" CornerRadius= "5" >
< Border. BorderBrush>
< LinearGradientBrush StartPoint= "0,0" EndPoint= "1,0" >
< GradientStop Color= "#FFF" Offset= "0" / >
< GradientStop Color= "#14AAE6" Offset= "0.4" / >
< GradientStop Color= "#14AAE6" Offset= "0.6" / >
< GradientStop Color= "#FFF" Offset= "1" / >
< / LinearGradientBrush>
< / Border. BorderBrush>
< StackPanel HorizontalAlignment= "Center" VerticalAlignment= "Center" >
< TextBlock Text= "" FontFamily= "{StaticResource iconfont}" FontSize= "50" Foreground= "#14AAE6"
HorizontalAlignment= "Center" / >
< TextBlock Text= "{Binding Name}" Margin= "0,10" FontWeight= "Bold" / >
< TextBlock Text= "8937-45834659" HorizontalAlignment= "Center" / >
< / StackPanel>
< / Border>
< Grid Grid. Row= "2" Margin= "10,20,0,20" >
< Grid. ColumnDefinitions>
< ColumnDefinition Width= "1.5*" / >
< ColumnDefinition Width= "2*" / >
< ColumnDefinition/ >
< / Grid. ColumnDefinitions>
< Grid. RowDefinitions>
< RowDefinition/ >
< RowDefinition/ >
< RowDefinition/ >
< RowDefinition/ >
< / Grid. RowDefinitions>
< TextBlock VerticalAlignment= "Center" >
< Run Text= "P:" Foreground= "#888" / >
< Run Text= "{Binding MonitorValueList[0].Value,StringFormat=\{0\}kW}" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Column= "1" >
< Run Text= "Va:" Foreground= "#888" / >
< Run Text= "668,126.2kV" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Column= "2" >
< Run Text= "La:" Foreground= "#888" / >
< Run Text= "188A" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "1" >
< Run Text= "Q:" Foreground= "#888" / >
< Run Text= "56.3kVar" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "1" Grid. Column= "1" >
< Run Text= "Vb:" Foreground= "#888" / >
< Run Text= "768,126.2kV" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "1" Grid. Column= "2" >
< Run Text= "Lb:" Foreground= "#888" / >
< Run Text= "89A" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "2" >
< Run Text= "PF:" Foreground= "#888" / >
< Run Text= "0.8" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "2" Grid. Column= "1" >
< Run Text= "Vc:" Foreground= "#888" / >
< Run Text= "253,212.8kV" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "2" Grid. Column= "2" >
< Run Text= "Lc:" Foreground= "#888" / >
< Run Text= "956A" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "3" >
< Run Text= "PF:" Foreground= "#888" / >
< Run Text= "0.8" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "3" Grid. Column= "1" >
< Run Text= "Vc:" Foreground= "#888" / >
< Run Text= "253,212.8kV" FontWeight= "Bold" / >
< / TextBlock>
< TextBlock VerticalAlignment= "Center" Grid. Row= "3" Grid. Column= "2" >
< Run Text= "Lc:" Foreground= "#888" / >
< Run Text= "956A" FontWeight= "Bold" / >
< / TextBlock>
< / Grid>
< / Grid>
< TextBlock Grid. Row= "2" VerticalAlignment= "Top" HorizontalAlignment= "Right" Margin= "15,0" >
< Hyperlink Command= "{Binding EditCommand}" > 编辑设备信息< / Hyperlink>
< / TextBlock>
< / Grid>
< Grid Grid. Column= "1" Margin= "10,0" >
< Grid. RowDefinitions>
< RowDefinition Height= "40" / >
< RowDefinition/ >
< RowDefinition Height= "60" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< TextBlock Text= "[设备健康状态跟踪]" VerticalAlignment= "Center" / >
< lvc: CartesianChart Grid. Row= "1" >
< lvc: CartesianChart. Series>
< lvc: LineSeries Stroke= "#FF3269DE" PointGeometrySize= "0" Values= "56,60,70,76,32,54,88,34,50" >
< lvc: LineSeries. Fill>
< LinearGradientBrush StartPoint= "0,0" EndPoint= "0,1" >
< GradientStop Color= "#773269DE" Offset= "0" / >
< GradientStop Color= "Transparent" Offset= "1" / >
< / LinearGradientBrush>
< / lvc: LineSeries. Fill>
< / lvc: LineSeries>
< / lvc: CartesianChart. Series>
< lvc: CartesianChart. AxisX>
< lvc: Axis ShowLabels= "True" Labels= "5/22,5/23,5/24,5/25,5/26,5/27,5/28,5/29,5/30"
LabelsRotation= "0" FontSize= "10" >
< lvc: Axis. Separator>
< lvc: Separator Step= "1" StrokeThickness= "0" / >
< / lvc: Axis. Separator>
< / lvc: Axis>
< / lvc: CartesianChart. AxisX>
< lvc: CartesianChart. AxisY>
< lvc: Axis MinValue= "0" ShowLabels= "True" FontSize= "10" >
< lvc: Axis. Separator>
< lvc: Separator Step= "20" / >
< / lvc: Axis. Separator>
< / lvc: Axis>
< / lvc: CartesianChart. AxisY>
< / lvc: CartesianChart>
< TextBlock Text= "[设备管理跟踪]" VerticalAlignment= "Bottom" Grid. Row= "2" / >
< UniformGrid Rows= "1" Grid. Row= "3" Margin= "10" >
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "2*" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< lvc: PieChart InnerRadius= "25" Width= "90" Height= "90" Margin= "0,10" >
< lvc: PieChart. Series>
< lvc: PieSeries Values= "1" StrokeThickness= "0" Fill= "LightGray" / >
< lvc: PieSeries Values= "20" StrokeThickness= "0" Fill= "#00E4ED" / >
< / lvc: PieChart. Series>
< / lvc: PieChart>
< TextBlock Text= "94%" VerticalAlignment= "Center" HorizontalAlignment= "Center" / >
< Border CornerRadius= "5" Background= "#F1F2F3" Grid. Row= "1" Margin= "10,5" >
< Grid>
< Grid. ColumnDefinitions>
< ColumnDefinition/ >
< ColumnDefinition/ >
< / Grid. ColumnDefinitions>
< Border BorderBrush= "#DDD" BorderThickness= "0,0,1,0" Margin= "0,10" / >
< StackPanel VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "已完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123123" HorizontalAlignment= "Center" Foreground= "#14AAE6" Margin= "0,5,0,0" / >
< / StackPanel>
< StackPanel Grid. Column= "1" VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "未完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123" HorizontalAlignment= "Center" Foreground= "Orange" Margin= "0,5,0,0" / >
< / StackPanel>
< / Grid>
< / Border>
< / Grid>
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "2*" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< lvc: PieChart InnerRadius= "25" Width= "90" Height= "90" Margin= "0,10" >
< lvc: PieChart. Series>
< lvc: PieSeries Values= "1" StrokeThickness= "0" Fill= "LightGray" / >
< lvc: PieSeries Values= "52" StrokeThickness= "0" Fill= "#FDB628" / >
< / lvc: PieChart. Series>
< / lvc: PieChart>
< TextBlock Text= "97%" VerticalAlignment= "Center" HorizontalAlignment= "Center" / >
< Border CornerRadius= "5" Background= "#F1F2F3" Grid. Row= "1" Margin= "10,5" >
< Grid>
< Grid. ColumnDefinitions>
< ColumnDefinition/ >
< ColumnDefinition/ >
< / Grid. ColumnDefinitions>
< Border BorderBrush= "#DDD" BorderThickness= "0,0,1,0" Margin= "0,10" / >
< StackPanel VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "已完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123123" HorizontalAlignment= "Center" Foreground= "#14AAE6" Margin= "0,5,0,0" / >
< / StackPanel>
< StackPanel Grid. Column= "1" VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "未完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123" HorizontalAlignment= "Center" Foreground= "Orange" Margin= "0,5,0,0" / >
< / StackPanel>
< / Grid>
< / Border>
< / Grid>
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "2*" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< lvc: PieChart InnerRadius= "25" Width= "90" Height= "90" Margin= "0,10" >
< lvc: PieChart. Series>
< lvc: PieSeries Values= "8" StrokeThickness= "0" Fill= "LightGray" / >
< lvc: PieSeries Values= "15" StrokeThickness= "0" Fill= "#14AAE6" / >
< / lvc: PieChart. Series>
< / lvc: PieChart>
< TextBlock Text= "67%" VerticalAlignment= "Center" HorizontalAlignment= "Center" / >
< Border CornerRadius= "5" Background= "#F1F2F3" Grid. Row= "1" Margin= "10,5" >
< Grid>
< Grid. ColumnDefinitions>
< ColumnDefinition/ >
< ColumnDefinition/ >
< / Grid. ColumnDefinitions>
< Border BorderBrush= "#DDD" BorderThickness= "0,0,1,0" Margin= "0,10" / >
< StackPanel VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "已完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123123" HorizontalAlignment= "Center" Foreground= "#14AAE6" Margin= "0,5,0,0" / >
< / StackPanel>
< StackPanel Grid. Column= "1" VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "未完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123" HorizontalAlignment= "Center" Foreground= "Orange" Margin= "0,5,0,0" / >
< / StackPanel>
< / Grid>
< / Border>
< / Grid>
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "2*" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< lvc: PieChart InnerRadius= "25" Width= "90" Height= "90" Margin= "0,10" >
< lvc: PieChart. Series>
< lvc: PieSeries Values= "3" StrokeThickness= "0" Fill= "LightGray" / >
< lvc: PieSeries Values= "15" StrokeThickness= "0" Fill= "#EB6F49" / >
< / lvc: PieChart. Series>
< / lvc: PieChart>
< TextBlock Text= "80%" VerticalAlignment= "Center" HorizontalAlignment= "Center" / >
< Border CornerRadius= "5" Background= "#F1F2F3" Grid. Row= "1" Margin= "10,5" >
< Grid>
< Grid. ColumnDefinitions>
< ColumnDefinition/ >
< ColumnDefinition/ >
< / Grid. ColumnDefinitions>
< Border BorderBrush= "#DDD" BorderThickness= "0,0,1,0" Margin= "0,10" / >
< StackPanel VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "已完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123123" HorizontalAlignment= "Center" Foreground= "#14AAE6" Margin= "0,5,0,0" / >
< / StackPanel>
< StackPanel Grid. Column= "1" VerticalAlignment= "Center" HorizontalAlignment= "Center" >
< TextBlock Text= "未完成" FontSize= "10" HorizontalAlignment= "Center" / >
< TextBlock Text= "123" HorizontalAlignment= "Center" Foreground= "Orange" Margin= "0,5,0,0" / >
< / StackPanel>
< / Grid>
< / Border>
< / Grid>
< / UniformGrid>
< / Grid>
< Grid Grid. Column= "2" >
< Grid. RowDefinitions>
< RowDefinition Height= "30" / >
< RowDefinition Height= "auto" / >
< RowDefinition Height= "auto" / >
< RowDefinition Height= "40" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< TextBlock Text= "[事件统计]" VerticalAlignment= "Center" / >
< lvc: PieChart Grid. Row= "1" InnerRadius= "25" Width= "90" Height= "90" Margin= "0,10" >
< lvc: PieChart. Series>
< lvc: PieSeries Values= "22" StrokeThickness= "0" Fill= "Red" / >
< lvc: PieSeries Values= "56" StrokeThickness= "0" Fill= "Orange" / >
< lvc: PieSeries Values= "17" StrokeThickness= "0" Fill= "#14AAE6" / >
< / lvc: PieChart. Series>
< / lvc: PieChart>
< StackPanel Grid. Row= "1" VerticalAlignment= "Center" >
< TextBlock Text= "95" Grid. Row= "1" VerticalAlignment= "Center" HorizontalAlignment= "Center" Foreground= "Orange"
FontSize= "16" FontWeight= "Bold" / >
< TextBlock Text= "事件总数" HorizontalAlignment= "Center" FontSize= "8" / >
< / StackPanel>
< StackPanel Grid. Row= "2" TextBlock. FontSize= "11" Margin= "0,10" >
< Grid Margin= "20,0" >
< Border Background= "Red" Width= "7" Height= "7" HorizontalAlignment= "Left" / >
< TextBlock Text= "重大事件" HorizontalAlignment= "Left" Margin= "20,0,0,0" / >
< TextBlock Text= "22" HorizontalAlignment= "Right" Foreground= "Orange" / >
< / Grid>
< Grid Margin= "20,10" >
< Border Background= "Orange" Width= "7" Height= "7" HorizontalAlignment= "Left" / >
< TextBlock Text= "普通事件" HorizontalAlignment= "Left" Margin= "20,0,0,0" / >
< TextBlock Text= "56" HorizontalAlignment= "Right" Foreground= "Orange" / >
< / Grid>
< Grid Margin= "20,0" >
< Border Background= "#14AAE6" Width= "7" Height= "7" HorizontalAlignment= "Left" / >
< TextBlock Text= "XXX嫌疑事件" HorizontalAlignment= "Left" Margin= "20,0,0,0" / >
< TextBlock Text= "17" HorizontalAlignment= "Right" Foreground= "Orange" / >
< / Grid>
< / StackPanel>
< TextBlock Grid. Row= "3" Text= "[最近事件记录]" VerticalAlignment= "Center" / >
< UniformGrid Columns= "1" Grid. Row= "4" >
< Border Background= "#11000000" >
< Grid Margin= "20,6" >
< Grid. RowDefinitions>
< RowDefinition/ >
< RowDefinition/ >
< RowDefinition/ >
< / Grid. RowDefinitions>
< Ellipse Fill= "red" Width= "6" Height= "6" VerticalAlignment= "Center" HorizontalAlignment= "Left" / >
< TextBlock Text= "#1 Master device" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "事件类型:重大事件" Grid. Row= "1" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "报警时间:2021/05/30 20:00:00" Grid. Row= "2" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< / Grid>
< / Border>
< Border>
< Grid Margin= "20,6" >
< Grid. RowDefinitions>
< RowDefinition/ >
< RowDefinition/ >
< RowDefinition/ >
< / Grid. RowDefinitions>
< Ellipse Fill= "red" Width= "6" Height= "6" VerticalAlignment= "Center" HorizontalAlignment= "Left" / >
< TextBlock Text= "#1 Master device" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "事件类型:重大事件" Grid. Row= "1" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "报警时间:2021/05/30 20:00:00" Grid. Row= "2" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< / Grid>
< / Border>
< Border Background= "#11000000" >
< Grid Margin= "20,6" >
< Grid. RowDefinitions>
< RowDefinition/ >
< RowDefinition/ >
< RowDefinition/ >
< / Grid. RowDefinitions>
< Ellipse Fill= "red" Width= "6" Height= "6" VerticalAlignment= "Center" HorizontalAlignment= "Left" / >
< TextBlock Text= "#1 Master device" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "事件类型:重大事件" Grid. Row= "1" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "报警时间:2021/05/30 20:00:00" Grid. Row= "2" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< / Grid>
< / Border>
< Border>
< Grid Margin= "20,6" >
< Grid. RowDefinitions>
< RowDefinition/ >
< RowDefinition/ >
< RowDefinition/ >
< / Grid. RowDefinitions>
< Ellipse Fill= "red" Width= "6" Height= "6" VerticalAlignment= "Center" HorizontalAlignment= "Left" / >
< TextBlock Text= "#1 Master device" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "事件类型:重大事件" Grid. Row= "1" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< TextBlock Text= "报警时间:2021/05/30 20:00:00" Grid. Row= "2" FontSize= "9" VerticalAlignment= "Center" Margin= "15,0,0,0" / >
< / Grid>
< / Border>
< / UniformGrid>
< / Grid>
< / Grid>
< !- - 设备列表- - >
< Grid Grid. Row= "2" Margin= "10,0" >
< Grid. RowDefinitions>
< RowDefinition Height= "40" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< Grid. ColumnDefinitions>
< ColumnDefinition Width= "50" / >
< ColumnDefinition / >
< ColumnDefinition Width= "50" / >
< / Grid. ColumnDefinitions>
< Border Background= "#EEE" Grid. ColumnSpan= "3" Height= "30" / >
< TextBlock Text= "设备选择" VerticalAlignment= "Center" Margin= "10,0,0,0" Grid. ColumnSpan= "3" / >
< Button Content= "" Grid. Row= "1" Margin= "0,5" Template= "{StaticResource FlipButtonTemplate}" / >
< UniformGrid Rows= "1" Grid. Column= "1" Grid. Row= "1" Visibility= "Collapsed" >
< RadioButton IsChecked= "True" Style= "{StaticResource DeviceItemButtonStyle}" / >
< RadioButton Style= "{StaticResource DeviceItemButtonStyle}" / >
< RadioButton Style= "{StaticResource DeviceItemButtonStyle}" / >
< RadioButton Style= "{StaticResource DeviceItemButtonStyle}" / >
< / UniformGrid>
< ListView Grid. Row= "1" Grid. Column= "1" ItemsSource= "{Binding Path=(base:GlobalMonitor.DeviceList)}"
BorderThickness= "0" Background= "Transparent" Name= "lvDeviceList"
SelectedIndex= "0" >
< ListView. ItemContainerStyle>
< Style TargetType= "ListBoxItem" >
< Setter Property= "Margin" Value= "0" / >
< Setter Property= "Padding" Value= "0" / >
< Setter Property= "VerticalContentAlignment" Value= "Stretch" / >
< Setter Property= "HorizontalContentAlignment" Value= "Stretch" / >
< Setter Property= "Template" >
< Setter. Value>
< ControlTemplate TargetType= "{x:Type ListBoxItem}" >
< Border Background= "{TemplateBinding Background}"
BorderBrush= "{TemplateBinding BorderBrush}"
BorderThickness= "{TemplateBinding BorderThickness}" >
< Border Background= "Transparent" BorderBrush= "#DDD" BorderThickness= "1" CornerRadius= "5"
Margin= "5" Name= "bor" >
< Grid>
< Grid. RowDefinitions>
< RowDefinition Height= "auto" / >
< RowDefinition/ >
< / Grid. RowDefinitions>
< StackPanel Orientation= "Horizontal" VerticalAlignment= "Center" HorizontalAlignment= "Center" Margin= "0,15" >
< TextBlock Text= "" FontFamily= "{StaticResource iconfont}"
VerticalAlignment= "Center" HorizontalAlignment= "Center"
FontSize= "40" Foreground= "#888" Name= "device_icon" / >
< StackPanel VerticalAlignment= "Center" Margin= "20,0" >
< TextBlock Text= "{Binding Name}" FontSize= "13" HorizontalAlignment= "Center" / >
< TextBlock Text= "{Binding SN}" FontSize= "10" Margin= "0,5,0,0" HorizontalAlignment= "Center" / >
< / StackPanel>
< / StackPanel>
< Grid Grid. Row= "1" >
< UniformGrid Columns= "4" Grid. Column= "1" TextBlock. FontSize= "10" TextBlock. Foreground= "#888" >
< TextBlock Text= "正在运行" VerticalAlignment= "Top" HorizontalAlignment= "Center" Grid. Row= "1" Foreground= "#333" FontSize= "11" / >
< TextBlock>
< Run Text= "电压:" / >
< Run Text= "220V" / >
< / TextBlock>
< TextBlock>
< Run Text= "电流:" / >
< Run Text= "220A" / >
< / TextBlock>
< TextBlock>
< Run Text= "温度:" / >
< Run Text= "220℃" / >
< / TextBlock>
< Border/ >
< TextBlock Text= "流量:220" / >
< TextBlock Text= "温度:220" / >
< TextBlock Text= "时长:220" / >
< / UniformGrid>
< / Grid>
< / Grid>
< / Border>
< / Border>
< ControlTemplate. Triggers>
< Trigger Property= "IsMouseOver" Value= "True" >
< !- - 鼠标悬停- - >
< Setter Property= "Background" Value= "Transparent" / >
< !- - value中写你要的颜色的值- - >
< / Trigger>
< Trigger Property= "IsSelected" Value= "true" >
< !- - 选中- - >
< Setter Property= "Background" Value= "Transparent" / >
< Setter Property= "BorderBrush" Value= "#14AAE6" TargetName= "bor" / >
< Setter Property= "Foreground" Value= "#14AAE6" TargetName= "device_icon" / >
< / Trigger>
< / ControlTemplate. Triggers>
< / ControlTemplate>
< / Setter. Value>
< / Setter>
< / Style>
< / ListView. ItemContainerStyle>
< ListView. ItemsPanel>
< ItemsPanelTemplate>
< UniformGrid Rows= "1" / >
< / ItemsPanelTemplate>
< / ListView. ItemsPanel>
< / ListView>
< Button Content= "" Grid. Row= "1" Grid. Column= "2" Margin= "0,5" Template= "{StaticResource FlipButtonTemplate}" / >
< / Grid>
< / Grid>
< / UserControl>
// / < summary>
// / DeviceView. xaml 的交互逻辑
// / < / summary>
public partial class DeviceView : UserControl
{
public DeviceView( )
{
InitializeComponent( ) ;
// this. DataContext = new DeviceViewModel( ) ;
}
}
public class DeviceModel : NotifyBase
{
private CommandBase _editCommand;
public CommandBase EditCommand
{
get
{
if ( _editCommand == null)
{
_editCommand = new CommandBase( ) ;
_editCommand. DoExecute = new Action< object > ( obj = >
{
WindowManager. ShowDialog( "DeviceEditWindow" , this) ;
} ) ;
}
return _editCommand;
}
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; this. NotifyChanged( ) ; }
}
private string _sn;
public string SN
{
get { return _sn; }
set { _sn = value; this. NotifyChanged( ) ; }
}
private int _param1;
public int Param1
{
get { return _param1; }
set { _param1 = value; this. NotifyChanged( ) ; }
}
// / < summary>
// / 通信方式
// / < / summary>
public int CommType { get; set ; }
public ProtocolS7Model S7 { get; set ; }
public ProtocolModbus Modbus { get; set ; }
public ObservableCollection< MonitorValueModel> MonitorValueList { get; set ; } = new ObservableCollection< MonitorValueModel> ( ) ;
}
public class ProtocolModbus
{
public int CommType { get; set ; } = 1 ;
public string IP { get; set ; }
public int Port { get; set ; } = 502 ;
public int BaudRate { get; set ; } = 9600 ;
public int DataBits { get; set ; } = 8 ;
public int Parity { get; set ; } = 0 ;
public int StopBits { get; set ; } = 1 ;
}
public class ProtocolS7Model
{
public string IP { get; set ; }
public int Port { get; set ; }
public int Rock { get; set ; }
public int Slot { get; set ; }
}
public class MonitorValueModel : NotifyBase
{
public string ValueId { get; set ; }
public string ValueName { get; set ; }
public string Address { get; set ; }
public string DataType { get; set ; }
public string Unit { get; set ; }
private object _value;
public object Value
{
get { return _value; }
set { _value = value; this. NotifyChanged( ) ; }
}
}
public class DeviceViewModel
{
private CommandBase _editCommand;
public CommandBase EditCommand
{
get
{
if ( _editCommand == null)
{
_editCommand = new CommandBase( ) ;
_editCommand. DoExecute = new Action< object > ( obj = >
{
WindowManager. ShowDialog( "DeviceEditWindow" , null) ;
} ) ;
}
return _editCommand;
}
}
public DeviceModel CurrentDeviceModel { get; set ; } = new DeviceModel( ) ;
public DeviceViewModel( )
{
Task. Run( async ( ) = >
{
Zhaoxi. Communication. Siemens. S7Net s7Net = new Communication. Siemens. S7Net( "192.168.2.1" , 102 , 0 , 0 ) ;
while ( true)
{
await Task. Delay( 500 ) ;
var result = s7Net. Read< ushort> ( "VW100" ) ;
if ( result. IsSuccessed)
CurrentDeviceModel. Param1 = result. Datas[ 0 ] ;
}
} ) ;
}
}
public class DeviceService
{
SqlServerAccess sqlServerAccess = new SqlServerAccess( ) ;
public List< DeviceModel> GetDevices( )
{
List< DeviceModel> deviceModels = new List< DeviceModel> ( ) ;
// 获取点位信息
// 获取设备信息
var d_info = sqlServerAccess. GetDevices( ) ;
foreach ( var item in d_info. AsEnumerable( ) )
{
DeviceModel deviceModel = new DeviceModel( ) ;
deviceModel. Name = item. Field< string> ( "d_name" ) ;
deviceModel. SN = item. Field< string> ( "d_sn" ) ;
deviceModel. CommType = ( int ) item. Field< Int32> ( "comm_type" ) ;
// 获取协议信息
var p_info = sqlServerAccess. GetProtocolSettings( item. Field< string> ( "d_id" ) , deviceModel. CommType) ;
if ( p_info != null& & p_info. AsEnumerable( ) . Count( ) > 0 )
{
var p_row = p_info. AsEnumerable( ) . First( ) ;
if ( deviceModel. CommType == 1 )
{
deviceModel. Modbus = new ProtocolModbus( )
{
IP = p_row. Field< string> ( "d_ip" ) ,
Port = ( int ) p_row. Field< Int32> ( "d_port" ) ,
// 其他属性
BaudRate = ( int ) p_row. Field< Int32> ( "baudrate" )
} ;
}
else if ( deviceModel. CommType == 2 )
{
deviceModel. S7 = new ProtocolS7Model( )
{
IP = p_row. Field< string> ( "d_ip" ) ,
Port = ( int ) p_row. Field< Int32> ( "d_port" ) ,
Rock = ( int ) p_row. Field< Int32> ( "d_rock" ) ,
Slot = ( int ) p_row. Field< Int32> ( "d_slot" )
} ;
}
}
// 获取点位信息
var v_info = sqlServerAccess. GetMonitorValues( item. Field< string> ( "d_id" ) ) ;
if ( v_info != null & & v_info. AsEnumerable( ) . Count( ) > 0 )
{
List< MonitorValueModel> vList = ( from q in v_info. AsEnumerable( )
select new MonitorValueModel
{
ValueName = q. Field< string> ( "tag_name" ) ,
Address = q. Field< string> ( "address" ) ,
DataType = q. Field< string> ( "data_type" ) ,
Unit = q. Field< string> ( "unit" )
} ) . ToList( ) ;
deviceModel. MonitorValueList = new System. Collections. ObjectModel. ObservableCollection< MonitorValueModel> ( vList) ;
}
deviceModels. Add( deviceModel) ;
}
return deviceModels;
}
}