using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Misc;
namespace FLY.FeedbackRenZiJia.Server
{
///
/// 记录加热变化
/// 给加热 附加 时间 与 加热序号
/// 只有2个对外接口, SetHeats, GetHeats
///
public class HeatChanged : INotifyPropertyChanged
{
private int channelcnt = 44;
///
/// 总是有第1个记录
///
public RList- mItem;
public class ITEM
{
public DateTime Time;//修改的时间
public int No;//加热序号!!!
public int[] Heats;//加热
}
public DateTime Last { get; set; } = DateTime.MinValue;
///
/// 根据加热,判断是否改变了
///
///
public bool Add(int[] heats)
{
if ((mItem.Count() == 0) || (!IsSame(mItem.Last().Heats, heats)))
{
return Add(heats, DateTime.Now);
}
else
{
return false;
}
}
public bool Add(int[] heats, DateTime time)
{
ITEM item = new ITEM();
item.Heats = heats.Clone() as int[];
item.Time = time;
mItem.RAdd(item);
item.No = mItem.GetLastNo();
Last = item.Time;
return true;
}
///
/// 判断两个数组是否完全一样
///
///
///
///
bool IsSame(int[] heats1, int[] heats2)
{
int channelcnt = heats1.Count();
for (int i = 0; i < channelcnt; i++)
{
if (heats1[i] != heats2[i])
return false;
}
return true;
}
///
/// 获取时间点前的加热策略,
///
/// 时间点
///
public ITEM Get(DateTime dt)
{
for (int i = 0; i < mItem.Count(); i++)
{
int idx = mItem.Count() - i - 1;
if (mItem[idx].Time < dt)
{
return mItem[idx];
}
}
return mItem.First();
}
public ITEM Get()
{
return mItem.Last();
}
public void Init(int channelcnt)
{
if (this.channelcnt != channelcnt)
{
this.channelcnt = channelcnt;
mItem.Clear();
//放入第1幅数据,空数据!!!!
Add(new int[channelcnt], DateTime.Now);
}
}
public HeatChanged()
{
mItem = new RList
- (30);
Add(new int[channelcnt], DateTime.Now);
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}