private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); RepositorioConsoles repositorio = new RepositorioConsoles(); VideoGame videoGame = repositorio.ObterPeloId(id); AlterarCadastroConsole alterarCadastro = new AlterarCadastroConsole(videoGame); alterarCadastro.ShowDialog(); }
private void btnCadastrar_Click(object sender, EventArgs e) { VideoGame videoGame = new VideoGame(); if (cbTipo.SelectedIndex == -1) { MessageBox.Show("Selecione uma Marca"); cbTipo.DroppedDown = true; return; } videoGame.Tipo = cbTipo.Text; videoGame.Versao = cbVersao.Text; try { videoGame.Preco = Convert.ToDecimal(txtPreco.Text); if (videoGame.Preco < 0) { MessageBox.Show("Somente preço maior que 0"); txtPreco.Focus(); return; } } catch (Exception) { MessageBox.Show("Somente números"); txtPreco.Focus(); return; } try { videoGame.QtdEstoque = Convert.ToInt32(txtEstoque.Text); if (videoGame.QtdEstoque < 0) { MessageBox.Show("Quantidade precisa ser maior que 0"); txtEstoque.Focus(); return; } } catch (Exception) { MessageBox.Show("Somente números"); txtEstoque.Focus(); return; } videoGame.ID = Convert.ToInt32(lblID.Text); RepositorioConsoles repositorio = new RepositorioConsoles(); repositorio.AtualizarPeloObjeto(videoGame); MessageBox.Show("Cadastro alterado com sucesso"); Close(); }
private void AtualizarTabela() { RepositorioConsoles repositorio = new RepositorioConsoles(); List <VideoGame> videoGames = repositorio.ObterTodos(); dataGridView1.Rows.Clear(); for (int i = 0; i < videoGames.Count; i++) { VideoGame videoGame = videoGames[i]; string precoTexto = $"R$ {videoGame.Preco}"; dataGridView1.Rows.Add(new object[] { videoGame.ID, videoGame.Tipo, videoGame.Versao, precoTexto, videoGame.QtdEstoque }); } }
private void btnDeletar_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count <= 0) { MessageBox.Show("Por favor, selecione uma linha"); return; } else { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); DialogResult result = MessageBox.Show("Quer mesmo deletar?", "AVISO", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { RepositorioConsoles repositorio = new RepositorioConsoles(); repositorio.DeletarPeloID(id); AtualizarTabela(); } } }