コード例 #1
0
        public static void ModifierClient(Data_Clients dataClient, string id)
        {
            // Fonction permettant la supression d'un client via l'id selectionné
            var sql = "update client set nom = @nom, adresse = @adresse where id_client = @id";
            var con = Fcts_DB.GetConnection();
            var cmd = new MySqlCommand(sql, con)
            {
                CommandType = CommandType.Text
            };

            cmd.Parameters.Add("@id", MySqlDbType.VarChar).Value      = id;
            cmd.Parameters.Add("@nom", MySqlDbType.VarChar).Value     = dataClient.Nom;
            cmd.Parameters.Add("@adresse", MySqlDbType.VarChar).Value = dataClient.Adresse;
            try
            {
                cmd.ExecuteNonQuery();
                MessageBox.Show("Le client " + dataClient.Nom + " a bien été modifié.\n", "Information",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (MySqlException ex)
            {
                MessageBox.Show("Erreur lors de la modification " + ex.Message, "Information", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }
コード例 #2
0
        public static void AjouterClient(Data_Clients dataClient)
        {
            var sql = "insert into client (id_client, nom, adresse) values (NULL, @nom, @adresse)";
            var con = Fcts_DB.GetConnection();
            var cmd = new MySqlCommand(sql, con);

            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@nom", MySqlDbType.Text).Value     = dataClient.Nom;
            cmd.Parameters.Add("@adresse", MySqlDbType.Text).Value = dataClient.Adresse;
            try
            {
                cmd.ExecuteNonQuery();
                MessageBox.Show("Insertion du client : " + dataClient.Nom + " réussie.");
            }
            catch (MySqlException ex)
            {
                MessageBox.Show("Erreur lors de l'insertion : " + ex.Message, "");
            }
        }
コード例 #3
0
        private void btnEnr_Click(object sender, EventArgs e)
        {
            if (txtNom.Text == "" || txtAdresse.Text == "")
            {
                MessageBox.Show("Veuillez remplir les champs.", "Information", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                if (btnEnr.Text == "Ajouter")
                {
                    var dataClient = new Data_Clients(txtNom.Text.Trim(), txtAdresse.Text.Trim());
                    Fcts_Clients.AjouterClient(dataClient);
                }
                else if (btnEnr.Text == "Modifier")
                {
                    var dataClient = new Data_Clients(txtNom.Text.Trim(), txtAdresse.Text.Trim());
                    Fcts_Clients.ModifierClient(dataClient, id);
                }
            }

            _parent.Display();
        }