ARSChoise.cs 21.1 KB
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 29 30 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
using GeneralLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SunVoteARSPPT
{

    public class ARSChoise : IResponse
    {
        /// <summary>
        /// 选择类
        /// </summary>
        public SunVote.Choices Choise = null;
        public SunVote.Sequence Sequence = null;//杨斌 2012-06-27 多选保留顺序
        public SunVote.Vote Vote = null;//杨斌 2013-11-12
        public SunVote.TrueFalse TrueFalse = null;//杨斌 2014-10-20

        /// <summary>
        /// 硬件测试类
        /// </summary>
        private SunVote.HardwareTest hardwareTest = null;

        //杨斌 2012-06-27
        private bool IsStartChoise = false;
        private bool IsStartSequence = false;
        //杨斌 2013-11-13
        private bool IsStartVote = false;
        //杨斌 2014-10-20
        private bool IsStartTF = false;
        /// <summary>
        /// 键盘模拟测试。杨斌 2015-03-30
        /// </summary>
        private bool IsStartTest = false;

        /// <summary>
        /// 构造函数
        /// </summary>
        public ARSChoise()
        {
            Choise = new SunVote.Choices();
            Sequence = new SunVote.Sequence();//杨斌 2012-06-27
            TrueFalse = new SunVote.TrueFalse();//杨斌 2014-10-20
            //事件绑定
            Choise.KeyStatus += new SunVote.IChoicesEvents_KeyStatusEventHandler(Choise_KeyStatus);
            Sequence.KeyStatus += new SunVote.ISequenceEvents_KeyStatusEventHandler(Choise_KeyStatus);//杨斌 2012-06-27
            TrueFalse.KeyStatus += new SunVote.ITrueFalseEvents_KeyStatusEventHandler(TrueFalse_KeyStatus);//杨斌 2014-10-20

            //杨斌 2013-11-12
            Vote = new SunVote.Vote();
            Vote.KeyStatus += new SunVote.IVoteEvents_KeyStatusEventHandler(Vote_KeyStatus);

            //杨斌 2015-01-09
            Choise.KeyStatusSN += new SunVote.IChoicesEvents_KeyStatusSNEventHandler(Choise_KeyStatusSN);
            Sequence.KeyStatusSN += new SunVote.ISequenceEvents_KeyStatusSNEventHandler(Sequence_KeyStatusSN);
            TrueFalse.KeyStatusSN += new SunVote.ITrueFalseEvents_KeyStatusSNEventHandler(TrueFalse_KeyStatusSN);
            Vote.KeyStatusSN += new SunVote.IVoteEvents_KeyStatusSNEventHandler(Vote_KeyStatusSN);

            //硬件测试类
            hardwareTest = new SunVote.HardwareTest();
            //键盘测试绑定事件
            hardwareTest.KeyMonitorStatus += hardwareTest_KeyMonitorStatus;


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

            TagSet = new TagSet();
        }

        void hardwareTest_KeyMonitorStatus(string BaseTag, int KeyID, int InputStatus, int ChargeStatus, double BatteryVoltage, int RfIntensity)
        {
            ////杨斌 2015-03-27。用电量测试模拟选择
            string KeyValue = BatteryVoltage.ToString();
            double KeyTime = 0;
            if (ResponseType == ResponseType.Choice)
            {
                KeyValue = "ABCDEFGHIJ";
            }

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

        void myPVS_KeyVote(int ID, int iMode, string sInfo)
        {
            ResponsePar ObjResponseValue = new ResponsePar();
            //ObjResponseValue.BaseTag = BaseTag;
            ObjResponseValue.KeyID = ID.ToString();

            ////杨斌 2015-03-27。用电量测试模拟选择
            //if (ResponseType == ResponseType.Choice)
            //{
            //    sInfo = "ABCDEFGHIJ,0";
            //}

            string KeyValue = "";
            double KeyTime = 0;
            switch (ResponseType)
            {
                case SunVoteARSPPT.ResponseType.Choice:
                case SunVoteARSPPT.ResponseType.Group:
                case SunVoteARSPPT.ResponseType.Judge:
                case SunVoteARSPPT.ResponseType.Vote:
                case SunVoteARSPPT.ResponseType.Grade:
                    string[] ary = sInfo.Split(new char[] { ',' });
                    KeyValue = ary[0];
                    if (ary.Length >= 2)
                        double.TryParse(ary[1], out KeyTime);
                    ObjResponseValue.KeyValue = KeyValue;
                    ObjResponseValue.Speed = KeyTime;
                    break;
            }

            //杨斌 2016-07-18 屏蔽乱码
            if (!ARSChoise.JudgePVSSelectResult(ObjResponseValue.KeyValue))
                return;

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

        /// <summary>
        /// 键盘状态事件
        /// </summary>
        /// <param name="BaseTag"></param>
        /// <param name="KeyID"></param>
        /// <param name="KeyValue"></param>
        /// <param name="KeyTime"></param>
        void Choise_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            Choise_KeyStatusSN(BaseTag, KeyID.ToString(), KeyValue, KeyTime);
        }
        void Choise_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            ResponsePar ObjResponseValue = new ResponsePar();
            ObjResponseValue.BaseTag = BaseTag;
            ObjResponseValue.KeyID = KeySN;
            ObjResponseValue.KeyValue = KeyValue;
            ObjResponseValue.Speed = KeyTime;
            if (ResponseEventHander != null)
                ResponseEventHander(ObjResponseValue);
        }

        void Sequence_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            Choise_KeyStatusSN(BaseTag, KeySN, KeyValue, KeyTime);
        }

        /// <summary>
        /// 判断题键盘事件
        /// 杨斌 2014-10-20
        /// </summary>
        /// <param name="BaseTag"></param>
        /// <param name="KeyID"></param>
        /// <param name="KeyValue"></param>
        /// <param name="KeyTime"></param>
        void TrueFalse_KeyStatus(string BaseTag, int KeyID, string KeyValue, double KeyTime)
        {
            Choise_KeyStatus(BaseTag, KeyID, KeyValue, KeyTime);
        }
        void TrueFalse_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            Choise_KeyStatusSN(BaseTag, KeySN, KeyValue, KeyTime);
        }

        /// <summary>
        /// 表决键盘状态
        /// 杨斌 2013-11-12
        /// </summary>
        /// <param name="BaseTag"></param>
        /// <param name="KeyID"></param>
        /// <param name="KeyValue"></param>
        void Vote_KeyStatus(string BaseTag, int KeyID, string KeyValue)
        {
            Choise_KeyStatus(BaseTag, KeyID, KeyValue, 0);
        }
        void Vote_KeyStatusSN(string BaseTag, string KeySN, string KeyValue, double KeyTime)
        {
            Choise_KeyStatusSN(BaseTag, KeySN, KeyValue, KeyTime);
        }

        #region IResponse 成员
        /// <summary>
        /// 基站连接类
        /// </summary>
        public SunVote.BaseConnection BaseConnection { get; set; }
        /// <summary>
        /// 反馈事件
        /// </summary>
        public event ResponseEventHander ResponseEventHander;

        public TagSet TagSet { get; set; }
        /// <summary>
        /// 反馈类型
        /// </summary>
        public ResponseType ResponseType { get; set; }

        /// <summary>
        /// 启用
        /// 修改:杨斌 2012-06-27
        /// 杨斌 2015-03-16
        /// </summary>
        public void Start()
        {
            //杨斌 2016-07-18
            JudgePVSSelectMax = 0;
            JudgePVSSelectMin = 0;

            if (GlobalInfo.GetSdkType() == 0)
            {
                //设置参数
                Choise.BaseConnection = BaseConnection;
                //选项编号模式 0:按字母,1:按数字
                Choise.OptionsMode = TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;//杨斌 2012-06-25
                //修改模式
                Choise.ModifyMode = (TagSet.GetValue(TagKey.KeypadPara_ModifyMode).ToInt == 0 ? 1 : 0);
                //保密模式。杨斌 2016-02-15
                Choise.SecrecyMode = TagSet.GetValue(TagKey.KeypadPara_SecrecyMode).ToInt;

                bool bKeepSort = false;//是否保留多选顺序
                Sequence.BaseConnection = Choise.BaseConnection;
                Sequence.OptionsMode = Choise.OptionsMode;
                Sequence.ModifyMode = Choise.ModifyMode;
                Sequence.SecrecyMode = Choise.SecrecyMode;//杨斌 2016-02-15
                Vote.BaseConnection = BaseConnection;//杨斌 2013-11-13

                //杨斌 2014-10-20
                TrueFalse.BaseConnection = BaseConnection;
                TrueFalse.ModifyMode = Choise.ModifyMode;
                TrueFalse.SecrecyMode = Choise.SecrecyMode;

                switch (ResponseType)
                {
                    case ResponseType.Choice:
                        //迫交模式
                        Choise.LessEnabled = TagSet.GetValue(TagKey.Choice_IisN).ToInt;
                        //Choise.LessEnabled = 0;//杨斌 2012-06-04 日本的不要
                        //选项个数
                        Choise.Options = TagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
                        //可选个数
                        Choise.OptionalN = TagSet.GetValue(TagKey.Choice_OptionLimit).ToInt;

                        if (bKeepSort && (Choise.OptionalN > 1))//多选
                        {
                            Sequence.LessEnabled = Choise.LessEnabled;
                            Sequence.OptionalN = Choise.Options;
                            Sequence.OptionalCount = Choise.OptionalN;
                        }

                        break;
                    case ResponseType.Group:
                        //迫交模式
                        Choise.LessEnabled = 0;
                        //选项个数
                        Choise.Options = TagSet.GetValue(TagKey.Group_OptionCount).ToInt;
                        //可选个数
                        Choise.OptionalN = 1;
                        break;
                    case ResponseType.Judge:
                        TrueFalse.Mode = 1;//杨斌 2014-10-20

                        //迫交模式
                        Choise.LessEnabled = 0;
                        //选项个数
                        Choise.Options = 2;
                        //可选个数
                        Choise.OptionalN = 1;
                        break;
                    case ResponseType.Vote:
                        //迫交模式
                        Choise.LessEnabled = 0;
                        //选项个数
                        Choise.Options = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
                        //可选个数
                        Choise.OptionalN = 1;

                        //杨斌 2013-11-12
                        if (Choise.Options == 2)
                            Vote.Mode = 1;
                        else
                            Vote.Mode = 0;
                        Vote.ModifyMode = Choise.ModifyMode;
                        Vote.SecrecyMode = Choise.SecrecyMode;

                        break;
                    case ResponseType.Grade:
                        //迫交模式
                        Choise.LessEnabled = 0;
                        //选项个数
                        Choise.Options = TagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
                        //可选个数
                        Choise.OptionalN = 1;
                        break;
                }

                if (ResponseType == ResponseType.Vote)
                {
                    Vote.StartMode = 1;
                    Vote.Start();
                    IsStartVote = true;
                }
                else
                {
                    //杨斌 2014-10-20
                    if ((GlobalInfo.hardwareManage.KeyModel == "S50") && (ResponseType == ResponseType.Judge))
                    {
                        TrueFalse.StartMode = 1;
                        TrueFalse.Start();
                        IsStartTF = true;
                    }
                    else
                    {
                        //键盘模拟测试。杨斌 2015-03-30
                        IsStartTest = false;
                        if (IsStartTest)
                        {
                            IsStartSequence = false;
                            IsStartChoise = false;
                            hardwareTest.BaseConnection = BaseConnection;
                            hardwareTest.Start();
                        }
                        else
                        {
                            //杨斌 2012-06-27
                            if (bKeepSort && (Choise.OptionalN > 1))//多选
                            {
                                ////Sequence.SecrecyMode = 0;//杨斌 2016-02-15
                                Sequence.StartMode = 1;
                                Sequence.Start();
                                IsStartSequence = true;
                            }
                            else
                            {
                                //保密模式
                                ////Choise.SecrecyMode = 0;//杨斌 2016-02-15
                                Choise.StartMode = 1;
                                Choise.Start();
                                IsStartChoise = true;
                            }
                        }
                    }
                }
            }
            else if (GlobalInfo.GetSdkType() == 1)
            {
                int iMax = 0;
                int iMin = 0;
                //选项编号模式 0:按字母,1:按数字
                int iOptionsMode = TagSet.GetValue(TagKey.KeypadPara_OptionMode).ToInt == 1 ? 0 : 1;
                int iModifyMode = TagSet.GetValue(TagKey.KeypadPara_ModifyMode).ToInt == 0 ? 1 : 0;

                int pvsVoteMode = 0;
                string pvsVoteSetting = "";
                switch (ResponseType)
                {
                    //case SunVoteARSPPT.ResponseType.SignIn:
                    //    pvsVoteMode = 1;
                    //    pvsVoteSetting = "1";
                    //    break;
                    case ResponseType.Choice:
                        //选项个数
                        iMax = TagSet.GetValue(TagKey.Choice_OptionCount).ToInt;
                        //可选个数
                        iMin = TagSet.GetValue(TagKey.Choice_OptionLimit).ToInt;
                        pvsVoteMode = 5;
                        pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;

                        //杨斌 2016-07-18
                        JudgePVSSelectMax = iMax;
                        JudgePVSSelectMin = iMin;

                        if (iMin > 1)//特殊型号,多选时必须可以修改。杨斌 2015-11-10
                        {
                            switch (GlobalInfo.hardwareManage.KeyModel)
                            {
                                case "W00":
                                case "W40":
                                    iModifyMode = 1;
                                    break;
                            }
                        }

                        ////杨斌 用电量测试模拟选择题
                        //pvsVoteMode = 15;
                        //pvsVoteSetting = "0";

                        break;
                    case ResponseType.Group:
                        //选项个数
                        iMax = TagSet.GetValue(TagKey.Group_OptionCount).ToInt;
                        //可选个数
                        iMin = 1;
                        pvsVoteMode = 5;
                        pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;

                        //杨斌 2016-07-18
                        JudgePVSSelectMax = iMax;
                        JudgePVSSelectMin = iMin;

                        break;
                    case ResponseType.Judge:
                        //选项个数
                        iMax = 2;
                        //可选个数
                        iMin = 1;
                        if (SystemConfig.KeypadType == "W00")
                        {
                            pvsVoteMode = 2;
                            pvsVoteSetting = (iModifyMode == 0 ? 1 : 3).ToString();
                        }
                        else
                        {
                            pvsVoteMode = 5;
                            pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;

                            //杨斌 2016-07-18
                            JudgePVSSelectMax = iMax;
                            JudgePVSSelectMin = iMin;
                        }
                        break;
                    case ResponseType.Vote:
                        if (SystemConfig.KeypadType == "W00")
                        {
                            iMax = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;

                            pvsVoteMode = 2;
                            if (iMax >= 3)//三键
                                pvsVoteSetting = (iModifyMode == 0 ? 5 : 7).ToString();
                            else//二键
                                pvsVoteSetting = (iModifyMode == 0 ? 1 : 3).ToString();

                            ////杨斌 用电量测试模拟选择题
                            //pvsVoteMode = 15;
                            //pvsVoteSetting = "0";
                        }
                        else
                        {
                            //选项个数
                            iMax = TagSet.GetValue(TagKey.Vote_OptionCount).ToInt;
                            //可选个数
                            iMin = 1;
                            pvsVoteMode = 5;
                            pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;

                            //杨斌 2016-07-18
                            JudgePVSSelectMax = iMax;
                            JudgePVSSelectMin = iMin;
                        }
                        break;
                    case ResponseType.Grade:
                        //选项个数
                        iMax = TagSet.GetValue(TagKey.Grade_OptionCount).ToInt;
                        //可选个数
                        iMin = 1;
                        pvsVoteMode = 5;
                        pvsVoteSetting = (iOptionsMode == 0 ? 1 : 2) + "," + iMax + "," + iMin;

                        //杨斌 2016-07-18
                        JudgePVSSelectMax = iMax;
                        JudgePVSSelectMin = iMin;

                        break;
                    default:
                        return;
                }

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

        private static int JudgePVSSelectMax = 0;
        private static int JudgePVSSelectMin = 0;
        /// <summary>
        /// 判断键盘数据乱码
        /// 杨斌 2016-07-18
        /// </summary>
        public static bool JudgePVSSelectResult(string result)
        {
            bool res = false;
            try
            {
                if (JudgePVSSelectMax > 0)
                {
                    if (result.Length <= JudgePVSSelectMin)
                    {
                        for (int i = 0; i < result.Length; i++)
                        {
                            string s = result.Substring(i, 1).ToUpper();
                            int n = Convert.ToInt32(s) - 64;
                            if ((n >= 1) && (n <= JudgePVSSelectMax))
                                res = true;
                        }
                    }
                }
                else
                    res = true;
            }
            catch(Exception ex)
            {
                res = true;
                SystemLog.WriterLog(ex, false);
            }
            return res;
        }

        /// <summary>
        /// 停止
        /// 修改:杨斌 2012-06-27
        /// </summary>
        public void Stop()
        {
            if (GlobalInfo.GetSdkType() == 0)
            {
                if (IsStartChoise)
                    Choise.Stop();

                if (IsStartSequence)
                    Sequence.Stop();//杨斌 2012-06-27

                //杨斌 2013-11-13
                if (IsStartVote)
                    Vote.Stop();

                if (IsStartTF)
                    TrueFalse.Stop();

                if (IsStartTest)//杨斌 2015-03-30
                    hardwareTest.Stop();
            }
            else if (GlobalInfo.GetSdkType() == 1)
            {
                FrmPvsServer.GetFrmPvs().VoteStop();
            }

            //杨斌 2013-11-13
            IsStartChoise = false;
            IsStartSequence = false;
            IsStartVote = false;
            IsStartTF = false;
            IsStartTest = false;//杨斌 2015-03-30
        }

        #endregion



    }
}