FrmLineStore.cs 28.0 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
using log4net;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OnlineStore.AssemblyLine
{
    internal partial class FrmLineStore : Form
    {

        internal static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private LineBean lineBean = null;
        private List<TabPage> tabPageList = new List<TabPage>();
        private bool LoadOk = false;
        private System.Timers.Timer startTimer = null;
        internal FrmLineStore()
        {
            InitializeComponent();
            LogUtil.logBox = this.logBox;
            startTimer = new System.Timers.Timer();
            startTimer.Interval = 1000;
            startTimer.Enabled = false;
            startTimer.AutoReset = false;
        }

        private void LoadStoreData()
        {

            lineBean = LineManager.Line;
            if (lineBean == null)
            {
                Application.Exit();
            }

            FrmIOStatus ioStatus = new FrmIOStatus();
            AddForm("流水线IO  ", ioStatus);
          
            List<MoveEquip> moveEquipList = new List<MoveEquip>(lineBean.MoveEquipMap.Values);
            for (int i = 0; i < moveEquipList.Count; i++)
            {
                MoveEquip equip = moveEquipList[i];
                FrmMoveEquip test = new FrmMoveEquip(equip);
                AddForm(" " + equip.Name, test); 
            }
            List<FeedingEquip> feeds = new List<FeedingEquip>(lineBean.FeedingEquipMap.Values);
            for (int i = 0; i < feeds.Count; i++)
            {
                FeedingEquip feed = feeds[i];
                FrmFeedingEquip test = new FrmFeedingEquip(feed);
                AddForm(" " + feed.Name+ " ", test); 
            }
            List<ProvidingEquip> provids = new List<ProvidingEquip>(lineBean.ProvidingEquipMap.Values);
            for (int i = 0; i < provids.Count; i++)
            {
                ProvidingEquip provid = provids[i];
                FrmProvidingEquip test = new FrmProvidingEquip(provid);
                AddForm(" " + provid.Name + " ", test); 
            }

            List<DischargeLine> diss = new List<DischargeLine>(lineBean.DisLineMap.Values);
            for(int i = 0; i < diss.Count; i++)
            {
                DischargeLine line = diss[i];
                FrmDischargeLine frm = new FrmDischargeLine(line);
                AddForm(" " + line.Name + " ", frm);
            }

            lblCID.Text = ConfigAppSettings.GetValue(Setting_Init.Line_CID);
             
        }
        private void AddForm(string text, Form form)
        {
            text = text.PadLeft(10, ' ');
            TabPage lineTabPage = new TabPage(text);
           // lineTabPage.AutoScroll = true;
            lineTabPage.Tag = lineBean;
            Panel linePan = new Panel();
            linePan.Dock = DockStyle.Fill;
            linePan.AutoScroll = true;
            lineTabPage.Controls.Add(linePan);
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            linePan.Controls.Add(form);
            form.Dock = DockStyle.Fill;
            linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
            form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
            form.Show();
            tabPageList.Add(lineTabPage);
            tabControl1.Controls.Add(lineTabPage);
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
            FrmBase.GetVersion(true); 
            if (!LineManager.Init())
            {
                LogUtil.error("加载配置失败,直接退出程序");
                Application.Exit();
            }

            formLineStatus(false);
            string title = ConfigAppSettings.GetValue(Setting_Init.App_Title);
            this.Text = title;
            this.notifyIcon1.Text = title;
            int autoValue = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun);
            chbAutoRun.Checked = autoValue.Equals(1);

            LoadStoreData();
            LoadListView();
             
            托盘初始化ToolStripMenuItem.Visible = ConfigAppSettings.GetIntValue(Setting_Init.OpenRFIDWrite).Equals(1);
            LoadOk = true;
            HideForm();
            timer1.Start();
        }

        private void LoadListView()
        {
            this.listView1.Columns.Clear();
            AddHealder("设备名称", 100);
            AddHealder("启用", 40);
            AddHealder("报警", 100); 
            AddHealder("状态", 100);
            AddHealder("BOX_CID", 80);
            AddHealder("BOX报警", 100);
            AddHealder("更新时间", 80);
            AddHealder("BOX状态", 100);
            //AddHealder("BOX状态", listView1.Size.Width - 100 - 80 - 80 - 100 - 100 - 100 -40- 8);
            foreach (MoveEquip move in lineBean.MoveEquipMap.Values)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = move.Name;
                lvi.SubItems.Add(move.Config.IsDebug.Equals(1) ? "✘" : "✔");
                lvi.SubItems.Add(move.alarmType.ToString());
                //   lvi.SubItems.Add(move.lineStatus.ToString());
                lvi.SubItems.Add(KTK_Store.GetRunStr(move.lineStatus, move.runStatus));
                BoxInfo box = LineServer.GetBoxInfo(move.DeviceID);
                if (box != null)
                {
                    lvi.SubItems.Add(box.CId.ToString());  
                    lvi.SubItems.Add(box.SAlarmType.ToString());
                    lvi.SubItems.Add(box.LastMsgTime.ToLongTimeString());
                    lvi.SubItems.Add(box.ToShowStr());
                }
                else
                {
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add("");
                }
                this.listView1.Items.Add(lvi);
            }
            ListViewItem emptyView = new ListViewItem();
            this.listView1.Items.Add(emptyView);
            foreach (FeedingEquip equip in lineBean.FeedingEquipMap.Values)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = equip.Name;
                lvi.SubItems.Add(equip.alarmType.ToString());
                lvi.SubItems.Add(KTK_Store.GetRunStr(equip.lineStatus, equip.runStatus)); 
                this.listView1.Items.Add(lvi);
            }
             
            this.listView1.Items.Add((ListViewItem)emptyView.Clone());
            foreach (ProvidingEquip equip in lineBean.ProvidingEquipMap.Values)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = equip.Name;
                lvi.SubItems.Add(equip.alarmType.ToString());
                lvi.SubItems.Add(KTK_Store.GetRunStr(equip.lineStatus, equip.runStatus));
                this.listView1.Items.Add(lvi);
            }
            this.listView1.Items.Add((ListViewItem)emptyView.Clone());
            foreach (DischargeLine equip in lineBean.DisLineMap.Values)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = equip.Name;
                lvi.SubItems.Add(equip.alarmType.ToString()); 
                lvi.SubItems.Add(KTK_Store.GetRunStr(equip.lineStatus, equip.runStatus));
                this.listView1.Items.Add(lvi);
            }
            cmbBoxIndex.Items.Clear();
            foreach(int key in lineBean.MoveEquipMap.Keys)
            {
                cmbBoxIndex.Items.Add("BOX-" + key);

            }
            if (cmbBoxIndex.Items.Count > 0)
            {
                cmbBoxIndex.SelectedIndex = 0;
            }
        }
        private void AddHealder(string name, int widht)
        {
            ColumnHeader preSendwire = new ColumnHeader();
            preSendwire.Text = name;   //设置列标题
            preSendwire.Width = widht;    //设置列宽度
            preSendwire.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            this.listView1.Columns.Add(preSendwire);    //将列头添加到ListView控件。
        }
        /// <summary>
        /// 隐藏窗口
        /// </summary>
        private void HideForm()
        {
            this.Opacity = 0;
            this.ShowInTaskbar = false;
            this.notifyIcon1.Visible = true;
            this.Hide();
            GC.Collect();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                this.contextMenuStrip1.Show();
            }
            if (e.Button == MouseButtons.Left)
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Maximized;
                this.ShowInTaskbar = true;
            }
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生           
            {
                e.Cancel = true;
                HideForm();
            }
        } 

        private void ExitApp()
        {
            DialogResult result = MessageBox.Show("是否确定退出流水线客户端?", "提示", MessageBoxButtons.YesNo);
            if (result.Equals(DialogResult.Yes))
            {
                //如果料仓还在运行状态,先关闭料仓
                if (!lineBean.runStatus.Equals(LineRunStatus.Wait))
                {
                    LogUtil.info(LOGGER, "退出程序之前先停止运行 ");
                    lineBean.StopRun();
                }

                //  IOManager.instance.CloseAllDO();
                IOManager.instance.CloseAllConnection();
                //AIManager.CloseConnect();
                ACServerManager.CloseAllPort();
                // CodeManager.CloseAllCamera();
                RFIDManager.RfidReader.Close();
                //this.Close();
                System.Environment.Exit(System.Environment.ExitCode);
            }
        }
        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FrmPwd fw = new FrmPwd(10);
                DialogResult result = fw.ShowDialog();
                if (!result.Equals(DialogResult.OK))
                {
                    LogUtil.info("切换界面显示时,没有正确输入密码");
                    return;
                }

                this.Opacity = 100;
                this.Visible = true;
                this.WindowState = FormWindowState.Maximized;
                this.notifyIcon1.Visible = false;
                this.ShowInTaskbar = true;
            }
            catch (Exception ex)
            {
                LogUtil.error("显示界面出错:" + ex.ToString());
            }
        }

        private void 启动所有料仓AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lineBean.runStatus != LineRunStatus.Wait)
            {
                MessageBox.Show(lineBean.Name + "当前状态:" + lineBean.runStatus + ",不能启动!");
                return;
            }
            LogUtil.info(LOGGER, "开始启动");
            startTimer.Interval = 300;
            startTimer.Elapsed += timer_Elapsed;
            startTimer.Enabled = true;
            this.timer1.Start();
        }
        private delegate void ShowFormDelegate();
        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            startTimer.Enabled = false;
            if (lineBean.StartRun())
            {
                BeginInvoke(new ShowFormDelegate(ShowStatus));
            }
        }
        private void ShowStatus()
        {
            formLineStatus(true);
        }

        private void formLineStatus(bool isStart)
        {
            foreach (TabPage tab in tabPageList)
            {
                bool find = false;
                foreach (Control control in tab.Controls)
                {
                    if (control is Panel)
                    {
                        foreach (Control con in control.Controls)
                        {
                            if (con is FrmMoveEquip)
                            {
                                FrmMoveEquip frm = (FrmMoveEquip)con;
                                frm.FormStatus(isStart);
                                find = true;
                                break;
                            }

                        }
                    }
                    if (find)
                    {
                        break;
                    }
                }
            }
            启动AToolStripMenuItem.Enabled = !isStart;
            停止TToolStripMenuItem.Enabled = isStart;

        }
        private void 停止所有料仓TToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lineBean != null)
            {
                if (lineBean.runStatus.Equals(LineRunStatus.Wait))
                {
                    MessageBox.Show(lineBean.Name + "流水线未启动,不需要停止");
                    return;
                }
                if (lineBean != null)
                {
                    lineBean.StopRun();
                }
                formLineStatus(false);
            }
        }

        private void 复位RToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lineBean.runStatus.Equals(LineRunStatus.Wait))
            {
                MessageBox.Show(lineBean.Name + "流水线未启动,无法复位");
                return;
            }
            lineBean.Reset();
        }
        private void FrmLineStore_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (停止TToolStripMenuItem.Enabled)
            {
                停止所有料仓TToolStripMenuItem_Click(null, null);
            }
        }
        private void btnClearLog_Click(object sender, EventArgs e)
        {
            logBox.Clear(); 
        }

        private void debug_enable_checkBox_CheckedChanged(object sender, EventArgs e)
        {
            LogUtil.debug_opened = chkDebug.Checked;
        }

        private void btnCopyLog_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(logBox.Text);
            MessageBox.Show("已复制日志到粘贴板!");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                return;
            }
            string canScanCode = "";
            if (lineBean.lineStatus.Equals(LineStatus.StoreOnline) && lineBean.runStatus.Equals(LineRunStatus.Runing))
            {
                canScanCode = lineBean.CanScanCode() ? "(可扫码入库)" : "(出库未完成,不可扫码入库)";
            }
            lblStatus.Text = KTK_Store.GetRunStr(lineBean.lineStatus, lineBean.runStatus)+canScanCode;
            lblWarnMsg.Text = LineManager.Line.WarnMsg;
            //if (lineBean.isNotScanCode && lblWarnMsg.Text.Equals(""))
            //{
            //    lblWarnMsg.Text = "未扫到二维码,请重新放入料盘";
            //}
            lblMoveInfo.Text = LineManager.Line.GetMoveStr();
            if (lblWarnMsg.Text.Equals(""))
            {
                lblWarnMsg.Text = TrayManager.TrayErrorMsg;
            }
            if (lblWarnMsg.Text.Equals(""))
            {
                foreach (EquipBase move in lineBean.AllEquipMap.Values)
                {
                    if (move.WarnMsg.Equals("").Equals(false))
                    {
                        lblWarnMsg.Text = move.WarnMsg;
                        break;
                    }
                }
            }
            int i = 0;

            int item_debug_index = 1;
            int item_alarm_index = 2;
            int item_runStr_index = 3;
            int item_cid_index = 4;
            int item_SAlarmType_index = 5;
            int item_LastMsgTime_index = 6;
            int item_BoxStr_index =7;
            foreach (MoveEquip move in lineBean.MoveEquipMap.Values)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = move.Name;
                SetItemText(i, item_debug_index, move.Config.IsDebug.Equals(1) ? "✘" : "✔");
                SetItemText(i, item_alarm_index, move.alarmType.ToString()); 
                SetItemText(i, item_runStr_index, KTK_Store.GetRunStr(move.lineStatus, move.runStatus));
                BoxInfo box = LineServer.GetBoxInfo(move.DeviceID);
                if (box != null)
                {
                    SetItemText(i, item_cid_index, box.CId.ToString());
                    SetItemText(i, item_SAlarmType_index, box.SAlarmType.ToString());
                    SetItemText(i, item_LastMsgTime_index, box.LastMsgTime.ToLongTimeString());
                    SetItemText(i, item_BoxStr_index, box.ToShowStr()); 
                }
                SetItemColor(i,move.runStatus); 
                i++;
            }
            i++;
            foreach (FeedingEquip equip in lineBean.FeedingEquipMap.Values)
            {
                SetItemText(i, item_debug_index, equip.Config.IsDebug.Equals(1) ? "✘" : "✔");
                SetItemText(i, item_alarm_index, equip.alarmType.ToString());
                SetItemText(i, item_runStr_index, KTK_Store.GetRunStr(equip.lineStatus, equip.runStatus));
                SetItemColor(i, equip.runStatus);
                i++;
            }
            i++;
            foreach (ProvidingEquip equip in lineBean.ProvidingEquipMap.Values)
            {
                SetItemText(i, item_debug_index, equip.Config.IsDebug.Equals(1) ? "✘" : "✔");
                SetItemText(i, item_alarm_index, equip.alarmType.ToString());
                SetItemText(i, item_runStr_index, KTK_Store.GetRunStr(equip.lineStatus, equip.runStatus));
                SetItemColor(i, equip.runStatus);
                i++;
            }
            i++;
            foreach (DischargeLine equip in lineBean.DisLineMap.Values)
            {
                SetItemText(i, item_debug_index, equip.Config.IsDebug.Equals(1) ? "✘" : "✔");
                SetItemText(i, item_alarm_index, equip.alarmType.ToString());
                SetItemText(i, item_runStr_index, KTK_Store.GetRunStr(equip.lineStatus, equip.runStatus));
                SetItemColor(i, equip.runStatus);
                i++;
            }
            if (lineBean.runStatus > LineRunStatus.Wait)
            {
                if (启动AToolStripMenuItem.Enabled.Equals(true))
                {
                    formLineStatus(true);
                } 
                if ((lineBean.runStatus.Equals(LineRunStatus.HomeMoving) || lineBean.runStatus.Equals(LineRunStatus.Reset))
                    && lineBean.alarmType.Equals(LineAlarmType.None))
                {
                    SetMenuS(复位RToolStripMenuItem, false);
                    SetMenuS(启动AToolStripMenuItem, false);
                }
                else
                {
                    SetMenuS(复位RToolStripMenuItem, true);
                } 
            }
            else
            {
                SetMenuS(启动AToolStripMenuItem, true);
                SetMenuS(复位RToolStripMenuItem, false);
                SetMenuS(停止TToolStripMenuItem, false);
            }
        }
       
        private void  SetItemColor(int i, LineRunStatus runStatus)
        {
            if (runStatus.Equals(LineRunStatus.Wait))
            {
                SetItemColor(i, Color.White);
                //listView1.Items[i].BackColor = Color.White;
            }
            else if (runStatus.Equals(LineRunStatus.HomeMoving) || runStatus.Equals(LineRunStatus.Reset))
            {
                SetItemColor(i, Color.Orange);
            }
            else if (runStatus.Equals(LineRunStatus.Busy))
            {
                SetItemColor(i, Color.Green);
            }
            if (runStatus.Equals(LineRunStatus.Runing))
            {
                SetItemColor(i, Color.LightBlue);
            } 
        }

        private void SetMenuS(ToolStripMenuItem toolMenu,bool isEn)
        {
            if (!toolMenu.Enabled.Equals(isEn))
            {
                toolMenu.Enabled = isEn;
            }
        }
        private void SetItemColor(int i,Color color)
        {
            if (!listView1.Items[i].BackColor.Equals(color))
            {
                listView1.Items[i].BackColor = color;
            }
        }
        private void SetItemText(int rowIndex, int subIndex, string value)
        {
            if (this.listView1.Items[rowIndex].SubItems.Count > subIndex)
            {
                if (!this.listView1.Items[rowIndex].SubItems[subIndex].Text.Equals(value))
                {
                    this.listView1.Items[rowIndex].SubItems[subIndex].Text = value;
                }
            }
        } 
        private void chbAutoRun_CheckedChanged(object sender, EventArgs e)
        {
            if (!LoadOk)
            {
                return;
            }
            if (chbAutoRun.Checked)
            {
                ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 1);
                ManagerUtil.AutoRun(Application.ExecutablePath, true);
            }
            else
            {
                ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 0);
                ManagerUtil.AutoRun(Application.ExecutablePath, false);
            }
        }

        private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            Font fntTab;
            Brush bshBack;
            Brush bshFore;
            if (e.Index == this.tabControl1.SelectedIndex)
            {
                fntTab = new Font(e.Font, FontStyle.Regular);
                bshBack = new SolidBrush(Color.DodgerBlue);
                bshFore = Brushes.Black;
            }
            else
            {
                fntTab = e.Font;
                bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.White, Color.White, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
                bshFore = new SolidBrush(Color.Black);
            }
            string tabName = this.tabControl1.TabPages[e.Index].Text;
            StringFormat sftTab = new StringFormat();
            e.Graphics.FillRectangle(bshBack, e.Bounds);
            Rectangle recTab = e.Bounds;
            recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
            e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
        }

        private void 版本号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAbout about = new FrmAbout();
            about.ShowDialog();
        }

        private void 扫码测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
        //lineBean. GetCameraCode();
            //List<string> codes = CodeManager.CameraScan();
            //string result = "";
            //foreach (string s in codes)
            //{
            //    result += s + "\r\n";
            //}
            //LogUtil.info("扫到二维码:" + result);
        }

        private void 二维码学习ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CodeLibrary.FrmCodeDecode frm = new CodeLibrary.FrmCodeDecode();
            frm.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LineServer.StartServer(ConfigAppSettings.GetIntValue(Setting_Init.TCPServerPort));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            LineServer.StopServer();
        }

        private void 退出ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            LogUtil.info("点击:退出系统");
            ExitApp();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ExitApp();
        }

        private void btnInStoreTset_Click(object sender, EventArgs e)
        {
            if (LineServer.IsStart)
            {
                int index = cmbBoxIndex.SelectedIndex + 1;
                string posId = txtPosId.Text.Trim();
                if (String.IsNullOrEmpty(posId))
                {
                    MessageBox.Show("请输入正确的库位号");
                    txtPosId.Focus();
                    return;
                }
                LineServer.StartInStore(index, new InOutParam(0, "", posId,0,0));
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnUpdateStatus.Visible = false;
            if (listView1.SelectedItems != null && listView1.SelectedItems.Count > 0)
            {
                int index = listView1.SelectedItems[0].Index;

                string name = listView1.Items[index].SubItems[0].Text;
                name = "BOX-" + (index + 1);
                BoxInfo boxInfo = LineServer.GetBoxInfo(index + 1);
                if (boxInfo != null&&boxInfo.SRunStatus>=1)
                {
                    if (boxInfo.SStatus.Equals((int)LineStatus.Debugging))
                    {
                        btnUpdateStatus.Text = "更改[" + name + "]为工作状态";
                    }
                    else
                    { 
                        btnUpdateStatus.Text = "更改[" + name + "]为调试状态";
                    }
                    btnUpdateStatus.Visible = true;
                }
            } 
        }

        private void btnUpdateStatus_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems != null && listView1.SelectedItems.Count > 0)
            {
                int index = listView1.SelectedItems[0].Index;

                string name = "BOX-" + (index + 1);
                BoxInfo boxInfo = LineServer.GetBoxInfo(index + 1);
                if (boxInfo != null && boxInfo.SRunStatus >= 1)
                {
                    if (boxInfo.SStatus.Equals((int)LineStatus.Debugging))
                    {
                        LogUtil.info("点击【  更改[" + name + "]为工作状态 】");
                        LineServer.UpdateBoxDebug(boxInfo.ID, 0);
                    }
                    else
                    {
                        LogUtil.info("点击【  更改[" + name + "]为调试状态 】"); 
                        LineServer.UpdateBoxDebug(boxInfo.ID, 1);
                    }
                    btnUpdateStatus.Visible = false;
                }
            }
        }

       

        private void 托盘初始化ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //FrmRFIPEdit FRM = new FrmRFIPEdit();
            //FRM.ShowDialog();
        }

        private void iO模块状态ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmIOMsg frm = new FrmIOMsg();
            frm.ShowDialog();
        }

        private void btnTrayInfo_Click(object sender, EventArgs e)
        {
            List<TrayInfo> tray = TrayManager.getTrayList();
            LogUtil.info("-------------------开始打印托盘信息:");
            foreach(TrayInfo t in tray)
            {
                LogUtil.info(t.ToStr());
            }
            LogUtil.info("-------------------结束打印托盘信息");
        }

        private void btnClearTray_Click(object sender, EventArgs e)
        {
            List<TrayInfo> tray = TrayManager.getTrayList();
            LogUtil.info("-------------------点击:清空托盘。清空前打印托盘信息:");
            foreach (TrayInfo t in tray)
            {
                LogUtil.info(t.ToStr());
            }
            TrayManager.ClearTrayInfo();
            LogUtil.info("-------------------点击:清空托盘。托盘内容已清空");
        }
    }
}