Beispiel #1
0
        private void pesquisar(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            clienteF = bd.cliente.Where(c => c.telefone.Equals(txtTelefone.Text)).FirstOrDefault();
            if (clienteF != null)
            {
                txtNome.Text        = clienteF.nome;
                txtLogradouro.Text  = clienteF.logradouro;
                txtNumero.Text      = clienteF.numero;
                txtBairro.Text      = clienteF.bairro;
                txtComplemento.Text = clienteF.complemento;
                txtCpf.Text         = clienteF.cpf;
                txtCep.Text         = clienteF.cep;
                txtUf.Text          = clienteF.uf;
                txtCidade.Text      = clienteF.cidade;
                clienteF            = bd.cliente.Where(c => c.telefone.Equals(txtTelefone.Text)).FirstOrDefault();

                delivery achado = bd.delivery.Where(u => u.id_cliente.Equals(clienteF.id) && u.processamento == false).FirstOrDefault();
                if (achado != null)
                {
                    dataGridView1.Rows.Add(clienteF.id, clienteF.nome);
                }
                //bd.delivery.ToList().ForEach(g =>
                //{
                //    if (g.id_cliente == clienteF.id && g.processamento != true)
                //    {
                //    }
                //});
            }
            else
            {
                MessageBox.Show("Cliente não cadastrado");
            }
        }
        private void excluir(object sender, EventArgs e)
        {
            int    idUsuario = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            string nome      = Convert.ToString(dataGridView1.SelectedRows[0].Cells[1].Value);

            logado = bd.usuario.Where(u => u.login.Equals(TelaLogin.logado.nome) && u.tipo_usuario == 1).FirstOrDefault();

            int idEntregador = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);

            usado = bd.delivery.Where(u => u.id_entregador.Equals(idEntregador) && u.processamento == false).FirstOrDefault();

            if (logado != null && usado == null)
            {
                var db = bd.usuario.Where(u => u.id.Equals(idUsuario)).FirstOrDefault();
                bd.usuario.Remove(db);
                bd.SaveChanges();
                montarTabela();
            }

            else if (usado != null)
            {
                MessageBox.Show("Entregador está sendo usado!");
            }
        }
Beispiel #3
0
        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!");
            }
        }