Exemplo n.º 1
0
        async void ProximoPagamento()
        {
            try
            {
                if (string.IsNullOrEmpty(ECpercDesc.Text))
                {
                    ECpercDesc.Text = "0";
                }
                if (Convert.ToDouble(ECpercDesc.Text) > 10)
                {
                    await DisplayAlert("Alerta!", "Desconto inválido", "OK");

                    return;
                }
                if (GlobalVariables.formaPagamento > 0)
                {
                    if (GlobalVariables.GlobalPedido.IdPedido > 0)
                    {
                        PedidoItemService srvPedidoItem = new PedidoItemService();
                        var descPedido = srvPedidoItem.RetornaPercentualDescPedido(GlobalVariables.GlobalPedido.IdPedido);
                        ECpercDesc.Text = descPedido.ToString();
                        if (GlobalVariables.formaPagamento == 0)
                        {
                            PedidoService srvPedido = new PedidoService();
                            var           atu       = await srvPedido.AtualizaFormaPagamentoPedido(GlobalVariables.GlobalPedido.IdPedido, GlobalVariables.formaPagamento);
                        }
                    }
                }
                var i = this.Children.IndexOf(this.CurrentPage);
                CurrentPage = Children[2];
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
        protected async void MudaTab(object sender, EventArgs e)
        {
            try
            {
                var i = this.Children.IndexOf(this.CurrentPage);
                if (i == 3)
                {
                    if (GlobalVariables.GlobalClientePedido.IdCliente == 0)
                    {
                        await DisplayAlert("Alerta!", "Selecione o cliente para continuar", "OK");

                        CurrentPage = Children[0];
                        return;
                    }
                    if (GlobalVariables.formaPagamento == 0)
                    {
                        await DisplayAlert("Alerta!", "Selecione a forma de pagamento para continuar", "OK");

                        CurrentPage = Children[1];
                        return;
                    }
                    List <PedidoItemModel> items = await Item.BuscaItemPorIdPedido(GlobalVariables.GlobalPedido.IdPedido);

                    if (items.Count > 0)
                    {
                        CalculaQtdItemPedido();
                        CalculaVlrPedido();
                        CalculaDescPedido();
                        CalculaTotalPedido();
                    }
                }
                if (i == 2)
                {
                    if (GlobalVariables.GlobalClientePedido.IdCliente == 0)
                    {
                        await DisplayAlert("Alerta!", "Selecione o cliente para continuar", "OK");

                        CurrentPage = Children[0];
                        return;
                    }
                    if (GlobalVariables.formaPagamento == 0)
                    {
                        await DisplayAlert("Alerta!", "Selecione a forma de pagamento para continuar", "OK");

                        CurrentPage = Children[1];
                        return;
                    }
                    List <PedidoItemModel> items = await Item.BuscaItemPorIdPedido(GlobalVariables.GlobalPedido.IdPedido);

                    if (items.Count > 0)
                    {
                        CarregaItensPedido(items);
                    }
                }
                if (i == 1)
                {
                    if (GlobalVariables.GlobalClientePedido.IdCliente == 0)
                    {
                        await DisplayAlert("Alerta!", "Selecione o cliente para continuar", "OK");

                        CurrentPage = Children[0];
                        return;
                    }
                    if (GlobalVariables.GlobalPedido.IdPedido > 0)
                    {
                        PedidoItemService srvPedidoItem = new PedidoItemService();
                        var descPedido = await srvPedidoItem.RetornaPercentualDescPedido(GlobalVariables.GlobalPedido.IdPedido);

                        ECpercDesc.Text = descPedido.ToString();
                    }
                    CarregaPagamento();
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 3
0
        async void NovoPedido(object sender, EventArgs e)
        {
            try
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    await DisplayAlert("Alerta!", "Sem conexão com à Internet.", "OK");

                    return;
                }
                if (GlobalVariables.GlobalClientePedido.IdCliente == 0)
                {
                    await DisplayAlert("Alerta!", "Id do cliente inválido.", "OK");

                    return;
                }
                if (GlobalVariables.GlobalFuncionarioLogado.IdFuncionario == 0)
                {
                    await DisplayAlert("Alerta!", "Id do vendedor inválido.", "OK");

                    return;
                }

                PedidoService srvPedido  = new PedidoService();
                PedidoModel   novoPedido = new PedidoModel();

                // Verifica se existe pedido em aberto
                novoPedido = await srvPedido.BuscaPedidoEmAbertoPorIdCliente(GlobalVariables.GlobalClientePedido.IdCliente);

                if (novoPedido != null && novoPedido.IdPedido > 0)
                {
                    // Carrega pedido
                    GlobalVariables.GlobalPedido          = novoPedido;
                    GlobalVariables.GlobalPedido.IdPedido = novoPedido.IdPedido;
                    GlobalVariables.formaPagamento        = novoPedido.IdPagamento;
                    List <PedidoItemModel> items = await Item.BuscaItemPorIdPedido(novoPedido.IdPedido);

                    if (items.Count > 0)
                    {
                        ped_items.Clear();
                        foreach (PedidoItemModel itm in items)
                        {
                            ped_items.Add(itm);
                        }
                        CarregaItensPedido(items);
                    }

                    CalculaQtdItemPedido();
                    CalculaVlrPedido();
                    CalculaDescPedido();
                    CalculaTotalPedido();

                    PedidoItemService srvPedidoItem = new PedidoItemService();
                    var descPedido = await srvPedidoItem.RetornaPercentualDescPedido(GlobalVariables.GlobalPedido.IdPedido);

                    ECpercDesc.Text = descPedido.ToString();

                    CarregaPagamento();

                    CurrentPage = Children[1];
                }
                else
                {
                    // Insere novo pedido se não existir
                    novoPedido.IdFilial          = 1;
                    novoPedido.IdLote            = 0;
                    novoPedido.IdCliente         = GlobalVariables.GlobalClientePedido.IdCliente;
                    novoPedido.IdFuncionario     = GlobalVariables.GlobalFuncionarioLogado.IdFuncionario;
                    novoPedido.IdPagamento       = GlobalVariables.formaPagamento;
                    novoPedido.IdStatus          = 1;
                    novoPedido.Sessao            = "";
                    novoPedido.Parcelas          = 0;
                    novoPedido.Data              = DateTime.Now.ToString("yyyyMMdd hh:MM:ss");
                    novoPedido.DataEmissao       = novoPedido.Data;
                    novoPedido.Itens             = 0;
                    novoPedido.ValorBruto        = 0;
                    novoPedido.ValorDesconto     = 0;
                    novoPedido.ValorDescontoDist = 0;
                    novoPedido.ValorLiquido      = 0;
                    novoPedido.Obs = "Pedido inserido via App";
                    novoPedido.IdTransportadora = 1;
                    novoPedido.DataEntrega      = null;
                    novoPedido.DescontoGeral    = 0;

                    var inseriu = await srvPedido.NovoPedido(novoPedido);

                    if (inseriu > 0)
                    {
                        novoPedido = new PedidoModel();
                        novoPedido = await srvPedido.BuscaPedidoPorIdPedido(inseriu);

                        // Carrega pedido
                        GlobalVariables.GlobalPedido          = novoPedido;
                        GlobalVariables.GlobalPedido.IdPedido = novoPedido.IdPedido;
                        CalculaQtdItemPedido();
                        CalculaVlrPedido();
                        CalculaDescPedido();
                        CalculaTotalPedido();
                        CurrentPage = Children[1];
                    }
                    else
                    {
                        GlobalVariables.GlobalPedido          = null;
                        GlobalVariables.GlobalPedido.IdPedido = 0;
                    }
                }
            }
            catch (Exception)
            {
            }
        }