using NEIntelligentControl2.Models.Matrix;
using NEIntelligentControl2.Models.Pages;
using NEIntelligentControl2.Models.Station;
using NEIntelligentControl2.Models.Windturbine;
using NEIntelligentControl2.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
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;
namespace NEIntelligentControl2.Views.Matrix
{
///
/// 场站模块
///
public partial class WindStationBlock : UserControl, IStationInfo
{
// --------------依赖属性----------------
public static DependencyProperty CountTotalProperty = DependencyProperty.Register("CountTotal", typeof(int), typeof(WindStationBlock));
public static DependencyProperty CountConnectProperty = DependencyProperty.Register("CountConnect", typeof(int), typeof(WindStationBlock));
public static DependencyProperty CountStandbyProperty = DependencyProperty.Register("CountStandby", typeof(int), typeof(WindStationBlock));
public static DependencyProperty CountStoppedProperty = DependencyProperty.Register("CountStopped", typeof(int), typeof(WindStationBlock));
public static DependencyProperty CountMaintainProperty = DependencyProperty.Register("CountMaintain", typeof(int), typeof(WindStationBlock));
public static DependencyProperty CountFaultProperty = DependencyProperty.Register("CountFault", typeof(int), typeof(WindStationBlock));
public static DependencyProperty CountOfflineProperty = DependencyProperty.Register("CountOffline", typeof(int), typeof(WindStationBlock));
///
/// 总接入台数
///
public int CountTotal { get => (int)GetValue(CountTotalProperty); set => SetValue(CountTotalProperty, value); }
///
/// 并网台数
///
public int CountConnect { get => (int)GetValue(CountConnectProperty); set => SetValue(CountConnectProperty, value); }
///
/// 待机台数
///
public int CountStandby { get => (int)GetValue(CountStandbyProperty); set => SetValue(CountStandbyProperty, value); }
///
/// 停机台数
///
public int CountStopped { get => (int)GetValue(CountStoppedProperty); set => SetValue(CountStoppedProperty, value); }
///
/// 维护台数
///
public int CountMaintain { get => (int)GetValue(CountMaintainProperty); set => SetValue(CountMaintainProperty, value); }
///
/// 故障台数
///
public int CountFault { get => (int)GetValue(CountFaultProperty); set => SetValue(CountFaultProperty, value); }
///
/// 离线台数
///
public int CountOffline { get => (int)GetValue(CountOfflineProperty); set => SetValue(CountOfflineProperty, value); }
///
/// 场站信息
///
public StationInfo StationInfo { get; set; }
///
/// 矩阵块
///
private List _Blocks;
private Service.Windturbine.CacheManager _CacheManager;
public WindStationBlock(Service.Windturbine.CacheManager cm)
{
InitializeComponent();
_CacheManager = cm;
}
///
/// 更新数据
///
public void UpdateData(object obj)
{
var datas = obj as Dictionary;
if (datas == null) return;
var ls = datas.Values.Where(wi => wi.StationId == StationInfo.Id).ToList();
if (_Blocks == null)
{
InitBlocks(ls);
}
CountTotal = ls.Count;
CountStopped = ls.Where(s => (int)s.Status == 0).ToList().Count;
CountConnect = ls.Where(s => (int)s.Status == 4).ToList().Count;
CountStandby = ls.Where(s => (int)s.Status == 2 || s.Status == 3 || s.Status == 1).ToList().Count;
CountMaintain = ls.Where(s => (int)s.Status == 6).ToList().Count;
CountFault = ls.Where(s => (int)s.Status == 5).ToList().Count;
CountOffline = ls.Where(s => (int)s.Status == 7).ToList().Count;
if (_Blocks == null) return;
var lockInfo = _CacheManager.CustomLockInfos;
foreach (var v in _Blocks)
{
if (!datas.ContainsKey(v.WindturbineId)) continue;
if (lockInfo.ContainsKey(v.WindturbineId))
{
v.CustomLockInfo = lockInfo[v.WindturbineId];
}
else
{
v.CustomLockInfo = null;
}
v.Update(datas[v.WindturbineId]);
}
}
private void InitBlocks(List ls)
{
_Blocks = new List();
ls.Sort((x, y) => x.ID - y.ID);
Dispatcher.Invoke(() =>
{
foreach (var v in ls)
{
WindBlockSmall bs = new WindBlockSmall(v) { Title =v.ID.ToString(), WindturbineId = v.WindturbineId };
_Blocks.Add(bs);
_OPUGMain.Add(bs);
}
});
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
string tag = ((Control)sender).Tag as string;
switch (tag)
{
case "Start": // 启动
case "Stop": // 停机
case "Reset": // 复位
case "Maintain": // 维护
case "UnMaintain": // 取消维护
SendControl(tag);
break;
case "compar": // 参数对比
Compar();
break;
default: return;
}
}
private void MenuItem_Click_Lock(object sender, RoutedEventArgs e)
{
// lockValue
var type = ((Control)sender).Tag as string;
if (type == null) return;
bool b1 = Enum.TryParse(type, out HungType hungType);
if (!b1) return;
var bks = GetSelectedItems();
if (bks.Count <= 0) return;
string customValue = null;
if(hungType == HungType.CustomerLock)
{
customValue = CustomValueWindow.ShowWindow();
if (customValue == null) return;
}
var w = App.ServiceProvider.GetService(typeof(Windows.ConfirmWindow)) as Windows.ConfirmWindow;
var ls = bks.Select(item => item.Value.WindturbineInfo).ToList();
bool b = w.Show(hungType, ls, customValue);
if (!b) return;
//确认操作后,将所有选中的风机修改为非选中状态
foreach (var item in bks)
{
item.Value.IsSelected = false;
}
}
///
/// 参数对比
///
private void Compar()
{
var vs = GetSelectedItems();
foreach (var item in vs)
{
item.Value.IsSelected = false;
}
var ws = vs.Select(x=>x.Value.WindturbineInfo).ToList();
Windows.ParameterComparisonWindow.ShowWindow(ws);
}
///
/// 发送控制命令
///
public void SendControl(string tag)
{
OperateStyle os = (OperateStyle)Enum.Parse(typeof(OperateStyle), tag);
var bks = GetSelectedItems();
if (bks.Count <= 0) return;
var w = App.ServiceProvider.GetService(typeof(Windows.ConfirmWindow)) as Windows.ConfirmWindow;
var ls = bks.Select(item => item.Value.WindturbineInfo).ToList();
bool b = w.Show(os, ls);
if (!b) return;
//确认操作后,将所有选中的风机修改为非选中状态
foreach (var item in bks)
{
item.Value.IsSelected = false;
}
}
///
/// 获取控制数据
///
private WindBlockInfo GetSendData(WindBlockSmall item)
{
WindBlockInfo data = new WindBlockInfo();
data.OperatedTime = item.OperatedTime;
data.ID = item.WindturbineInfo.WindturbineId;
data.WindturbineId = item.WindturbineInfo.WindturbineId;
data.Status = item.WindturbineInfo.Status;
data.ModelId = item.WindturbineInfo.ModelId;
data.StationId = item.WindturbineInfo.StationId;
data.ProjectId = item.WindturbineInfo.ProjectId;
return data;
}
///
/// 获取选中的矩阵
///
private Dictionary GetSelectedItems()
{
Dictionary bsw = new Dictionary();
foreach (var v in _Blocks)
{
if (v.IsSelected && v.WindturbineInfo != null && !bsw.ContainsKey(v.WindturbineInfo.WindturbineId))
{
bsw.Add(v.WindturbineInfo.WindturbineId, v);
}
}
return bsw;
}
}
}