public void preencheProduto() { DataTable dtProduto = new DataTable(); Dados dados = new Dados(); if (txtCodigo.Text != null && txtCodigo.Text != " - - - -") { dtProduto = dados.ObterProduto(obterCodigoBarras()); int idFabricante = Convert.ToInt32(dtProduto.Rows[0]["id_fabricante"]); int idCategoria = Convert.ToInt32(dtProduto.Rows[0]["id_categoria"]); string fabricante = dados.ObterFabricante(idFabricante); string produto = dtProduto.Rows[0]["nome"].ToString(); string categoria = dados.ObterCategoria(idCategoria); txtMarca.Text = fabricante; txtProduto.Text = produto; txtTipo.Text = categoria; } }
private Boolean cadastrarProduto() { Dados dados = new Dados(); DataTable dtProduto = new DataTable(); dtProduto = dados.ObterTodosProdutos(); string nome = null; int id; int[] status = {0 , 0}; decimal codBarras = 0; Boolean cadastro = true, retorno = false; if (txtNome.Text != null && txtCodigo.Text != " - - - -" && cbFabricante.Text != " - Selecione um Fabricante - " && cbFabricante.Text != "" && cbCategoria.Text != " - Selecione uma Categoria - " && cbCategoria.Text != "") { txtCodigo.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; string strCodBarras = txtCodigo.Text.Replace(" ", "").Trim(); decimal txtCodBarras = Convert.ToDecimal(strCodBarras); foreach (DataRow dr in dtProduto.Rows) { nome = dr["nome"].ToString(); id = Convert.ToInt32(dr["id_fabricante"]); codBarras = Convert.ToDecimal(dr["cod_barras"]); if (txtCodBarras == codBarras) { cadastro = false; status[0] = 1; } else if (txtNome.Text == nome && dados.ObterFabricante(id) == cbFabricante.Text) { cadastro = false; status[1] = 1; } } if (cadastro == true) { dados.cadastrar_produto(txtCodBarras, cadastrarFabricante(), cadastrarCategoria(), txtNome.Text); cadastrarSubstancias(txtCodBarras); retorno = true; } else { if (status[0] == 1 && status[1] == 0) { MessageBox.Show("Código de barras já cadastrado!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (status[0] == 0 && status[1] == 1) { MessageBox.Show("Produto já cadastrado!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("Produto e código de barras já cadastrados!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("Preencha todos os campos!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return retorno; }