HeatChanged.cs 3.17 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Misc;

namespace FLY.FeedbackRenZiJia.Server
{
    /// <summary>
    /// 记录加热变化
    /// 给加热 附加 时间 与 加热序号
    /// 只有2个对外接口, SetHeats, GetHeats 
    /// </summary>
    public class HeatChanged : INotifyPropertyChanged
    {
        private int channelcnt = 44;
        /// <summary>
        /// 总是有第1个记录
        /// </summary>
        public RList<ITEM> mItem;
        public class ITEM
        {
            public DateTime Time;//修改的时间
            public int No;//加热序号!!! 
            public int[] Heats;//加热

        }
29 30

        public DateTime Last { get; set; } = DateTime.MinValue;
潘栩锋's avatar
潘栩锋 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112


        /// <summary>
        /// 根据加热,判断是否改变了
        /// </summary>
        /// <param name="heats"></param>
        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;
        }
        /// <summary>
        /// 判断两个数组是否完全一样
        /// </summary>
        /// <param name="heats1"></param>
        /// <param name="heats2"></param>
        /// <returns></returns>
        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;
        }
        /// <summary>
        /// 获取时间点前的加热策略,  
        /// </summary>
        /// <param name="dt">时间点</param>
        /// <returns></returns>
        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<ITEM>(30);
            Add(new int[channelcnt], DateTime.Now);
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
113

潘栩锋's avatar
潘栩锋 committed
114 115 116
        #endregion
    }
}