private void btnApagar_Click(object sender, EventArgs e) { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Apagar(id); dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex); }
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); ComestivelRepositorio repositorio = new ComestivelRepositorio(); Comestivel comestivel = repositorio.ObterPeloId(id); ComestivelEditar comestivelEditar = new ComestivelEditar(comestivel); comestivelEditar.ShowDialog(); }
private void btnSalvar_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); if (txtNome.Text.Length == 0) { MessageBox.Show("Digite no minimo 1 caracter no campo Nome"); txtNome.Focus(); return; } comestivel.Nome = txtNome.Text; try { comestivel.Valor = Convert.ToDouble(txtValor.Text); if (comestivel.Valor < 0) { MessageBox.Show("Valor nao aceita número menor que 0"); return; } } catch { MessageBox.Show("Digite apenas Números no campo Valor"); txtValor.Focus(); return; } comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text); try { comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text); } catch { MessageBox.Show("Digite apenas Números inteiros no campo Quantidade"); txtQuantidade.Focus(); return; } if (txtMarca.Text.Length == 0) { MessageBox.Show("Digite no minimo 1 caracter no campo Marca"); txtMarca.Focus(); return; } comestivel.Marca = txtMarca.Text; ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Inserir(comestivel); Close(); }
private void AtualizarTabela() { ComestivelRepositorio repositorio = new ComestivelRepositorio(); List <Comestivel> comestiveis = repositorio.ObterTodos(); dataGridView1.Rows.Clear(); for (int i = 0; i < comestiveis.Count; i++) { Comestivel comestivel = comestiveis[i]; dataGridView1.Rows.Add(new object[] { comestivel.Id, comestivel.Nome, comestivel.Preco, comestivel.DataVencimento, comestivel.Quantidade, comestivel.Marca }); } }
private void btnSalvar_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); comestivel.Id = Convert.ToInt32(txtId.Text); if (txtNome.Text.Length < 1) { MessageBox.Show("Registre o nome corretamente"); txtNome.Focus(); return; } comestivel.Nome = txtNome.Text; try { comestivel.Preco = Convert.ToDecimal(txtPreco.Text); if (comestivel.Preco < 0) { MessageBox.Show("Números devem ser maior do que zero"); } } catch { MessageBox.Show("Campo deve conter apenas números"); txtPreco.Focus(); return; } comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text); try { comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text); if (comestivel.Quantidade < 0) { MessageBox.Show("Test"); return; } } catch { MessageBox.Show("Campo deve conter apenas números"); txtQuantidade.Focus(); return; } comestivel.Marca = txtMarca.Text; ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Atualizar(comestivel); MessageBox.Show("Editado com sucesso"); Close(); }
private void btnSalvarComestivel_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); comestivel.Nome = txtNome.Text; comestivel.Valor = Convert.ToDecimal(mtdValor.Text.Replace("R$", "").Replace(" ", "")); comestivel.DataVencimento = dtpDataVencimento.Value; comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text); comestivel.Marca = txtMarca.Text; ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Inserir(comestivel); Close(); }
public void btnApagar_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { MessageBox.Show("Selecione uma linha para apagar"); return; } int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Apagar(id); dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex); }
private void btnSalvarComestivel_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); comestivel.Id = Convert.ToInt32(txtId.Text); comestivel.Nome = txtNome.Text; comestivel.Valor = Convert.ToDecimal(mtdValor.Text.Replace("R$", "").Replace(" ", "")); comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text); comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text); comestivel.Marca = txtMarca.Text; ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Atualizar(comestivel); MessageBox.Show("Editado com sucesso"); }
private void btnSalvar_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); comestivel.Nome = txtNome.Text; comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text); comestivel.Marca = txtMarca.Text; if (txtNome.Text.Length < 3) { MessageBox.Show("Informe ao menos 3 caracteres em NOME"); txtNome.Focus(); return; } try { comestivel.Valor = Convert.ToDecimal(txtValor.Text); } catch (Exception) { MessageBox.Show("Digite um número no campo VALOR"); txtValor.Focus(); return; } try { comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text); } catch (Exception) { MessageBox.Show("Digite um valor Inteiro no campo QUANTIDADE"); txtQuantidade.Focus(); return; } if (txtMarca.Text.Length < 3) { MessageBox.Show("Informe ao menos 3 caracteres no campo MARCA"); txtMarca.Focus(); return; } Close(); ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Inserir(comestivel); MessageBox.Show("Registro Criado com sucesso"); }
private void btnSalvar_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); ComestivelRepositorio repositorio = new ComestivelRepositorio(); comestivel.Id = Convert.ToInt32(txtCodigo.Text); comestivel.Nome = txtNome.Text; comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text); comestivel.Marca = txtMarca.Text; if (txtNome.Text.Length < 3) { MessageBox.Show("Digite ao menos 3 Caracteres em NOME"); txtNome.Focus(); return; } try { comestivel.Valor = Convert.ToDecimal(txtValor.Text); } catch (Exception) { MessageBox.Show("Digite um valor no campo VALOR"); txtValor.Focus(); return; } try { comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text); } catch (Exception) { MessageBox.Show("Digite um valor Inteiro no campo QUANTIDADE"); txtQuantidade.Focus(); return; } if (txtMarca.Text.Length < 3) { MessageBox.Show("Didite ao menos 3 caracteres em MARCA"); txtMarca.Focus(); return; } MessageBox.Show("Editado com Sucesso."); Close(); repositorio.Atualizar(comestivel); }
public void AtualizarTabela() { ComestivelRepositorio repositorio = new ComestivelRepositorio(); List <Comestivel> comestiveis = repositorio.ObterTodos(); dataGridView1.Rows.Clear(); for (int i = 0; i < comestiveis.Count; i++) { Comestivel comestivel = comestiveis[i]; string valorTexto = $"R$ {comestivel.Valor}"; dataGridView1.Rows.Add( new object[] { comestivel.Id, comestivel.Nome, valorTexto, comestivel.DataVencimento, comestivel.Quantidade, comestivel.Marca } ); } }
private void btnApagar_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Não há nenhum registro para ser apagado."); return; } else { DialogResult dialogResult = MessageBox.Show("AVISO!", "DESEJA APAGAR?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Apagar(id); dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex); MessageBox.Show("Registro apagado com sucesso."); AtualizarTabela(); } } }
private void btnSalvar_Click(object sender, EventArgs e) { Comestivel comestivel = new Comestivel(); comestivel.Nome = txtNome.Text; if (txtNome.Text.Length == 0) { MessageBox.Show("Informe o nome do produto."); txtNome.Focus(); return; } comestivel.Marca = txtMarca.Text; if (txtMarca.Text.Length == 0) { MessageBox.Show("Informe a marca do produto."); txtMarca.Focus(); return; } try { comestivel.Valor = Convert.ToDecimal(txtValor.Text .Replace("R$", "") .Replace(" ", "") .Replace(".", "")); } catch { if (txtValor.Text.Length == 0) { MessageBox.Show("Por favor, informe o valor do produto."); txtValor.Focus(); return; } MessageBox.Show("Permitido somente a entrada do valor neste campo, não é permitido letras."); txtValor.Focus(); return; } comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text); try { comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text .Replace(" ", "")); } catch { if (txtQuantidade.Text.Length == 0) { MessageBox.Show("Informe a quantidade."); txtQuantidade.Focus(); return; } MessageBox.Show("Permitido somente números inteiros."); txtQuantidade.Focus(); return; } ComestivelRepositorio repositorio = new ComestivelRepositorio(); repositorio.Inserir(comestivel); MessageBox.Show("Registrado com sucesso."); Close(); }