SunVoteARSAddIn.cs 41.2 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 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using System.Collections.Specialized;
using Microsoft.Office.Interop.PowerPoint;
using System.Windows.Forms;
using GeneralLib;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
using System.IO;
using System.Collections;
using ProService;
//using HotKeyPress;

namespace SunVoteARSPPT
{
    public partial class SunVoteARSAddIn
    {
        //API申明
        [DllImport("user32")]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
        private static extern IntPtr GetParent(IntPtr hWnd);
        [DllImport("user32.dll", SetLastError = false)]
        private static extern IntPtr GetDesktopWindow();
        [DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
        enum GetWindow_Cmd : uint
        {
            GW_HWNDFIRST = 0,
            GW_HWNDLAST = 1,
            GW_HWNDNEXT = 2,
            GW_HWNDPREV = 3,
            GW_OWNER = 4,
            GW_CHILD = 5,
            GW_ENABLEDPOPUP = 6
        }

        public delegate bool EnumedWindow(IntPtr handleWindow, ArrayList handles);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EnumWindows(EnumedWindow lpEnumFunc, ArrayList lParam);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool IsWindowVisible(IntPtr hWnd);

        /// <summary>
        /// PPT编辑类,编辑题目用
        /// </summary>
        public PPTEdit PPTEdit;

        /// <summary>
        /// PPT显示类,播放控制用
        /// </summary>
        public PPTShow PPTShow;

        /// <summary>
        /// 自定义Esc动作,用来记忆当前遥控器按Esc如何处理,如打开了窗体,则按Esc是关闭
        /// </summary>
        private string RemoteActionEsc = "";

        /// <summary>
        /// 自定义Enter动作,用来记忆当前遥控器按Enter如何处理
        /// </summary>
        private string RemoteActionEnter = "";

        /// <summary>
        /// 自定义C键,可用来返回上一级菜单
        /// </summary>
        private string RemoteActionC = "";

        /// <summary>
        /// 自定义向上键,可用来上移菜单
        /// </summary>
        private string RemoteActionUp = "";

        /// <summary>
        /// 自定义向下键,可用来下移菜单
        /// </summary>
        private string RemoteActionDown = "";
        /// <summary>
        /// 控制条
        /// </summary>
        public FrmVoteBar frmVoteBar;
        /// <summary>
        /// 按键明细
        /// </summary>
        //public FrmVoteDetail frmVoteDetail;


        /// <summary>
        /// 全局快捷键对象
        /// </summary>
        //public HotKey HotKey = new HotKey();

        /// <summary>
        /// 初始化Addin入口
        /// </summary>
        public void AddinStartupInit()
        {
            try
            {

                //GlobalInfo.InitMain();
                PPTEdit = new PPTEdit(this.Application);
                PPTShow = new PPTShow(this.Application);

                //屏蔽。杨斌 2016-10-26
                //修改标志 赵丽 2012-05-02 遥控器使用不了可能是由于初始化音频文件失败退出引起的
                //GlobalInfo.response.ARSRequest.Enabled = GlobalInfo.sysConfig.RemontControl;
                //GlobalInfo.response.ARSRequest.ChairControl += new SunVote.IRequestEvents_ChairControlEventHandler(ARSRequest_ChairControl);
                //GlobalInfo.response.ARSRequest.ChairControlSN += ARSRequest_ChairControlSN;

                GlobalInfo.InitRemontControl();//杨斌 2017-03-31
                
                GlobalInfo.DXSoundPlay = new PLSound();//杨斌 2012-06-25
                if (!GlobalInfo.DXSoundPlay.InitSound(new Form())) return;
                
                GlobalInfo.DXSoundPlay.LoadSound(GlobalInfo.Sound_Key_Back, GlobalInfo.SOUND_DIR + GlobalInfo.sysConfig.BackgSoundPath);
                GlobalInfo.DXSoundPlay.LoadSound(GlobalInfo.Sound_Key_Vote, GlobalInfo.SOUND_DIR + GlobalInfo.sysConfig.PressSoundPath, 10);//混音10个够了,杨斌 2012-02-28
                //杨斌 2019-01-07
                GlobalInfo.DXSoundPlay.LoadSound(GlobalInfo.Sund_Key_SlideShowResult, GlobalInfo.SOUND_DIR + GlobalInfo.sysConfig.ShowResultChartSoundPath);
                GlobalInfo.DXSoundPlay.LoadSound(GlobalInfo.Sund_Key_ShowCorrectAnswer, GlobalInfo.SOUND_DIR + GlobalInfo.sysConfig.CorrectAnswerSoundPath);
                                
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex);
            }
        }

