Exemplo n.º 1
0
        private void btnModifierClient_Click(object sender, EventArgs e)
        {
            frmAjoutModificationClient frmClientAjout = new frmAjoutModificationClient();

            frmClientAjout.intChoix = 2;

            dynamic clientSelectionne = clientBindingSource.Current;

            //MessageBox.Show(Convert.ToString(clientSelectionne["NoClient"]));

            frmClientAjout.strNo         = Convert.ToString(clientSelectionne["NoClient"]);
            frmClientAjout.strNom        = Convert.ToString(clientSelectionne["Nom"]);
            frmClientAjout.strPrenom     = Convert.ToString(clientSelectionne["Prenom"]);
            frmClientAjout.strVille      = Convert.ToString(clientSelectionne["Ville"]);
            frmClientAjout.strPays       = Convert.ToString(clientSelectionne["Pays"]);
            frmClientAjout.strAdresse    = Convert.ToString(clientSelectionne["Adresse"]);
            frmClientAjout.strCodePostal = Convert.ToString(clientSelectionne["CodePostal"]);
            frmClientAjout.strDate       = Convert.ToString(clientSelectionne["DateInscription"]);

            if (frmClientAjout.ShowDialog() == DialogResult.OK)
            {
                DisplayData();
            }
        }
Exemplo n.º 2
0
        private void btnAjouterClient_Click(object sender, EventArgs e)
        {
            int          intNoClient          = 0;
            bool         blnIntNoClientTrouve = true;
            List <Int32> lstIntNoClient       = new List <Int32>();

            // requete sql
            String        maChaineDeConnexion = Projet1BaseDeDonnee3.Properties.Settings.Default.BDTP1Guelleh_MarreroConnectionString;
            SqlConnection maConnexion         = new SqlConnection(maChaineDeConnexion);

            maConnexion.Open();

            String        maRequeteSQL = "select NoCLient from client";
            SqlCommand    maCommande   = new SqlCommand(maRequeteSQL, maConnexion);
            SqlDataReader monReader    = maCommande.ExecuteReader();

            if (monReader.HasRows)       // monreader n'est pas vide
            {
                while (monReader.Read()) // Lire le prochain enregistrement (la prochaine ligne)
                {
                    // L'index peut être un numéro de colonne ou le nom d'une colonne
                    //Console.WriteLine(monReader["empNo"] + ", " + monReader["empNom"] + ", " + monReader[2]);

                    lstIntNoClient.Add(monReader.GetInt32(0));
                }
            }
            else // monreader est vide
            {
                blnIntNoClientTrouve = false;
            }
            monReader.Close();   // IMPORTANT: Libérer les ressources

            maConnexion.Close();
            // fin de la requete sql

            if (blnIntNoClientTrouve)
            {
                lstIntNoClient.Sort();

                int intStartingValue = 10,
                    intEndingValue   = lstIntNoClient[lstIntNoClient.Count - 1],
                    intIncrement     = 10;

                var intMissing = Enumerable.
                                 Range(0, (intEndingValue - intStartingValue) / intIncrement + 1).
                                 Select(i => i * intIncrement + intStartingValue).
                                 Except(lstIntNoClient);

                if (intMissing.Count() != 0) // get le premier nb qui manque
                {
                    intNoClient = intMissing.First();
                }
                else // aucun nombre ne manque, so get le dernier nb + 10
                {
                    intNoClient = lstIntNoClient[lstIntNoClient.Count - 1] + 10;
                }
            }
            else
            {
                intNoClient = 10;
            }

            frmAjoutModificationClient frmClientAjout = new frmAjoutModificationClient();

            frmClientAjout.intChoix = 1;

            frmClientAjout.strNo = intNoClient.ToString();

            if (frmClientAjout.ShowDialog() == DialogResult.OK)
            {
                DisplayData();
            }
        }