private async void btnSubmitError_Click(object sender, EventArgs e)
        {
            DowntimeTimer.Stop();

            try
            {
                //await _connection.InvokeAsync("Send", "WinFormsApp", messageTextBox.Text);
                await _connection.InvokeAsync("SendMachineError", DateTime.Now.ToString(), cmbErrorReason.Text, txtErrorDescription.Text);

                Log(Color.Brown, "SendError to server " + ": " + cmbErrorReason.Text, messagesList);
            }
            catch (Exception ex)
            {
                Log(Color.Red, ex.ToString(), messagesList);
                serverRequestData   = false;
                countSenddataToHubs = 0;
            }

            txtErrorDescription.Text = "";
            //Send data Hubs

            tikerTime                   = DateTime.Now.TimeOfDay;
            countIdletimes              = tikerTime - startTime - countRunningtimes - countDownTimetimes - countSettingtimes;
            bbcountIdletimes            = countIdletimes;
            PanelAlertMessage.BackColor = Color.DarkOrange;

            IdleTimer.Start();
        }
        private void btnResetConfig_Click(object sender, EventArgs e)
        {
            PanelAlertMessage.BackColor = Color.Gray;
            lbAlertMessage.Text         = "RESET TIME";
            lbAlertMessage.Left         = (PanelAlertMessage.Width - lbAlertMessage.Width) / 2;

            //reset data and save to local
            IdleTimer.Stop();
            RuningTimer.Stop();
            SettingTimer.Stop();
            DowntimeTimer.Stop();

            countSettingtimes  = new TimeSpan(0);
            countIdletimes     = new TimeSpan(0);
            countDownTimetimes = new TimeSpan(0);
            countRunningtimes  = new TimeSpan(0);

            txtRunningTimes.Text = "00h:00m:00s";
            txtSettingTimes.Text = "00h:00m:00s";
            txtDownTimes.Text    = "00h:00m:00s";
            txtIdleTimes.Text    = "00h:00m:00s";


            Properties.Settings.Default.RunningTimes = countRunningtimes;
            Properties.Settings.Default.DownTimes    = countDownTimetimes;
            Properties.Settings.Default.SettingTimes = countSettingtimes;

            Properties.Settings.Default.Save();

            planQty         = 0;
            expectValue     = 0;
            totalInputValue = 0;
            totalPassValue  = 0;
            yieldValue      = 0.0;
            OEEValue        = 0.0;

            expectRatio = 0;
            qtyPerInput = 0;

            txtQtyPlan.Text   = planQty.ToString();
            txtQtyExpect.Text = expectValue.ToString();
            txtQtyInput.Text  = totalInputValue.ToString();
            btnQtyPass.Text   = totalPassValue.ToString();
            txtQtyYield.Text  = yieldValue.ToString("N2") + "%";
            txtOEEvalue.Text  = OEEValue.ToString("N3") + "%";

            tikerTime                   = DateTime.Now.TimeOfDay;
            countIdletimes              = tikerTime - startTime - countRunningtimes - countDownTimetimes - countSettingtimes;
            bbcountIdletimes            = countIdletimes;
            PanelAlertMessage.BackColor = Color.DarkOrange;
            IdleTimer.Start();
        }
        private void btnTrial_Click(object sender, EventArgs e)
        {
            txtMessage.Text = "Machine is trial";

            tikerTime = DateTime.Now.TimeOfDay;
            RuningTimer.Stop();
            IdleTimer.Stop();
            DowntimeTimer.Stop();

            PanelAlertMessage.BackColor = Color.DeepSkyBlue;
            bbcountSettingtimes         = countSettingtimes;
            SettingTimer.Start();
        }
        private void btnStop_Click(object sender, EventArgs e)
        {
            getJobFromHubs     = false;
            txtBarcode.Enabled = true;
            txtBarcode.Text    = "SCAN BARCODE";
            txtMessage.Text    = "Machine is stop";
            RuningTimer.Stop();
            SettingTimer.Stop();
            DowntimeTimer.Stop();

            PanelAlertMessage.BackColor = Color.DarkOrange;
            tikerTime = DateTime.Now.TimeOfDay;

            countIdletimes   = tikerTime - startTime - countRunningtimes - countDownTimetimes - countSettingtimes;
            bbcountIdletimes = countIdletimes;
            IdleTimer.Start();
        }
        private void btnExit_Click(object sender, EventArgs e)
        {
            IdleTimer.Stop();
            currentTimer.Stop();
            RuningTimer.Stop();
            SettingTimer.Stop();
            DowntimeTimer.Stop();
            updateChartTimer.Stop();

            Properties.Settings.Default.RunningTimes = countRunningtimes;
            Properties.Settings.Default.DownTimes    = countDownTimetimes;
            Properties.Settings.Default.SettingTimes = countSettingtimes;

            Properties.Settings.Default.Save();

            Close();
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            // job detail from server
            if (txtJobNo.Text != "")
            {
                txtBarcode.Enabled = false;
                txtMessage.Text    = "Machine is running";

                tikerTime = DateTime.Now.TimeOfDay;
                IdleTimer.Stop();
                SettingTimer.Stop();
                DowntimeTimer.Stop();

                PanelAlertMessage.BackColor = Color.LimeGreen;
                bbcountRunningtimes         = countRunningtimes;
                RuningTimer.Start();
            }
            else
            {
                MessageBox.Show("Please scan barcode or key job number before start");
            }
        }
        private void updateChartTimer_Tick(object sender, EventArgs e)
        {
            if ((DateTime.Now.TimeOfDay >= endTime) && (DateTime.Now.TimeOfDay > startTime))
            {
                if (resetDone == false)
                {
                    resetDone = true;
                    //startTime =startTime.Subtract(new TimeSpan(1, 0, 0, 0));
                    txtMessage.Text = "Stop all process because now is reset data time !!!";
                    //send data to server



                    //reset data and save to local
                    IdleTimer.Stop();
                    RuningTimer.Stop();
                    SettingTimer.Stop();
                    DowntimeTimer.Stop();

                    countSettingtimes  = new TimeSpan(0);
                    countIdletimes     = new TimeSpan(0);
                    countDownTimetimes = new TimeSpan(0);
                    countRunningtimes  = new TimeSpan(0);

                    txtRunningTimes.Text = "00h:00m:00s";
                    txtSettingTimes.Text = "00h:00m:00s";
                    txtDownTimes.Text    = "00h:00m:00s";
                    txtIdleTimes.Text    = "00h:00m:00s";


                    Properties.Settings.Default.RunningTimes = countRunningtimes;
                    Properties.Settings.Default.DownTimes    = countDownTimetimes;
                    Properties.Settings.Default.SettingTimes = countSettingtimes;

                    Properties.Settings.Default.Save();

                    lbAlertMessage.Text         = "RESET TIME";
                    PanelAlertMessage.BackColor = Color.Gray;
                    lbAlertMessage.Left         = (PanelAlertMessage.Width - lbAlertMessage.Width) / 2;
                }
                else
                {
                    lbAlertMessage.Text         = "END PROCESS TIME";
                    PanelAlertMessage.BackColor = Color.DarkOrange;
                    lbAlertMessage.Left         = (PanelAlertMessage.Width - lbAlertMessage.Width) / 2;
                    txtMessage.Text             = "Now is End of Process time";
                }
            }
            else if ((DateTime.Now.TimeOfDay < endTime) && (DateTime.Now.TimeOfDay > startTime))
            {
                TimeSpan countAlltime = countSettingtimes + countIdletimes + countDownTimetimes + countRunningtimes;

                if (countSettingtimes.TotalSeconds > 0)
                {
                    chart1.Series[0].Points[0].SetValueY((double)(countSettingtimes.TotalSeconds * 100 / (countAlltime.TotalSeconds)));
                }
                if (countIdletimes.TotalSeconds > 0)
                {
                    chart1.Series[0].Points[1].SetValueY((double)(countIdletimes.TotalSeconds * 100 / (countAlltime.TotalSeconds)));
                }
                if (countDownTimetimes.TotalSeconds > 0)
                {
                    chart1.Series[0].Points[2].SetValueY((double)(countDownTimetimes.TotalSeconds * 100 / (countAlltime.TotalSeconds)));
                }
                if (countRunningtimes.TotalSeconds > 0)
                {
                    chart1.Series[0].Points[3].SetValueY((double)(countRunningtimes.TotalSeconds * 100 / (countAlltime.TotalSeconds)));
                }

                calYieldandOEE();


                chart1.Refresh();

                resetDone = false;

                if (!DowntimeTimer.Enabled && !SettingTimer.Enabled && !RuningTimer.Enabled && !IdleTimer.Enabled)
                {
                    txtMessage.Text             = "Please key or scan job barcode before start process";
                    tikerTime                   = DateTime.Now.TimeOfDay;
                    countIdletimes              = tikerTime - startTime - countRunningtimes - countDownTimetimes - countSettingtimes;
                    bbcountIdletimes            = countIdletimes;
                    PanelAlertMessage.BackColor = Color.DarkOrange;
                    IdleTimer.Start();
                }
            }
        }