        private FrmReceive FrmGetMsg = new FrmReceive();//杨斌 2014-04-11


        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;//杨斌 2016-06-24
            try//杨斌 2014-04-11。放到加载项启动里
            {
                //调试。注释掉。杨斌 2015-07-10
                //if (Globals.SunVoteARSAddIn.GetPPTVersion() >= 15)//杨斌 2020-07-27
                {
                    FrmGetMsg.Show();
                    //FrmGetMsg.Hide();
                    Process.Start(GlobalInfo.GetAppWorkDir() + @"HotKeyServer.exe");
                }
            }
            catch { }
            
        }

        /// <summary>
        /// 是否正在退出插件
        /// 杨斌 2015-11-10
        /// </summary>
        public bool IsExitApp = false;
        /// <summary>
        /// 修改:杨斌 2012-05-16
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            //杨斌 2017-03-02
            try
            {
                Globals.Ribbons.rbSunVoteARS.tmrCheckActivePres.Stop();
                TimerCount.Delay(50);//杨斌 2017-03-06
            }
            catch { }

            try//杨斌 2017-03-02
            {
                Param p = new Param();
                p.Pa.Add("ToExit", "");
                GlobalInfo.ServerRequest(p);
                TimerCount.Delay(50);//杨斌 2017-03-06
            }
            catch { }
            
            IsExitApp = true;//杨斌 2015-11-10
            
            try
            {
                GlobalInfo.baseConnect.DisConnect();
            }
            catch { }

            try
            {
                GlobalInfo.DBOperation.CloseConn();

                List<Presentation> lstPres = new List<Presentation>();
                foreach (var v in Globals.SunVoteARSAddIn.Application.Presentations)
                {
                    lstPres.Add(v as Presentation);
                }
                foreach (var v in Globals.SunVoteARSAddIn.PPTEdit.DicNPres)
                {
                    if (!lstPres.Contains(v.Key))
                    {
                        string db = GlobalInfo.DB_PATH + v.Value;
                        if (File.Exists(db))
                            File.Delete(db);
                    }
                }                
            }
            catch { }

            try//杨斌 2014-04-11。放到加载项卸载里
            {
                //if (Globals.SunVoteARSAddIn.GetPPTVersion() >= 15)//杨斌 2020-07-27
                {
                    SendMsg.SendMsgKey("ExitHotKey");
                    if ((FrmGetMsg != null) && (!FrmGetMsg.IsDisposed))
                        FrmGetMsg.Close();                    
                }
            }
            catch { }

            try//杨斌 2015-11-10。杀HotKeyServer进程
            {
                Process[] proSer = Process.GetProcessesByName("HotKeyServer");
                foreach (var v in proSer)
                {
                    v.Kill();
                }
            }
            catch { }

            try
            {
                RegistryKey sKey = null;
                try
                {
                    sKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("SunVote ARS").OpenSubKey(GlobalInfo.GetAppName());
                }
                catch { }
                string loadType = "0"; //自动加载
                if (sKey != null)
                {
                    loadType = sKey.GetValue("LoadType").ToString();
                }
                loadType = GlobalInfo.sysConfig.AddType.ToString();//从配置文件获取加载方式。杨斌 2013-05-07

                if (loadType == "1")
                {
                    RegistryKey cKey = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Microsoft", true).OpenSubKey("Office", true)
                                     .OpenSubKey("PowerPoint", true).OpenSubKey("Addins", true).OpenSubKey(GlobalInfo.GetAppName(), true);
                    cKey.SetValue("LoadBehavior", 2);
                }                
            }
            catch { }

            try//杨斌 2015-04-14
            {
                FrmPvsServer.FreeMyPvs();
            }
            catch { }

            try//杨斌 2015-01-22
            {
                if (GlobalInfo.OEMLogo == OEMLogos.oemRealVote)
                {
                    try
                    {
                        if (GlobalInfo.RealVoteSoftDog != null)
                        {
                            //FrmDebugMsg.ShowMsg("Call RealVoteSoftDog.LogOff ...");

                            //GlobalInfo.RealVoteSoftDog.LogOff();

                            if (GlobalInfo.ShowDebug)
                                MessageBox.Show("RealVoteSoftDog.LogOff Called");
                        }
                    }
                    catch (Exception ex)
                    {
                        SystemLog.WriterLog(ex);
                    }
                    
                }
            }
            catch { }
            
