ARSElection.cs 6.75 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeneralLib;

namespace SunVoteARSPPT
{
    public class ARSElection : IResponse
    {
        /// <summary>
        /// 数字评分类
        /// </summary>
        public SunVote.Election Elec = null;

        /// <summary>
        /// 构造函数
        /// </summary>
        public ARSElection()
        {
            Elec = new SunVote.Election();
            Elec.KeyStatus += Elec_KeyStatus;

            Elec.KeyStatusSN += Elec_KeyStatusSN;

            //PVS事件。杨斌 2015-03-17
            FrmPvsServer.GetFrmPvs().OnKeyVote += myPVS_KeyVote;

            TagSet = new TagSet();
        }

        void Elec_KeyStatusSN(string BaseTag, string KeySN, int CommitOK, string KeyValue)
        {
            //KeyValue = ConvertOper.DoNumberString(KeyValue);

            ResponsePar ObjResponseValue = new ResponsePar();
            ObjResponseValue.BaseTag = BaseTag;
            ObjResponseValue.KeyID = KeySN;
            ObjResponseValue.KeyValue = KeyValue;
            ObjResponseValue.Speed = 0;
            if (ResponseEventHander != null)
                ResponseEventHander(ObjResponseValue);
        }

        void Elec_KeyStatus(string BaseTag, int KeyID, int CommitOK, string KeyValue)
        {
            Elec_KeyStatusSN(BaseTag, KeyID.ToString(), CommitOK, KeyValue);
        }

        void myPVS_KeyVote(int ID, int iMode, string sInfo)
        {
            string KeyValue = ConvertOper.DoNumberString(sInfo);

            ResponsePar ObjResponseValue = new ResponsePar();
            //ObjResponseValue.BaseTag = BaseTag;
            ObjResponseValue.KeyID = ID.ToString();
            ObjResponseValue.KeyValue = KeyValue;
            ObjResponseValue.Speed = 0;

            if (ResponseEventHander != null)
                ResponseEventHander(ObjResponseValue);
        }

        #region IResponse 成员

        public event ResponseEventHander ResponseEventHander;

        /// <summary>
        /// 修改:杨斌 2012-06-27
        /// </summary>
        public void Start()
        {
            int iModifyMode = (TagSet.GetValue(TagKey.KeypadPara_ModifyMode).ToInt == 0 ? 1 : 0);

            if (GlobalInfo.GetSdkType() == 0)
            {
                Elec.BaseConnection = BaseConnection;

                //修改模式 0:不允许修改,1:允许修改
                Elec.ModifyMode = iModifyMode;

                //保密模式
                Elec.SecrecyMode = TagSet.GetValue(TagKey.KeypadPara_SecrecyMode).ToInt;
                //UI模式,数字选举
                Elec.UIMode = 4;

                if (ResponseType == ResponseType.Poll)
                {
                    //候选人个数                    
                    //Elec.NumberOptions = GlobalInfo.response.CandidateInfoList.Count;
                    //if ((Elec.NumberOptions < 1) || (Elec.NumberOptions > 200))
                        Elec.NumberOptions = 200;
                    //可选个数
                    Elec.Selects = TagSet.GetValue(TagKey.Poll_EffectiveVotes).ToInt;
                }
                //启动模式
                Elec.StartMode = 1;
                Elec.Start();
            }
            else if (GlobalInfo.GetSdkType() == 1)
            {
                string lowRange = "";
                string highRange = "";
                double min = 0;
                double max = 0;
                int dec = 0;

                int pvsVoteMode = 0;
                string pvsVoteSetting = "";
                if (ResponseType == ResponseType.Score)
                {
                    lowRange = TagSet.GetValue(TagKey.Score_LowRange).Value;
                    highRange = TagSet.GetValue(TagKey.Score_HighRange).Value;

                    //最小值
                    min = (lowRange.Trim() == "") ? 0 : (Convert.ToInt32(lowRange));
                    //最大值
                    max = (highRange.Trim() == "") ? 0 : (Convert.ToInt32(highRange));

                    dec = TagSet.GetValue(TagKey.Score_DecimalFormat).ToInt;

                    int aMax = 255;
                    if (min > aMax)
                        min = aMax;

                    if (max > aMax)
                        max = aMax;

                    if (dec > 9)
                        dec = 9;

                    pvsVoteMode = 6;
                    pvsVoteSetting = 1 + "," + min + "," + max + "," + dec;
                }
                if (ResponseType == ResponseType.Poll)
                {
                    min = 0;
                    max = 0;
                    dec = 0;

                    pvsVoteMode = 6;
                    pvsVoteSetting = 1 + "," + min + "," + max + "," + dec;
                }
                if (ResponseType == ResponseType.Number)
                {
                    lowRange = TagSet.GetValue(TagKey.Number_LowRange).Value;
                    highRange = TagSet.GetValue(TagKey.Number_HighRange).Value;

                    //最小值
                    min = (lowRange.Trim() == "") ? 0 : (Convert.ToInt32(lowRange));
                    //最大值
                    max = (highRange.Trim() == "") ? 0 : (Convert.ToInt32(highRange));

                    min = 0;
                    max = 0;
                    dec = 9;

                    dec = TagSet.GetValue(TagKey.Number_DecimalFormat).ToInt;

                    pvsVoteMode = 6;
                    pvsVoteSetting = 1 + "," + min + "," + max + "," + dec;
                }
                if (ResponseType == ResponseType.SignIn)
                {
                    min = 0;
                    max = 0;
                    dec = 0;

                    pvsVoteMode = 6;
                    pvsVoteSetting = 1 + "," + min + "," + max + "," + dec;
                }

                ////杨斌 2015-05-13
                //FrmPvsServer.GetFrmPvs().VoteStart(15, "0");
                //FrmPvsServer.GetFrmPvs().VoteStop();

                FrmPvsServer.GetFrmPvs().VoteStart(pvsVoteMode, pvsVoteSetting, iModifyMode);
            }
        }

        public void Stop()
        {
            if (GlobalInfo.GetSdkType() == 0)
            {
                Elec.Stop();
            }
            else if (GlobalInfo.GetSdkType() == 1)
            {
                //for (int i = 1; i <= 3; i++)
                {
                    FrmPvsServer.GetFrmPvs().VoteStop();
                }
            }
        }
        /// <summary>
        /// 基站连接类
        /// </summary>
        public SunVote.BaseConnection BaseConnection { get; set; }
        /// <summary>
        /// 幻灯片Tag值
        /// </summary>
        public TagSet TagSet { get; set; }
        /// <summary>
        /// 反馈类型
        /// </summary>
        public ResponseType ResponseType { get; set; }

        #endregion
    }
}