private void selecionarItem(object sender, EventArgs e) { ver = bd.mesa.Where(d => d.id.Equals(selecionada.id) && d.disponibilidade == false).FirstOrDefault(); if (ver == null) { select = bd.mesa.Single(c => c.id.Equals(selecionada.id) && c.disponibilidade == true); select.disponibilidade = false; cbDisponibilidade.Checked = false; bd.SaveChanges(); } if (nUpDown.Value != 0) { int idProduto = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); p = bd.produto.Find(idProduto); //ACHAR VALOR IDPRODUTO int qtd = Convert.ToInt32(nUpDown.Value); pedido pd = new pedido() { data = DateTime.Now, id_mesa = selecionada.id }; bd.pedido.Add(pd); pedidosMesa.Add(pd); itens_pedido ip = new itens_pedido() { id_pedido = pd.id, id_produto = p.id, quantidade = qtd }; bd.itens_pedido.Add(ip); bd.SaveChanges(); dataGridView1.Rows.Clear(); cbxNome.ResetText(); carregPedidos2(); } else { MessageBox.Show("Preencha os campos!"); } }
private void BtnSalvarAlteracao_Click(object sender, EventArgs e) { int idProduto = Convert.ToInt32(dgProdutos.SelectedRows[0].Cells[0].Value); categoria selecionada = categorias.ElementAt(cbxCategoria.SelectedIndex); produto alteracao = new produto(); if (String.IsNullOrWhiteSpace(txtNome.Text) && String.IsNullOrWhiteSpace(txtValor.Text)) { MessageBox.Show("Não houve alteração!"); } else { alteracao = bd.produto.Single(c => c.id.Equals(idProduto)); alteracao.nome = txtNome.Text; alteracao.descricao = txtDescricao.Text; alteracao.id_categoria = selecionada.id; alteracao.preco = Convert.ToDecimal(txtValor.Text); bd.SaveChanges(); montarTabela(); txtNome.Clear(); txtValor.Clear(); txtDescricao.Clear(); bd.SaveChanges(); clbIngredientes.Items.Clear(); carregaIngredientes(); ingredientesUsados.ForEach(u => { produto_ingrediente novoProdIng = new produto_ingrediente() { id_produto = idProduto, id_ingrediente = u.id }; bd.produto_ingrediente.Add(novoProdIng); bd.SaveChanges(); }); } btnSalvarAlteracao.Visible = false; }
private void excluirMesa(object sender, EventArgs e) { nUP.ResetText(); int excluirEscolhida = Convert.ToInt32(dgMesa.SelectedRows[0].Cells[0].Value); //bool statusMesa = Convert.ToBoolean(dgMesa.SelectedRows[0].Cells[3].Value); //statusMesa = bd.pedido.Where(u => u.id_mesa.Equals(excluirEscolhida)).FirstOrDefault(); usando = bd.mesa.Where(u => u.id.Equals(excluirEscolhida) && u.disponibilidade == true).FirstOrDefault(); produto excluir = new produto(); if (usando == null) { MessageBox.Show("Mesa está sendo usada!"); } else { var db = bd.mesa.Where(u => u.id.Equals(excluirEscolhida)).FirstOrDefault(); bd.mesa.Remove(db); bd.SaveChanges(); } montarTabela(); nUP.Value = 0; }
private void salvarCadastroProduto(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtNome.Text) || String.IsNullOrWhiteSpace(txtValor.Text)) { MessageBox.Show("Preencha os campos!"); } else { nomeUsado = bd.produto.Where(c => c.nome.Equals(txtNome.Text)).FirstOrDefault(); if (nomeUsado == null) { categoria selecionada = categorias.ElementAt(cbxCategoria.SelectedIndex); produto novo = new produto() { nome = txtNome.Text, descricao = txtDescricao.Text, preco = Convert.ToDecimal(txtValor.Text), id_categoria = selecionada.id, imagem = caminhoFoto }; bd.produto.Add(novo); bd.SaveChanges(); montarTabela(); produto nomeProd = bd.produto.Where(u => u.nome.Equals(txtNome.Text)).FirstOrDefault(); ingredientesUsados.ForEach(u => { produto_ingrediente novoProdIng = new produto_ingrediente() { id_produto = nomeProd.id, id_ingrediente = u.id }; bd.produto_ingrediente.Add(novoProdIng); bd.SaveChanges(); }); //bd.produto.ToList().ForEach(f => //{ // if (txtNome.Text == f.nome) // { // ingredientesUsados.ForEach(u => // { // produto_ingrediente novoProdIng = new produto_ingrediente() // { // id_produto = f.id, // id_ingrediente = u.id // }; // bd.produto_ingrediente.Add(novoProdIng); // }); // } //}); txtNome.Clear(); txtValor.Clear(); txtDescricao.Clear(); bd.SaveChanges(); clbIngredientes.Items.Clear(); carregaIngredientes(); } else { MessageBox.Show("Produto ja cadastrado!"); } } }
private void procurar(object sender, EventArgs e) { dataGridView2.Rows.Clear(); dataGridView2.Columns.Clear(); dataGridView2.Columns.Add("id", "id"); dataGridView2.Columns.Add("id_pedido", "id_Pedido"); dataGridView2.Columns.Add("nome", "Nome do Cliente"); dataGridView2.Columns.Add("id", "Entregador"); dataGridView2.Columns.Add("processamento", "Processamento"); dataGridView2.Columns.Add("preco", "Preço"); dataGridView2.Columns.Add("hora", "Horário do pedido"); int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); bd.delivery.ToList().ForEach(u => { if (u.processamento != true) { bd.cliente.ToList().ForEach(f => { itens_pedido itemPedido = bd.itens_pedido.Where(h => h.id_pedido.Equals(u.id_pedido)).FirstOrDefault(); produto produtoS = bd.produto.Where(g => g.id.Equals(itemPedido.id_produto)).FirstOrDefault(); pedido pedido = bd.pedido.Single(i => i.id.Equals(u.id_pedido)); if (u.id_cliente == f.id && id == u.id_cliente) { total = produtoS.preco * itemPedido.quantidade; usuario nomeEntregador = bd.usuario.Single(t => t.id.Equals(u.id_entregador)); dataGridView2.Rows.Add(u.id, u.id_pedido, f.nome, nomeEntregador.nome, u.processamento, total, pedido.data); } }); } }); somar(); //bd.delivery.ToList().ForEach(u => //{ // if (u.processamento != true) // { // bd.cliente.ToList().ForEach(f => // { // if (u.id_cliente == f.id && id == u.id_cliente) // { // usuario nomeEntregador = bd.usuario.Single(g => g.id.Equals(u.id_entregador)); // dataGridView2.Rows.Add(u.id, u.id_pedido, f.nome, nomeEntregador.nome, u.processamento, total); // } // }); // } //}); //deliverys.ForEach(u => //{ // if (u.processamento != true) // { // clientes.ForEach(e => // { // if (e.id == u.id_cliente) // { // cliente client = bd.cliente.Single(f => f.id.Equals(e.id)); // } // }); // } //}); }
private void incluir(object sender, EventArgs e) { //ver = bd.pedido.Where(d => d.id.Equals(selecionada.id) && d.disponibilidade == false).FirstOrDefault(); //if (ver != null) //{ // select = bd.mesa.Single(c => c.id.Equals(selecionada.id) && c.disponibilidade == false); // cbDisponibilidade.Checked = true; // select.disponibilidade = true; // bd.SaveChanges(); //}; //MessageBox.Show($"O total é de {resultado}"); //LimpaLista(); //total = 0; //resultado = 0; //anterior = 0; if (nUPQuantidade.Value != 0 && !string.IsNullOrEmpty(txtNome.Text) && !string.IsNullOrEmpty(txtTelefone.Text) && !string.IsNullOrEmpty(cbxProdutos.Text) && !string.IsNullOrEmpty(cbxEntregador.Text) && cbxProdutos.Text != "-SELECIONE-" && cbxEntregador.Text != "-SELECIONE-") { int idProduto = Convert.ToInt32(dataGridViewPedido.SelectedRows[0].Cells[0].Value); produto p = bd.produto.Find(idProduto); //ACHAR VALOR IDPRODUTO int qtd = Convert.ToInt32(nUPQuantidade.Value); cliente cliente = bd.cliente.Where(u => u.nome.Equals(txtNome.Text)).FirstOrDefault(); pedido pd = new pedido() { data = DateTime.Now, }; bd.pedido.Add(pd); itens_pedido ip = new itens_pedido() { id_pedido = pd.id, id_produto = p.id, quantidade = qtd }; bd.itens_pedido.Add(ip); delivery dl = new delivery() { id_pedido = pd.id, id_cliente = cliente.id, //ERRO NO ID //id_entregador = cbxEntregador.SelectedIndex }; entregadores.ForEach(u => { if (cbxEntregador.Text == u.nome) { dl.id_entregador = u.id; } }); bd.delivery.Add(dl); bd.SaveChanges(); MessageBox.Show("Incluido com sucesso! "); decimal precoProduto = Convert.ToDecimal(dataGridViewPedido.SelectedRows[0].Cells[2].Value); anterior = resultado; resultado = anterior + (precoProduto * qtd); lblTotal.Text = Convert.ToString(resultado); dataGridViewPedido.Rows.Clear(); cbxProdutos.ResetText(); cbxEntregador.ResetText(); } else { MessageBox.Show("Preencha os campos!"); } }