private void dgvDados_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { this.codigo = Convert.ToInt32(dgvDados.Rows[e.RowIndex].Cells[0].Value); } this.alteraBotoes(3); this.operacao = "alterar"; DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao); BLLSetor bll = new BLLSetor(cx); DTOSetor modelo = bll.CarregaModeloGrupo(codigo); txtId.Text = modelo.IdSetor.ToString(); txtNomeSetor.Text = modelo.NomeSetor.ToString(); cbUnidade.Text = modelo.IdUnidade.ToString(); //carrega dados na tabela }
private void btSalvar_Click(object sender, EventArgs e) { try { //leitura dos dados DTOSetor modelo = new DTOSetor(); modelo.NomeSetor = txtNomeSetor.Text; modelo.IdUnidade = Convert.ToInt32(cbUnidade.Text); //conexão DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao); BLLSetor bll = new BLLSetor(cx); if (this.operacao == "inserir") { bll.Incluir(modelo); MessageBox.Show("Cadastro efetuado com sucesso. Produto: " + modelo.NomeSetor.ToString() + "."); this.LimpaCampos(); this.alteraBotoes(1); } else { // altera produto modelo.IdSetor = Convert.ToInt32(txtId.Text); bll.Alterar(modelo); MessageBox.Show("Cadastro alterado com sucesso. Produto: " + modelo.NomeSetor.ToString() + "."); this.LimpaCampos(); this.alteraBotoes(1); } } catch (Exception erro) { MessageBox.Show(erro.Message); } this.CarregaDados(); }