private void btngravar_Click(object sender, EventArgs e) { CAMADAS.MODEL.Automoveis auto = new CAMADAS.MODEL.Automoveis(); CAMADAS.DAL.Automoveis dalauto = new CAMADAS.DAL.Automoveis(); auto.id = Convert.ToInt32(txtid.Text); auto.nome = txtnome.Text; auto.marca = txtmarca.Text; auto.cor = txtcor.Text; auto.placa = txtplaca.Text; if (txtmarca.Text == string.Empty && txtcor.Text == string.Empty && txtplaca.Text == string.Empty) { MessageBox.Show("Preencha os Campos do Formulario!!!"); } else { string msg; if (OP == 'I') { msg = "Deseja Confirmar Inserção dos Dados?"; } else { msg = "Deseja Confirmar Alteração dos Dados?"; } DialogResult resp; resp = MessageBox.Show(msg, "Gravar", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (resp == DialogResult.OK) { if (OP == 'I') { dalauto.Insert(auto); } else if (OP == 'E') { dalauto.Update(auto); } } dtgautomoveis.DataSource = dalauto.Select(); OP = 'V'; txtid.Text = "00"; txtnome.Text = ""; txtmarca.Text = ""; txtcor.Text = ""; txtplaca.Text = ""; habilitacampos(false); } }
private void btnexcluir_Click(object sender, EventArgs e) { if (Convert.ToInt32(txtid.Text) > 0) { CAMADAS.MODEL.Automoveis auto = new CAMADAS.MODEL.Automoveis(); CAMADAS.DAL.Automoveis dalauto = new CAMADAS.DAL.Automoveis(); auto.id = Convert.ToInt32(txtid.Text); DialogResult result; result = MessageBox.Show("Deseja Remover?", "Remover", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { dalauto.Delete(auto); MessageBox.Show("Removido com Sucesso..."); } else { MessageBox.Show("Não confirmada Remoção...", "Remover"); } dtgautomoveis.DataSource = dalauto.Select(); //atualizar lista de registro habilitacampos(false); } else { MessageBox.Show("Não há registro Selecionado", "Remover"); } txtid.Text = "00"; txtmarca.Text = ""; txtmarca.Text = ""; txtcor.Text = ""; txtplaca.Text = ""; OP = 'V'; habilitacampos(false); }
private void Automoveis_Load(object sender, EventArgs e) { CAMADAS.DAL.Automoveis dalauto = new CAMADAS.DAL.Automoveis(); dtgautomoveis.DataSource = dalauto.Select(); habilitacampos(false); }