refactor: 将Framework库和RT、UI放在同一个解决方案中。
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Aitex.Core.RT.Event;
|
||||
|
||||
namespace Aitex.Core.UI.View.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用于UI端显示的报警信息对象。
|
||||
/// </summary>
|
||||
public class AlarmItem
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警发生的时间。
|
||||
/// </summary>
|
||||
public string OccuringTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警描述。
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回报警类型文本。
|
||||
/// <remarks>
|
||||
/// 可用的报警类型请参考<see cref="EventType"/>枚举。
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
public string LevelString =>
|
||||
Level == EventLevel.Alarm ? "Alarm" : (Level == EventLevel.Information ? "Info" : "Warning");
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警等级。
|
||||
/// </summary>
|
||||
public EventLevel Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警编号。
|
||||
/// </summary>
|
||||
public int EventId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警名称。
|
||||
/// </summary>
|
||||
public string EventEnum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警的详细解释。
|
||||
/// </summary>
|
||||
public string Explaination { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警的处理方法描述。
|
||||
/// </summary>
|
||||
public string Solution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回报警来源。
|
||||
/// </summary>
|
||||
public string Source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回当前报警是否已被应答。
|
||||
/// </summary>
|
||||
public bool IsAcknowledged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回当前报警被应答的时间。
|
||||
/// </summary>
|
||||
public DateTime AcknowledgeTime { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 判断当前报警信息是否和指定的报警信息相同。
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsEqualTo(AlarmItem item)
|
||||
{
|
||||
return item.OccuringTime == OccuringTime &&
|
||||
item.Description == Description &&
|
||||
item.Level == Level;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Aitex.Core.UI.View.Common
|
||||
{
|
||||
public class TreeViewFileItem : TreeViewItem
|
||||
{
|
||||
public TreeViewFileItem(string fileName)
|
||||
{
|
||||
FileName = fileName;
|
||||
|
||||
Image image = new Image();
|
||||
image.Stretch = Stretch.Fill;
|
||||
image.Source = new BitmapImage(new Uri(@"/MECF.Framework.Common;component/Resources/RecipeFile.png", UriKind.Relative));
|
||||
|
||||
TextBlock txtBNode = new TextBlock();
|
||||
int lastIndex = FileName.LastIndexOf('\\');
|
||||
if (lastIndex >= 0)
|
||||
txtBNode.Text = fileName.Substring(lastIndex + 1);
|
||||
else
|
||||
txtBNode.Text = fileName;
|
||||
|
||||
StackPanel panel = new StackPanel();
|
||||
panel.Children.Add(image);
|
||||
panel.Children.Add(txtBNode);
|
||||
|
||||
panel.Orientation = Orientation.Horizontal;
|
||||
this.Header = panel;
|
||||
}
|
||||
|
||||
public string FileName
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class TreeViewFolderItem : TreeViewItem
|
||||
{
|
||||
public string FolderName
|
||||
{
|
||||
set;
|
||||
get;
|
||||
}
|
||||
|
||||
public TreeViewFolderItem(string folderName)
|
||||
{
|
||||
FolderName = folderName;
|
||||
|
||||
Image image = new Image();
|
||||
image.Stretch = Stretch.Fill;
|
||||
image.Source = new BitmapImage(new Uri(@"/MECF.Framework.Common;component/Resources/RecipeFolder.png", UriKind.Relative));
|
||||
|
||||
TextBlock txtBNode = new TextBlock();
|
||||
txtBNode.Text = folderName;
|
||||
|
||||
StackPanel panel = new StackPanel();
|
||||
panel.Children.Add(image);
|
||||
panel.Children.Add(txtBNode);
|
||||
|
||||
panel.Orientation = Orientation.Horizontal;
|
||||
this.Header = panel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<UserControl x:Class="Aitex.Core.UI.View.Common.MonitorView"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="325" d:DesignWidth="1200">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="7*" />
|
||||
<ColumnDefinition Width="5*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="{DynamicResource GlobalLableMonitorViewEventList}" Margin="5,0,12,5">
|
||||
<DataGrid AutoGenerateColumns="False" Margin="5" Name="eventList"
|
||||
Background="White" ItemsSource="{Binding AlarmEvents, Mode=OneWay}"
|
||||
SelectionMode="Single" SelectionUnit="FullRow"
|
||||
FontFamily="Arial,SimSun" FontSize="13"
|
||||
SelectionChanged="listView1_SelectionChanged" BorderThickness="0.1"
|
||||
CanUserDeleteRows="True" CanUserAddRows="True" IsReadOnly="True" RowHeight="25">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Header="Type" Width="90" CanUserSort="True" SortMemberPath="Type">
|
||||
<DataGridTemplateColumn.HeaderTemplate >
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{DynamicResource GlobalLableMonitorViewType}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Label Content="{Binding Type}" Background="{Binding TextColor}" FontSize="12"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTextColumn Header="Time" Width="80" CanUserSort="True" IsReadOnly="True" Binding="{Binding OccuringTime,Mode=OneWay}">
|
||||
<DataGridTextColumn.HeaderTemplate >
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{DynamicResource GlobalLableMonitorViewTime}" />
|
||||
</DataTemplate>
|
||||
</DataGridTextColumn.HeaderTemplate>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Description" Width="*" CanUserSort="True" IsReadOnly="True" Binding="{Binding Description,Mode=OneWay}">
|
||||
<DataGridTextColumn.HeaderTemplate >
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{DynamicResource GlobalLableMonitorViewDescription}" />
|
||||
</DataTemplate>
|
||||
</DataGridTextColumn.HeaderTemplate>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="1" Header="{DynamicResource GlobalLableMonitorViewDetail}" Margin="0,0,5,5">
|
||||
<TextBlock x:Name="AnalysisText" FontSize="14" Margin="5" Background="White" TextWrapping="Wrap" Style="{x:Null}"/>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Aitex.Core.UI.View.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MonitorView.xaml
|
||||
/// </summary>
|
||||
public partial class MonitorView : UserControl
|
||||
{
|
||||
public MonitorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
IsVisibleChanged += new DependencyPropertyChangedEventHandler(MainWindow_IsVisibleChanged);
|
||||
}
|
||||
|
||||
void MainWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alarm, Warning selected item changed
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count == 1)
|
||||
{
|
||||
var item = e.AddedItems[0] as AlarmItem;
|
||||
AnalysisText.Text = string.Format("Event Type:{0}\r\n\r\nEvent Name:{1}\r\n\r\nTime:{2}\r\n\r\nDescription:{3}",
|
||||
item.LevelString,
|
||||
item.EventEnum,
|
||||
//item.EventId, Event Number:{ 2}\r\n\r\n
|
||||
item.OccuringTime,
|
||||
item.Description);
|
||||
//item.Solution);\r\n\r\nSolution:{ 5}
|
||||
}
|
||||
else
|
||||
{
|
||||
AnalysisText.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
|
||||
namespace Aitex.Core.UI.View.Common
|
||||
{
|
||||
public class MonitorViewModel : ViewModelBase
|
||||
{
|
||||
public List<AlarmItem> AlarmEvents { get; set; }
|
||||
|
||||
public void UpdateAlarmEvent(List<EventItem> evItems)
|
||||
{
|
||||
var alarmEvents = new List<AlarmItem>();
|
||||
foreach (EventItem item in evItems)
|
||||
{
|
||||
var it = new AlarmItem()
|
||||
{
|
||||
Level = item.Level,
|
||||
OccuringTime = item.OccuringTime.ToString("yyyy/MM/dd HH:mm:ss"),
|
||||
Source = item.Source,
|
||||
Description = item.Description,
|
||||
EventEnum = item.EventEnum,
|
||||
EventId = item.Id,
|
||||
Explaination = item.Explaination,
|
||||
Solution = item.Solution,
|
||||
};
|
||||
|
||||
alarmEvents.Add(it);
|
||||
}
|
||||
if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
|
||||
{
|
||||
AlarmEvents = alarmEvents;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isEqual = true;
|
||||
if (alarmEvents.Count == AlarmEvents.Count)
|
||||
{
|
||||
for (int i = 0; i < alarmEvents.Count; i++)
|
||||
{
|
||||
if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
|
||||
{
|
||||
isEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isEqual)
|
||||
AlarmEvents = alarmEvents;
|
||||
}
|
||||
|
||||
InvokePropertyChanged("AlarmEvents");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MECF.Framework.Common.DataCenter;
|
||||
|
||||
namespace MECF.Framework.UI.Core.View.Common
|
||||
{
|
||||
public class PageSCValue
|
||||
{
|
||||
protected Dictionary<string, PropertyInfo> _fieldMap = new Dictionary<string, PropertyInfo>();
|
||||
|
||||
public PageSCValue()
|
||||
{
|
||||
}
|
||||
|
||||
public List<string> GetKeys()
|
||||
{
|
||||
return _fieldMap.Keys.ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UpdateKeys(PropertyInfo[] property)
|
||||
{
|
||||
_fieldMap.Clear();
|
||||
foreach (PropertyInfo fiGroup in property)
|
||||
{
|
||||
_fieldMap[fiGroup.Name.Replace("_", ".")] = fiGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(Dictionary<string, object> result)
|
||||
{
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
foreach (KeyValuePair<string, object> item in result)
|
||||
{
|
||||
if (_fieldMap.ContainsKey(item.Key))
|
||||
{
|
||||
_fieldMap[item.Key].SetValue(this, item.Value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(string key, string value)
|
||||
{
|
||||
|
||||
if (!_fieldMap.ContainsKey(key))
|
||||
return;
|
||||
|
||||
if (_fieldMap[key].PropertyType == typeof(double))
|
||||
{
|
||||
_fieldMap[key].SetValue(this, Convert.ToDouble(value), null);
|
||||
}
|
||||
else if (_fieldMap[key].PropertyType == typeof(int))
|
||||
{
|
||||
_fieldMap[key].SetValue(this, Convert.ToInt32(value), null);
|
||||
}
|
||||
else if (_fieldMap[key].PropertyType == typeof(string))
|
||||
{
|
||||
_fieldMap[key].SetValue(this, value, null);
|
||||
|
||||
}
|
||||
else if (_fieldMap[key].PropertyType == typeof(bool))
|
||||
{
|
||||
_fieldMap[key].SetValue(this, Convert.ToBoolean(value), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<string, object> GetValue()
|
||||
{
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
foreach (var item in _fieldMap)
|
||||
{
|
||||
result[item.Key] = item.Value.GetValue(this, null);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<UserControl x:Class="Aitex.Core.UI.View.Common.ParameterView"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="1024" d:DesignWidth="768">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="290" />
|
||||
<ColumnDefinition Width="900*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TreeView Grid.Row="0" Grid.Column="0" Margin="4,4,0,0" Name="treeView1" Style="{StaticResource ConfigTreeView}" />
|
||||
<Grid Grid.Row="0" Grid.Column="1">
|
||||
<DataGrid x:Name="dataGrid1" Margin="5,30,5,0" ItemsSource="{Binding}"
|
||||
AutoGenerateColumns="False"
|
||||
BorderThickness="0.1"
|
||||
CanUserAddRows="False"
|
||||
CanUserDeleteRows="False"
|
||||
CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="True"
|
||||
CanUserResizeRows="False"
|
||||
CanUserSortColumns="False"
|
||||
SelectionMode="Single"
|
||||
SelectionUnit="FullRow"
|
||||
Background="#05000000"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
FontSize="12" MinRowHeight="20"
|
||||
VerticalAlignment="Stretch"
|
||||
FontFamily="Arial,SimSun">
|
||||
<DataGrid.RowValidationRules>
|
||||
<DataErrorValidationRule ValidationStep="UpdatedValue"/>
|
||||
</DataGrid.RowValidationRules>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="275*" Binding="{Binding EntryName}" Header="名称" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="200*" Binding="{Binding Description}" Header="描述" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="55" Binding="{Binding Type}" Header="类型" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="50" Binding="{Binding Unit}" Header="单位" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="70" Binding="{Binding RangeLowLimit}" Header="最小值" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="70" Binding="{Binding RangeUpLimit}" Header="最大值" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="70" Binding="{Binding Default}" Header="默认值" CanUserSort="False" CanUserReorder="False" IsReadOnly="True" />
|
||||
<DataGridTextColumn Width="105" Binding="{Binding Value, Mode=TwoWay}" Header="设定值" CanUserSort="False" CanUserReorder="False" IsReadOnly="False" >
|
||||
<DataGridTextColumn.EditingElementStyle>
|
||||
<Style TargetType="{x:Type TextBox}">
|
||||
<EventSetter Event="LostFocus" Handler="GridEditor_LostFocus" />
|
||||
<EventSetter Event="GotFocus" Handler="GridEditor_GotFocus" />
|
||||
</Style>
|
||||
|
||||
</DataGridTextColumn.EditingElementStyle>
|
||||
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Button Content="保存参数" Height="23" HorizontalAlignment="Right" Margin="0,4,108,0" Name="btnSaveParam" Click="btnSaveParam_Click" VerticalAlignment="Top" Width="75" FontSize="13" FontFamily="Arial,SimSun" />
|
||||
<Button Content="重新获取" Height="23" HorizontalAlignment="Right" Margin="0,4,13,0" Name="btnResetParam" Click="btnResetParam_Click" VerticalAlignment="Top" Width="75" FontSize="13" FontFamily="Arial,SimSun" />
|
||||
<Label Content="参数设置 " Height="40" HorizontalAlignment="Left" Name="labelTile" VerticalAlignment="Top" Width="525" FontSize="13" Margin="1,4,0,0" FontFamily="Arial,SimSun" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
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.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Aitex.Core.RT.Log;
|
||||
using System.Xml;
|
||||
using Aitex.Core.RT.ConfigCenter;
|
||||
using Aitex.Core.UI.View.Frame;
|
||||
|
||||
namespace Aitex.Core.UI.View.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ParameterView.xaml
|
||||
/// </summary>
|
||||
public partial class ParameterView : UserControl
|
||||
{
|
||||
bool _isLoaded;
|
||||
ParameterViewModel _vm;
|
||||
string _gridEditorOldValue;
|
||||
bool _isGridModified;
|
||||
|
||||
public ParameterView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += new RoutedEventHandler(ParameterView_Loaded);
|
||||
}
|
||||
|
||||
void ParameterView_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//set permission
|
||||
this.IsEnabled = true;
|
||||
this.Name = "Parameter";
|
||||
|
||||
Account.ViewPermission viewPermission; // chaossong@add 20160414 for permission
|
||||
if (ViewManager.LoginAccount != null)
|
||||
viewPermission = ViewManager.LoginAccount.Permission[this.Name];
|
||||
else
|
||||
viewPermission = Account.ViewPermission.FullyControl;
|
||||
|
||||
switch (viewPermission)
|
||||
{
|
||||
case Account.ViewPermission.FullyControl:
|
||||
btnResetParam.IsEnabled = true;
|
||||
btnSaveParam.IsEnabled = true;
|
||||
dataGrid1.IsEnabled = true;
|
||||
break;
|
||||
default:
|
||||
btnResetParam.IsEnabled = false;
|
||||
btnSaveParam.IsEnabled = false;
|
||||
dataGrid1.IsEnabled = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (_isLoaded)
|
||||
return;
|
||||
|
||||
_vm = DataContext as ParameterViewModel;
|
||||
if (_vm == null)
|
||||
throw new ApplicationException("系统配置页面没有设置DataContext,需要在窗口创建之前,设置初始配置数据");
|
||||
|
||||
InitTree();
|
||||
|
||||
_isLoaded = true;
|
||||
}
|
||||
|
||||
void InitTree()
|
||||
{
|
||||
treeView1.Items.Clear();
|
||||
|
||||
List<KeyValuePair<string, string>> lstSections = _vm.GetSectionList();
|
||||
foreach (KeyValuePair<string, string> item in lstSections)
|
||||
{
|
||||
var fNode = new TreeViewFolderItem(item.Key);
|
||||
|
||||
fNode.Tag = item;
|
||||
fNode.Selected += new RoutedEventHandler(sectionNode_Selected);
|
||||
|
||||
treeView1.Items.Add(fNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void sectionNode_Selected(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedNode = sender as TreeViewFolderItem;
|
||||
if (selectedNode == null)
|
||||
return;
|
||||
|
||||
if (_isGridModified)
|
||||
{
|
||||
if (MessageBox.Show("是否需要保存未存盘的参数?", "未保存", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
btnSaveParam_Click(null, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
_isGridModified = false;
|
||||
}
|
||||
}
|
||||
|
||||
KeyValuePair<string, string> keyPair = (KeyValuePair<string, string>)selectedNode.Tag;
|
||||
labelTile.Content = keyPair.Key;
|
||||
dataGrid1.Tag = keyPair.Value;
|
||||
|
||||
dataGrid1.ItemsSource = _vm.GetConfigEntries(keyPair.Value);
|
||||
}
|
||||
|
||||
private void GridEditor_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TextBox tb = (sender as TextBox);
|
||||
if (tb != null)
|
||||
_isGridModified = tb.Text != _gridEditorOldValue;
|
||||
}
|
||||
|
||||
private void GridEditor_GotFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TextBox tb = (sender as TextBox);
|
||||
if (tb != null)
|
||||
_gridEditorOldValue = tb.Text;
|
||||
}
|
||||
|
||||
private void btnSaveParam_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_isGridModified = false;
|
||||
|
||||
string reason;
|
||||
if (!VerifyInputData(out reason))
|
||||
{
|
||||
MessageBox.Show(reason, "Aitex", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
string xpath = dataGrid1.Tag as string;
|
||||
if (_vm.SaveConfigSection(xpath.Substring(xpath.IndexOf("'") + 1, xpath.LastIndexOf("'") - xpath.IndexOf("'")-1), dataGrid1.ItemsSource as List<ConfigEntry>))
|
||||
MessageBox.Show("设定值保存成功!", "Aitex", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show("设定值保存失败!", "Aitex", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
btnResetParam_Click(null, null);
|
||||
}
|
||||
|
||||
private void btnResetParam_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
dataGrid1.ItemsSource = _vm.GetConfigEntries(dataGrid1.Tag as string);
|
||||
}
|
||||
|
||||
private bool VerifyInputData(out string reason)
|
||||
{
|
||||
bool ret = true;
|
||||
dataGrid1.CancelEdit();
|
||||
var entryList = this.dataGrid1.ItemsSource.Cast<object>();
|
||||
reason = string.Empty;
|
||||
foreach (ConfigEntry entry in entryList)
|
||||
{
|
||||
try
|
||||
{
|
||||
var inputText = entry.Value;
|
||||
var typeText = entry.Type;
|
||||
var minText = entry.RangeLowLimit;
|
||||
var maxText = entry.RangeUpLimit;
|
||||
|
||||
if (string.IsNullOrEmpty(inputText))
|
||||
continue;
|
||||
|
||||
if (String.Compare(typeText, "Int32", true) == 0)
|
||||
{
|
||||
int res = 0;
|
||||
if (!int.TryParse(inputText, out res))
|
||||
throw new Exception();
|
||||
int min = Convert.ToInt32(minText);
|
||||
int max = Convert.ToInt32(maxText);
|
||||
if (res < min || res > max)
|
||||
{
|
||||
ret = false;
|
||||
reason += string.Format("{0} 输入值错误!\n", entry.Description);
|
||||
var textBlock = dataGrid1.Columns[7].GetCellContent(entry) as System.Windows.Controls.TextBlock;
|
||||
if (textBlock != null)
|
||||
textBlock.Background = Brushes.Red;
|
||||
}
|
||||
}
|
||||
else if (String.Compare(typeText, "Double", true) == 0)
|
||||
{
|
||||
double res = 0;
|
||||
if (!double.TryParse(inputText, out res))
|
||||
throw new Exception();
|
||||
double min = Convert.ToDouble(minText);
|
||||
double max = Convert.ToDouble(maxText);
|
||||
if (res < min || res > max)
|
||||
{
|
||||
ret = false;
|
||||
reason += string.Format("{0} 输入值错误!\n", entry.Description);
|
||||
var textBlock = dataGrid1.Columns[7].GetCellContent(entry) as System.Windows.Controls.TextBlock;
|
||||
if (textBlock != null)
|
||||
textBlock.Background = Brushes.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
reason += string.Format("{0} 输入值错误!\n", entry.Description);
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using Aitex.Core.RT.Log;
|
||||
using System.Xml;
|
||||
using Aitex.Core.RT.ConfigCenter;
|
||||
|
||||
namespace Aitex.Core.UI.View.Common
|
||||
{
|
||||
public class ParameterViewModel : ViewModelBase
|
||||
{
|
||||
public ParameterViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual string GetConfigXmlContent()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public virtual bool SaveConfigSection(string groupName, List<ConfigEntry> lstEntry)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//description, navigation, sectionPath
|
||||
public List<KeyValuePair<string, string>> GetSectionList()
|
||||
{
|
||||
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
|
||||
|
||||
string xmlContent = GetConfigXmlContent();
|
||||
|
||||
if (string.IsNullOrEmpty(xmlContent))
|
||||
{
|
||||
LOG.Error("没有读取到SC配置文件");
|
||||
return result;
|
||||
}
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xmlContent);
|
||||
|
||||
XmlNodeList lst = doc.SelectSingleNode("/SCData").ChildNodes;
|
||||
foreach (XmlElement node in lst)
|
||||
{
|
||||
result.Add(new KeyValuePair<string, string>(GetNodeText(node, "Description"), string.Format("/SCData/Section[@Name='{0}']", GetNodeText(node, "Name"))));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ConfigEntry> GetConfigEntries(string sectionPath)
|
||||
{
|
||||
List<ConfigEntry> result = new List<ConfigEntry>();
|
||||
|
||||
string xmlContent = GetConfigXmlContent();
|
||||
|
||||
if (string.IsNullOrEmpty(xmlContent))
|
||||
{
|
||||
LOG.Error("没有读取到SC配置文件");
|
||||
return result;
|
||||
}
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xmlContent);
|
||||
|
||||
XmlNode parentNode = doc.SelectSingleNode(sectionPath);
|
||||
|
||||
XmlNodeList lstNode = parentNode.ChildNodes;
|
||||
|
||||
foreach (XmlNode node in lstNode)
|
||||
{
|
||||
try
|
||||
{
|
||||
result.Add(new ConfigEntry()
|
||||
{
|
||||
EntryName = GetNodeText(node, "Name"),
|
||||
SectionName = GetNodeText(node, "Name"),
|
||||
Description = GetNodeText(node, "Description"),
|
||||
Type = GetNodeText(node, "Type"),
|
||||
Default = GetNodeText(node, "Default"),
|
||||
RangeLowLimit = GetNodeText(node, "RangeLowLimit"),
|
||||
RangeUpLimit = GetNodeText(node, "RangeUpLimit"),
|
||||
SystemType = GetNodeText(parentNode, "Name"),
|
||||
Unit = GetNodeText(node, "Unit"),
|
||||
Value = ((string.IsNullOrEmpty(GetNodeText(node, "Type")) || GetNodeText(node, "Type") == "Double") ?
|
||||
Math.Round(Convert.ToDouble(GetNodeText(node, "Value")), 3).ToString() : GetNodeText(node, "Value")),
|
||||
XPath = string.Format("{0}/{1}", sectionPath, node.Name),
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Error("SC配置项错误," + node.Name, ex);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string GetNodeText(XmlNode parent, string child, string defaultValue = "")
|
||||
{
|
||||
return (parent.Attributes[child] == null) ? defaultValue : parent.Attributes[child].Value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user