Beispiel #1
0
        public BarcodeScannerBLL(FillingLineData fillingLineData)
        {
            try
            {
                timerTest.Enabled  = true;
                timerTest.Elapsed += new System.Timers.ElapsedEventHandler(timerTest_Elapsed);

                base.FillingLineData        = fillingLineData;
                this.privateFillingLineData = this.FillingLineData.ShallowClone();

                this.barcodeScannerName = GlobalVariables.BarcodeScannerName.MatchingScanner;

                this.ipAddress = IPAddress.Parse(GlobalVariables.IpAddress(this.BarcodeScannerName));



                this.barcodeScannerStatus = new BarcodeScannerStatus[3];
                this.barcodeScannerStatus[(int)GlobalVariables.BarcodeScannerName.QualityScanner - 1]  = new BarcodeScannerStatus(GlobalVariables.BarcodeScannerName.QualityScanner);
                this.barcodeScannerStatus[(int)GlobalVariables.BarcodeScannerName.MatchingScanner - 1] = new BarcodeScannerStatus(GlobalVariables.BarcodeScannerName.MatchingScanner);
                this.barcodeScannerStatus[(int)GlobalVariables.BarcodeScannerName.CartonScanner - 1]   = new BarcodeScannerStatus(GlobalVariables.BarcodeScannerName.CartonScanner);



                this.serialPort          = new SerialPort();
                this.serialPort.PortName = GlobalVariables.ImageS8PortName;
                this.serialPort.BaudRate = 9600;
                this.serialPort.NewLine  = GlobalVariables.charETX.ToString();


                this.serialPort.ReadTimeout = 500;
                //this.serialPort.WriteTimeout = 500;
                //this.serialPort.Parity = value;
                //this.serialPort.DataBits = value;
                //this.serialPort.StopBits = value;
                //this.serialPort.Handshake = value;

                this.serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
                this.serialPort.PinChanged   += new SerialPinChangedEventHandler(serialPort_PinChanged);



                this.matchingPackList = new MessageQueue(GlobalVariables.NoItemDiverter());
                this.packInOneCarton  = new MessageQueue();
                this.cartonDataTable  = new DataDetail.DataDetailCartonDataTable();
            }
            catch (Exception exception)
            {
                this.MainStatus = exception.Message;
            }
        }
        public InkjetDominoPrinterBLL(GlobalVariables.DominoPrinterName dominoPrinterNameID, FillingLineData fillingLineData)
        {
            try
            {
                this.FillingLineData        = fillingLineData;
                this.privateFillingLineData = this.FillingLineData.ShallowClone();

                this.dominoPrinterNameID = dominoPrinterNameID;

                this.ipAddress = IPAddress.Parse(GlobalVariables.IpAddress(this.DominoPrinterNameID));
            }
            catch (Exception exception)
            {
                this.MainStatus = exception.Message; // ToString();
            }
        }