            try
            {
                GC.Collect();
            }
            catch { }

            //MessageBox.Show("ThisAddIn_Shutdown End");

            try//杨斌 2015-04-16
            {
                if (this.Application.Presentations.Count < 1)
                {
                    if (this.Application.Visible == Microsoft.Office.Core.MsoTriState.msoFalse)
                    {
                        //Process[] pros2 = Process.GetProcessesByName("OfficeClickToRun");
                        //foreach (var v in pros2)
                        //{
                        //    MessageBox.Show("Kill " + v.ProcessName);
                        //    v.CloseMainWindow();
                        //    v.WaitForExit();
                        //    v.Kill();
                        //    v.WaitForExit();
                        //    MessageBox.Show(v.ProcessName);
                        //}

                        this.Application.Quit();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(this.Application);
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        //杨斌 2015-11-13
                        //Process.GetCurrentProcess().Kill();                        

                        //Process[] pros = Process.GetProcessesByName("POWERPNT");                        
                        //foreach (var v in pros)
                        //    v.Kill();

                        //MessageBox.Show("Kill");

                        //杨斌 2018-03-06
                        Stopwatch t = Stopwatch.StartNew();
                        while (Process.GetProcessesByName("POWERPNT").Length > 0)
                        {
                            try
                            {
                                Process.GetCurrentProcess().Kill();
                            }
                            catch { }
                            System.Windows.Forms.Application.DoEvents();
                            if (t.ElapsedMilliseconds > 1000)
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }

            //MessageBox.Show("End");
        }

        /// <summary>
        /// 判断焦点是否在PowerPoint窗体上面
        /// </summary>
        /// <returns>是否激活焦点</returns>
        public bool IsFocusPowerPoint()
        {
            return (GetForegroundWindow() == GetPPTFormHandle());
        }

        /// <summary>
        /// 说明:获取PowerPoint窗体句柄
        /// 创建:杨斌 2010-08-01
        /// </summary>
        /// <returns>PowerPoint窗体句柄</returns>
        public IntPtr GetPPTFormHandle()
        {
            string className = "";
            //杨斌 2013-11-15
            string sVer = ConvertOper.DoNumberString(this.Application.Version);
            int v = (int)Convert.ToDouble(sVer);

            switch (v)
            {
                case 14:
                case 15://杨斌 2013-10-16
                case 16://杨斌 2016-07-12
                    className = "PPTFrameClass";
                    break;
                default:
                    className = "PP" + v.ToString() + "FrameClass";
                    break;

            }
            return FindWindow(className, null);
            //return FindWindow("PP12FrameClass", null);
        }

        /// <summary>
        /// 说明:获取PowerPoint播放SlideShow窗体句柄
        /// 创建:杨斌 2010-08-08
        /// </summary>
        /// <returns></returns>
        public IntPtr GetPPTSlideShowHandle()
        {
            //杨斌 2013-11-15
            string sVer = ConvertOper.DoNumberString(this.Application.Version);
            int v = (int)Convert.ToDouble(sVer);

            return FindWindow("screenClass", null);
        }

        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild,
          IntPtr hWndNewParent
        );

        /// <summary>
        /// 杨斌 2016-07-12
        /// </summary>
        public static bool SetPPTSlideShowParent(Form frm)
        {
            bool res = false;
            try
            {
                IntPtr p = Globals.SunVoteARSAddIn.GetPPTSlideShowHandle();
                if (p == IntPtr.Zero)
                    return res;
                SetParent(frm.Handle, p);
                frm.FormBorderStyle = FormBorderStyle.Sizable;
                res = true;
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex, false);
            }
            return res;
        }

        public static ArrayList GetWindows()
        {
            ArrayList windowHandles = new ArrayList();
            EnumedWindow callBackPtr = GetWindowHandle;
            EnumWindows(callBackPtr, windowHandles);

            return windowHandles;
        }

        private static bool GetWindowHandle(IntPtr windowHandle, ArrayList windowHandles)
        {
            windowHandles.Add(windowHandle);
            return true;
        }

        public List<IntPtr> GetPPTSlideShowHandles()
        {
            List<IntPtr> res = new List<IntPtr>();
            ArrayList all = GetWindows();

            foreach (var v in all)
            {
                IntPtr p = (IntPtr)v;
                if (IsWindowVisible(p))
                {
                    StringBuilder ClassName = new StringBuilder(256);
                    int nRet = GetClassName(p, ClassName, ClassName.Capacity);
                    if (ClassName.ToString() == "screenClass")
                        res.Add(p);
                }
            }            

            return res;
        }
        
