// ________________________________________________________________________

        private void BtOk_Click(object sender, RoutedEventArgs e)
        {
            string selectQuery = "SELECT * FROM `tb_employee` WHERE employee_login = '******' and employee_password = '******'";

            //Clipboard.SetDataObject(selectQuery);
            //MessageBox.Show("Ok");
            lbMessages.Visibility = Visibility.Hidden;
            //TxBoxLogin.IsEnabled = false;

            MyData data = new MyData();

            DataTable dt = data.fillMyAdapter(selectQuery);

            if (data.Error != "0")
            {
                lbMessages.Background = new SolidColorBrush(Colors.Red);
                lbMessages.Visibility = Visibility.Visible;
                lbMessages.Content    = data.Error;
                //GridTest.IsEnabled = true;
            }
            else
            {
                try
                {
                    //Clipboard.SetDataObject(dt.Rows[0][1].ToString());
                    data.Id_employee        = dt.Rows[0][0].ToString();
                    data.FirstName_employee = dt.Rows[0][1].ToString();
                    //data.Dismissed_employee = dt.Rows[0][4].ToString();
                    data.Login_employee     = dt.Rows[0][5].ToString();
                    data.Password_employee  = dt.Rows[0][6].ToString();
                    data.Privilege_employee = dt.Rows[0][7].ToString();
                    string s = data.Privilege_employee.ToString();
                    data.Administrator = s[0].ToString();
                    data.Dismissed     = s[1].ToString();
                    data.PreClean      = s[2].ToString();
                    data.Testing       = s[3].ToString();
                    data.Repaire       = s[4].ToString();
                    data.Debug         = s[5].ToString();
                    data.FinalQC       = s[6].ToString();
                    data.Report        = s[7].ToString();

                    //GridTest.IsEnabled = true;
                }
                catch
                {
                    lbMessages.Background = new SolidColorBrush(Colors.Red);
                    lbMessages.Visibility = Visibility.Visible;
                    lbMessages.Content    = "Wrong login or password!!";

                    //GridTest.IsEnabled = true;
                }


                if (data.Dismissed == "0")

                //if (data.Dismissed_employee == "1")


                {
                    if (!CheckBoxRememberMe.IsChecked ?? true)
                    {
                        DailyUpdate_v3._1.Properties.Settings.Default.TxBoxLogin = string.Empty;
                        Properties.Settings.Default.Save();
                    }
                    else
                    {
                        DailyUpdate_v3._1.Properties.Settings.Default.TxBoxLogin = TxBoxLogin.Text;
                        Properties.Settings.Default.Save();
                    }



                    FireEvent();
                    this.Close();
                }
                else
                {
                    lbMessages.Background = new SolidColorBrush(Colors.Red);
                    lbMessages.Visibility = Visibility.Visible;
                    lbMessages.Content    = "Wrong login or password!!";
                }


                //MessageBox.Show(data.Login_employee);

                //MessageBox.Show(data.Privilege_employee);
                //this.Close();
            }

            //lbMessages.Visibility = Visibility.Hidden;
            //lbMessages.Visibility = Visibility.Collapsed;

            /*
             * MyData data = new MyData();
             * DataTable dt = new DataTable();
             * data.connectionOpen();
             * if (data.Connection.State == ConnectionState.Open)
             * {
             *  MySqlDataAdapter da = new MySqlDataAdapter(selectQuery, data.Connection);
             *  da.Fill(dt);
             *  data.connectionClose();
             * }
             *
             * try
             * {
             *  MessageBox.Show(dt.Rows[0][3].ToString());
             * }
             * catch
             * {
             *  MessageBox.Show("Wrong password!!");
             * }
             */



            // DataTable dt = da.fillMyAdapter(selectQuery);
            //MessageBox.Show(dt.Rows[0][3].ToString());



            /* works!!
             * {
             *  try
             *  {
             *      MyData da = new MyData();
             *      DataTable dt = da.fillMyAdapter(selectQuery);
             *      MessageBox.Show(dt.Rows[0][3].ToString());
             *  }
             *  catch
             *  {
             *      MessageBox.Show("Wrong password!!");
             *  }
             * }
             */



            //this.Close();



            //connection.connectionOpenClose();
            //MessageBox.Show("Connection pass");
        }
        private void addDeleteUpdateEmployee(string query)
        {
            MyData data = new MyData();

            data.addDeleteUpdateData(query);
        }
        private void BtSave_Click(object sender, RoutedEventArgs e)
        {
            //DateTime dateValue = DateTime.Parse(datePickerFrom.ToString());

            //dataGridViewSubTbMain.Items.Clear();
            //dataGridViewSubTbMain.Items.Refresh();
            //dataGridViewSubTbMain.ItemsSource = null;
            MyData error = new MyData();


            if (cmbox_Stage.SelectedValue == null)
            {
                MessageBox.Show("Fill in field stage");
            }
            else
            {
                MyData data      = new MyData();
                string dateMysql = Convert.ToDateTime(datePickerFrom.Text).ToString("yyyy-MM-dd");

                string idStage = cmbox_Stage.SelectedValue.ToString();
                string query   = "insert INTO tb_main(`main_date_create`, `main_wo`, `main_sku`, `main_sn`, `main_ref`, `id_tb_stage`, `id_tb_employee`) VALUES('" + dateMysql + "','" + textBox_WO.Text + "', '" + textBox_SKU.Text + "', '" + textBox_SN.Text + "', '" + textBox_REF.Text + "', '" + idStage + "','" + data.Id_employee + "')";
                //Clipboard.SetDataObject(query);
                data.fillMyAdapter(query);
                string selectQuery = "SELECT id_main FROM tb_main WHERE main_wo ='" + textBox_WO.Text + "'"; //Id for SUB DataGridWiev


                if (error.Error.Contains("Duplicate entry"))
                {
                    MessageBox.Show("The WO already exists");
                    DataTable dt      = data.fillMyAdapter(selectQuery);
                    string    id_main = dt.Rows[0][0].ToString(); //for Updete SUB DataGridView
                    selectQuery = "SELECT tb_main.*, tb_stage.stage_type, tb_employee.employee_first_name " +
                                  "FROM tb_main " +
                                  "left Join tb_stage ON tb_main.id_tb_stage = tb_stage.id_stage " +
                                  "left Join tb_employee ON id_tb_employee = tb_employee.id_employee " +
                                  "WHERE main_wo ='" + textBox_WO.Text + "'" +
                                  " order by  id_main desc";

                    populateDataGridViewMain(selectQuery);
                    //queryForMainDataGridView(dateMysql, dateMysql);
                    populateDataGridViewSubTbMain(id_main);
                }
                else
                {
                    DataTable dt      = data.fillMyAdapter(selectQuery);
                    string    id_main = dt.Rows[0][0].ToString(); //for Updete SUB DataGridView

                    DateTime dateValue = DateTime.Now;

                    string dateTimeMysql = dateMysql + dateValue.ToString(" HH:mm:ss");


                    string idFailureCode = cmbox_FailureCode.SelectedValue.ToString();

                    query = "insert INTO tb_worksheet(`worksheet_date`, `worksheet_notes`, `id_tb_main`, `id_tb_employee" +
                            "`, `id_tb_failure_code`) VALUES('" + dateTimeMysql + "','" + textBoxNotes.Text + "','" + dt.Rows[0][0].ToString() + "', '" + data.Id_employee + "', '" + idFailureCode + "')";
                    //Clipboard.SetDataObject(query);
                    data.fillMyAdapter(query);
                    selectQuery = "SELECT tb_main.*, tb_stage.stage_type, tb_employee.employee_first_name " +
                                  "FROM tb_main " +
                                  "left Join tb_stage ON tb_main.id_tb_stage = tb_stage.id_stage " +
                                  "left Join tb_employee ON id_tb_employee = tb_employee.id_employee " +
                                  "WHERE main_wo ='" + textBox_WO.Text + "'" +
                                  " order by  id_main desc";

                    populateDataGridViewMain(selectQuery);
                    //queryForMainDataGridView(dateMysql, dateMysql);
                    populateDataGridViewSubTbMain(id_main);
                    clearControls();
                }



                /*
                 * selectQuery = "SELECT tb_main.*, tb_stage.stage_type, tb_employee.employee_first_name " +
                 * "FROM tb_main " +
                 * "left Join tb_stage ON tb_main.id_tb_stage = tb_stage.id_stage " +
                 * "left Join tb_employee ON id_tb_employee = tb_employee.id_employee " +
                 * "WHERE main_wo ='" + textBox_WO.Text + "'" +
                 * " order by  id_main desc";
                 *
                 * populateDataGridViewMain(selectQuery);
                 * //queryForMainDataGridView(dateMysql, dateMysql);
                 * populateDataGridViewSubTbMain(id_main);
                 * clearControls();
                 */
            }
        }