Beispiel #3
0
        public SettingFillingLineData(FillingLineData fillingLineData, bool isMessageQueueEmpty)
        {
            InitializeComponent();

            this.globalFillingLineData  = fillingLineData;
            this.privateFillingLineData = fillingLineData.ShallowClone();


            DataTable dataTable = ADODatabase.GetDataTable("SELECT ProductID, ProductCode, ProductCodeOriginal, ProductName, ProductCode + '    [' + ProductCodeOriginal + '] ' + ProductName AS ProductDisplayName FROM ListProductName");

            this.comboBoxProductID.DataSource    = dataTable;
            this.comboBoxProductID.ValueMember   = "ProductID";
            this.comboBoxProductID.DisplayMember = "ProductDisplayName";


            fillingLineNameBinding = this.textBoxFillingLineName.DataBindings.Add("Text", this.privateFillingLineData, "FillingLineName", true);
            productIDBinding       = this.comboBoxProductID.DataBindings.Add("SelectedValue", this.privateFillingLineData, "ProductID", true, DataSourceUpdateMode.OnPropertyChanged);

            batchNoBinding     = this.textBoxBatchNo.DataBindings.Add("Text", this.privateFillingLineData, "BatchNo", true);
            settingDateBinding = this.dateTimePickerSettingDate.DataBindings.Add("Value", this.privateFillingLineData, "SettingDate", true, DataSourceUpdateMode.OnPropertyChanged);

            batchSerialNumberBinding = this.textBoxBatchSerialNumber.DataBindings.Add("Text", this.privateFillingLineData, "BatchSerialNumber", true);
            monthSerialNumberBinding = this.textBoxMonthSerialNumber.DataBindings.Add("Text", this.privateFillingLineData, "MonthSerialNumber", true);

            batchCartonNumberBinding = this.textBoxBatchCartonNumber.DataBindings.Add("Text", this.privateFillingLineData, "BatchCartonNumber", true);
            monthCartonNumberBinding = this.textBoxMonthCartonNumber.DataBindings.Add("Text", this.privateFillingLineData, "MonthCartonNumber", true);


            fillingLineNameBinding.BindingComplete += new BindingCompleteEventHandler(fillingLineNameBinding_BindingComplete);
            productIDBinding.BindingComplete       += new BindingCompleteEventHandler(productIDBinding_BindingComplete);

            batchNoBinding.BindingComplete     += new BindingCompleteEventHandler(batchNoBinding_BindingComplete);
            settingDateBinding.BindingComplete += new BindingCompleteEventHandler(settingDateBinding_BindingComplete);

            batchSerialNumberBinding.BindingComplete += new BindingCompleteEventHandler(batchSerialNumberBinding_BindingComplete);
            monthSerialNumberBinding.BindingComplete += new BindingCompleteEventHandler(monthSerialNumberBinding_BindingComplete);

            batchCartonNumberBinding.BindingComplete += new BindingCompleteEventHandler(batchCartonNumberBinding_BindingComplete);
            monthCartonNumberBinding.BindingComplete += new BindingCompleteEventHandler(monthCartonNumberBinding_BindingComplete);

            this.privateFillingLineData.PropertyChanged += new PropertyChangedEventHandler(privateFillingLineData_PropertyChanged);

            this.comboBoxProductID.Enabled = isMessageQueueEmpty;
        }
        //Private Function lfStatusAlert(ByRef lInReceive() As Byte) As Boolean
        //    Static lAlertArray() As Byte '//lAlertArray: DE LUU LAI Alert TRUOC DO, KHI Alert THAY DOI => UPDATE TO DATABASE
        //    Dim lAlertNew As Boolean, i As Long

        //On Error GoTo ARRAY_INIT '//KIEM TRA, TRONG T/H CHU KHOI TAO CHO lAlertArray THI REDIM lAlertArray (0)
        //    If LBound(lAlertArray()) >= 0 Then GoTo ARRAY_OK
        //ARRAY_INIT:
        //    ReDim lAlertArray(0)

        //ARRAY_OK:
        //On Error GoTo ERR_HANDLER

        //    lAlertNew = UBound(lAlertArray) <> UBound(lInReceive)
        //    If Not lAlertNew Then
        //        For i = LBound(lInReceive) To UBound(lInReceive)
        //            If lInReceive(i) <> lAlertArray(i) Then lAlertNew = True: Exit For
        //        Next i
        //    End If
        //    If lAlertNew Then
        //        'DISPLAY NEW ALERT
        //        'SAVE NEW ALERT
        //        'Debug.Print "ALERT - " + Chr(lInReceive(5)) + Chr(lInReceive(6)) + Chr(lInReceive(7))
        //    End If

        //    lfStatusAlert = True
        //ERR_RESUME:
        //    Exit Function
        //ERR_HANDLER:
        //    Call psShowError: lfStatusAlert = False: GoTo ERR_RESUME
        //End Function



        #endregion Public Method


        #region Public Thread

        public void ThreadRoutine()
        {
            this.privateFillingLineData = this.FillingLineData.ShallowClone();


            string stringReadFrom = ""; bool lPrinterReady = false;
            bool   ReadyToPrint = false; bool HeadEnable = false;


            this.LoopRoutine = true; this.StopPrint();


            //This command line is specific to CartonInkJet ON FillingLine.Pail (Just here only for this specific)
            if (this.FillingLineData.FillingLineID == GlobalVariables.FillingLine.Pail && this.DominoPrinterNameID == GlobalVariables.DominoPrinterName.CartonInkJet)
            {
                this.LedGreenOn = true; return;
            }                                                                                                                                                                                             //DO NOTHING


            try
            {
                if (!this.Connect())
                {
                    throw new System.InvalidOperationException("NMVN: Can not connect to printer.");
                }

                #region INITIALISATION PRINTER
                do                                                                                   //INITIALISATION COMMAND
                {
                    this.WriteToStream(GlobalVariables.charESC + "/A/?/" + GlobalVariables.charEOT); //A: Printer Identity
                    if (this.ReadFromStream(ref stringReadFrom, false, "A", 14))
                    {
                        lPrinterReady = true;                                                          //A: Printer Identity OK"
                    }
                    if (lPrinterReady)
                    {
                        do                                                                                     //CHECK PRINTER READY TO PRINT
                        {
                            this.WriteToStream(GlobalVariables.charESC + "/O/1/?/" + GlobalVariables.charEOT); //O/1: Current status
                            if (this.ReadFromStream(ref stringReadFrom, false, "O", 9))
                            {
                                lfStatusLED(ref stringReadFrom); ReadyToPrint = this.LedGreenOn; this.LedGreenOn = false;
                            }                                                                                                                                                         //After Set LED, If LedGreenOn => ReadyToPrint

                            if (!ReadyToPrint)
                            {
                                this.WriteToStream(GlobalVariables.charESC + "/O/S/1/" + GlobalVariables.charEOT); //O/S/1: Turn on ink-jet
                                if (this.ReadFromStream(ref stringReadFrom, true))
                                {
                                    this.MainStatus = "Turn printer sequencing on. Please wait for 5 minutes";
                                    Thread.Sleep(50000);
                                }
                                else
                                {
                                    throw new System.InvalidOperationException("NMVN: Can not turn printer sequencing on: " + stringReadFrom);
                                }
                            }
                            else //ReadyToPrint: OK
                            {
                                this.WriteToStream(GlobalVariables.charESC + "/Q/1/?/" + GlobalVariables.charEOT);    //Q: HEAD ENABLE: ENABLE

                                if (this.ReadFromStream(ref stringReadFrom, false, "Q", 5))
                                {
                                    if (stringReadFrom.ElementAt(3).ToString() == "Y")
                                    {
                                        HeadEnable = true;
                                    }
                                    else
                                    {
                                        this.WriteToStream(GlobalVariables.charESC + "/Q/1/Y/" + GlobalVariables.charEOT);
                                        if (this.ReadFromStream(ref stringReadFrom, true))
                                        {
                                            this.MainStatus = "Head enable. Please wait for 10 seconds";
                                            Thread.Sleep(10000);
                                        }
                                        else
                                        {
                                            throw new System.InvalidOperationException("NMVN: Can not enable head: " + stringReadFrom);
                                        }
                                    }
                                }
                            }
                        } while (this.LoopRoutine && (!ReadyToPrint || !HeadEnable));
                    }
                    else
                    {
                        this.MainStatus = "Can not connect to printer. Trying to connect ... Press disconnect to exit.";
                    }
                } while (this.LoopRoutine && !lPrinterReady && !ReadyToPrint && !HeadEnable);

                #endregion INITIALISATION COMMAND


                //P: Message To Head Assugment '//CHU Y QUAN TRONG: DUA MSG SO 1 LEN DAU IN (SAN SANG KHI IN, BOI VI KHI IN TA STORAGE MSG VAO VI TRI SO 1 MA KHONG QUAN TAM DEN VI TRI SO 2, 3,...)
                this.WriteToStream(GlobalVariables.charESC + "/P/1/001/" + GlobalVariables.charEOT);
                if (this.ReadFromStream(ref stringReadFrom, true))
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    throw new System.InvalidOperationException("NMVN: Can not assign message to head: " + stringReadFrom);
                }


                //C: Set Clock
                this.WriteToStream(GlobalVariables.charESC + "/C/" + DateTime.Now.ToString("yyyy/MM/dd/00/hh/mm/ss") + "/" + GlobalVariables.charEOT);     //C: Set Clock
                if (!this.ReadFromStream(ref stringReadFrom, true))
                {
                    throw new System.InvalidOperationException("NMVN: Can not synchronize clock: " + stringReadFrom);
                }

                //T: Reset Product Counting
                this.WriteToStream(GlobalVariables.charESC + "/T/1/0/" + GlobalVariables.charEOT);
                if (!this.ReadFromStream(ref stringReadFrom, true))
                {
                    throw new System.InvalidOperationException("NMVN: Can not reset counting: " + stringReadFrom);
                }



                #region Status
                //SET STATUS

                this.WriteToStream(GlobalVariables.charESC + "/0/N/0/" + GlobalVariables.charEOT);     //0: Status Report Mode: OFF: NO ERROR REPORTING
                if (!this.ReadFromStream(ref stringReadFrom, true))
                {
                    throw new System.InvalidOperationException("NMVN: Can not set status report mode: " + stringReadFrom);
                }

                //co gang viet cho nay cho hay hay
                //this.WriteToStream( GlobalVariables.charESC + "/1/C/?/" + GlobalVariables.charEOT) ;   //1: REQUEST CURRENT STATUS
                //if (!this.ReadFromStream(ref stringReadFrom, false, "1", 12) )
                //    throw new System.InvalidOperationException("NMVN: Can not request current status: " + stringReadFrom);
                //else
                ////        Debug.Print "STATUS " + Chr(lInReceive(3)) + Chr(lInReceive(4)) + Chr(lInReceive(5))
                ////'        If Not ((lInReceive(3) = Asc("0") Or lInReceive(3) = Asc("1")) And lInReceive(4) = Asc("0") And lInReceive(5) = Asc("0")) Then GoTo ERR_HANDLER   'NOT (READY OR WARNING)
                ////    End If
                #endregion Status


                while (this.LoopRoutine)    //MAIN LOOP. STOP WHEN PRESS DISCONNECT
                {
                    if (!this.OnPrinting)
                    {
                        #region Reset Message: Clear message

                        if (this.resetMessage)
                        {
                            this.WriteToStream(GlobalVariables.charESC + "/S/001/  /" + GlobalVariables.charEOT);//S: Message Storage: Set Blank (Two Space)
                            if (this.ReadFromStream(ref stringReadFrom, true))
                            {
                                Thread.Sleep(500);
                            }
                            else
                            {
                                throw new System.InvalidOperationException("NMVN: Can not set message: " + stringReadFrom);
                            }

                            this.WriteToStream(GlobalVariables.charESC + "/I/1/ /" + GlobalVariables.charEOT); //SET OF: Print Acknowledgement Flags I
                            if (this.ReadFromStream(ref stringReadFrom, true))
                            {
                                Thread.Sleep(50);
                            }
                            else
                            {
                                throw new System.InvalidOperationException("NMVN: Can not set printing acknowledge: " + stringReadFrom);
                            }

                            this.MainStatus   = "Ready to print";
                            this.resetMessage = false; //Setup first message: Only one times
                        }
                        #endregion Reset Message: Clear message
                    }

                    else //this.OnPrinting
                    {
                        #region Reset Message: Setup FirstMessage

                        if (this.resetMessage)
                        {
                            this.WriteToStream(GlobalVariables.charESC + "/S001/" + this.WholeMessageLine() + "/" + GlobalVariables.charEOT);
                            if (this.ReadFromStream(ref stringReadFrom, true))
                            {
                                Thread.Sleep(750);
                            }
                            else
                            {
                                throw new System.InvalidOperationException("NMVN: Can not set message: " + stringReadFrom);
                            }



                            #region Update serial number - Note: Some DOMINO firmware version does not need to update serial number. Just set startup serial number only when insert serial number. BUT: FOR SURE, It will be updated FOR ALL
                            if (this.DominoPrinterNameID != GlobalVariables.DominoPrinterName.CartonInkJet) //ONLY CartonInkJet
                            {
                                //    U: UPDATE SERIAL NUMBER - Counter 1
                                this.WriteToStream(GlobalVariables.charESC + "/U/001/1/" + this.privateFillingLineData.MonthSerialNumber + "/" + GlobalVariables.charEOT);
                                if (this.ReadFromStream(ref stringReadFrom, true))
                                {
                                    Thread.Sleep(1000);
                                }
                                else
                                {
                                    throw new System.InvalidOperationException("NMVN: Can not update serial number: " + stringReadFrom);
                                }


                                //    U: UPDATE SERIAL NUMBER - Counter 2
                                this.WriteToStream(GlobalVariables.charESC + "/U/001/2/" + this.privateFillingLineData.MonthSerialNumber + "/" + GlobalVariables.charEOT);
                                if (this.ReadFromStream(ref stringReadFrom, true))
                                {
                                    Thread.Sleep(1000);
                                }
                                else
                                {
                                    throw new System.InvalidOperationException("NMVN: Can not update serial number: " + stringReadFrom);
                                }
                            }
                            #endregion Update serial number



                            this.WriteToStream(GlobalVariables.charESC + "/I/1/" + (this.DominoPrinterNameID == GlobalVariables.DominoPrinterName.CartonInkJet ? "a" : " ") + "/" + GlobalVariables.charEOT); //SET ON for DominoPrinterName.CartonInkJet ONLY
                            if (this.ReadFromStream(ref stringReadFrom, true))
                            {
                                Thread.Sleep(50);
                            }
                            else
                            {
                                throw new System.InvalidOperationException("NMVN: Can not set printing acknowledge: " + stringReadFrom);
                            }

                            this.MainStatus   = "Printing ....";
                            this.resetMessage = false; //Setup first message: Only one times
                        }

                        #endregion Reset Message: Setup FirstMessage

                        #region setup message for every message. Only for DominoPrinterName.CartonInkJet

                        if (this.DominoPrinterNameID == GlobalVariables.DominoPrinterName.CartonInkJet) //ONLY CartonInkJet
                        {
                            if (this.WaitForPrintingAcknowledge(ref stringReadFrom))
                            {
                                //Manual increase BatchCartonNumber & MonthCartonNumber
                                this.privateFillingLineData.BatchCartonNumber = (int.Parse(this.privateFillingLineData.BatchCartonNumber) + 1).ToString("0000000").Substring(1);//Format 7 digit, then cut 6 right digit: This will reset a 0 when reach the limit of 6 digit
                                this.privateFillingLineData.MonthCartonNumber = (int.Parse(this.privateFillingLineData.MonthCartonNumber) + 1).ToString("0000000").Substring(1);

                                Thread.Sleep(20); this.WriteToStream(GlobalVariables.charESC + "/S001/" + this.WholeMessageLine() + "/" + GlobalVariables.charEOT);//Required 20ms? For sure only, this maybe no need
                                if (this.ReadFromStream(ref stringReadFrom, true))
                                {
                                    Thread.Sleep(300);                                                //else throw new System.InvalidOperationException("NMVN: Can not set message: " + stringReadFrom);
                                }
                                //If place this COMMAND BEFORE increase BatchCartonNumber & MonthCartonNumber, It will show the printed value on User Interface
                                this.NotifyPropertyChanged("BatchCartonNumber"); //this.NotifyPropertyChanged("MonthCartonNumber"); //Just NotifyPropertyChanged only, no need to duplicate
                            }
                        }

                        #endregion setup message for every message. Only for DominoPrinterName.CartonInkJet

                        #region Read counter; only for DominoPrinterName.BarCodeInkJet
                        if (this.DominoPrinterNameID == GlobalVariables.DominoPrinterName.BarCodeInkJet)
                        {
                            //    U: Read Counter 1 (ONLY COUNTER 1---COUNTER 2: THE SAME COUNTER 1: Principlely)
                            this.WriteToStream(GlobalVariables.charESC + "/U/001/1/?/" + GlobalVariables.charEOT);
                            if (this.ReadFromStream(ref stringReadFrom, false, "U", 13))
                            {
                                int serialNumber = 0;
                                if (int.TryParse(stringReadFrom.Substring(6, 6), out serialNumber) && int.Parse(this.privateFillingLineData.MonthSerialNumber) != ++serialNumber) //Increase serialNumber by 1: Because: this.privateFillingLineData.MonthSerialNumber MUST GO AHEAD BY 1
                                {
                                    this.privateFillingLineData.MonthSerialNumber = serialNumber.ToString("0000000").Substring(1);
                                    this.NotifyPropertyChanged("MonthSerialNumber");
                                }
                            }
                        }
                        #endregion Read counter
                    }


                    if (!this.OnPrinting || this.DominoPrinterNameID != GlobalVariables.DominoPrinterName.CartonInkJet)
                    {
                        #region Get current status

                        this.WriteToStream(GlobalVariables.charESC + "/O/1/?/" + GlobalVariables.charEOT);  //O/1: Current status
                        if (this.ReadFromStream(ref stringReadFrom, false, "O", 9))
                        {
                            lfStatusLED(ref stringReadFrom);
                            if (!this.LedGreenOn)
                            {
                                throw new System.InvalidOperationException("Connection fail! Please check your printer.");
                            }
                        }


                        ////'//STATUS ONLY.BEGIN
                        //this.WriteToStream(GlobalVariables.charESC + "/1/H/?/" + GlobalVariables.charEOT);      //H: Request History Status
                        //if (this.ReadFromStream(ref stringReadFrom, false, "1", 12)) this.lfStatusHistory(ref stringReadFrom);

                        //this.WriteToStream(GlobalVariables.charESC + "/O/1/?/" + GlobalVariables.charEOT);      //O/1: Get Current LED Status
                        //if (this.ReadFromStream(ref stringReadFrom, false, "O", 9)) this.lfStatusLED(ref stringReadFrom);

                        //this.WriteToStream(GlobalVariables.charESC + "/O/2/?/" + GlobalVariables.charEOT);      //O/2: Get Current Alert
                        //if (this.ReadFromStream(ref stringReadFrom, false, "O", 0)) this.lfStatusAlert(ref stringReadFrom);
                        ////'//STATUS ONLY.END
                        #endregion Get current status

                        Thread.Sleep(110);
                    }
                } //End while this.LoopRoutine


                //DISCONNECT.BEGIN
                this.WriteToStream(GlobalVariables.charESC + "/O/1/?/" + GlobalVariables.charEOT);  //O/1: Current status
                if (this.ReadFromStream(ref stringReadFrom, false, "O", 9))
                {
                    lfStatusLED(ref stringReadFrom);
                }

                //DISCONNECT.END
            }
            catch (Exception exception)
            {
                this.LoopRoutine = false;
                this.MainStatus  = exception.Message; // ToString();

                this.LedRedOn = true;
                this.NotifyPropertyChanged("LedStatus");
            }
            finally
            {
                this.Disconnect();
            }
        }
