private void excluirIng(object sender, EventArgs e) { DialogResult dialog = MessageBox.Show("Essa ação irá retirar o ingrediente escolhido da lista de ingredientes dos produtos que o continham. Deseja continuar?", "Confirmação", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { MessageBox.Show("a"); int excluir = Convert.ToInt32(textBox3.Text); ingrediente excluirI = new ingrediente(); produto pro = new produto(); bd.ingrediente.ToList().ForEach(f => { if (f.id == excluir) { excluirI = f; f.produto.Remove(pro); } }); bd.ingrediente.Remove(excluirI); bd.SaveChanges(); ClearData(); carregaTabelaIng(); MessageBox.Show("Excluído com sucesso"); } else if (dialog == DialogResult.No) { MessageBox.Show("Produto não excluído"); } }
private void alterarProd(object sender, EventArgs e) { string novoValorNome = textBox1.Text; string novoalorDescricao = textBox2.Text; int novoValorCategoria = Convert.ToInt32(comboBox1.SelectedIndex + 1); double novoValorPreco = Convert.ToDouble(textBox3.Text); int alterar = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); produto alterarP = new produto(); bd.produto.ToList().ForEach(f => { if (f.id == alterar) { f.nome = novoValorNome; f.descricao = novoalorDescricao; f.categoria = novoValorCategoria; f.preco = novoValorPreco; dataGridView1.SelectedRows[0].Cells[1].Value = f.nome; dataGridView1.SelectedRows[0].Cells[2].Value = f.descricao; dataGridView1.SelectedRows[0].Cells[3].Value = f.categoria1; dataGridView1.SelectedRows[0].Cells[4].Value = f.preco; bd.SaveChanges(); } }); carregarTblProds(); ClearData(); MessageBox.Show("Alterado com sucesso!"); }
private void salvarProduto(object sender, EventArgs e) { Image img = pictureBox1.Image; byte[] arr; ImageConverter converter = new ImageConverter(); arr = (byte[])converter.ConvertTo(img, typeof(byte[])); categoria selecionada = categorias.ElementAt(comboBox2.SelectedIndex); produto novo = new produto() { nome = textBox1.Text, descricao = textBox4.Text, imagem = arr, categoria = selecionada.id, preco = Convert.ToDouble(maskedTextBox1.Text) }; bd.produto.Add(novo); bd.ingrediente.ToList().ForEach(q => { if (checkedListBox1.GetItemChecked(q.id - 1)) { novo.ingrediente.Add(q); } }); bd.SaveChanges(); MessageBox.Show("Produto salvo com sucesso!"); ClearData(); }
private void incluirProduto(object sender, EventArgs e) { int idProduto = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); produto p = bd.produto.Find(idProduto); int quant = Convert.ToInt32(numericUpDown1.Value); pedido novo = new pedido() { data = DateTime.Now, id_mesa = selecionada.id, finalizado = false }; bd.pedido.Add(novo); bd.SaveChanges(); itens_pedido novin = new itens_pedido() { id_pedido = novo.id, id_produto = p.id, quantidade = quant }; bd.itens_pedido.Add(novin); bd.SaveChanges(); MessageBox.Show("Pedido inserido com sucesso"); totalMesaPed(); }
private void incluirProduto(object sender, EventArgs e) { int idProduto = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); produto p = bd.produto.Find(idProduto); int quant = Convert.ToInt32(numericUpDown1.Value); double tota = 0; int idcliente = 0; bd.clients.ToList().ForEach(f => { if (f.telefone == maskedTextBox1.Text) { idcliente = f.id_cliente; } }); if (idcliente != 0) { pedido novo = new pedido() { data = DateTime.Now, id_cliente_ped = idcliente, finalizado = false }; bd.pedido.Add(novo); bd.SaveChanges(); itens_pedido novin = new itens_pedido() { id_pedido = novo.id, id_produto = p.id, quantidade = quant }; bd.itens_pedido.Add(novin); bd.SaveChanges(); bd.itens_pedido.ToList().ForEach(m => { if (m.id_pedido == novo.id) { if (m.id_produto == m.produto.id) { tota = (m.produto.preco * m.quantidade); } } }); MessageBox.Show("Total do pedido: " + tota.ToString()); MessageBox.Show("Pedido Delivery inserido com sucesso"); numericUpDown1.Value = 0; maskedTextBox1.Text = null; } else { MessageBox.Show("O cliente não está cadastrado no sistema. Cadastre o cliente para prosseguir."); } }
private void alterar(object sender, EventArgs e) { int excluir = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); ingrediente ingre = new ingrediente(); bd.produto.ToList().ForEach(f => { if (f.id == excluir) { bd.ingrediente.ToList().ForEach(i => { i.produto.Remove(f); }); } }); bd.SaveChanges(); string selecionado = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); selected = bd.produto.Where(u => u.nome.Equals(selecionado)).FirstOrDefault(); bd.ingrediente.ToList().ForEach(q => { if (checkedListBox1.GetItemChecked(q.id - 1)) { bd.produto.ToList().ForEach(z => { if (z.id == selected.id) { z.ingrediente.Add(q); } }); } }); bd.SaveChanges(); MessageBox.Show("Alterado com sucesso!"); //Pra desmarcar os itens da checklist foreach (int i in checkedListBox1.CheckedIndices) { checkedListBox1.SetItemCheckState(i, CheckState.Unchecked); } }
private void pesquisarProduto(object sender, EventArgs e) { if (textBox1.Text != "") { pesquisado = bd.produto.Where(u => u.nome.Equals(textBox1.Text)).FirstOrDefault(); if (pesquisado != null) { dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(pesquisado.id, pesquisado.nome, pesquisado.descricao, pesquisado.preco); textBox1.Text = ""; } else { MessageBox.Show("Produto não encontrado"); textBox1.Text = ""; } } else { pesquisada = bd.categoria.Where(u => u.id.Equals(comboBox1.SelectedIndex + 1)).FirstOrDefault(); if (pesquisada != null) { dataGridView1.Rows.Clear(); bd.produto.ToList().ForEach(m => { if (m.categoria == pesquisada.id) { dataGridView1.Rows.Add(m.id, m.nome, m.descricao, m.preco); } }); textBox1.Text = ""; comboBox1.Text = ""; } else { MessageBox.Show("Nenhum produto encontrado nesta categoria."); textBox1.Text = ""; comboBox1.Text = ""; } } }
private void preencher() { //cliente label4.Text = $"Cliente: {selecionada.nome}"; label5.Text = $"Telefone: {selecionada.telefone}"; label6.Text = $"CEP: {selected.cep}"; label7.Text = $"Logradouro: {selected.logradouro}"; label8.Text = $"Número: {selected.numero}"; label9.Text = $"Complemento: {selected.complemento}"; label10.Text = $"Bairro: {selected.bairro}"; label11.Text = $"UF: {selected.uf}"; label12.Text = $"Cidade: {selected.cidade}"; //pedido produto teste = bd.produto.Where(q => q.id.Equals(selee.id_produto)).FirstOrDefault(); label13.Text = selecionado.id.ToString(); label14.Text = $"Data: {selecionado.data}"; label15.Text = $"Produto: {teste.nome}"; label16.Text = $"Quantidade: {selee.quantidade}"; label17.Text = $"Total: {(selee.quantidade*teste.preco)}"; }
private void excluirProd(object sender, EventArgs e) { int excluir = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); produto excluirP = new produto(); itens_pedido abc = new itens_pedido(); bd.itens_pedido.ToList().ForEach(q => { if (q.id_produto == excluir) { if (q.pedido.finalizado == false) // pedido nao finalizado { abc = q; } } }); if (abc.id_pedido > 0) // pedido tiver o produto e nao tiver finalizado { MessageBox.Show("Você não pode deletar um produto até que todos seus pedidos estejam finalizados. Pedido em aberto: " + abc.id_pedido.ToString()); } else { ingrediente ingre = new ingrediente(); bd.produto.ToList().ForEach(f => { if (f.id == excluir) { excluirP = f; f.ingrediente.Remove(ingre); } }); bd.produto.Remove(excluirP); bd.SaveChanges(); carregarTblProds(); ClearData(); MessageBox.Show("Excluído com sucesso!"); } }