1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507 |
- 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;
- /// <summary>
- /// MainWindow ViewModel
- /// </summary>
- 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<DictItem>(lstCategory);
- }
- if (LevelList == null)
- {
- var lstLevel = DataCache.Instance.GetDataDictByCategory("AlertLevel");
- LevelList = new ObservableCollection<DictItem>(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<CustomDialogMessage>(message);
- }
- finally
- {
- Messenger.Default.Send(new LoadingMessage(false));
- }
- }
- /// <summary>
- /// 初始化风场数据
- /// </summary>
- public void InitStation()
- {
- if (ItemsStation == null || ItemsStation.Count == 0)
- {
- ItemsStation = DataCache.Instance.DictStation;
- }
- if (SelectedItemsStation == null)
- {
- SelectedItemsStation = new Dictionary<string, object>();
- }
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 初始化风机类型数据
- /// </summary>
- public void InitEquipmentModel()
- {
- Dictionary<string, object> dictModel = new Dictionary<string, object>();
- Dictionary<string, object> dictSelectedModel = new Dictionary<string, object>();
- if (SelectedItemsStation != null && SelectedItemsStation.Count > 0)
- {
- IList<string> lstModels = new List<string>();
- 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;
- }
- /// <summary>
- /// 初始化风机数据
- /// </summary>
- public void InitWindturbine()
- {
- Dictionary<string, object> dictWindturbine = new Dictionary<string, object>();
- Dictionary<string, object> dictSelectedWindturbine = new Dictionary<string, object>();
- 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;
- }
- /// <summary>
- /// 初始化线路
- /// </summary>
- public void InitLine()
- {
- if (ItemsLine == null || ItemsLine.Count == 0)
- {
- ItemsLine = DataCache.Instance.DictLine;
- }
- if (SelectedItemsLine == null)
- {
- SelectedItemsLine = new Dictionary<string, object>();
- }
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 初始化工程
- /// </summary>
- public void InitProject()
- {
- if (ItemsProject == null || ItemsProject.Count == 0)
- {
- ItemsProject = DataCache.Instance.DictProject;
- }
- if (SelectedItemsProject == null)
- {
- SelectedItemsProject = new Dictionary<string, object>();
- }
- 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<SelectionChangedEventArgs>(EquipmentSelectionChangedCommandExecute);
- categorySelectionChangedCommand = new RelayCommand<SelectionChangedEventArgs>(CategorySelectionChangedCommandExecute);
- stationSelectionChangedCommand = new RelayCommand<EventArgs>(StationSelectionChangedCommandExecute);
- modelSelectionChangedCommand = new RelayCommand<EventArgs>(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<DictItem> levelList;
- public ObservableCollection<DictItem> 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<DictItem> categoryList;
- public ObservableCollection<DictItem> 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<CustomDialogMessage>(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<CustomDialogMessage>(message);
- }
- else
- navService.NavigateToRuleList();
- }
- #endregion
- #region 表达式设计器
- #region AI测点
- private IList<TestingPointBase> allAI;
- private ObservableCollection<TestingPointBase> aiList;
- public ObservableCollection<TestingPointBase> AiList
- {
- get
- {
- if (aiList == null && this.alertRule != null)// && equipmentList != null)
- {
- var lst = WindTurbineRepository.GetTestPointAIsByModelId(alertRule.ModelId);
- allAI = Convert2TestingPointBase(lst);
- aiList = new ObservableCollection<TestingPointBase>(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<TestingPointBase>(allAI.Where(s => (s.UniformCode.Contains(aiFilter) || s.Name.Contains(aiFilter))).ToList());
- }
- #endregion
- #region DI测点
- private IList<TestingPointBase> allDI;
- private ObservableCollection<TestingPointBase> diList;
- public ObservableCollection<TestingPointBase> DiList
- {
- get
- {
- if (diList == null && this.alertRule != null)// && equipmentList != null)
- {
- var lst = WindTurbineRepository.GetTestPointDIsByModelId(alertRule.ModelId);
- allDI = Convert2TestingPointBase(lst);
- diList = new ObservableCollection<TestingPointBase>(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<TestingPointBase>(allDI.Where(s => (s.UniformCode.Contains(diFilter) || s.Name.Contains(diFilter))).ToList());
- }
- #endregion
- #region 函数
- private ObservableCollection<string> methodList;
- public ObservableCollection<string> MethodList
- {
- get
- {
- if (methodList == null)
- methodList = AllMethodes;
- return methodList;
- }
- set
- {
- methodList = value;
- RaisePropertyChanged(() => MethodList);
- }
- }
- private ObservableCollection<string> allMethodes;
- private ObservableCollection<string> AllMethodes
- {
- get
- {
- if (allMethodes == null)
- allMethodes = LoadMethodList();
- return allMethodes;
- }
- }
- private ObservableCollection<string> LoadMethodList()
- {
- ObservableCollection<string> lst = new ObservableCollection<string>();
- 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<string>(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<string, object> _itemsStation;
- private Dictionary<string, object> _selectedItemsStation;
- public Dictionary<string, object> ItemsStation
- {
- get
- {
- return _itemsStation;
- }
- set
- {
- _itemsStation = value;
- RaisePropertyChanged(() => ItemsStation);
- }
- }
- public Dictionary<string, object> SelectedItemsStation
- {
- get
- {
- return _selectedItemsStation;
- }
- set
- {
- _selectedItemsStation = value;
- RaisePropertyChanged(() => SelectedItemsStation);
- }
- }
- private RelayCommand<EventArgs> 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<string> GetSelectedStationIds()
- {
- IList<string> selectedStationIds = new List<string>();
- 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<string, object> _itemsModel;
- private Dictionary<string, object> _selectedItemsModel;
- public Dictionary<string, object> ItemsModel
- {
- get
- {
- return _itemsModel;
- }
- set
- {
- _itemsModel = value;
- RaisePropertyChanged(() => ItemsModel);
- }
- }
- public Dictionary<string, object> SelectedItemsModel
- {
- get
- {
- return _selectedItemsModel;
- }
- set
- {
- _selectedItemsModel = value;
- RaisePropertyChanged(() => SelectedItemsModel);
- }
- }
- private IList<string> GetSelectedModelIds()
- {
- IList<string> selectedModelIds = new List<string>();
- 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<EventArgs> modelSelectionChangedCommand;
- public ICommand ModelSelectionChangedCommand
- {
- get { return modelSelectionChangedCommand; }
- }
- private void ModelSelectionChangedCommandExecute(EventArgs e)
- {
- //更新风机列表
- InitWindturbine();
- //更新AI、DI测点
- UpdateWindturbineTestingPoint();
- }
- #endregion
- #region 风机
- private Dictionary<string, object> _itemsWindturbine;
- private Dictionary<string, object> _selectedItemsWindturbine;
- public Dictionary<string, object> ItemsWindturbine
- {
- get
- {
- return _itemsWindturbine;
- }
- set
- {
- _itemsWindturbine = value;
- RaisePropertyChanged(() => ItemsWindturbine);
- }
- }
- public Dictionary<string, object> SelectedItemsWindturbine
- {
- get
- {
- return _selectedItemsWindturbine;
- }
- set
- {
- _selectedItemsWindturbine = value;
- RaisePropertyChanged(() => SelectedItemsWindturbine);
- }
- }
- #endregion
- #region 线路
- private Dictionary<string, object> _itemsLine;
- private Dictionary<string, object> _selectedItemsLine;
- public Dictionary<string, object> ItemsLine
- {
- get
- {
- return _itemsLine;
- }
- set
- {
- _itemsLine = value;
- RaisePropertyChanged(() => ItemsLine);
- }
- }
- public Dictionary<string, object> SelectedItemsLine
- {
- get
- {
- return _selectedItemsLine;
- }
- set
- {
- _selectedItemsLine = value;
- RaisePropertyChanged(() => SelectedItemsLine);
- }
- }
- #endregion
- #region 工程
- private Dictionary<string, object> _itemsProject;
- private Dictionary<string, object> _selectedItemsProject;
- public Dictionary<string, object> ItemsProject
- {
- get
- {
- return _itemsProject;
- }
- set
- {
- _itemsProject = value;
- RaisePropertyChanged(() => ItemsProject);
- }
- }
- public Dictionary<string, object> 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<SelectionChangedEventArgs> 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 测点列表更新
- /// <summary>
- /// 更新风机测点
- /// </summary>
- 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<TestingPointBase>(allAI);
- DiList = new ObservableCollection<TestingPointBase>(allDI);
- }
- }
- /// <summary>
- /// 更新电气测点
- /// </summary>
- 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<TestingPointBase>(allAI);
- DiList = new ObservableCollection<TestingPointBase>(allDI);
- }
- }
- /// <summary>
- /// 更新风场、工程、线路 测点
- /// </summary>
- 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<LevelTypeTestingPoint> lstAI = DataCache.Instance.GetTestingPointByLevelType(levelType);
- allAI = Convert2TestingPointBase(lstAI);
- AiList = new ObservableCollection<TestingPointBase>(lstAI);
- DiList = null;
- }
- private IList<TestingPointBase> Convert2TestingPointBase(IList<TestingPointAI> lst)
- {
- IList<TestingPointBase> ret = new List<TestingPointBase>();
- if (lst != null)
- {
- foreach (var t in lst)
- {
- ret.Add((TestingPointBase)t);
- }
- }
- return ret;
- }
- private IList<TestingPointBase> Convert2TestingPointBase(IList<TestingPointDI> lst)
- {
- IList<TestingPointBase> ret = new List<TestingPointBase>();
- if (lst != null)
- {
- foreach (var t in lst)
- {
- ret.Add((TestingPointBase)t);
- }
- }
- return ret;
- }
- private IList<TestingPointBase> Convert2TestingPointBase(IList<LevelTypeTestingPoint> lst)
- {
- IList<TestingPointBase> ret = new List<TestingPointBase>();
- if (lst != null)
- {
- foreach (var t in lst)
- {
- ret.Add((TestingPointBase)t);
- }
- }
- return ret;
- }
- private IList<TestingPointBase> Convert2TestingPointBase(IList<ElectricalTestingPointAI> lst)
- {
- IList<TestingPointBase> ret = new List<TestingPointBase>();
- if (lst != null)
- {
- foreach (var t in lst)
- {
- ret.Add((TestingPointBase)t);
- }
- }
- return ret;
- }
- private IList<TestingPointBase> Convert2TestingPointBase(IList<ElectricalTestingPointDI> lst)
- {
- IList<TestingPointBase> ret = new List<TestingPointBase>();
- 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
- }
- }
|