        public int GetPPTVersion()
        {
            int res = 0;
            try
            {
                //杨斌 2015-09-17
                res = (int)Convert.ToDouble(ConvertOper.DoNumberString(this.Application.Version));
            }
            catch { }
            return res;
        }

        /// <summary>
        /// 激活PowerPoint,用于遥控器
        /// 杨斌 2013-12-24
        /// </summary>
        public void ActivePres()
        {
            try
            {
                Globals.SunVoteARSAddIn.Application.Activate();
            }
            catch { }
        }

        /// <summary>
        /// 获取遥控按键。杨斌 2016-10-25
        /// </summary>
        public void GetRequestPress()
        {
            Param p = new Param();
            p.Pa.Add("GetRequestPress", "");
            Param r = GlobalInfo.ServerRequest(p);

            if (r.Pa.ContainsKey("GetRequestPress"))
            {
                Dictionary<string, string> dic = MyService.DeserializeObj<Dictionary<string, string>>(r.Pa["GetRequestPress"].ToString());
                foreach (var v in dic)
                {
                    ARSRequest_ChairControlSN("", v.Key, 1, v.Value);
                }
            }
        }

        /// <summary>
        /// 50R转换R5X按键。杨斌 2019-07-02
        /// </summary>
        Dictionary<string, string> Dic50R_R5X = new Dictionary<string, string>();

        private void SendKey(string keys)//杨斌 2018-03-16
        {
            if (Globals.Ribbons.rbSunVoteARS.tmrCheckActivePres is System.Timers.Timer)
                SendKeys.SendWait(keys);
            else
                SendKeys.Send(keys);
        }

