private void DeltaCon_StateChange(object sender, StateChangeEventArgs e)
 {
     if (!bclosing && e.CurrentState != ConnectionState.Connecting && (e.CurrentState == ConnectionState.Closed || e.CurrentState == ConnectionState.Broken))
     {
         DeltaCon.Open();
     }
 }
        private bool connecter()
        {
            string ConStr = "";

            DeltaCon.Close();
            DeltaConTmp1.Close();
            deltaConTmp2.Close();
            deltaConMod.Close();

            ConStr = "SERVER=" + Inif.ReadString("BDD", "hostname") + "; Allow User Variables=True; DATABASE=" + baseInit +
                     "; UID=" + Inif.ReadString("BDD", "user") + "; PASSWORD="******"BDD", "password") + "; PORT=" + Inif.ReadString("BDD", "port") + ";default command timeout=600;ConnectionTimeout=600";

            DeltaCon.ConnectionString = DeltaConTmp1.ConnectionString = deltaConMod.ConnectionString = deltaConTmp2.ConnectionString = ConStr;

            //server=localhost;User Id=root;password=za;Persist Security Info=True;database=deltareal
            ConStr = "server=" + Inif.ReadString("BDD", "hostname") + "; DATABASE=" + baseInit +
                     "; User ID=" + Inif.ReadString("BDD", "user") + "; PASSWORD="******"BDD", "password") + "; Persist Security Info=True" + ";default command timeout=600;ConnectionTimeout=600";
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                DeltaCon.Open();
                DeltaConTmp1.Open();
                deltaConTmp2.Open();
                deltaConMod.Open();

                DeltaSQLTmp.Connection = DeltaConTmp1;
                //DeltaSQLCon.Connection = DeltaConTmp1;
                Cursor.Current        = Cursors.Default;
                this.ActiveControl    = edUser;
                this.StatusLabel.Text = "Connection à la base réussie !";


                Properties.Settings.Default["deltarealConnectionString"] = ConStr;

                return(true);
            }
            catch
            {
                //var result = MessageBox.Show(this, "Connexion échouée ! Veuillez vérifier les paramètres !", "Connexion action la Base de Données.");
                Util.AfficherErreur("Connexion à la base échouée ! Veuillez vérifier les paramètres !");
                DeltaCon.Close();
                DeltaConTmp1.Close();
                deltaConTmp2.Close();
                deltaConMod.Close();
                return(false);

                //System.Windows.Forms.Application.Exit();
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            //connecter();
            DeltaSQLCon.CommandText = "SELECT nomprenom, username, password, initials, idcollaborateur FROM " + baseInit + ".Collaborateur WHERE username = '******' AND password = '******'";

            MySqlDataReader myReader = DeltaSQLCon.ExecuteReader();

            if (myReader.Read())
            {
                //var result = MessageBox.Show(myReader.GetString(myReader.GetOrdinal("nomprenom")) + ". Vous êtes connecté !");

                Menu1.Enabled         = true;
                ToolBar1.Enabled      = true;
                panel1.Enabled        = true;
                panel3.Visible        = false;
                this.StatusLabel.Text = "Accès réussi de : " + myReader.GetString(myReader.GetOrdinal("nomprenom")) + "!";
                lUser    = myReader.GetString(myReader.GetOrdinal("nomprenom"));
                InitUser = myReader.GetString(myReader.GetOrdinal("initials"));
                idUser   = myReader.GetInt32(myReader.GetOrdinal("idcollaborateur"));
            }
            else
            {
                Util.AfficherErreur("Attention ! Login ou Mot de pass incorrect ! Veuillez rééssayer !");
                edUser.Focus();
                myReader.Close();
                return;
            }
            myReader.Close();
            szU = Inif.ReadString("BDD", "user");
            szH = Inif.ReadString("BDD", "Hostname");
            szP = Inif.ReadString("BDD", "password");
            //if (cb_base.SelectedIndex > 0)
            //{
            bclosing = true;
            DeltaCon.Close();
            DeltaConTmp1.Close();
            deltaConTmp2.Close();
            deltaConMod.Close();
            string ConStr = "SERVER=" + Inif.ReadString("BDD", "hostname") + "; Allow User Variables=True; DATABASE=" + basefact +
                            "; UID=" + Inif.ReadString("BDD", "user") + "; PASSWORD="******"BDD", "password") + "; PORT=" + Inif.ReadString("BDD", "port") + ";default command timeout=600;ConnectionTimeout=600";

            DeltaCon.ConnectionString = DeltaConTmp1.ConnectionString = deltaConMod.ConnectionString = deltaConTmp2.ConnectionString = ConStr;
            Properties.Settings.Default["deltarealConnectionString"] = ConStr;
            bclosing = false;

            DeltaCon.Open();
            DeltaConTmp1.Open();
            deltaConTmp2.Open();
            deltaConMod.Open();
            myReader.Close();
            Util.RemplirCombo(cmbentreprisesource, "SELECT identreprise, if (entreprise.iddeltareal > 0, concat(clidelta.socligne1, ' ', clidelta.socligne2), concat(entreprise.socligne1, ' ', entreprise.socligne2)) as entreprise FROM fact_entreprise entreprise left join " + baseInit + ".client clidelta ON clidelta.idclient = entreprise.iddeltareal ORDER BY identreprise", DeltaSQLCon, mySqlDataAdapter1);
            if (cmbentreprisesource.Items.Count == 0)
            {
                Util.AfficherErreur("Il n'y a pas encore d'entreprise enregistré ! Veuillez vérifier.");
                bt_marchandises.Enabled = bt_debiteur.Enabled = bt_facture.Enabled = false;
            }
            else
            {
                for (int i = 0; i < cmbentreprisesource.Items.Count; i++)
                {
                    cmbentreprise.Items.Add(cmbentreprisesource.GetItemText(cmbentreprisesource.Items[i]));
                }
                cmbentreprise.SelectedItem = cmbentreprise.Items[0];
            }

            this.Text = "DeltaFact v.1.2" + " - Base : " + basefact + " - Entreprise : " + cmbentreprisesource.Text;
        }