FrmKeypadTest.cs 26.7 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
/*-------------------------------------------------------------------------------------------
 * 键盘测试窗体
 * 创建:赵丽 2011-11-30
 * 修改:杨斌 2012-03-01 控件布局,Esc退出
 * ----------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;
using Microsoft.Office.Interop.PowerPoint;
using GeneralLib;

namespace SunVoteARSPPT
{
    public partial class FrmKeypadTest : Form
    {
        public delegate void ShowSelfEvent();
        public event ShowSelfEvent ShowSelfEventHander;
        /// <summary>
        /// 坐席图对象
        /// </summary>
        Units Map;

        /// <summary>
        /// 是否正在测试
        /// </summary>
        bool IsStart;

        /// <summary>
        /// 键盘状态画刷:在线
        /// </summary>
        private Brush BrushOnline;

        /// <summary>
        /// 键盘状态画刷:不在线
        /// </summary>
        private Brush BrushOffline;

        /// <summary>
        /// 键盘状态画刷:弱电
        /// </summary>
        private Brush BrushELV;

        /// <summary>
        /// 在线的键盘集合,用于统计个数
        /// </summary>
        private StringCollection KeyOnline = new StringCollection();
        private SortedList<string, string> KeyTestList = null;

        private string[] PersonList = null;
        //private string[] KeyIDList=null;
        /// <summary>
        /// 弱电的键盘集合,用于统计个数
        /// </summary>
        private StringCollection KeyELV = new StringCollection();
        /// <summary>
        /// 是单基站模式显示单个
        /// </summary>
        public bool ShowSingle = false;

        private int KeyNum = 0;
        /// <summary>
        /// 基站编号
        /// </summary>
        public int BaseID = 1;
        public FrmKeypadTest()
        {
            InitializeComponent();
            btnKeypadTest.Tag = 0;
            cobTestType.SelectedIndex = 0;
            KeyTestList = new SortedList<string, string>();
            //GlobalInfo.hardwareManage.HardwareMonitorEvent += new HardwareMonitorEvent(HardwareMonitorEventHander);
            GlobalInfo.hardwareManage.KeyTestStatusEvent += new KeyTestStatusEvent(hardwareManage_KeyTestStatusEvent);
            GlobalInfo.hardwareManage.KeyMonitorStatusEvent += new KeyMonitorStatusEvent(hardwareManage_KeyMonitorStatusEvent);
            GlobalInfo.hardwareManage.ReadOnlyEvent += new ReadOnlyEvent(hardwareManage_ReadOnlyEvent);
            GlobalInfo.baseConnect.ResponseStateEvent += new ResponseStateEventHander(baseConnect_ResponseStateEvent);

            Roster.LoadRoster();//杨斌 2015-01-14

            InitMap();
        }

        void baseConnect_ResponseStateEvent(bool isResponse)
        {
            btnKeypadTest.Enabled = (!GlobalInfo.hardwareManage.ReadBaseInfo) && (!isResponse);
        }

        void hardwareManage_ReadOnlyEvent(bool ReadOnly)
        {
            //2012-05-02 断开基站,需要停止键盘测试
            if (Convert.ToInt32(btnKeypadTest.Tag) == 1)
                btnKeypadTest_Click(null, null);
            btnKeypadTest.Enabled = (!ReadOnly) && (!GlobalInfo.baseConnect.IsResponse);
            if (ReadOnly)
                ClearMap();
        }

        private void btnKeypadTest_Click(object sender, EventArgs e)
        {
            KeyTestList.Clear();
            if (Convert.ToInt32(btnKeypadTest.Tag) == 0)
            {
                ClearMap();
                btnKeypadTest.Tag = 1;

                GlobalInfo.hardwareManage.KeyNum = 0;
                GlobalInfo.hardwareManage.CheckBase = (cobBaseList.SelectedIndex == 0) ? "0" : cobBaseList.Text;
                if (cobTestType.SelectedIndex == 0)
                {
                    GlobalInfo.hardwareManage.HardwareTestMode = 0;
                    Map.IsShowData = true;//杨斌 2013-08-02
                }//开启硬件监控
                else
                {
                    GlobalInfo.hardwareManage.HardwareTestMode = 1;
                    Map.IsShowData = true;
                }//开启自动表决
                GlobalInfo.hardwareManage.HardwareTestEnable = true;
                System.Threading.Thread.Sleep(100);
                //清空键盘状态
                for (int i = 0; i < GlobalInfo.hardwareManage.KeyStatus.Count; i++)
                {
                    GlobalInfo.hardwareManage[i].InputStatus = -1;
                }

                cobBaseList.Enabled = false;
                cobTestType.Enabled = false;
                btnKeypadTest.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "btnKeypadTest_Stop", "停止测试");
            }
            else
            {
                //Map.IsShowData = false;
                btnKeypadTest.Tag = 0;
                //关闭硬件测试
                GlobalInfo.hardwareManage.HardwareTestEnable = false;
                System.Threading.Thread.Sleep(100);
                cobTestType.Enabled = true;
                cobBaseList.Enabled = true;
                btnKeypadTest.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "btnKeypadTest_Start", "开始测试");

                DrawMap();//杨斌 2013-06-18
                tmrMap.Enabled = false;
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 初始化坐席图
        /// 创建:杨斌 2010-07-14
        /// </summary>
        private void InitMap()
        {
            //初始化键盘状态画刷
            BrushOnline = new SolidBrush(pnlOnline.BackColor);
            BrushOffline = new SolidBrush(pnlOffline.BackColor);
            BrushELV = new SolidBrush(pnlELV.BackColor);
            List<int> keypads = new List<int>();
            //通过读取基站键盘范围来初始化坐席图单元。
            //int keyCount = GlobalInfo. - GlobalInfo.BaseInfo.MinKeypadID + 1;

            Map = new Units(this.picMap.ClientSize.Width, this.picMap.ClientSize.Height);
            int personNum = GlobalInfo.hardwareManage.PersonNum;
            if (EnableList)
            {
                PersonList = LoadPersonList();
                Array.Sort(PersonList);
                personNum = PersonList.Length;

            }//启用名单
            //编号先排序
            string[] KeyIDList = PublicFunction.KeyIDSort();
            //for (int i = 0; i < personNum; i++)//键盘数量=6000时,非常耗时。杨斌 2012-10-12
            //{
            //    Unit unit = new Unit();
            //    //键盘范围=参加投票的人数
            //    unit.ID = "";
            //    unit.Data = "";
            //    unit.Brush = BrushOffline;
            //    Map.Add(unit);
            //    if (EnableList)
            //    {
            //        Map[i].ID = PersonList[i].ToString();
            //    }//启用名单
            //    else
            //    {
            //        if (PersonNumEqualKeyNum)
            //        {
            //            //编号先排序
            //            //string[] KeyIDList = KeyIDSort();
            //            Map[i].ID = KeyIDList[i];
            //            //Map[i].ID = GlobalInfo.hardwareManage[i].KeyID.ToString();
            //        }
            //    }//未启用名单
            //}

            //将名单判断放到循环外面,提高速度。杨斌 2012-10-12
            if (EnableList)//启用名单
            {
                for (int i = 0; i < personNum; i++)
                {
                    Unit unit = new Unit();
                    //键盘范围=参加投票的人数
                    unit.ID = PersonList[i].ToString();
                    unit.Data = "";

                    //杨斌 2015-01-14
                    unit.Name = "";
                    if (unit.ID.Length > 0)
                    {
                        for (int n = 0; n < Roster.Rows.Count; n++)
                        {
                            if (Roster.Rows[n].Cells[0] == unit.ID)
                            {
                                unit.Name = Roster.Rows[n].Cells[1];
                                break;
                            }
                        }
                    }

                    unit.Brush = BrushOffline;
                    Map.Add(unit);
                }
            }
            else//未启用名单
            {
                if (PersonNumEqualKeyNum)//设置人数与有效范围个数正好相同
                {
                    for (int i = 0; i < personNum; i++)
                    {
                        Unit unit = new Unit();
                        //键盘范围=参加投票的人数
                        unit.ID = KeyIDList[i];
                        unit.Data = "";
                        unit.Brush = BrushOffline;
                        Map.Add(unit);
                    }
                }
                else
                {
                    for (int i = 0; i < personNum; i++)
                    {
                        Unit unit = new Unit();
                        //键盘范围=参加投票的人数
                        unit.ID = "";
                        unit.Data = "";
                        unit.Brush = BrushOffline;
                        Map.Add(unit);
                    }
                }
            }

            Map.Sort();//杨斌 2013-06-18

            //FrmKeypadTest_Resize(null, null);

            labCount.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "labCount", "键盘总数:") + Map.Count;
        }

        public RosterList Roster = new RosterList();//杨斌 2015-01-14

        /// <summary>
        /// 加载人员名单
        /// </summary>
        public string[] LoadPersonList()
        {
            string[] personList = null;
            try
            {

                //获取所有名单的键盘ID
                string sSql = "select a.* from ST_RosterValue a,ST_RosterColumn b where a.RC_ID=b.RC_ID and b.RC_Index=1";
                DataSet ds = null;
                ds = GlobalInfo.DBOperation.OpenDataSet(sSql);
                personList = new string[ds.Tables[0].Rows.Count];
                if (ds.Tables[0].Rows.Count == 0) { return personList; }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string keypadID = ds.Tables[0].Rows[i]["RV_Text"].ToString();
                    personList[i] = keypadID;//杨斌 2015-01-14
                }
                return personList;
            }
            catch (Exception ex)
            {
                return personList;
            }

        }


        /// <summary>
        /// 更新键盘状态:在线、不在线、弱电
        /// </summary>
        private void ShowKeyState()
        {
            lblOnline.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblOnline", "在线:") + (KeyOnline.Count + KeyELV.Count).ToString();
            lblOffline.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblOffline", "不在线:") + (Map.Count - KeyOnline.Count - KeyELV.Count).ToString();
            lblELV.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblELV", "弱电:") + KeyELV.Count.ToString();

        }

        private void FrmKeypadTest_Load(object sender, EventArgs e)
        {
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);

            cobTestType.SelectedIndex = 0;
            if (cobBaseList.Items.Count > 0)
                cobBaseList.SelectedIndex = 0;
            btnKeypadTest.Enabled = (!GlobalInfo.hardwareManage.ReadBaseInfo) && (!GlobalInfo.baseConnect.IsResponse);
            GlobalInfo.hardwareManage.HardwareTestStarMode = 1;
            if (SystemConfig.MultiBase == 0)
            {
                lblBaseList.Visible = false;
                cobBaseList.SelectedIndex = -1;
                cobBaseList.Visible = false;
                pnlCtrl.Visible = true;
            }
            else
            {
                lblBaseList.Visible = true;
                cobBaseList.Visible = true;
                cobBaseList.Items.Clear();
                cobBaseList.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "cobBaseList", "所有基站"));
                for (int i = 0; i < GlobalInfo.baseConnect.BaseList.Count; i++)
                {
                    if (GlobalInfo.baseConnect[i].BaseConnectStatus == BasePara.ConnectStatus.csSuccess)
                    {
                        cobBaseList.Items.Add(GlobalInfo.baseConnect[i].BaseID.ToString());
                    }
                }
                cobBaseList.SelectedIndex = 0;
            }
            FrmKeypadTest_Resize(null, null);
            ShowKeyState();

            //杨斌 2015-03-13
            if (GlobalInfo.GetSdkType() == 1)
            {
                lblTestType.Visible = cobTestType.Visible = false;
            }
            //tmrMap.Elapsed += tmrMap_Elapsed;
            tmrMap.Tick += tmrMap_Tick;

            //陈总说的,打开窗体即启动扫描 杨斌 2012-03-12
            if (!GlobalInfo.hardwareManage.ReadBaseInfo)
                btnKeypadTest_Click(null, null);

            //杨斌 2012-06-11
            switch (GlobalInfo.OEMLogo)
            {
                case OEMLogos.oem3eAnalyzer:
                    lblTestType.Visible = false;
                    cobTestType.Visible = false;
                    break;
                case OEMLogos.SunVote:
                default:
                    break;
            }
        }

        /// <summary>
        /// 改变坐席图单元状态
        /// 创建:杨斌 2013-06-18
        /// </summary>
        /// <param name="KeyID"></param>
        /// <param name="BrushVal"></param>
        /// <param name="sData"></param>
        private void ChangeMap(string BaseID, string KeyID, string sData, Brush BrushVal, bool ShowData)
        {
            //判断扫描查询的基站 
            if ((GlobalInfo.baseConnect.MultiBase == 1) && (cobBaseList.SelectedIndex > 0) && (cobBaseList.Text != BaseID.ToString())) { return; }

            //启用名单以名单为主
            if (EnableList)
            {
                //if (!PersonList.Contains<int>(KeyID))
                //    return;
                if (!Map.Contains(KeyID.ToString()))
                    return;
            }
            else
            {
                if (KeyTestList.Count > GlobalInfo.hardwareManage.PersonNum)//达到指定键盘数量,不做处理
                    return;
                if (!GlobalInfo.hardwareManage.JudgeKeyStatus(KeyID))
                    return;
            }

            if (KeyTestList.ContainsKey(KeyID))
                KeyTestList[KeyID] = sData;
            else
                KeyTestList.Add(KeyID, sData);

            string sID = KeyID.ToString();
            Unit u = null;
            if (!Map.Contains(sID))
            {
                if (Map.CountNoID > 0)
                {
                    u = Map[""];
                    Map.RemoveAt(Map.CountHaveID);//移除没有ID的单元           
                    u.ID = sID;
                    Map.Add(u);
                }
            }
            else
            {
                u = Map[sID];
            }
            if (u != null)
            {
                u.Brush = BrushVal;
                u.Data = sData;
            }

            //杨斌 2015-03-13                
            tmrMap.Interval = 200;
            tmrMap.Enabled = true;
        }

        //void tmrMap_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        void tmrMap_Tick(object sender, EventArgs e)
        {
            tmrMap.Enabled = false;
            DrawMap();//杨斌 2013-06-18
            if (!GlobalInfo.hardwareManage.HardwareTestEnable)
                return;
            tmrMap.Enabled = true;
        }

        /// <summary>
        /// 杨斌 2015-03-13
        /// </summary>
        //System.Timers.Timer tmrMap = new System.Timers.Timer();
        System.Windows.Forms.Timer tmrMap = new System.Windows.Forms.Timer();

        /// <summary>
        /// 刷新坐席图和统计值:在开始清空时,数据改变时,停止时,坐席图滚动条滚动时
        /// 创建:杨斌 2013-06-18
        /// </summary>
        private void DrawMap()
        {
            TimerCount t = new TimerCount();
            t.StartCount();

            if (picMap.IsDisposed) return;

            //需要排序和重新布局
            if ((!PersonNumEqualKeyNum) && (!EnableList))
            {
                Map.Sort();
                InitMapLayoutAtuo();
            }

            Map.DrawVisibleUnits(picMap, pnlMapBack);
            //Map.DrawVisibleUnits(picMap, picMap.Parent);
            SetBitmap();

            int onLineKeyNum = GetOnLineNum();
            RefreshLable(onLineKeyNum);

            button1.Text = t.GetCountMS().ToString();
        }

        /// <summary>
        /// 刷新标签,在线个数
        /// </summary>
        /// <param name="onLineCount"></param>
        private void RefreshLable(int onLineKeyNum)
        {
            lblOnline.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblOnline", "在线:") + onLineKeyNum.ToString();
            lblOffline.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblOffline", "不在线:") + (Map.Count - onLineKeyNum - GetELVNum()).ToString();
            lblELV.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblELV", "弱电:") + GetELVNum().ToString();
        }

        /// <summary>
        /// 是否启用名单,初始化时调用一次,避免受到按键值时判断增加时间,影响速度
        /// 杨斌 2013-06-14
        /// </summary>
        private bool EnableList = GlobalInfo.response.EnableList;
        /// <summary>
        /// 判断键盘数量是否正好等于范围,初始化时调用一次,避免受到按键值时判断增加时间,影响速度
        /// 杨斌 2013-06-14
        /// </summary>
        private bool PersonNumEqualKeyNum = GlobalInfo.hardwareManage.PersonNumEqualKeyNum();

        /// <summary>
        /// 键盘监控触发事件
        /// </summary>
        /// <param name="KeyResponsStatiusObj"></param>
        void hardwareManage_KeyMonitorStatusEvent(int BaseID, string KeyID, double BatteryVoltage)
        {
            Brush BrushVal = null;
            if (BatteryVoltage < GlobalInfo.hardwareManage.Voltage)
                BrushVal = BrushELV;
            else
                BrushVal = BrushOnline;
            ChangeMap(BaseID.ToString(), KeyID.ToString(), BatteryVoltage.ToString(), BrushVal, false);
        }

        /// <summary>
        /// 自动表决触发事件
        /// </summary>
        /// <param name="BaseTag"></param>
        /// <param name="KeyID"></param>
        /// <param name="KeyValue"></param>
        void hardwareManage_KeyTestStatusEvent(string BaseTag, string KeyID, string KeyValue)
        {
            ChangeMap(BaseTag, KeyID, KeyValue, BrushOnline, true);
        }

        /// <summary>
        /// 坐席图重新布局
        /// 创建:杨斌 2013-06-18
        /// </summary>
        private void InitMapLayoutAtuo_old()
        {
            Map.IsShowData = true;//杨斌 2013-08-02

            int count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 2000;//自动根据面积计算个数 杨斌 2010-01-06

            //杨斌 2012-10-15
            if (cobTestType.SelectedIndex == 1)//自动表决测试
            {
                count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 2000;
            }
            else
            {
                //杨斌 2012-10-15
                if (Map.Count > 500)
                    count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 1500;
                else
                    count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 2000;
            }

            if (count < 5) count = 5;
            Map.InitUnitsLayoutAtuo(count, picMap.ClientSize.Width, pnlMapBack.ClientSize.Height, picMap);
            //picMap.CreateGraphics().Clear(picMap.BackColor);//先清空避免尺寸改变时难看
        }

        /// <summary>
        /// 坐席图重新布局
        /// 创建:杨斌 2015-09-17
        /// </summary>
        private void InitMapLayoutAtuo()
        {
            Map.IsShowData = true;//杨斌 2013-08-02

            int count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 4500;//自动根据面积计算个数 杨斌 2010-01-06

            //杨斌 2012-10-15
            if (cobTestType.SelectedIndex == 1)//自动表决测试
            {
                count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 5000;
            }
            else
            {
                //杨斌 2012-10-15
                if (Map.Count > 500)
                    count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 4500;
                else
                    count = picMap.ClientSize.Width * pnlMapBack.ClientSize.Height / 5000;
            }

            if (count < 5) count = 5;
            Map.InitUnitsLayoutAtuo(count, picMap.ClientSize.Width, pnlMapBack.ClientSize.Height, picMap, 1);
            //picMap.CreateGraphics().Clear(picMap.BackColor);//先清空避免尺寸改变时难看
        }

        private void FrmKeypadTest_Resize(object sender, EventArgs e)
        {
            if (Map == null)
            {
                InitMap();
            }
            try
            {
                InitMapLayoutAtuo();//杨斌 2013-06-18

                DrawMap();//杨斌 2013-06-18
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex);
            }
        }

        /// <summary>
        /// 设置坐席图图片
        /// 创建:杨斌 2010-07-14
        /// </summary>
        private void SetBitmap()
        {
            try
            {
                if (picMap.IsDisposed) return;
                this.picMap.BackgroundImage = Map.Bitmap;
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex);
            }
        }

        private void pnlStatuTag_Click(object sender, EventArgs e)
        {
            if (!(this.Parent == null))
            {
                ShowSelfEventHander();
            }
        }

        private void FrmKeypadTest_FormClosed(object sender, FormClosedEventArgs e)
        {
            //停止键盘测试
            GlobalInfo.hardwareManage.HardwareTestEnable = false;
        }

        /// <summary>
        /// 清空键盘面板信息
        /// </summary>
        private void ClearMap()
        {
            Graphics gc = picMap.CreateGraphics();
            if ((!PersonNumEqualKeyNum) && (!EnableList))
            {
                List<Unit> LstU = new List<Unit>();
                for (int i = 0; i < Map.Count; i++)
                {
                    Map[i].ID = "";
                    Map[i].Data = "";
                    Map[i].Brush = BrushOffline;
                    Map[i].LineColor = Color.Red;
                    Map[i].LineBroad = 1;
                    LstU.Add(Map[i]);
                }
                Map.Clear();
                for (int i = 0; i < LstU.Count; i++)
                {
                    Map.Add(LstU[i]);
                }
            }
            else
            {
                for (int i = 0; i < Map.Count; i++)
                {
                    Map[i].Data = "";
                    Map[i].Brush = BrushOffline;
                    Map[i].LineColor = Color.Red;
                    Map[i].LineBroad = 1;
                }
            }

            DrawMap();//杨斌 2013-06-18

            lblOnline.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblOnline", "在线:") + "0";
            lblOffline.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblOffline", "不在线:") + Map.Count.ToString();
            lblELV.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "lblELV", "弱电:") + "0";
            //杨斌 2015-01-16
            labCount.Text = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "labCount", "键盘总数:") + Map.Count;
        }

        /// <summary>
        /// 获得在线数量
        /// </summary>
        /// <returns></returns>
        private int GetOnLineNum()
        {
            int iNum = 0;
            for (int i = 0; i < Map.Count; i++)
            {
                if (Map[i].Brush == BrushOnline)
                    iNum += 1;
            }
            return iNum;
        }

        /// <summary>
        /// 获得弱电数量
        /// </summary>
        /// <returns></returns>
        private int GetELVNum()
        {
            int iNum = 0;
            for (int i = 0; i < Map.Count; i++)
            {
                if (Map[i].Brush == BrushELV)
                    iNum += 1;
            }
            return iNum;
        }

        private void picMap_DoubleClick(object sender, EventArgs e)
        {
            if (this.WindowState == System.Windows.Forms.FormWindowState.Maximized)
                this.WindowState = System.Windows.Forms.FormWindowState.Normal;
            else
                this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }

        private void pnlMapBack_Scroll(object sender, ScrollEventArgs e)
        {
            DrawMap();//杨斌 2013-06-18
        }

        //杨斌 2012-10-15
        private void cobTestType_SelectedIndexChanged(object sender, EventArgs e)
        {
            FrmKeypadTest_Resize(null, null);
        }

        int testCnt = 2000;
        private void button1_Click(object sender, EventArgs e)
        {
            //TimerCount t = new TimerCount();
            //t.StartCount();

            Map.IsShowData = (cobTestType.SelectedIndex == 1);//YB 2013-06-18
            //Map.IsShowData = true;

            KeyTestList.Clear();
            ClearMap();

            //t.StartCount();            
            //for (int i = 0; i < Map.Count; i++)
            //{
            //    Map[i].Brush = BrushOffline;
            //    Map[i].Data = "";
            //}
            Random rd = new Random();
            for (int i = 1; i <= testCnt; i++)
            {
                if (cobTestType.SelectedIndex == 0)
                    hardwareManage_KeyMonitorStatusEvent(1, i.ToString(), 2 + rd.NextDouble());
                else
                    hardwareManage_KeyTestStatusEvent("1", i.ToString(), ((int)(rd.NextDouble() * 3 + 1)).ToString());
            }

            //DrawMap();

            if (testCnt == 2000)
                testCnt = 1;
            else
                testCnt = 2000;

            //button1.Text = t.GetCountMS().ToString();
        }


    }
}