        /// <summary>
        /// 50R遥控。杨斌 2016-08-08
        /// </summary>
        private void ARSRequest_ChairControlSN(string BaseTag, string KeySN, int ReqType, string ReqInfo)
        {
            PowerPoint.Presentation pres = null;
            PowerPoint.SlideShowWindow sldShowWin = null;

            try
            {
                sldShowWin = Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.SlideShowWindow;
            }
            catch
            {
                //仅用来尝试获取PPT是否播放的窗体,因此不处理异常
            }
            bool isPlay = (sldShowWin != null);//是否正在播放状态
            bool isNomalSlide = false;
            if (isPlay)
            {
                //杨斌 2014-08-06
                if ((Globals.SunVoteARSAddIn.PPTShow.ResponseType == ResponseType.None)
                    || (Globals.SunVoteARSAddIn.PPTShow.ResponseType == ResponseType.Slide)
                    || (Globals.SunVoteARSAddIn.PPTShow.ResponseType == ResponseType.ScoreRankChart)
                    || (Globals.SunVoteARSAddIn.PPTShow.ResponseType == ResponseType.ScoreRankGroupChart)
                    || (Globals.SunVoteARSAddIn.PPTShow.ResponseType == ResponseType.OperatorSlide))//杨斌 2015-07-23
                    isNomalSlide = true;
            }

            if (GlobalInfo.sysConfig.RemontControl == "R51")//50R转换R51。杨斌 2017-03-28
            {
                if (ReqInfo == "2")//开始
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.IsRunFrmRushAnswer)
                            return;
                        if (frmVoteBar.IsFrmRunLuckyShow)
                            return;

                        if (frmVoteBar.IsVoteStart) return;

                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteStart.Enabled) return;
                        frmVoteBar.VoteBarChange(4);
                    }
                    return;
                }
                else if (ReqInfo == "3")//停止反馈、停止随机点名
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.IsVoteStart)
                        {
                            if (isNomalSlide) return;
                            if (!frmVoteBar.tsbVoteStart.Enabled) return;
                            frmVoteBar.VoteBarChange(4);
                        }
                        if (frmVoteBar.IsFrmRunLuckyShow)
                        {
                            if (frmVoteBar.frmLuckyShow.tmrRoll.Enabled)
                                frmVoteBar.frmLuckyShow.tmrRoll.Enabled = false;
                        }
                    }
                    return;
                }
                else if (ReqInfo == "5")//开始随机点名
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.IsVoteStart)
                            return;
                        if (frmVoteBar.IsRunFrmRushAnswer)
                            return;
                        //if (frmVoteBar.IsFrmRunLuckyShow)
                        //{
                        //    frmVoteBar.frmLuckyShow.PressSpace();
                        //    return;
                        //}
                        if (frmVoteBar.IsFrmRunLuckyShow)
                        {
                            if (frmVoteBar.frmLuckyShow.tmrRoll.Enabled)
                                return;
                            else
                                frmVoteBar.frmLuckyShow.tmrRoll.Enabled = true;
                        }
                        else
                        {
                            InitTmrRunRemote();
                            tmrRunRemote.Tag = "10";
                            tmrRunRemote.Start();
                        }
                    }
                    return;
                }
                else if (ReqInfo == "11")//正确答案
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.tsbCorrectAnswer.Enabled)
                            frmVoteBar.tsbCorrectAnswer.Checked = !frmVoteBar.tsbCorrectAnswer.Checked;
                    }
                    return;
                }
                if (Dic50R_R5X == null)
                    Dic50R_R5X = new Dictionary<string, string>();

                if (Dic50R_R5X.Count < 1)
                {
                    Dic50R_R5X.Add("10", "11");//ESC键
                    //Dic50R_R5X.Add("5", "10");//随机点名
                    Dic50R_R5X.Add("6", "12");//启动抢答
                    Dic50R_R5X.Add("1", "1");//从当前页播放PPT
                    Dic50R_R5X.Add("4", "2");//上翻键
                    //Dic50R_R5X.Add("", "3");//从头播放PPT
                    //Dic50R_R5X.Add("", "4");//启动/停止投票反馈
                    //Dic50R_R5X.Add("", "5");//回车键/显示答案 暂做下翻键
                    Dic50R_R5X.Add("12", "6");//清除反馈数据
                    Dic50R_R5X.Add("8", "7");//显示/隐藏反馈图表
                    Dic50R_R5X.Add("7", "8");//下翻键
                    Dic50R_R5X.Add("9", "9");//按键明细查看键
                }
                ReqInfo = Dic50R_R5X[ReqInfo];
            }
            else if (GlobalInfo.sysConfig.RemontControl == "R52")//50R转换R52。杨斌 2019-07-02
            {
                if (ReqInfo == "9")//启动反馈
                {
                    if (isPlay)
                    {
                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteStart.Enabled) return;
                        if (!frmVoteBar.IsVoteStart)
                            frmVoteBar.VoteBarChange(4);
                    }
                    return;
                }
                if (ReqInfo == "12")//停止反馈
                {
                    if (isPlay)
                    {
                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteStart.Enabled) return;
                        if (frmVoteBar.IsVoteStart)
                            frmVoteBar.VoteBarChange(4);
                    }
                    return;
                }
                if (ReqInfo == "7")//正确答案
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.tsbCorrectAnswer.Enabled)
                            frmVoteBar.tsbCorrectAnswer.Checked = !frmVoteBar.tsbCorrectAnswer.Checked;
                    }
                    return;
                }
                if (ReqInfo == "8")//选项选择率
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.ddbAnalyzer.Enabled)
                        {
                            bool beCatch = false;
                            frmVoteBar.BeShowDialogFullAndTrySelect = true;
                            frmVoteBar.ShowSlideID = Globals.SunVoteARSAddIn.PPTShow.SlideShow.SlideID;
                            frmVoteBar.HotKey_KeyDownEvent((int)Keys.D2, "", 4, out beCatch);
                        }
                    }
                    return;
                }
                if (ReqInfo == "15")//退出播放
                {
                    sldShowWin.View.Exit();
                    return;
                }

                if (Dic50R_R5X == null)
                    Dic50R_R5X = new Dictionary<string, string>();

                if (Dic50R_R5X.Count < 1)
                {
                    Dic50R_R5X.Add("13", "11");//ESC键
                    Dic50R_R5X.Add("10", "10");//随机点名
                    Dic50R_R5X.Add("11", "12");//启动抢答
                    Dic50R_R5X.Add("1", "1");//从当前页播放PPT
                    Dic50R_R5X.Add("3", "2");//上翻键
                    Dic50R_R5X.Add("2", "3");//从头播放PPT
                    //Dic50R_R5X.Add("", "4");//启动/停止投票反馈
                    //Dic50R_R5X.Add("", "5");//回车键/显示答案 暂做下翻键
                    Dic50R_R5X.Add("14", "6");//清除反馈数据
                    Dic50R_R5X.Add("5", "7");//显示/隐藏反馈图表
                    Dic50R_R5X.Add("6", "8");//下翻键
                    Dic50R_R5X.Add("4", "9");//按键明细查看键
                }
                ReqInfo = Dic50R_R5X[ReqInfo];
            }
            else if (GlobalInfo.sysConfig.RemontControl == "R53")//50R转换R53。杨斌 2020-03-20
            {
                //硬件换人搞遥控器,按键值协议全乱了,跟以前40R、50R、R51、R52完全不兼容,只好进行转换。杨斌 2020-03-24
                Dictionary<string, string> dicR53_Old = new Dictionary<string, string>();
                dicR53_Old.Add("19", "1");
                dicR53_Old.Add("20", "3");
                dicR53_Old.Add("1", "4");
                dicR53_Old.Add("2", "5");
                dicR53_Old.Add("3", "6");
                dicR53_Old.Add("4", "7");
                dicR53_Old.Add("5", "8");
                dicR53_Old.Add("6", "9");
                dicR53_Old.Add("7", "10");
                dicR53_Old.Add("8", "11");
                dicR53_Old.Add("9", "12");
                dicR53_Old.Add("16", "13");
                dicR53_Old.Add("10", "14");
                dicR53_Old.Add("17", "15");
                if (dicR53_Old.ContainsKey(ReqInfo))
                {
                    ReqInfo = dicR53_Old[ReqInfo];
                }
                else
                {
                    return;
                }

                if (ReqInfo == "12")//启动反馈
                {
                    if (isPlay)
                    {
                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteStart.Enabled) return;
                        if (!frmVoteBar.IsVoteStart)
                            frmVoteBar.VoteBarChange(4);
                    }
                    return;
                }
                if (ReqInfo == "15")//停止反馈
                {
                    if (isPlay)
                    {
                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteStart.Enabled) return;
                        if (frmVoteBar.IsVoteStart)
                            frmVoteBar.VoteBarChange(4);
                    }
                    return;
                }
                if (ReqInfo == "7")//正确答案
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.tsbCorrectAnswer.Enabled)
                            frmVoteBar.tsbCorrectAnswer.Checked = !frmVoteBar.tsbCorrectAnswer.Checked;
                    }
                    return;
                }
                /*//
                if (ReqInfo == "2")//选项选择率。R53对比R52去掉一个"选项选择率"按键。杨斌 2020-03-20
                {
                    if (isPlay)
                    {
                        if (frmVoteBar.ddbAnalyzer.Enabled)
                        {
                            bool beCatch = false;
                            frmVoteBar.BeShowDialogFullAndTrySelect = true;
                            frmVoteBar.ShowSlideID = Globals.SunVoteARSAddIn.PPTShow.SlideShow.SlideID;
                            frmVoteBar.HotKey_KeyDownEvent((int)Keys.D2, "", 4, out beCatch);
                        }
                    }
                    return;
                }//*/
                if (ReqInfo == "8")//退出播放
                {
                    sldShowWin.View.Exit();
                    return;
                }

                if (Dic50R_R5X == null)
                    Dic50R_R5X = new Dictionary<string, string>();

                if (Dic50R_R5X.Count < 1)
                {
                    Dic50R_R5X.Add("13", "11");//ESC键
                    Dic50R_R5X.Add("10", "10");//随机点名
                    Dic50R_R5X.Add("11", "12");//启动抢答
                    Dic50R_R5X.Add("1", "1");//从当前页播放PPT
                    Dic50R_R5X.Add("6", "2");//上翻键
                    Dic50R_R5X.Add("3", "3");//从头播放PPT
                    //Dic50R_R5X.Add("", "4");//启动/停止投票反馈
                    //Dic50R_R5X.Add("", "5");//回车键/显示答案 暂做下翻键
                    Dic50R_R5X.Add("14", "6");//清除反馈数据
                    Dic50R_R5X.Add("5", "7");//显示/隐藏反馈图表
                    Dic50R_R5X.Add("9", "8");//下翻键
                    Dic50R_R5X.Add("4", "9");//按键明细查看键
                }
                ReqInfo = Dic50R_R5X[ReqInfo];
            }//50R转换R53。杨斌 2020-03-20

            //先处理模式窗体判断
            switch (ReqInfo)
            {
                case "11"://ESC键
                    if (isPlay)
                    {
                        //if (!isPlay) return;
                        if (frmVoteBar.IsRunFrmRushAnswer)
                        {
                            frmVoteBar.frmRushAnswer.Close();
                            return;
                        }
                        if (frmVoteBar.IsFrmRunLuckyShow)
                        {
                            frmVoteBar.frmLuckyShow.Close();
                            return;
                        }
                        if (frmVoteBar.IsFrmRunAnalyzeRateOption)//杨斌 2019-07-04
                        {
                            frmVoteBar.FDialog.Close();
                            return;
                        }

                        if (frmVoteBar.DetailShow)
                        {
                            if ((GlobalInfo.sysConfig.RemontControl == "R52")
                                || (GlobalInfo.sysConfig.RemontControl == "R53"))//杨斌 2020-03-20
                            {
                                frmVoteBar.frmVoteDetail.Close();
                            }
                            else
                            {
                                frmVoteBar.VoteBarChange(9);
                            }
                        }
                        else if ((GlobalInfo.sysConfig.RemontControl != "R52") //杨斌 2019-07-03
                            && (GlobalInfo.sysConfig.RemontControl != "R53"))//杨斌 2020-03-20
                        {
                            sldShowWin.View.Exit();
                            return;
                        }
                    }
                    break;
                case "10"://随机点名 杨斌 2013-12-24
                    if (!isPlay) return;
                    ////2014-2-25 云智慧要求显示正确答案 赵丽
                    //if (GlobalInfo.OEMLogo == OEMLogos.oemYZH)
                    //{
                    //    if (isNomalSlide) return;
                    //    if (!frmVoteBar.tsbVoteDetail.Enabled) return;

                    //    frmVoteBar.tsbCorrectAnswer.Checked = !frmVoteBar.tsbCorrectAnswer.Checked;
                    //}
                    //else
                    //{
                    if (frmVoteBar.IsRunFrmRushAnswer)
                        return;
                    if (frmVoteBar.IsFrmRunLuckyShow)
                    {
                        frmVoteBar.frmLuckyShow.PressSpace();
                        return;
                    }

                    InitTmrRunRemote();
                    tmrRunRemote.Tag = ReqInfo;
                    if (tmrRunRemote is System.Timers.Timer)
                        tmrRunRemote_Tick(null, null);//杨斌 2018-03-16
                    else
                        tmrRunRemote.Start();

                    //}
                    break;
                case "12"://启动抢答 杨斌 2013-12-24
                    if (!isPlay) return;

                    if (frmVoteBar.IsVoteStart)//杨斌 2017-03-29
                        return;
                    if (frmVoteBar.IsRunFrmRushAnswer)
                        return;
                    if (frmVoteBar.IsFrmRunLuckyShow)
                        return;

                    InitTmrRunRemote();
                    tmrRunRemote.Tag = ReqInfo;
                    if (tmrRunRemote is System.Timers.Timer)
                        tmrRunRemote_Tick(null, null);//杨斌 2018-03-16
                    else
                        tmrRunRemote.Start();

                    break;
                default://其他按键在模式窗体下无效
                    if (!isPlay) break;
                    if (frmVoteBar.IsRunFrmRushAnswer)
                        return;
                    if (frmVoteBar.IsFrmRunLuckyShow)
                        return;
                    break;
            }
            
            switch (ReqInfo)
            {
                case "1"://从当前页播放PPT
                    if (isPlay) return;
                    if (!IsFocusPowerPoint()) ActivePres();//if (!IsFocusPowerPoint()) return;
                    SendKey("+{F5}");
                    break;
                case "2"://上翻键
                    if (!isPlay)
                    {
                        SendKey("{UP}");
                    }
                    else//杨斌 2016-10-26
                    {
                        if (frmVoteBar.IsVoteStart)
                            frmVoteBar.VoteStart(false);
                        else
                            sldShowWin.View.Previous();
                    }
                    break;
                case "3"://从头播放PPT
                    if (isPlay) return;
                    if (!IsFocusPowerPoint()) ActivePres();//if (!IsFocusPowerPoint()) return;
                    SendKey("{F5}");
                    break;
                case "4"://启动/停止投票反馈
                    if (isPlay)
                    {
                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteStart.Enabled) return;
                        frmVoteBar.VoteBarChange(4);
                    }
                    else
                    {
                        SendKey("{LEFT}");
                    }
                    break;
                case "5"://回车键 暂做下翻键 杨斌 2013-12-24  
                    if (isPlay)
                    {
                        //杨斌 2014-08-12
                        if (frmVoteBar.tsbCorrectAnswer.Enabled)
                            frmVoteBar.tsbCorrectAnswer.Checked = !frmVoteBar.tsbCorrectAnswer.Checked;
                    }
                    else
                    {
                        SendKey("{DOWN}");
                    }

                    break;
                case "6"://清除反馈数据
                    if (isPlay)
                    {
                        if (isNomalSlide) return;
                        if (!frmVoteBar.tsbVoteClear.Enabled) return;
                        //frmVoteBar.VoteBarChange(6);
                        frmVoteBar.VoteClearNoMsg();
                    }
                    else
                    {
                        SendKey("{RIGHT}");
                    }
                    break;
                case "7"://显示/隐藏反馈图表
                    if (!isPlay) return;
                    if (isNomalSlide) return;
                    frmVoteBar.VoteBarChange(7);
                    break;
                case "8"://下翻键
                    if (!isPlay)
                        SendKey("{DOWN}");
                    else//杨斌 2014-08-21
                    {
                        if (frmVoteBar.IsVoteStart)
                            frmVoteBar.VoteStart(false);
                        else
                            sldShowWin.View.Next();
                    }
                    break;
                case "9"://按键明细查看键
                    if (!isPlay) return;
                    if (isNomalSlide) return;
                    if (!frmVoteBar.tsbVoteDetail.Enabled) return;
                    frmVoteBar.VoteBarChange(9);
                    break;
            }
        }
        /// <summary>
        /// 50R遥控。杨斌 2016-08-08
        /// </summary>
        void ARSRequest_ChairControl(string BaseTag, int KeyID, int ReqType, string ReqInfo)
        {
            ARSRequest_ChairControlSN(BaseTag, KeyID.ToString(), ReqType, ReqInfo);
        }

        private Timer tmrRunRemote = null;
        private void InitTmrRunRemote()
        {
            if (tmrRunRemote == null)
            {
                tmrRunRemote = new Timer();
                tmrRunRemote.Interval = 1;
                tmrRunRemote.Tick += new EventHandler(tmrRunRemote_Tick);
            }
        }
        void tmrRunRemote_Tick(object sender, EventArgs e)
        {
            tmrRunRemote.Stop();

            if (IsExitApp)//杨斌 2015-11-10
                return;
            
            switch (tmrRunRemote.Tag.ToString())
            {
                case "10"://随机点名 杨斌 2013-12-24
                    //if (!isPlay) return;
                    if (!frmVoteBar.tsbLuckyShow.Enabled) return;
                    frmVoteBar.tsbLuckyShow_Click(frmVoteBar.tsbLuckyShow, null);
                    break;
                case "12"://启动抢答 杨斌 2013-12-24
                    //if (!isPlay) return;
                    if (!frmVoteBar.tsbRushAnswer.Enabled) return;
                    frmVoteBar.tsbRushAnswer_Click(frmVoteBar.tsbRushAnswer, null);
                    break;
            }
        }

        #region VSTO 生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion


        /// <summary>
        /// 调用授权菜单
        /// </summary>
        /// <param name="Index"></param>
        public void ShowCanVoteSet(string cboValue)
        {
            TagSet tagSet = new TagSet();
            tagSet.Tags = Globals.SunVoteARSAddIn.PPTEdit.SlideEdit.Tags;
            switch (cboValue)
            {
                case "cvAll":
                    tagSet.SetValue(TagKey.ResponsePara_CanVote, cboValue);
                    break;
                case "cvPerson":
                    FrmCanVoteVoterGroup frmCanVoteVoterGroup = new FrmCanVoteVoterGroup();
                    frmCanVoteVoterGroup.ShowDialog();
                    if (frmCanVoteVoterGroup.DialogResult == DialogResult.OK)
                    {
                        tagSet.SetValue(TagKey.ResponsePara_CanVote, cboValue);
                        //tagSet.SetValue(TagKey.ResponsePara_CanVote,((ComboItem)cbo.Items[index]).EnumValue 
                    }
                    break;
                case "cvTopic":
                    FrmCanVoteSlideResult frmCanVoteSlideResult = new FrmCanVoteSlideResult();
                    frmCanVoteSlideResult.ShowDialog();
                    if (frmCanVoteSlideResult.DialogResult == DialogResult.OK)
                    {
                        tagSet.SetValue(TagKey.ResponsePara_CanVote, cboValue);

                    }
                    break;
                default:
                    break;
            }


        }
    }
}