private void MQCShowForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     nGPanel.Dispose();
     nGRework.Dispose();
     nGPanel                      = null;
     nGRework                     = null;
     bgWorker.DoWork             -= new DoWorkEventHandler(bg_DoWork);
     bgWorker.ProgressChanged    -= BgWorker_ProgressChanged;
     bgWorker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);
     tmrCallBgWorker.Tick        -= new EventHandler(tmrCallBgWorker_Tick);
     tmrCallBgWorker.Stop();
     bgWorker.Dispose();
     tmrCallBgWorker.Dispose();
 }
        public void LoadUIFromMQCITEM()
        {
            try
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                lb_outputTotal.Text = mQCItem.TotalOutput.ToString("N0"); /*1234.567 ("N", en-US) -> 1,234.57*/
                lb_TargetValue.Text = mQCItem.TargetMQC.TargetOutput.ToString("N0");
                //lb_CurrentTarget.Text = mQCItem.InputMaterialNotYet.ToString("N0");
                lb_TotalNG.Text   = mQCItem.TotalNG.ToString("N0");
                lb_TotalRW.Text   = mQCItem.TotalRework.ToString("N0");
                lb_percentNG.Text = mQCItem.percentNG.ToString("P1");
                lb_percentRW.Text = mQCItem.percentRework.ToString("P1");
                lb_dept.Text      = deptFull;
                lb_po.Text        = mQCItem.PO;
                lb_process.Text   = mQCItem.line;
                lb_product.Text   = mQCItem.product;

                double CurrentTarget = 0;
                if (DateTime.Now.Hour >= 8 && DateTime.Now.Hour <= 19)
                {
                    TimeSpan StartTime   = new TimeSpan(8, 0, 0);
                    TimeSpan CurrentTime = DateTime.Now.TimeOfDay;
                    TimeSpan WorkingTime = CurrentTime - StartTime;
                    if ((CurrentTime >= BreakTime1DayShiftBegin && CurrentTime < BreakTime1DayShiftEnd) || (CurrentTime >= BreakTime2DayShiftBegin && CurrentTime < BreakTime2DayShiftEnd))
                    {
                        lb_Intime.Text = "BREAK-TIME";
                    }
                    else
                    {
                        if (CurrentTime < BreakTime1DayShiftBegin)
                        {
                            CurrentTarget = mQCItem.TargetMQC.TargetOutput / (20 * 60) * (WorkingTime.TotalMinutes);
                        }
                        else if (CurrentTime >= BreakTime1DayShiftEnd && CurrentTime < BreakTime2DayShiftBegin)
                        {
                            CurrentTarget = mQCItem.TargetMQC.TargetOutput / (20 * 60) * (WorkingTime.TotalMinutes - 60);
                        }
                        else if (CurrentTime > BreakTime2DayShiftEnd)
                        {
                            CurrentTarget = mQCItem.TargetMQC.TargetOutput / (20 * 60) * (WorkingTime.TotalMinutes - 120);
                            if (CurrentTarget > (mQCItem.TargetMQC.TargetOutput / 2))
                            {
                                CurrentTarget = (mQCItem.TargetMQC.TargetOutput / 2);
                            }
                        }
                        lb_Intime.Text        = "[" + "8:00" + "-" + CurrentTime.Hours.ToString("00") + ":" + CurrentTime.Minutes.ToString("00") + "]";
                        lb_CurrentTarget.Text = CurrentTarget.ToString("N0");
                    }
                    //if (CurrentTarget >= mQCItem.TotalOutput)
                    //    lb_productionStatus.Text = "NORMAL";
                    //else lb_productionStatus.Text = "BELOW TARGET";
                }
                else if (DateTime.Now.Hour >= 20)
                {
                    TimeSpan StartTime   = new TimeSpan(20, 0, 0);
                    TimeSpan CurrentTime = DateTime.Now.TimeOfDay;
                    TimeSpan WorkingTime = CurrentTime - StartTime;
                    if ((CurrentTime >= BreakTime2DayShiftBegin && CurrentTime < BreakTime2DayShiftEnd) || CurrentTime >= BreakTime1NightShiftBegin || CurrentTime < BreakTime1NightShiftEnd)
                    {
                        lb_Intime.Text = "BREAK-TIME";
                    }
                    else
                    {
                        if (CurrentTime < BreakTime1DayShiftBegin)
                        {
                            CurrentTarget = mQCItem.TargetMQC.TargetOutput / (20 * 60) * (WorkingTime.TotalMinutes - 120);
                        }

                        lb_Intime.Text        = "[" + "8:00" + "-" + CurrentTime.Hours.ToString("00") + ":" + CurrentTime.Minutes.ToString("00") + "]";
                        lb_CurrentTarget.Text = CurrentTarget.ToString("N0");
                    }
                }
                else
                {
                    TimeSpan StartTime   = new TimeSpan(0, 0, 0);
                    TimeSpan CurrentTime = DateTime.Now.TimeOfDay;
                    TimeSpan WorkingTime = CurrentTime - StartTime;
                    if (CurrentTime >= BreakTime1DayShiftEnd && CurrentTime < BreakTime2DayShiftBegin)
                    {
                        CurrentTarget = mQCItem.TargetMQC.TargetOutput / (20 * 60) * (WorkingTime.TotalMinutes + (4 * 60) - 180);
                    }
                    else if (CurrentTime > BreakTime2DayShiftEnd)
                    {
                        CurrentTarget = mQCItem.TargetMQC.TargetOutput / (20 * 60) * (WorkingTime.TotalMinutes - 240);
                        if (CurrentTarget > (mQCItem.TargetMQC.TargetOutput))
                        {
                            CurrentTarget = (mQCItem.TargetMQC.TargetOutput);
                        }
                    }


                    lb_Intime.Text        = "[" + "20:00(Y)" + "-" + CurrentTime.Hours.ToString("00") + ":" + CurrentTime.Minutes.ToString("00") + "]";
                    lb_CurrentTarget.Text = CurrentTarget.ToString("N0");
                }
                if (CurrentTarget <= mQCItem.TotalOutput)
                {
                    lb_productionStatus.Text = "NORMAL";
                }
                else
                {
                    lb_productionStatus.Text = "BELOW TARGET";
                }

                if (mQCItem.Status == ProductionStatus.ShortageMaterial.ToString())
                {
                    lb_productionStatus.Text = mQCItem.Measage;
                }
                if (mQCItem.Status == ProductionStatus.HighDefect.ToString())
                {
                    lb_mesage_defect.Text = mQCItem.Measage;
                }
                if (mQCItem.Status == ProductionStatus.Normal.ToString())
                {
                    lb_productionStatus.Text = "";
                    lb_mesage_defect.Text    = "";
                }
                nGPanel.Dispose();
                nGPanel = new NGPanel(mQCItem.listNGItems);
                pa_NGPanel.Controls.Clear();

                if (!pa_NGPanel.Controls.Contains(nGPanel))
                {
                    nGPanel.Name = mQCItem.product;

                    nGPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                            | System.Windows.Forms.AnchorStyles.Left)
                                                                           | System.Windows.Forms.AnchorStyles.Right)));
                    pa_NGPanel.Controls.Add(nGPanel);

                    //    nGPanel.Dispose();
                }


                pa_rework.Controls.Clear();
                nGRework.Dispose();
                nGRework = new RWPanel(mQCItem.listRWItems);
                if (!pa_rework.Controls.Contains(nGRework))
                {
                    nGRework.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                             | System.Windows.Forms.AnchorStyles.Left)
                                                                            | System.Windows.Forms.AnchorStyles.Right)));
                    pa_rework.Controls.Add(nGRework);

                    //  nGRework.Dispose();
                }
                lb_clock.Text = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "LoadUIFromMQCITEM()", ex.Message);
            }
        }
        public void LoadUIFromMQCITEM()
        {
            try
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                lb_outputTotal.Text = mQCItem.TotalOutput.ToString("N0"); /*1234.567 ("N", en-US) -> 1,234.57*/
                lb_TargetValue.Text = mQCItem.TargetMQC.TargetOutput.ToString("N0");
                lb_NotyetSFT.Text   = mQCItem.InputMaterialNotYet.ToString("N0");
                lb_TotalNG.Text     = mQCItem.TotalNG.ToString("N0");
                lb_TotalRW.Text     = mQCItem.TotalRework.ToString("N0");
                lb_percentNG.Text   = mQCItem.percentNG.ToString("P1");
                lb_percentRW.Text   = mQCItem.percentRework.ToString("P1");
                lb_dept.Text        = deptFull;
                lb_po.Text          = mQCItem.PO;
                lb_process.Text     = mQCItem.line;
                lb_product.Text     = mQCItem.product;
                if (mQCItem.Status == ProductionStatus.ShortageMaterial.ToString())
                {
                    lb_messageMaterial.Text = mQCItem.Measage;
                }
                if (mQCItem.Status == ProductionStatus.HighDefect.ToString())
                {
                    lb_mesage_defect.Text = mQCItem.Measage;
                }
                if (mQCItem.Status == ProductionStatus.Normal.ToString())
                {
                    lb_messageMaterial.Text = "";
                    lb_mesage_defect.Text   = "";
                }
                nGPanel.Dispose();
                nGPanel = new NGPanel(mQCItem.listNGItems);
                pa_NGPanel.Controls.Clear();

                if (!pa_NGPanel.Controls.Contains(nGPanel))
                {
                    nGPanel.Name = mQCItem.product;

                    nGPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                            | System.Windows.Forms.AnchorStyles.Left)
                                                                           | System.Windows.Forms.AnchorStyles.Right)));
                    pa_NGPanel.Controls.Add(nGPanel);

                    //    nGPanel.Dispose();
                }


                pa_rework.Controls.Clear();
                nGRework.Dispose();
                nGRework = new RWPanel(mQCItem.listRWItems);
                if (!pa_rework.Controls.Contains(nGRework))
                {
                    nGRework.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                             | System.Windows.Forms.AnchorStyles.Left)
                                                                            | System.Windows.Forms.AnchorStyles.Right)));
                    pa_rework.Controls.Add(nGRework);

                    //  nGRework.Dispose();
                }
                lb_clock.Text = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "LoadUIFromMQCITEM()", ex.Message);
            }
        }