public void Save(Fornecedor fornecedor)
 {
     if (fornecedor.Id != null)
         this.Update(fornecedor);
     else
         this.Insert(fornecedor);
 }
 private void ClearControls()
 {
     txtID.Text = string.Empty;
     txtNome.Text = string.Empty;
     txtCNPJ.Text = string.Empty;
     GetAllFornecedores();
     dgvFornecedores.ClearSelection();
     this.fornecedorAtual = null;
     txtNome.Focus();
 }
 private void Update(Fornecedor fornecedor)
 {
     var command = new SqlCommand("update FORNECEDORES set cnpj=@cnpj, nome=@nome where id=@id", this.connection);
     command.Parameters.AddWithValue("@cnpj", fornecedor.CNPJ);
     command.Parameters.AddWithValue("@nome", fornecedor.Nome);
     command.Parameters.AddWithValue("@id", fornecedor.Id);
     connection.Open();
     command.ExecuteNonQuery();
     connection.Close();
 }
        private void dgvFornecedores_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
                return;

            this.fornecedorAtual = GetFornecedorById(Convert.
                ToInt64(dgvFornecedores.Rows[e.RowIndex].Cells[0].
                Value));
            txtID.Text = this.fornecedorAtual.Id.ToString();
            txtNome.Text = this.fornecedorAtual.Nome;
            txtCNPJ.Text = this.fornecedorAtual.CNPJ;
        }
Esempio n. 5
0
 protected bool Equals(Fornecedor other)
 {
     return(Id.Equals(other.Id));
 }
 private Fornecedor GetFornecedorById(long id)
 {
     Fornecedor fornecedor = new Fornecedor();
     var connection = DBConnection.DB_Connection;
     var command = new SqlCommand("select id, cnpj, nome from FORNECEDORES where id = @id", connection);
     command.Parameters.AddWithValue("@id", id);
     connection.Open();
     using (SqlDataReader reader=command.ExecuteReader()) {
         while (reader.Read()) {
             fornecedor.Id = reader.GetInt32(0);
             fornecedor.CNPJ = reader.GetString(1);
             fornecedor.Nome = reader.GetString(2);
         }
     }
     connection.Close();
     return fornecedor;
 }
Esempio n. 7
0
 private void Insert(Fornecedor fornecedor)
 {
     throw new System.NotImplementedException();
 }
 //TODO: [Implementar]
 private void Insert(Fornecedor fornecedor)
 {
     throw new System.NotImplementedException();
 }