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 System.Net;
using System.ComponentModel;
using FLY.FeedbackRenZiJia.Client;
using FLY.OBJComponents.Client;
using FLY.OBJComponents.Common;
using System.Windows.Threading;
namespace FLY.FeedbackRenZiJia.UI.Client.UIModule
{
///
/// Page_DynArea.xaml 的交互逻辑
///
public partial class Page_DynArea : Page
{
#region 延时推送 MARKNO
const int MARKNO_UPDATEERROR = 1;
#endregion
FeedbackHeatServiceClient mFeedback;
HeatBufServiceClient mHeatBuf;
BufferWindow mWindow;
DispatcherTimer timer_error;
DynAreaViewModelParams props = new DynAreaViewModelParams();
public Page_DynArea()
{
InitializeComponent();
}
public void Init(int id)
{
//获取设备
SysParam sysparam = SysParam.Current;
//把 FeedbackHeat 共享。 1个程序,只能有一个 FeedbackHeat
mFeedback = TDGage.Current.mFeedback;
mHeatBuf = TDGage.Current.mHeatBuf;
view_stability.DataContext = sysparam;
grid_feedback.DataContext = mFeedback;
grid_heatbuf.DataContext = mHeatBuf;
//创建窗口观察 报警原因列表
mWindow = TDGage.Current.mWarningReasonWindow;
//报警原因轮流显示
timer_error = new DispatcherTimer();
timer_error.Interval = TimeSpan.FromSeconds(3);
timer_error.Tick += (s, e) =>
{
reason_list_index--;
if (reason_list_index < 0)
reason_list_index = mWindow.Record.Count();
updateError();
};
mWindow.Record.CollectionChanged += Record_CollectionChanged;
grid_error.DataContext = props;
mFeedback.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "IsConnected")
{
updateError();
}
};
updateError();
}
void Dispose()
{
//mFeedbackHeatService.Dispose();
}
private void Record_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
FObjBase.PollModule.Current.Poll_JustOnce(
new FObjBase.PollModule.PollHandler(delegate ()
{
reason_list_index = mWindow.Record.Count() - 1;
updateError();
}), this, MARKNO_UPDATEERROR);
}
void updateError()
{
if (!mFeedback.IsConnected)
{
props.Error = "风环服务器连接断开";
props.IsError = true;
reason_list_index = -1;
timer_error.Stop();
}
else if (mWindow.Record.Count > 0)
{
if (reason_list_index >= mWindow.Record.Count)
reason_list_index = mWindow.Record.Count - 1;
else if (reason_list_index < 0)
reason_list_index = 0;
props.Error = mWindow.Record[reason_list_index].Description;
props.IsError = true;
timer_error.Start();
}
else
{
props.IsError = false;
props.Error = "";
reason_list_index = -1;
timer_error.Stop();
}
}
private int reason_list_index = -1;
private void Button_Click(object sender, RoutedEventArgs e)
{
//if (props.IsError)
{
NavigationService ns = Application.Current.Properties["NavigationService"] as NavigationService;
if (ns != null)
{
Page_ErrorTable p = new Page_ErrorTable();
ns.Navigate(p);
}
}
}
}
public class DynAreaViewModelParams : INotifyPropertyChanged
{
///
/// 有异常
///
public bool IsError { get; set; }
///
/// 异常消息
///
public string Error { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public class UIModule_DynAreaFB : FLY.UI.Module.IUIModule
{
///
/// 控件标题
/// 它的值取决于culture
///
public string Title
{
get
{
return "自动风环状态";
}
}
///
/// 控件
/// 创建时,需要给它唯一ID,让加载自己的数据
///
///
///
public FrameworkElement GetComponent(int id)
{
Page_DynArea graph = new Page_DynArea();
graph.Init(id);
return graph;
}
///
/// 控件缩略图,用于编辑界面时,大致看看
/// 创建时,需要给它唯一ID,让加载自己的数据
///
///
///
public FrameworkElement GetThumbnail(int id)
{
return new System.Windows.Controls.Grid();
}
///
/// 给出全部控件ID, 控件自行删除没有的参数
///
///
public void MatchParam(int[] IDs)
{
}
}
}