Beispiel #5
0
        public void ThreadRoutine()
        {
            this.privateFillingLineData = this.FillingLineData.ShallowClone();

            string stringReadFrom = ""; bool matchingPackListChanged = false; bool packInOneCartonChanged = false;

            this.LoopRoutine = true; this.StopPrint();



            try
            {
                if (this.Connect(false))
                {
                    this.serialPort.NewLine = GlobalVariables.charETX.ToString();
                }
                else
                {
                    throw new System.InvalidOperationException("NMVN: Can not connect to comport.");
                }

                while (this.LoopRoutine)    //MAIN LOOP. STOP WHEN PRESS DISCONNECT
                {
                    this.MainStatus = this.OnPrinting ? "Scanning..." : "Ready to scan";

                    ////////////if (this.FillingLineData.FillingLineID != GlobalVariables.FillingLine.Pail)
                    ////////////{

                    ////////////    #region Read every pack

                    ////////////    if (this.WaitForBarcode(ref stringReadFrom) && this.OnPrinting)
                    ////////////    {
                    ////////////        string[] arrayBarcode = stringReadFrom.Split(new Char[] { GlobalVariables.charETX });

                    ////////////        foreach (string stringBarcode in arrayBarcode)
                    ////////////        {
                    ////////////            if (stringBarcode.Trim() != "" && stringBarcode.Trim() != "NoRead") //Add to MatchingPackList
                    ////////////            {
                    ////////////                lock (this.matchingPackList)
                    ////////////                {
                    ////////////                    MessageData messageData = this.AddDataDetailPack(stringBarcode + " " + this.privateFillingLineData.BatchSerialNumber, this.matchingPackList.NextPackSubQueueID);
                    ////////////                    if (messageData != null)
                    ////////////                    {
                    ////////////                        this.matchingPackList.Enqueue(messageData);
                    ////////////                        matchingPackListChanged = true;
                    ////////////                    }
                    ////////////                }

                    ////////////                this.privateFillingLineData.BatchSerialNumber = (int.Parse(this.privateFillingLineData.BatchSerialNumber) + 1).ToString("0000000").Substring(1);//Format 7 digit, then cut 6 right digit: This will reset a 0 when reach the limit of 6 digit
                    ////////////                this.NotifyPropertyChanged("BatchSerialNumber"); //APPEND TO stringBarcode, and then: Increase BatchSerialNumber by 1 PROGRAMMATICALLY BY SOFTWARE

                    ////////////            }
                    ////////////        }
                    ////////////    }

                    ////////////    #endregion Read every pack


                    ////////////    #region Make One Carton

                    ////////////    if (this.OnPrinting)
                    ////////////    {
                    ////////////        lock (this.packInOneCarton)
                    ////////////        {
                    ////////////            if (this.packInOneCarton.Count <= 0)
                    ////////////            {
                    ////////////                lock (this.matchingPackList)
                    ////////////                {                             //<Dequeue from matchingPackList to this.packInOneCarton>
                    ////////////                    this.packInOneCarton = this.matchingPackList.DequeuePack(); //This Dequeue successful WHEN There is enought MessageData IN THE COMMON GLOBAL matchingPackList, ELSE: this.packListInCarton is still NULL
                    ////////////                }

                    ////////////                if (this.packInOneCarton.Count > 0)
                    ////////////                {
                    ////////////                    matchingPackListChanged = true;
                    ////////////                    packInOneCartonChanged = true;

                    ////////////                    if (!UpdateDataDetailPack(GlobalVariables.BarcodeStatus.ReadyToCarton)) this.MainStatus = "Insufficient update pack status";
                    ////////////                }
                    ////////////            }
                    ////////////        }

                    ////////////    }
                    ////////////    #endregion Make One Carton


                    ////////////    if (matchingPackListChanged) { this.NotifyPropertyChanged("MatchingPackList"); matchingPackListChanged = false; }
                    ////////////    if (packInOneCartonChanged) { this.NotifyPropertyChanged("PackInOneCarton"); packInOneCartonChanged = false; }

                    ////////////}
                    Thread.Sleep(100);
                } //End while this.LoopRoutine
            }
            catch (Exception exception)
            {
                this.LoopRoutine = false;
                this.MainStatus  = exception.Message;

                this.LedRedOn = true;
                this.NotifyPropertyChanged("LedStatus");
            }
            finally
            {
                this.Disconnect();
            }
        }
        public MainControllingInterface()
        {
            InitializeComponent();

            try
            {
                //Test Only
                this.toolStripButton1.Visible = GlobalVariables.MyTest;
                this.toolStripButton2.Visible = GlobalVariables.MyTest;
                this.toolStripButton3.Visible = GlobalVariables.MyTest;
                this.toolStripButton4.Visible = GlobalVariables.MyTest;
                //Test Only


                //DataTable aa = new DataTable();
                //aa.Columns.Add("1");
                //aa.Columns.Add("2");
                //aa.Columns.Add("3");
                //aa.Columns.Add("4");
                //aa.Columns.Add("5");
                //aa.Columns.Add("6");

                //aa.Rows.Add("123456", "123456", "123456", "123456", "123456", "123456");

                //this.dataGridViewPackInOneCarton.DataSource = aa;


                //DataTable a = new DataTable();
                //a.Columns.Add("1", typeof(string));
                //a.Columns.Add("2", typeof(string));
                //a.Columns.Add("3", typeof(string));
                //a.Columns.Add("4", typeof(string));
                ////a.Columns.Add("E", typeof(string));
                ////a.Columns.Add("F", typeof(string));

                //a.Rows.Add("111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111");
                //a.Rows.Add("111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111");
                //a.Rows.Add("111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111");
                //a.Rows.Add("111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111");
                //a.Rows.Add("111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111");
                //a.Rows.Add("111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111", "111111111111111111111111111111");

                //this.dataGridViewPackInOneCarton.DataSource = a;



                this.dataGridViewCartonList.AutoGenerateColumns = false;


                //FillingLineData
                this.fillingLineData = new FillingLineData();

                this.toolStripTextBoxFillingLineID.TextBox.DataBindings.Add("Text", this.fillingLineData, "FillingLineName");
                this.toolStripTextBoxProductID.TextBox.DataBindings.Add("Text", this.fillingLineData, "ProductCode");
                this.toolStripTextBoxProductCodeOriginal.TextBox.DataBindings.Add("Text", this.fillingLineData, "ProductCodeOriginal");
                this.toolStripTextBoxBatchNo.TextBox.DataBindings.Add("Text", this.fillingLineData, "BatchNo");
                this.toolStripTextBoxBatchSerialNo.TextBox.DataBindings.Add("Text", this.fillingLineData, "BatchSerialNumber");
                this.toolStripTextBoxMonthSerialNo.TextBox.DataBindings.Add("Text", this.fillingLineData, "MonthSerialNumber");
                this.toolStripTextBoxBatchCartonNo.TextBox.DataBindings.Add("Text", this.fillingLineData, "BatchCartonNumber");
                this.toolStripTextBoxMonthCartonNo.TextBox.DataBindings.Add("Text", this.fillingLineData, "MonthCartonNumber");



                this.toolStripTextBoxNoItemPerCartonSetByProductID.TextBox.DataBindings.Add("Text", this, "NoItemPerCartonSetByProductID");


                //Inkjet Printer
                digitInkjetDominoPrinter   = new InkjetDominoPrinterBLL(GlobalVariables.DominoPrinterName.DegitInkJet, this.fillingLineData);
                barcodeInkjetDominoPrinter = new InkjetDominoPrinterBLL(GlobalVariables.DominoPrinterName.BarCodeInkJet, this.fillingLineData);
                cartonInkjetDominoPrinter  = new InkjetDominoPrinterBLL(GlobalVariables.DominoPrinterName.CartonInkJet, this.fillingLineData);



                digitInkjetDominoPrinter.PropertyChanged   += new PropertyChangedEventHandler(InkjetDominoPrinter_PropertyChanged);
                barcodeInkjetDominoPrinter.PropertyChanged += new PropertyChangedEventHandler(InkjetDominoPrinter_PropertyChanged);
                cartonInkjetDominoPrinter.PropertyChanged  += new PropertyChangedEventHandler(InkjetDominoPrinter_PropertyChanged);


                //Barcode Scanner
                barcodeScannerMCU = new BarcodeScannerBLL(this.fillingLineData);

                barcodeScannerMCU.PropertyChanged += new PropertyChangedEventHandler(InkjetDominoPrinter_PropertyChanged);


                this.splitContainerQuality.SplitterDistance  = this.SplitterDistanceQuality();
                this.splitContainerMatching.SplitterDistance = this.SplitterDistanceMatching();
                this.splitContainerCarton.SplitterDistance   = this.SplitterDistanceCarton();



                this.toolStripTextBoxCartonDateFrom.TextBox.DataBindings.Add("Text", this.barcodeScannerMCU, "CartonDateFrom");
                this.toolStripTextBoxCartonDateTo.TextBox.DataBindings.Add("Text", this.barcodeScannerMCU, "CartonDateTo");
            }
            catch (Exception exception)
            {
                GlobalExceptionHandler.ShowExceptionMessageBox(this, exception);
            }
        }