using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;

namespace FLY.Thick.Base.Server.OBJProxy
{
    public class ScanWarning_OBJProxy : FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        #endregion
        IScanWarningService mScanWarning;
        int reasonlist_newcnt = 0;
        public ScanWarning_OBJProxy(int objsys_idx, IScanWarningService scanWarning):base(objsys_idx)
        {
            ID = SCANWARNING_OBJ_INTERFACE.ID;
            mScanWarning = scanWarning;
            mScanWarning.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mScanWarning_PropertyChanged);
        }

   
        void mScanWarning_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "AlarmLine") ||
                (e.PropertyName == "AlarmCnt") ||
                (e.PropertyName == "Enable") ||
                (e.PropertyName == "Mix")
                )
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, SCANWARNING_OBJ_INTERFACE.GET_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, SCANWARNING_OBJ_INTERFACE.PUSH_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_PARAMS);
            }

        }
        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case SCANWARNING_OBJ_INTERFACE.GET_PARAMS:
                    {
                        SCANWARNING_OBJ_INTERFACE.Pack_Params p = new SCANWARNING_OBJ_INTERFACE.Pack_Params()
                        {
                            alarmline =  mScanWarning.AlarmLine,
                            alarmcnt = mScanWarning.AlarmCnt,
                            enable = mScanWarning.Enable,
                            mix = mScanWarning.Mix
                        };

                        infodata = p.ToBytes();
                    } break;
                default:

                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case SCANWARNING_OBJ_INTERFACE.SET_PARAMS:
                    {
                        SCANWARNING_OBJ_INTERFACE.Pack_Params p = new SCANWARNING_OBJ_INTERFACE.Pack_Params();
                        if (!p.TryParse(infodata))
                            return;
                        mScanWarning.AlarmLine = p.alarmline;
                        mScanWarning.AlarmCnt = p.alarmcnt;
                        mScanWarning.Enable = p.enable;
                        mScanWarning.Mix = p.mix;
                        mScanWarning.Apply();
                    } break;
            }
        }
    }
}
