namespace GDNXFD.Alert.Config.ViewModel
{
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using GDNXFD.Alert.Config.Model;
using GDNXFD.Alert.Config.Resources.Strings;
using GDNXFD.Alert.Config.Services.Navigation;
using GDNXFD.Data;
using GDNXFD.Alert.Interpreter;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Base;
using System.ComponentModel;
using Data.Repositories;
using System.Windows.Controls;
using Validations;
using System.Text;
///
/// MainWindow ViewModel
///
public class RuleFormViewModel : VMBase
{
#region 初始化
private readonly INavigationService navService;
private FormMode fMode = FormMode.Create;
private AlertRule oriAlertRule;
public RuleFormViewModel(INavigationService navService)
{
this.navService = navService;
SubscribeCommands();
}
public void InitializeData(AlertRule aRule, FormMode formMode)
{
Messenger.Default.Send(new LoadingMessage(true));
try
{
IsIdEditable = true;
IsFormEditable = true;
isDirty = false;
if (CategoryList == null)
{
var lstCategory = DataCache.Instance.GetDataDictByCategory("custom");
CategoryList = new ObservableCollection(lstCategory);
}
if (LevelList == null)
{
var lstLevel = DataCache.Instance.GetDataDictByCategory("AlertLevel");
LevelList = new ObservableCollection(lstLevel);
}
this.fMode = formMode;
AlertRuleIDValidationRule.Enabled = fMode == FormMode.Create ? true : false;
if (fMode == FormMode.Create)
{
FormTitle = StringProvider.GetString("NewRuleTitle");
}
else if (fMode == FormMode.Update)
{
FormTitle = StringProvider.GetString("EditRuleTitle");
IsIdEditable = false;
IsFormEditable = true;
}
else
{
FormTitle = StringProvider.GetString("ViewRuleTitle");
IsFormEditable = false;
IsIdEditable = false;
}
AlertRule = aRule;
this.AlertRule.PropertyChanged += RuleFormViewModel_PropertyChanged;
oriAlertRule = new AlertRule();
oriAlertRule.Category = aRule.Category;
oriAlertRule.Expression = aRule.Expression;
oriAlertRule.Tag = aRule.Tag;
if (SelectedItemsStation != null)
SelectedItemsStation.Clear();
if (SelectedItemsModel != null)
SelectedItemsModel.Clear();
if (SelectedItemsWindturbine != null)
SelectedItemsWindturbine.Clear();
if (SelectedItemsProject != null)
SelectedItemsProject.Clear();
if (SelectedItemsLine != null)
SelectedItemsLine.Clear();
InitStation();
InitEquipmentModel();
InitWindturbine();
InitLine();
InitProject();
CategorySelectionChangedCommandExecute(null);
}
catch (Exception ex)
{
CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError + ex.Message + ex.StackTrace, Visibility.Collapsed);
Messenger.Default.Send(message);
}
finally
{
Messenger.Default.Send(new LoadingMessage(false));
}
}
///
/// 初始化风场数据
///
public void InitStation()
{
if (ItemsStation == null || ItemsStation.Count == 0)
{
ItemsStation = DataCache.Instance.DictStation;
}
if (SelectedItemsStation == null)
{
SelectedItemsStation = new Dictionary();
}
if (SelectedItemsStation.Count == 0)
{
if (String.IsNullOrWhiteSpace(alertRule.Station))
{
foreach (var kv in ItemsStation)
{
SelectedItemsStation.Add(kv.Key, kv.Value);
}
}
else
{
string[] arr = alertRule.Station.Split(',');
foreach (var kv in DataCache.Instance.WindPowerStation)
{
if (arr.Contains(kv.Id))
SelectedItemsStation.Add(kv.Name, kv);
}
}
}
}
///
/// 初始化风机类型数据
///
public void InitEquipmentModel()
{
Dictionary dictModel = new Dictionary();
Dictionary dictSelectedModel = new Dictionary();
if (SelectedItemsStation != null && SelectedItemsStation.Count > 0)
{
IList lstModels = new List();
foreach(var kv in SelectedItemsStation)
{
var v = kv.Value as WindPowerStation;
if (v != null)
{
string[] arr = v.Models.Split('/');
foreach(string s in arr)
{
if (!string.IsNullOrWhiteSpace(s))
{
lstModels.Add(s.Trim());
}
}
}
}
string[] arrModelId = null;
if (fMode != FormMode.Create && !string.IsNullOrWhiteSpace(alertRule.ModelId))
arrModelId = alertRule.ModelId.Split(',');
foreach(var kv in DataCache.Instance.EquipmentModel)
{
if (lstModels.Contains(kv.Id))
{
dictModel.Add(kv.Id, kv);
if (arrModelId != null)
{
if (arrModelId.Contains(kv.Id))
dictSelectedModel.Add(kv.Id, kv);
}
else
dictSelectedModel.Add(kv.Id, kv);
}
}
}
ItemsModel = dictModel;
SelectedItemsModel = dictSelectedModel;
}
///
/// 初始化风机数据
///
public void InitWindturbine()
{
Dictionary dictWindturbine = new Dictionary();
Dictionary dictSelectedWindturbine = new Dictionary();
string[] arrId = null;
if (fMode != FormMode.Create && !string.IsNullOrWhiteSpace(alertRule.Windturbine))
arrId = alertRule.Windturbine.Split(',');
var lstStation = GetSelectedStationIds();
var lstModel = GetSelectedModelIds();
foreach (var kv in DataCache.Instance.WindTurbinies)
{
if (lstStation.Contains(kv.WindPowerStationId) &&
lstModel.Contains(kv.ModelId))
{
dictWindturbine.Add(kv.Name, kv);
if (arrId != null)
{
if (arrId.Contains(kv.Id))
dictSelectedWindturbine.Add(kv.Name, kv);
}
else
dictSelectedWindturbine.Add(kv.Name, kv);
}
}
ItemsWindturbine = dictWindturbine;
SelectedItemsWindturbine = dictSelectedWindturbine;
}
///
/// 初始化线路
///
public void InitLine()
{
if (ItemsLine == null || ItemsLine.Count == 0)
{
ItemsLine = DataCache.Instance.DictLine;
}
if (SelectedItemsLine == null)
{
SelectedItemsLine = new Dictionary();
}
if (SelectedItemsLine.Count == 0)
{
if (String.IsNullOrWhiteSpace(alertRule.Line))
{
foreach (var kv in ItemsLine)
{
SelectedItemsLine.Add(kv.Key, kv.Value);
}
}
else
{
string[] arr = alertRule.Line.Split(',');
foreach (var kv in DataCache.Instance.Lines)
{
if (arr.Contains(kv.Id))
SelectedItemsLine.Add(kv.Name, kv);
}
}
}
}
///
/// 初始化工程
///
public void InitProject()
{
if (ItemsProject == null || ItemsProject.Count == 0)
{
ItemsProject = DataCache.Instance.DictProject;
}
if (SelectedItemsProject == null)
{
SelectedItemsProject = new Dictionary();
}
if (SelectedItemsProject.Count == 0)
{
if (String.IsNullOrWhiteSpace(alertRule.Project))
{
foreach (var kv in ItemsProject)
{
SelectedItemsProject.Add(kv.Key, kv.Value);
}
}
else
{
string[] arr = alertRule.Project.Split(',');
foreach (var kv in DataCache.Instance.Projects)
{
if (arr.Contains(kv.Id))
SelectedItemsProject.Add(kv.Name, kv);
}
}
}
}
private bool isDirty;
void RuleFormViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
isDirty = true;
}
private void SubscribeCommands()
{
saveCommand = new RelayCommand(SaveCommandExecute);
cancelCommand = new RelayCommand(CancelCommandExecute);
checkExpressionCommand = new RelayCommand(CheckExpressionCommandExecute);
showExpressionEditorCommand = new RelayCommand(ShowExpressionEditorCommandExecute);
//equipmentSelectionChangedCommand = new RelayCommand(EquipmentSelectionChangedCommandExecute);
categorySelectionChangedCommand = new RelayCommand(CategorySelectionChangedCommandExecute);
stationSelectionChangedCommand = new RelayCommand(StationSelectionChangedCommandExecute);
modelSelectionChangedCommand = new RelayCommand(ModelSelectionChangedCommandExecute);
}
private string formTitle;
public string FormTitle
{
get { return formTitle; }
set
{
formTitle = value;
RaisePropertyChanged(() => FormTitle);
}
}
private bool isIdEditable;
public bool IsIdEditable
{
get { return isIdEditable; }
set
{
isIdEditable = value;
RaisePropertyChanged(() => IsIdEditable);
}
}
private bool isFormEditable;
public bool IsFormEditable
{
get { return isFormEditable; }
set
{
isFormEditable = value;
RaisePropertyChanged(() => IsFormEditable);
}
}
#endregion
#region 规则实体
private AlertRule alertRule;
public AlertRule AlertRule
{
get { return this.alertRule; }
set
{
this.alertRule = value;
RaisePropertyChanged(() => AlertRule);
RaisePropertyChanged(() => SelectedAlertLevel);
RaisePropertyChanged(() => SelectedAlertCategory);
RaisePropertyChanged(() => AlertRuleDisabled);
}
}
private bool alertRuleDisabled;
public bool AlertRuleDisabled
{
get
{
if (alertRule != null)
return !alertRule.Enabled;
return true;
}
set
{
alertRuleDisabled = value;
AlertRule.Enabled = !value;
}
}
private bool alertRuleEnabled;
public bool AlertRuleEnabled
{
get
{
if (alertRule != null)
return alertRule.Enabled;
return true;
}
set
{
alertRuleEnabled = value;
if (alertRule != null)
alertRule.Enabled = value;
}
}
public DictItem SelectedAlertLevel
{
get
{
if (this.alertRule != null && levelList != null)
return levelList.Where(a => a.Code == this.alertRule.Rank).FirstOrDefault();
else
return null;
}
set
{
if (this.alertRule != null && value != null)
{
this.alertRule.Rank = value.Code;
RaisePropertyChanged(() => AlertRule);
RaisePropertyChanged(() => SelectedAlertLevel);
}
}
}
private ObservableCollection levelList;
public ObservableCollection LevelList
{
get { return levelList; }
set
{
levelList = value;
RaisePropertyChanged(() => LevelList);
}
}
public DictItem SelectedAlertCategory
{
get
{
if (this.alertRule != null && categoryList != null)
return categoryList.Where(a => a.Code == this.alertRule.Category).FirstOrDefault();
else
return null;
}
set
{
if (this.alertRule != null && value != null)
{
this.alertRule.Category = value.Code;
RaisePropertyChanged(() => AlertRule);
RaisePropertyChanged(() => SelectedAlertCategory);
}
}
}
private ObservableCollection categoryList;
public ObservableCollection CategoryList
{
get { return categoryList; }
set
{
categoryList = value;
RaisePropertyChanged(() => CategoryList);
}
}
#endregion
#region 保存或取消
private RelayCommand saveCommand;
private RelayCommand cancelCommand;
public ICommand SaveCommand
{
get { return saveCommand; }
}
public ICommand CancelCommand
{
get { return cancelCommand; }
}
private bool ValidateForm()
{
if (String.IsNullOrWhiteSpace(alertRule.Id) ||
String.IsNullOrWhiteSpace(alertRule.Name) ||
String.IsNullOrWhiteSpace(alertRule.Expression) )
return false;
char[] arr = alertRule.Id.ToCharArray();
if (arr.Length < 5 || !IsLetter(arr[0]))
{
MessageBox.Show(StringProvider.GetString("CodeError"));
return false;
}
if (SelectedAlertLevel == null)
{
MessageBox.Show(StringProvider.GetString("AlertLevelNotEmpty"));
return false;
}
//else
// alertRule.Rank = SelectedAlertLevel.Code;
if (SelectedAlertCategory == null)
{
MessageBox.Show(StringProvider.GetString("AlertCategoryNotEmpty"));
return false;
}
//else
// alertRule.Category = SelectedAlertCategory.Code;
switch (SelectedAlertCategory.Code)
{
case "1": //风机
if (SelectedItemsStation == null || SelectedItemsStation.Count == 0)
{
MessageBox.Show(StringProvider.GetString("StationNotEmpty"));
return false;
}
else if (SelectedItemsModel == null || SelectedItemsModel.Count == 0)
{
MessageBox.Show(StringProvider.GetString("ModelNotEmpty"));
return false;
}
else if (SelectedItemsWindturbine == null || SelectedItemsWindturbine.Count == 0 )
{
MessageBox.Show(StringProvider.GetString("WindturbineNotEmpty"));
return false;
}
else
{
alertRule.Station = "";
alertRule.ModelId = "";
alertRule.Windturbine = "";
alertRule.Project = "";
alertRule.Line = "";
alertRule.Range = "";
foreach (var v in SelectedItemsStation.Values)
{
WindPowerStation w = v as WindPowerStation;
if (w != null)
{
alertRule.Station += w.Id;
alertRule.Station += ",";
}
}
foreach (var v in SelectedItemsModel.Values)
{
EquipmentModel w = v as EquipmentModel;
if (w != null)
{
alertRule.ModelId += w.Id;
alertRule.ModelId += ",";
}
}
foreach (var v in SelectedItemsWindturbine.Values)
{
WindTurbine w = v as WindTurbine;
if (w!= null)
{
alertRule.Windturbine += w.Id;
alertRule.Windturbine += ",";
alertRule.Range += w.Name;
alertRule.Range += ",";
}
}
}
break;
case "2": //风场
if (SelectedItemsStation == null || SelectedItemsStation.Count == 0)
{
MessageBox.Show(StringProvider.GetString("StationNotEmpty"));
return false;
}
else
{
alertRule.Station = "";
alertRule.ModelId = "";
alertRule.Windturbine = "";
alertRule.Project = "";
alertRule.Line = "";
alertRule.Range = "";
foreach (var v in SelectedItemsStation.Values)
{
WindPowerStation w = v as WindPowerStation;
if (w != null)
{
alertRule.Station += w.Id;
alertRule.Station += ",";
alertRule.Range += w.Name;
alertRule.Range += ",";
}
}
}
break;
case "3": //工程
if (SelectedItemsProject == null || SelectedItemsProject.Count == 0)
{
MessageBox.Show(StringProvider.GetString("ProjectNotEmpty"));
return false;
}
else
{
alertRule.Station = "";
alertRule.ModelId = "";
alertRule.Windturbine = "";
alertRule.Project = "";
alertRule.Line = "";
alertRule.Range = "";
foreach (var v in SelectedItemsProject.Values)
{
Project w = v as Project;
if (w != null)
{
alertRule.Project += w.Id;
alertRule.Project += ",";
alertRule.Range += w.Name;
alertRule.Range += ",";
}
}
}
break;
case "4": //线路
if (SelectedItemsLine == null || SelectedItemsLine.Count == 0)
{
MessageBox.Show(StringProvider.GetString("LineNotEmpty"));
return false;
}
else
{
alertRule.Station = "";
alertRule.ModelId = "";
alertRule.Windturbine = "";
alertRule.Project = "";
alertRule.Line = "";
alertRule.Range = "";
foreach (var v in SelectedItemsLine.Values)
{
Line w = v as Line;
if (w != null)
{
alertRule.Line += w.Id;
alertRule.Line += ",";
alertRule.Range += w.Name;
alertRule.Range += ",";
}
}
}
break;
case "5": //电气
if (SelectedItemsStation == null || SelectedItemsStation.Count == 0)
{
MessageBox.Show(StringProvider.GetString("StationNotEmpty"));
return false;
}
else
{
alertRule.Station = "";
alertRule.ModelId = "";
alertRule.Windturbine = "";
alertRule.Project = "";
alertRule.Line = "";
alertRule.Range = "";
foreach (var v in SelectedItemsStation.Values)
{
WindPowerStation w = v as WindPowerStation;
if (w != null)
{
alertRule.Station += w.Id;
alertRule.Station += ",";
alertRule.Range += w.Name;
alertRule.Range += ",";
}
}
}
break;
}
return true;
}
private void SaveCommandExecute()
{
try
{
if (!ValidateForm())
return;
ExpressionCompilerResults results = ExpressionCompiler.CompileExpression(alertRule);
if (results.HasErrors)
{
MessageBox.Show(StringProvider.GetString("ExpressionError") + results.ErrorText);
return;
}
Messenger.Default.Send(new LoadingMessage(true));
if (alertRule.Range.Length > 1500)
alertRule.Range = alertRule.Range.Substring(0, 1497);
AlertRuleRepository.SaveAlertRule(alertRule);
navService.NavigateToRuleList();
}
catch (Exception ex)
{
Messenger.Default.Send(new LoadingMessage(false));
CustomDialogMessage message = new CustomDialogMessage(() => { }, StringResources.UnexpectedError, Visibility.Collapsed);
Messenger.Default.Send(message);
}
}
private void CancelCommandExecute()
{
if (isDirty && fMode != FormMode.ReadOnly)
{
CustomDialogMessage message = new CustomDialogMessage(() =>
{
navService.NavigateToRuleList();
}, String.Format(Resources.Strings.StringResources.ConfirmCancelMessage), Visibility.Visible);
Messenger.Default.Send(message);
}
else
navService.NavigateToRuleList();
}
#endregion
#region 表达式设计器
#region AI测点
private IList allAI;
private ObservableCollection aiList;
public ObservableCollection AiList
{
get
{
if (aiList == null && this.alertRule != null)// && equipmentList != null)
{
var lst = WindTurbineRepository.GetTestPointAIsByModelId(alertRule.ModelId);
allAI = Convert2TestingPointBase(lst);
aiList = new ObservableCollection(allAI);
}
return aiList;
}
set
{
aiList = value;
RaisePropertyChanged(() => AiList);
}
}
private string aiFilter;
public string AIFilter
{
get { return this.aiFilter; }
set
{
this.aiFilter = value;
SearchAIs();
RaisePropertyChanged(() => AIFilter);
}
}
private void SearchAIs()
{
if (allAI == null) return;
var aaa = allAI.Where(s => (s.UniformCode.Contains(aiFilter) || s.Name.Contains(aiFilter))).ToList();
AiList = new ObservableCollection(allAI.Where(s => (s.UniformCode.Contains(aiFilter) || s.Name.Contains(aiFilter))).ToList());
}
#endregion
#region DI测点
private IList allDI;
private ObservableCollection diList;
public ObservableCollection DiList
{
get
{
if (diList == null && this.alertRule != null)// && equipmentList != null)
{
var lst = WindTurbineRepository.GetTestPointDIsByModelId(alertRule.ModelId);
allDI = Convert2TestingPointBase(lst);
diList = new ObservableCollection(allDI);
}
return diList;
}
set
{
diList = value;
RaisePropertyChanged(() => DiList);
}
}
private string diFilter;
public string DIFilter
{
get { return this.diFilter; }
set
{
this.diFilter = value;
SearchDIs();
RaisePropertyChanged(() => DIFilter);
}
}
private void SearchDIs()
{
if (allDI == null) return;
DiList = new ObservableCollection(allDI.Where(s => (s.UniformCode.Contains(diFilter) || s.Name.Contains(diFilter))).ToList());
}
#endregion
#region 函数
private ObservableCollection methodList;
public ObservableCollection MethodList
{
get
{
if (methodList == null)
methodList = AllMethodes;
return methodList;
}
set
{
methodList = value;
RaisePropertyChanged(() => MethodList);
}
}
private ObservableCollection allMethodes;
private ObservableCollection AllMethodes
{
get
{
if (allMethodes == null)
allMethodes = LoadMethodList();
return allMethodes;
}
}
private ObservableCollection LoadMethodList()
{
ObservableCollection lst = new ObservableCollection();
lst.Add("RiseExceed");
lst.Add("MR");
lst.Add("MAR");
lst.Add("Sustain");
lst.Add("LastUpdateTime");
lst.Add("abs");
lst.Add("acos");
lst.Add("asin");
lst.Add("atan");
lst.Add("atan2");
lst.Add("ceiling");
lst.Add("cos");
lst.Add("cosh");
lst.Add("exp");
lst.Add("floor");
lst.Add("log");
lst.Add("log10");
lst.Add("max");
lst.Add("min");
lst.Add("pow");
lst.Add("round");
lst.Add("sign");
lst.Add("sin");
lst.Add("sinh");
lst.Add("sqrt");
lst.Add("tan");
lst.Add("tanh");
lst.Add("E");
lst.Add("PI");
return lst;
}
private string methodFilter;
public string MethodFilter
{
get { return this.methodFilter; }
set
{
this.methodFilter = value;
SearchMethodes();
RaisePropertyChanged(() => MethodFilter);
}
}
private void SearchMethodes()
{
if (AllMethodes == null) return;
MethodList = new ObservableCollection(AllMethodes.Where(s => s.Contains(methodFilter)).ToList());
}
#endregion
#region 验证和显示控制
private bool showExpressionEditor = true;
public bool ShowExpressionEditor
{
get
{
return showExpressionEditor;
}
set
{
showExpressionEditor = value;
RaisePropertyChanged(() => ShowExpressionEditor);
}
}
private RelayCommand showExpressionEditorCommand;
public ICommand ShowExpressionEditorCommand
{
get { return showExpressionEditorCommand; }
}
private void ShowExpressionEditorCommandExecute()
{
ShowExpressionEditor = !showExpressionEditor;
}
private RelayCommand checkExpressionCommand;
public ICommand CheckExpressionCommand
{
get { return checkExpressionCommand; }
}
private void CheckExpressionCommandExecute()
{
if (string.IsNullOrWhiteSpace(alertRule.Expression))
return;
try
{
ExpressionCompilerResults results = ExpressionCompiler.CompileExpression(alertRule);
if (results.HasErrors)
MessageBox.Show(results.ErrorText);
else
MessageBox.Show(StringProvider.GetString("CheckSuccess"));
}
catch (ExpressionException eex)
{
MessageBox.Show(eex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#endregion
#region 范围选择
#region 风电场
private Dictionary _itemsStation;
private Dictionary _selectedItemsStation;
public Dictionary ItemsStation
{
get
{
return _itemsStation;
}
set
{
_itemsStation = value;
RaisePropertyChanged(() => ItemsStation);
}
}
public Dictionary SelectedItemsStation
{
get
{
return _selectedItemsStation;
}
set
{
_selectedItemsStation = value;
RaisePropertyChanged(() => SelectedItemsStation);
}
}
private RelayCommand stationSelectionChangedCommand;
public ICommand StationSelectionChangedCommand
{
get { return stationSelectionChangedCommand; }
}
private void StationSelectionChangedCommandExecute(EventArgs e)
{
if (SelectedAlertCategory.Code == "5")
{
UpdateElectricalTestingPoint();
}
else if (SelectedAlertCategory.Code=="1")
{
//更新设备类型列表
InitEquipmentModel();
//更新风机列表
InitWindturbine();
//更新AI、DI测点
UpdateWindturbineTestingPoint();
}
}
private IList GetSelectedStationIds()
{
IList selectedStationIds = new List();
if (SelectedItemsStation != null && SelectedItemsStation.Count > 0)
{
foreach (var v in SelectedItemsStation.Values)
{
WindPowerStation w = v as WindPowerStation;
if (w != null)
selectedStationIds.Add(w.Id);
}
}
return selectedStationIds;
}
#endregion
#region 风机类型
private Dictionary _itemsModel;
private Dictionary _selectedItemsModel;
public Dictionary ItemsModel
{
get
{
return _itemsModel;
}
set
{
_itemsModel = value;
RaisePropertyChanged(() => ItemsModel);
}
}
public Dictionary SelectedItemsModel
{
get
{
return _selectedItemsModel;
}
set
{
_selectedItemsModel = value;
RaisePropertyChanged(() => SelectedItemsModel);
}
}
private IList GetSelectedModelIds()
{
IList selectedModelIds = new List();
if (SelectedItemsModel != null && SelectedItemsModel.Count > 0)
{
foreach (var v in SelectedItemsModel.Values)
{
EquipmentModel w = v as EquipmentModel;
if (w != null)
selectedModelIds.Add(w.Id);
}
}
return selectedModelIds;
}
private RelayCommand modelSelectionChangedCommand;
public ICommand ModelSelectionChangedCommand
{
get { return modelSelectionChangedCommand; }
}
private void ModelSelectionChangedCommandExecute(EventArgs e)
{
//更新风机列表
InitWindturbine();
//更新AI、DI测点
UpdateWindturbineTestingPoint();
}
#endregion
#region 风机
private Dictionary _itemsWindturbine;
private Dictionary _selectedItemsWindturbine;
public Dictionary ItemsWindturbine
{
get
{
return _itemsWindturbine;
}
set
{
_itemsWindturbine = value;
RaisePropertyChanged(() => ItemsWindturbine);
}
}
public Dictionary SelectedItemsWindturbine
{
get
{
return _selectedItemsWindturbine;
}
set
{
_selectedItemsWindturbine = value;
RaisePropertyChanged(() => SelectedItemsWindturbine);
}
}
#endregion
#region 线路
private Dictionary _itemsLine;
private Dictionary _selectedItemsLine;
public Dictionary ItemsLine
{
get
{
return _itemsLine;
}
set
{
_itemsLine = value;
RaisePropertyChanged(() => ItemsLine);
}
}
public Dictionary SelectedItemsLine
{
get
{
return _selectedItemsLine;
}
set
{
_selectedItemsLine = value;
RaisePropertyChanged(() => SelectedItemsLine);
}
}
#endregion
#region 工程
private Dictionary _itemsProject;
private Dictionary _selectedItemsProject;
public Dictionary ItemsProject
{
get
{
return _itemsProject;
}
set
{
_itemsProject = value;
RaisePropertyChanged(() => ItemsProject);
}
}
public Dictionary SelectedItemsProject
{
get
{
return _selectedItemsProject;
}
set
{
_selectedItemsProject = value;
RaisePropertyChanged(() => SelectedItemsProject);
}
}
#endregion
#region 根据报警类型显示范围选择项
private bool showStation = true;
public bool ShowStation
{
get
{
return showStation;
}
set
{
showStation = value;
RaisePropertyChanged(() => ShowStation);
}
}
private bool showModel = true;
public bool ShowModel
{
get
{
return showModel;
}
set
{
showModel = value;
RaisePropertyChanged(() => ShowModel);
}
}
private bool showWindturbine = true;
public bool ShowWindturbine
{
get
{
return showWindturbine;
}
set
{
showWindturbine = value;
RaisePropertyChanged(() => ShowWindturbine);
}
}
private bool showProject = false;
public bool ShowProject
{
get
{
return showProject;
}
set
{
showProject = value;
RaisePropertyChanged(() => ShowProject);
}
}
private bool showLine = false;
public bool ShowLine
{
get
{
return showLine;
}
set
{
showLine = value;
RaisePropertyChanged(() => ShowLine);
}
}
#endregion
#region 报警类型变动
private RelayCommand categorySelectionChangedCommand;
public ICommand CategorySelectionChangedCommand
{
get { return categorySelectionChangedCommand; }
}
private void CategorySelectionChangedCommandExecute(SelectionChangedEventArgs e)
{
if (SelectedAlertCategory == null) return;
switch (SelectedAlertCategory.Code)
{
case "1": //风机
ShowWindturbine = true;
ShowStation = true;
ShowModel = true;
ShowProject = false;
ShowLine = false;
UpdateWindturbineTestingPoint();
break;
case "2": //风场
ShowStation = true;
ShowWindturbine = false;
ShowModel = false;
ShowProject = false;
ShowLine = false;
UpdateLevelTypeTestingPoint("windpowerstation");
break;
case "3": //工程
ShowProject = true;
ShowStation = false;
ShowWindturbine = false;
ShowModel = false;
ShowLine = false;
UpdateLevelTypeTestingPoint("project");
break;
case "4": //线路
ShowStation = false;
ShowWindturbine = false;
ShowModel = false;
ShowProject = false;
ShowLine = true;
UpdateLevelTypeTestingPoint("line");
break;
case "5": //电气
ShowStation = true;
ShowWindturbine = false;
ShowModel = false;
ShowProject = false;
ShowLine = false;
UpdateElectricalTestingPoint();
break;
}
}
#endregion
#endregion
#region 测点列表更新
///
/// 更新风机测点
///
private void UpdateWindturbineTestingPoint()
{
AIFilter = "";
DIFilter = "";
if(oriAlertRule != null && AlertRule.Category == oriAlertRule.Category)
{
AlertRule.Expression = oriAlertRule.Expression;
AlertRule.Tag = oriAlertRule.Tag;
}
else
{
AlertRule.Expression = "";
AlertRule.Tag = "";
}
var lstModels = GetSelectedModelIds();
if (lstModels == null || lstModels.Count == 0)
{
allAI = null;
allDI = null;
AiList = null;
DiList = null;
}
else
{
var lstA = WindTurbineRepository.GetTestPointAIsByModels(lstModels);
var lstD = WindTurbineRepository.GetTestPointDIsByModels(lstModels);
allAI = Convert2TestingPointBase(lstA);
allDI = Convert2TestingPointBase(lstD);
AiList = new ObservableCollection(allAI);
DiList = new ObservableCollection(allDI);
}
}
///
/// 更新电气测点
///
private void UpdateElectricalTestingPoint()
{
AIFilter = "";
DIFilter = "";
if (oriAlertRule != null && AlertRule.Category == oriAlertRule.Category)
{
AlertRule.Expression = oriAlertRule.Expression;
AlertRule.Tag = oriAlertRule.Tag;
}
else
{
AlertRule.Expression = "";
AlertRule.Tag = "";
}
var lstStations = GetSelectedStationIds();
if (lstStations == null || lstStations.Count == 0)
{
allAI = null;
allDI = null;
AiList = null;
DiList = null;
}
else
{
var lstA = WindPowerStationRepository.GetElecTestPointAIsByStations(lstStations);
var lstD = WindPowerStationRepository.GetElecTestPointDIsByStations(lstStations);
allAI = Convert2TestingPointBase(lstA);
allDI = Convert2TestingPointBase(lstD);
AiList = new ObservableCollection(allAI);
DiList = new ObservableCollection(allDI);
}
}
///
/// 更新风场、工程、线路 测点
///
private void UpdateLevelTypeTestingPoint(string levelType)
{
AIFilter = "";
DIFilter = "";
if (oriAlertRule != null && AlertRule.Category == oriAlertRule.Category)
{
AlertRule.Expression = oriAlertRule.Expression;
AlertRule.Tag = oriAlertRule.Tag;
}
else
{
AlertRule.Expression = "";
AlertRule.Tag = "";
}
IList lstAI = DataCache.Instance.GetTestingPointByLevelType(levelType);
allAI = Convert2TestingPointBase(lstAI);
AiList = new ObservableCollection(lstAI);
DiList = null;
}
private IList Convert2TestingPointBase(IList lst)
{
IList ret = new List();
if (lst != null)
{
foreach (var t in lst)
{
ret.Add((TestingPointBase)t);
}
}
return ret;
}
private IList Convert2TestingPointBase(IList lst)
{
IList ret = new List();
if (lst != null)
{
foreach (var t in lst)
{
ret.Add((TestingPointBase)t);
}
}
return ret;
}
private IList Convert2TestingPointBase(IList lst)
{
IList ret = new List();
if (lst != null)
{
foreach (var t in lst)
{
ret.Add((TestingPointBase)t);
}
}
return ret;
}
private IList Convert2TestingPointBase(IList lst)
{
IList ret = new List();
if (lst != null)
{
foreach (var t in lst)
{
ret.Add((TestingPointBase)t);
}
}
return ret;
}
private IList Convert2TestingPointBase(IList lst)
{
IList ret = new List();
if (lst != null)
{
foreach (var t in lst)
{
ret.Add((TestingPointBase)t);
}
}
return ret;
}
private bool IsLetter(char c)
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
return true;
return false;
}
#endregion
}
}