/// <summary> /// Il a inséré un donné de client dans le Base de données /// </summary> /// <param name="tableBD">table du Base de donnés</param> public void insererClient(string tableBD, Cliente objCliente) { try { // Objet pour l'exécution d'une commande SQL. SqlCommand objComandoSQL = new SqlCommand(); objComandoSQL.CommandText = "INSERT INTO " + tableBD + " VALUES ('" + objCliente.Nome + "','" + objCliente.Email + "','" + objCliente.Contato1 + "','" + objCliente.Contato2 + "','" + objCliente.Contato3 + "')"; objComandoSQL.CommandType = CommandType.Text; objComandoSQL.Connection = objConexao; objComandoSQL.ExecuteNonQuery(); } catch (Exception) { throw; } }
public int insererClient() { mtxtContato1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; // tira a formatação string vmtxtContato1 = mtxtContato1.Text; //texto não formatado mtxtContato1.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; // retorna a formatação mtxtContato2.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; // tira a formatação string vmtxtContato2 = mtxtContato2.Text; //texto não formatado mtxtContato2.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; // retorna a formatação mtxtContato3.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; // tira a formatação string vmtxtContato3 = mtxtContato3.Text; //texto não formatado mtxtContato3.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; // retorna a formatação Cliente objCliente = new Cliente(txtNom.Text, txtEmail.Text, vmtxtContato1, vmtxtContato2, vmtxtContato3); LaConnexion objConectar = new LaConnexion(Properties.Settings.Default.ManiaDeSushiConnectionString); try { objConectar.ouvertConnexion(); objConectar.insererClient("tb_cliente", objCliente); this.code = objConectar.retounerCodeClient("tb_cliente", objCliente); objConectar.fermerLaConnexion(); return this.code; } catch (Exception) { MessageBox.Show("Impossível Inserir este Cliente!. Verifique os dados"); throw; } }
public int retounerCodeClient(string tableBD, Cliente objCliente) { try { SqlCommand objComandoSQL = new SqlCommand(); int code; objComandoSQL.CommandText = "SELECT cli_id FROM " + tableBD + " WHERE cli_email = '" + objCliente.Email + "'"; objComandoSQL.CommandType = CommandType.Text; objComandoSQL.Connection = objConexao; objComandoSQL.ExecuteNonQuery(); //// Objet créé pour lire les donné de base SqlDataReader DR; // Effectue la lecture de retourner un objet SqlDataReader DR = objComandoSQL.ExecuteReader(); DR.Read(); code = DR.GetInt32(0); DR.Close(); return code; } catch (Exception) { throw; } }