예제 #1
0
 private void btnGravar_Click(object sender, EventArgs e)
 {
     dal.Save(new Fornecedor()
     {
         Id = string.IsNullOrEmpty(txtID.Text) ?
              (long?)null : Convert.ToInt64(txtID.Text),
         Nome = txtNome.Text,
         CNPJ = txtCNPJ.Text
     });
     MessageBox.Show("Manutenção realizada com sucesso");
     ClearControls();
 }
        private void btnGravar_Click(object sender, EventArgs e)
        {
            dal.Save(new Fornecedor()
            {
                Id   = string.IsNullOrEmpty(txtID.Text) ? (long?)null : Convert.ToInt64(txtID.Text),
                Nome = txtNome.Text,
                CNPJ = txtCNPJ.Text
            });
            MessageBox.Show("Manutenção realizada com sucesso");
            ClearControls();

            #region Versão 2
            //using (var connection = new SqlConnection(this.connectionString))
            //{
            //    connection.Open();
            //    SqlCommand command = connection.CreateCommand();
            //    command.CommandText = "insert into FORNECEDORES(nome, cnpj) values(@nome, @cnpj)";
            //    command.Parameters.AddWithValue("@nome", txtNome.Text);
            //    command.Parameters.AddWithValue("@cnpj", txtCNPJ.Text);
            //    command.ExecuteNonQuery();
            //}
            //MessageBox.Show("Fornecedor registrado com sucesso");
            //ClearControls();
            //GetAllFornecedores();
            #endregion

            #region Versão 1
            string connectionString = ConfigurationManager.ConnectionStrings["CS_ADO_NET"].ConnectionString;
            //SqlConnection connection = new SqlConnection(connectionString);
            //connection.Open();
            //SqlCommand command = connection.CreateCommand();
            //command.CommandText = "insert into FORNECEDORES(nome, cnpj) values(@nome, @cnpj)";
            //command.Parameters.AddWithValue("@nome", txtNome.Text);
            //command.Parameters.AddWithValue("@cnpj", txtCNPJ.Text);
            //command.ExecuteNonQuery();
            //connection.Close();
            //MessageBox.Show("Fornecedor registrado com sucesso");
            //ClearControls();
            //GetAllFornecedores();
            #endregion
        }