using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AR;
namespace Project
{
    public partial class FMain
    {


        void _Display_Interval_250ms()
        {
            //타워램프조정
            //if (COMM.SETTING.Data.Disable_TowerLamp == false) Update_TowerLamp();
            TowerLamp.Update(PUB.sm.Step);

            //컨베이어가동시간을 추적한다 230926
            if (VAR.BOOL[eVarBool.Use_Conveyor])
            {
                ////왼쪽컨베이어에 아이템이 존재하는 경우에만 누적
                //if (DIO.GetIOOutput(eDOName.LEFT_CONV) && VAR.BOOL[eVarBool.LEFT_ITEM_PICKOFF])
                //{
                //    if (VAR.TIME[eVarBool.LEFT_ITEM_PICKOFF].Year == 1982)
                //        VAR.TIME[eVarBool.LEFT_ITEM_PICKOFF] = DateTime.Now; //시간초기화
                //    else
                //    {
                //        var ts = DateTime.Now - VAR.TIME[eVarBool.LEFT_ITEM_PICKOFF];
                //        VAR.DBL[eVarDBL.LEFT_ITEM_PICKOFF] += ts.TotalSeconds; //경과시간누적
                //        VAR.TIME[eVarBool.LEFT_ITEM_PICKOFF] = DateTime.Now; //시간초기화
                //    }
                //}

                ////오른쪽컨베이어에 아이템이 존재하는 경우에만 누적
                //if (DIO.GetIOOutput(eDOName.RIGHT_CONV) && VAR.BOOL[eVarBool.RIGT_ITEM_PICKOFF] )
                //{
                //    if(VAR.TIME[eVarBool.RIGT_ITEM_PICKOFF].Year == 1982)
                //    {
                //        VAR.TIME[eVarBool.RIGT_ITEM_PICKOFF] = DateTime.Now; //시간초기화
                //    }
                //    else
                //    {
                //        var ts = DateTime.Now - VAR.TIME[eVarBool.RIGT_ITEM_PICKOFF];
                //        VAR.DBL[eVarDBL.RIGT_ITEM_PICKOFF] += ts.TotalSeconds; //경과시간누적
                //        VAR.TIME[eVarBool.RIGT_ITEM_PICKOFF] = DateTime.Now; //시간초기화
                //    }

                //}

                var t1 = VAR.I32[eVarInt32.LEFT_ITEM_COUNT];
                var t2 = VAR.I32[eVarInt32.RIGT_ITEM_COUNT];
                groupBox2.Text = $"Barcode({t1:N1}/{t2:N1})";
            }
            else
            {
                groupBox2.Text = "Barcode";
            }

            if((VAR.BOOL?.Get(eVarBool.Use_Conveyor) ?? false) == true)
            {
                btAutoReelOut.BackColor = PUB.Result.AutoReelOut ? Color.Lime : SystemColors.Control;
                btAutoReelOut.Visible = true;
            }
            else
            {
                btAutoReelOut.Visible = false;
            }

            
            groupBox1.Text = $"Equipment Operation({PUB.sm.Loop_ms:N0}ms)";
            //릴사이즈가 맞지 않으면 깜박인다.
            if (DIO.getCartSize(1) != eCartSize.None)
            {
                if (VAR.BOOL[eVarBool.Use_Conveyor] == false && DIO.getCartSize(1) != DIO.getCartSize(0))
                {
                    if (listView21.GetStyle(0, 1).BackColor != Color.Red)
                    {
                        listView21.GetStyle(0, 1).BackColor = Color.Red;
                    }
                    else
                    {
                        listView21.GetStyle(0, 1).BackColor = Color.FromArgb(32, 32, 32);
                    }
                }
                else
                {
                    listView21.GetStyle(0, 1).BackColor = Color.FromArgb(32, 32, 32);
                }

                if (VAR.BOOL[eVarBool.Use_Conveyor] == false && DIO.getCartSize(1) != DIO.getCartSize(2))
                {
                    if (listView21.GetStyle(0, 5).BackColor != Color.Red)
                    {
                        listView21.GetStyle(0, 5).BackColor = Color.Red;
                    }
                    else
                    {
                        listView21.GetStyle(0, 5).BackColor = Color.FromArgb(32, 32, 32);
                    }
                }
                else
                {
                    listView21.GetStyle(0, 5).BackColor = Color.FromArgb(32, 32, 32);
                }
            }
            else
            {
                //모두 동일하게 흑색한다
                //lbSize0.BackColor = Color.FromArgb(32, 32, 32);
                //lbSize1.BackColor = Color.FromArgb(32, 32, 32);
                //lbSize2.BackColor = Color.FromArgb(32, 32, 32);

                listView21.GetStyle(0, 1).BackColor = Color.FromArgb(32, 32, 32);
                listView21.GetStyle(0, 3).BackColor = Color.FromArgb(32, 32, 32);
                listView21.GetStyle(0, 5).BackColor = Color.FromArgb(32, 32, 32);

                listView21.GetStyle(0, 1).ForeColor = Color.White;
                listView21.GetStyle(0, 3).ForeColor = Color.White;
                listView21.GetStyle(0, 5).ForeColor = Color.White;

            }


            //락정보
            var l0 = DIO.GetIOOutput(eDOName.PORTL_MAGNET);
            var l1 = DIO.GetIOOutput(eDOName.PORTC_MAGNET);
            var l2 = DIO.GetIOOutput(eDOName.PORTR_MAGNET);

            lbLock0.Text = l0 ? "Cart Exchange" : "No Cart";
            lbLock1.Text = l1 ? "Cart Exchange" : "No Cart";
            lbLock2.Text = l2 ? "Cart Exchange" : "No Cart";

            var sbVisTitle0 = listView21.GetCell(0, 1);
            var sbVisTitle2 = listView21.GetCell(0, 5);

            if (PUB.wsL == null || PUB.wsL.Connected == false)
            {
                sbVisTitle0.ForeColor = Color.Red;
            }
            else
            {
                //데이터수신시간에 따른 색상
                var tswecv = DateTime.Now - VAR.TIME[eVarTime.lastRecvWSL];
                if (tswecv.TotalSeconds > 5)
                {
                    sbVisTitle0.ForeColor = Color.HotPink;
                }
                else
                {
                    if (PUB.flag.get(eVarBool.FG_RDY_CAMERA_L))
                        sbVisTitle0.ForeColor = Color.Lime;
                    else
                        sbVisTitle0.ForeColor = Color.Magenta;
                }

            }

            //
            if (PUB.wsR == null || PUB.wsR.Connected == false)
            {
                sbVisTitle2.ForeColor = Color.Red;
            }
            else
            {
                var tswecv = DateTime.Now - VAR.TIME[eVarTime.lastRecvWSR];
                if (tswecv.TotalSeconds > 5)
                {
                    sbVisTitle2.ForeColor = Color.HotPink;
                }
                else
                {
                    if (PUB.flag.get(eVarBool.FG_RDY_CAMERA_R))
                        sbVisTitle2.ForeColor = Color.Lime;
                    else
                        sbVisTitle2.ForeColor = Color.Magenta;
                }

            }

            //arLabel18.Text = camliveBusy ? "카메라 (라이브뷰)" : "카메라";

            btStart.Enabled = PUB.flag.get(eVarBool.FG_MOVE_PICKER) == false;
            btStop.Enabled = PUB.flag.get(eVarBool.FG_MOVE_PICKER) == false;
            btSetting.Enabled = PUB.flag.get(eVarBool.FG_MOVE_PICKER) == false;
            //btPickerMove.Visible = (Pub.mot.IsInit && PUB.mot.HasHomeSetOff == true);   //피커의 수동 이동 버튼표시여부


            var hwcol = 0;
            if (PUB.keyenceF != null)
            {
                HWState.setTitle(1, hwcol, (PUB.keyenceF.IsConnect ? (PUB.keyenceF.IsTriggerOn ? "TRIG" : "ON") : "OFF"));

                if (PUB.keyenceF.IsConnect)
                {
                    if (PUB.keyenceF.IsTriggerOn)
                    {
                        HWState.setValue(1, hwcol, 2);
                    }
                    else
                    {
                        HWState.setValue(1, hwcol, 1);
                    }
                }
                else
                {
                    HWState.setValue(1, hwcol, 3);
                }
            }
            else
            {
                HWState.setTitle(1, hwcol, "SET");
                HWState.setValue(1, hwcol, 0);
            }
            hwcol++;

            if (PUB.keyenceR != null)
            {
                HWState.setTitle(1, hwcol, (PUB.keyenceR.IsConnect ? (PUB.keyenceR.IsTriggerOn ? "TRIG" : "ON") : "OFF"));

                if (PUB.keyenceR.IsConnect)
                {
                    if (PUB.keyenceR.IsTriggerOn)
                    {
                        HWState.setValue(1, hwcol, 2);
                    }
                    else
                    {
                        HWState.setValue(1, hwcol, 1);
                    }
                }
                else
                {
                    HWState.setValue(1, hwcol, 3);
                }
            }
            else
            {
                HWState.setTitle(1, hwcol, "SET");
                HWState.setValue(1, hwcol, 0);
            }
            hwcol++;


            if (PUB.wsL != null)
            {
                HWState.setTitle(1, hwcol, (PUB.wsL.Connected ? "ON" : "OFF"));
                HWState.setValue(1, hwcol++, (ushort)(PUB.wsL.Connected ? 1 : 3));
            }


            if (PUB.wsR != null)
            {
                HWState.setTitle(1, hwcol, (PUB.wsR.Connected ? "ON" : "OFF"));
                HWState.setValue(1, hwcol++, (ushort)(PUB.wsR.Connected ? 1 : 3));
            }


            HWState.setTitle(1, hwcol, (PUB.BarcodeFix.IsOpen() ? AR.SETTING.Data.Barcode_Port : "OFF"));
            HWState.setValue(1, hwcol++, (ushort)(PUB.BarcodeFix.IsOpen() ? 1 : 3));

            if (PUB.PrinterL != null)
            {
                HWState.setTitle(1, hwcol, (PUB.PrinterL.IsOpen ? AR.SETTING.Data.PrintL_Port : "OFF"));
                HWState.setValue(1, hwcol++, (ushort)(PUB.PrinterL.IsOpen ? 1 : 3));
            }
            else HWState.setTitle(1, hwcol++, "SET");

            if (PUB.PrinterR != null)
            {

                HWState.setTitle(1, hwcol, (PUB.PrinterR.IsOpen ? AR.SETTING.Data.PrintR_Port : "OFF"));
                HWState.setValue(1, hwcol++, (ushort)(PUB.PrinterR.IsOpen ? 1 : 3));
            }
            else HWState.setTitle(1, hwcol++, "SET");

            if (PUB.plc != null)
            {
                HWState.setTitle(1, hwcol, (PUB.plc.Init ? AR.SETTING.Data.swplc_name : "OFF"));
                HWState.setValue(1, hwcol++, (ushort)(PUB.plc.Init ? 2 : 1));
            }
            else HWState.setTitle(1, hwcol++, "SET");

            HWState.Invalidate();

            IOState.setTitle(0, 0, $"{PUB.sm.Step}"); //this.sbStep.Text =  Pub.sm.Step.ToString();
            IOState.setTitle(0, 9, $"MC({PUB.MCCode}/{AR.SETTING.Data.McName})");
            IOState.setTitle(1, 0, $"{PUB.sm.Loop_ms.ToString("N1")}ms");// / " + intlockcnt.ToString();io 

            IOState.setValue(0, 1, (ushort)(DIO.isSaftyDoorF(2, false) ? 0 : 2));
            IOState.setValue(0, 2, (ushort)(DIO.isSaftyDoorF(1, false) ? 0 : 2));
            IOState.setValue(0, 3, (ushort)(DIO.isSaftyDoorF(0, false) ? 0 : 2));

            IOState.setValue(1, 1, (ushort)(DIO.GetIOOutput(eDOName.BUZZER) ? 2 : 0));
            IOState.setValue(1, 2, (ushort)(DIO.GetIOOutput(eDOName.ROOMLIGHT) ? 1 : 0));
            IOState.setValue(1, 3, (ushort)(DIO.GetIOInput(eDIName.AIR_DETECT) ? 1 : 0));

            IOState.setValue(0, 4, (ushort)(DIO.GetIOInput(eDIName.PORTL_DET_UP) ? 1 : 0));
            IOState.setValue(0, 5, (ushort)(DIO.GetIOInput(eDIName.PORTC_DET_UP) ? 1 : 0));
            IOState.setValue(0, 6, (ushort)(DIO.GetIOInput(eDIName.PORTR_DET_UP) ? 1 : 0));

            IOState.setValue(1, 4, (ushort)(DIO.GetIOInput(eDIName.PORTL_LIM_UP) ? 2 : 0));
            IOState.setValue(1, 5, (ushort)(DIO.GetIOInput(eDIName.PORTC_LIM_UP) ? 2 : 0));
            IOState.setValue(1, 6, (ushort)(DIO.GetIOInput(eDIName.PORTR_LIM_UP) ? 2 : 0));

            IOState.setValue(1, 9, (ushort)(PUB.flag.get(eVarBool.FG_KEYENCE_TRIGGER) ? 2 : 0));

            IOState.setValue(0, 10, (ushort)(PUB.flag.get(eVarBool.VS_DETECT_REEL_L) ? 2 : 0)); //reel-left detect
            IOState.setValue(0, 11, (ushort)(PUB.flag.get(eVarBool.VS_DETECT_REEL_R) ? 2 : 0));  //reel-right detect

            IOState.setValue(1, 10, (ushort)(PUB.flag.get(eVarBool.VS_DETECT_CONV_L) ? 2 : 0));  //conv-left detect
            IOState.setValue(1, 11, (ushort)(PUB.flag.get(eVarBool.VS_DETECT_CONV_R) ? 2 : 0));  //conv-right detect

            IOState.Invalidate();

            if (PUB.Result.isSetvModel)
            {
                var modelVision = PUB.Result.vModel;
                var modelName = modelVision.Title;
                var modelNameM = string.Empty;

                if (PUB.Result.isSetmModel) modelNameM = PUB.Result.mModel.Title;
                if (modelNameM.ToUpper().StartsWith("CONV"))
                {
                    arLabel1.Text = "CONVEYOR ON";
                    arLabel1.ForeColor = Color.Blue;
                }
                else
                {
                    arLabel1.Text = "CONVEYOR OFF";
                    arLabel1.ForeColor = Color.Red;
                }




                //시스템바이패스
                if (SETTING.Data.SystemBypass)
                {
                    lbModelName.Text = $"SYSTEM BYPASS";
                    lbModelName.ForeColor = Color.White;
                    lbModelName.BackColor = Color.Blue;
                    lbModelName.BackColor2 = Color.DeepSkyBlue;
                    lbModelName.ShadowColor = Color.DimGray;
                }
                else
                {
                    //바이패스는 색깔을 달리한다.
                    if (modelName.ToUpper().Contains("BYPASS"))
                    {
                        lbModelName.Text = $"{modelName}";
                        lbModelName.ForeColor = Color.DarkGreen;
                        lbModelName.BackColor = Color.Gold;
                        lbModelName.BackColor2 = Color.Yellow;
                        lbModelName.ShadowColor = Color.WhiteSmoke;
                    }
                    else if (modelName.ToUpper().Contains("CONVERT"))
                    {
                        lbModelName.Text = $"{modelName}";
                        lbModelName.ForeColor = Color.DarkBlue;
                        lbModelName.BackColor = Color.Gold;
                        lbModelName.BackColor2 = Color.Yellow;
                        lbModelName.ShadowColor = Color.WhiteSmoke;
                    }
                    else
                    {
                        var custname = VAR.STR[eVarString.JOB_CUSTOMER_CODE];
                        if (custname.isEmpty() == false)
                            lbModelName.Text = $"[{custname}] {modelName}";
                        else
                            lbModelName.Text = $"{modelName}";
                        lbModelName.ForeColor = Color.Black;
                        lbModelName.BackColor = Color.White;
                        lbModelName.BackColor2 = Color.WhiteSmoke;
                        lbModelName.ShadowColor = Color.DimGray;
                    }
                }

            }
            else
            {
                lbModelName.Text = "Please select a model";
                lbModelName.ForeColor = Color.Blue;
                lbModelName.BackColor = Color.Tomato;
                lbModelName.BackColor2 = Color.Red;
                lbModelName.ShadowColor = Color.DimGray;
            }
            arLabel1.BackColor = lbModelName.BackColor;
            arLabel1.BackColor2 = lbModelName.BackColor2;


            try
            {
                //바코드정보표시
                var row = 1;
                var col = 1;
                Class.VisionData visdata = PUB.Result.ItemDataL.VisionData;
                listView21.SetText(row++, col, visdata.RID);
                listView21.SetText(row++, col, visdata.SID);
                listView21.SetText(row++, col, visdata.QTY);
                listView21.SetText(row++, col, visdata.VNAME);
                listView21.SetText(row++, col, visdata.VLOT);
                listView21.SetText(row++, col, visdata.MFGDATE);
                listView21.SetText(row++, col, visdata.PARTNO);
                listView21.SetText(row++, col, visdata.ReelSize == eCartSize.None ? "--" : visdata.ReelSize.ToString());


                if (PUB.flag.get(eVarBool.FG_ENABLE_LEFT) == false)
                {
                    sbVisTitle0.Text = "DISABLE";
                    sbVisTitle0.BackColor = Color.Orange;
                    sbVisTitle0.BackColor2 = Color.Tomato;
                }
                else
                {
                    listView21.SetText(0, col, DIO.getCartSize(0) == eCartSize.None ? "?" : DIO.getCartSize(0).ToString());
                }

                if (VAR.BOOL[eVarBool.Use_Conveyor]) listView21.GetStyle(0, 1).ForeColor = Color.White;
                else
                    listView21.GetStyle(0, 1).ForeColor = AR.SETTING.Data.Detect_CartL ? Color.White : Color.Red;

                if (VAR.BOOL[eVarBool.Use_Conveyor]) listView21.GetStyle(0, 5).ForeColor = Color.White;
                else
                    listView21.GetStyle(0, 5).ForeColor = AR.SETTING.Data.Detect_CartR ? Color.White : Color.Red;
                //lbSize0.ForeColor = COMM.SETTING.Data.Detect_CartL ? Color.White : Color.Red;

                listView21.SetText(row, col, visdata.RID2);
                if (visdata.RID2.isEmpty() == false && visdata.RID.Equals(visdata.RID2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col, 1);

                listView21.SetText(row, col, visdata.SID2);
                if (visdata.SID2.isEmpty() == false && visdata.SID.Equals(visdata.SID2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                if (visdata.QTY2.Equals("0")) listView21.SetText(row, 1, string.Empty);
                else listView21.SetText(row, col, visdata.QTY2);
                if (visdata.QTY2.isEmpty() == false && visdata.QTY2.Equals("0") == false && visdata.QTY.Equals(visdata.QTY2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);


                listView21.SetText(row, col, visdata.VNAME2);
                if (visdata.VNAME2.isEmpty() == false && visdata.VNAME.Equals(visdata.VNAME2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.VLOT2);
                if (visdata.VLOT2.isEmpty() == false && visdata.VLOT.Equals(visdata.VLOT2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.MFGDATE2);
                if (visdata.MFGDATE2.isEmpty() == false && visdata.MFGDATE.Equals(visdata.MFGDATE2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.PARTNO2);
                if (visdata.PARTNO2.isEmpty() == false && visdata.PARTNO.Equals(visdata.PARTNO2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

            }
            catch { }

            try
            {
                var visdata = PUB.Result.ItemDataC.VisionData;
                Color textColor = visdata.Confirm ? Color.Lime : Color.WhiteSmoke;

                var row = 1;
                var col = 3;
                this.listView21.SetText(row, col, visdata.RID);
                if (visdata.RID_Trust)
                {
                    if (visdata.RIDNew) //new reelid mode
                    {
                        listView21.SetColor(row++, col - 1, 3);
                    }
                    else
                    {
                        listView21.SetColor(row++, col - 1, 6);
                    }
                }
                else
                {
                    listView21.SetColor(row++, col - 1, 0);
                }

                if (visdata.SID0.isEmpty())
                    listView21.SetText(row, col, visdata.SID);
                else
                    listView21.SetText(row, col, visdata.SID + "\n<< " + visdata.SID0);

                listView21.SetColor(row++, col - 1, (ushort)(visdata.SID_Trust ? 6 : 0));

                if (PUB.Result.ItemDataC.VisionData.QTYRQ)
                {
                    listView21.SetText(row, col, "RQ:" + visdata.QTY);
                    listView21.SetColor(row++, col - 1, 6);
                }
                else
                {
                    if (visdata.QTY.Equals("0")) listView21.SetText(row, col, string.Empty);
                    else listView21.SetText(row, col, visdata.QTY);
                    listView21.SetColor(row++, col - 1, (ushort)(visdata.QTY_Trust ? 6 : 0));
                }

                listView21.SetText(row, col, visdata.VNAME); listView21.SetColor(row++, col - 1, (ushort)(visdata.VNAME_Trust ? 6 : 0));
                listView21.SetText(row, col, visdata.VLOT); listView21.SetColor(row++, col - 1, (ushort)(visdata.VLOT_Trust ? 6 : 0));
                listView21.SetText(row, col, visdata.MFGDATE); listView21.SetColor(row++, col - 1, (ushort)(visdata.MFGDATE_Trust ? 6 : 0));
                listView21.SetText(row, col, visdata.PARTNO); listView21.SetColor(row++, col - 1, (ushort)(visdata.PARTNO_Trust ? 6 : 0));

                //lbSize1.Text = DIO.getCartSize(1) == eCartSize.None ? "?" : DIO.getCartSize(1).ToString();
                listView21.SetText(0, col, DIO.getCartSize(1) == eCartSize.None ? "?" : DIO.getCartSize(1).ToString());
                listView21.GetStyle(0, col - 1).ForeColor = AR.SETTING.Data.Detect_CartC ? Color.White : Color.Red;

                listView21.SetText(row++, col, visdata.ReelSize == eCartSize.None ? "--" : visdata.ReelSize.ToString());

                //Degree
                row++; //gridView2.setTitle(row++, 1, visdata.PARTNO);

                //QR
                row++; //gridView2.setTitle(row++, 1, visdata.PARTNO);

                //바코드수량
                //listView21.SetText(row, col-1, "BACD");
                listView21.SetText(row++, col, $"{visdata.barcodelist.Count}");

                listView21.SetText(row, col - 1, "REGEX");
                listView21.SetText(row++, col, $"{PUB.Result.BCDPattern.Count}");

                row++;//
                listView21.SetText(row, col - 1, "BATCH");
                listView21.SetText(row++, col, $"{visdata.BATCH}");

                listView21.SetText(row, col - 1, "MAX");
                listView21.SetText(row++, col, $"{visdata.QTYMAX}");

                var textcolor = visdata.Confirm ? 7 : 0;
                var crow = 1;
                listView21.SetColor(crow++, 3, textcolor);
                listView21.SetColor(crow++, 3, textcolor);
                listView21.SetColor(crow++, 3, textcolor);
                listView21.SetColor(crow++, 3, textcolor);
                listView21.SetColor(crow++, 3, textcolor);
                listView21.SetColor(crow++, 3, textcolor);
                listView21.SetColor(crow++, 3, textcolor);

                //arLabel25.ForeColor = textColor;
                //listView21.SetColor(2, 1, (visdata.QTYRQ ? 3 : 1));
            }
            catch { }


            try
            {
                var row = 1;
                var col = 5;
                Class.VisionData visdata = PUB.Result.ItemDataR.VisionData;
                listView21.SetText(row++, col, visdata.RID);
                listView21.SetText(row++, col, visdata.SID);
                listView21.SetText(row++, col, visdata.QTY);
                listView21.SetText(row++, col, visdata.VNAME);
                listView21.SetText(row++, col, visdata.VLOT);
                listView21.SetText(row++, col, visdata.MFGDATE);
                listView21.SetText(row++, col, visdata.PARTNO);
                listView21.SetText(row++, col, visdata.ReelSize == eCartSize.None ? "--" : visdata.ReelSize.ToString());


                if (PUB.flag.get(eVarBool.FG_ENABLE_RIGHT) == false)
                {
                    sbVisTitle2.Text = "DISABLE";
                    sbVisTitle2.BackColor = Color.Orange;
                    sbVisTitle2.BackColor2 = Color.Tomato;
                }
                else
                {
                    listView21.SetText(0, col, DIO.getCartSize(2) == eCartSize.None ? "?" : DIO.getCartSize(2).ToString());
                }


                listView21.GetStyle(0, col).ForeColor = AR.SETTING.Data.Detect_CartR ? Color.White : Color.Red;
                //lbSize2.Text = DIO.getCartSize(2) == eCartSize.None ? "?" : DIO.getCartSize(2).ToString();
                //lbSize2.ForeColor = COMM.SETTING.Data.Detect_CartR ? Color.White : Color.Red;

                listView21.SetText(row, col, visdata.RID2);
                if (visdata.RID2.isEmpty() == false && visdata.RID.Equals(visdata.RID2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.SID2);
                if (visdata.SID2.isEmpty() == false && visdata.SID.Equals(visdata.SID2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                if (visdata.QTY2.Equals("0")) listView21.SetColor(row, col, 0);
                else listView21.SetText(row, col, visdata.QTY2);
                if (visdata.QTY2.isEmpty() == false && visdata.QTY2.Equals("0") == false && visdata.QTY.Equals(visdata.QTY2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);


                listView21.SetText(row, col, visdata.VNAME2);
                if (visdata.VNAME2.isEmpty() == false && visdata.VNAME.Equals(visdata.VNAME2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.VLOT2);
                if (visdata.VLOT2.isEmpty() == false && visdata.VLOT.Equals(visdata.VLOT2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.MFGDATE2);
                if (visdata.MFGDATE2.isEmpty() == false && visdata.MFGDATE.Equals(visdata.MFGDATE2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);

                listView21.SetText(row, col, visdata.PARTNO2);
                if (visdata.PARTNO2.isEmpty() == false && visdata.PARTNO.Equals(visdata.PARTNO2) == false) listView21.SetColor(row++, col - 1, 2);
                else listView21.SetColor(row++, col - 1, 1);
            }
            catch { }

            listView21.Invalidate();
            listView21.Refresh();

            lbLock0.BackColor = l0 ? Color.FromArgb(0xff, 0x4c, 0x0e) : Color.FromArgb(32, 32, 32);
            lbLock0.BackColor2 = l0 ? Color.FromArgb(0xff, 0x4c, 0x0e) : Color.FromArgb(80, 80, 80);
            lbLock1.BackColor = l1 ? Color.FromArgb(0xff, 0x4c, 0x0e) : Color.FromArgb(32, 32, 32);
            lbLock1.BackColor2 = l1 ? Color.FromArgb(0xff, 0x4c, 0x0e) : Color.FromArgb(80, 80, 80);
            lbLock2.BackColor = l2 ? Color.FromArgb(0xff, 0x4c, 0x0e) : Color.FromArgb(32, 32, 32);
            lbLock2.BackColor2 = l2 ? Color.FromArgb(0xff, 0x4c, 0x0e) : Color.FromArgb(80, 80, 80);

            //display mesasge
            UpdateStatusMessage(); //left
        }
    }
}