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) { } }
public ActionResult Pedido(PedidoModel model) { bool verificdor = false; var context = new ContextMercadOn(); var pedidoService = new PedidoService(context); var clienteService = new ConsumidorService(context); var mercadoService = new MercadoService(context); var precoService = new PrecoService(context); var pedidoItemService = new PedidoItemService(context); PedidoEntity novoPedido = new PedidoEntity(); novoPedido.ativo = 1; novoPedido.ClienteEntity = clienteService.Consultar(model.clienteid); novoPedido.dataPedido = DateTime.Now; novoPedido.MercadoEntity = mercadoService.Consultar(model.mercadoid); novoPedido.dataConfirmado = DateTime.Now; var split = model.Carrinho.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var produtosItens = new List <ItemPedidoEntity>(); try { foreach (var item in split) { int id = int.Parse(item); var produto = precoService.ConsultarPorFiltro(x => x.idProduto == id, x => x.ProdutoEntity).FirstOrDefault(); var novoItem = new ItemPedidoEntity() { PedidoEntity = novoPedido, PrecoEntity = produto, quantidade = 1, precoItem = produto.precoProduto }; pedidoItemService.Adicionar(novoItem); verificdor = true; } } catch (Exception exp) { verificdor = false; } //bool adicionado = pedidoService.Adicionar(novoPedido); if (verificdor) { TempData["Status"] = true; TempData["Msg"] = "Pedido realizado com sucesso, aguarde entrega."; } else { TempData["Status"] = false; TempData["Msg"] = "Pedido não realizado, verifique com o administrador."; } return(RedirectToAction("Pedido", new { mercadoid = model.mercadoid, clienteid = model.clienteid })); }
public BaseController() { _clienteReposiroty = new ClienteRepository(); _produtoRepository = new ProdutoRepository(); _pedidoItemRepository = new PedidoItemRepository(); _pedidoRepository = new PedidoRepository(); _clienteService = new ClienteService(_clienteReposiroty); _produtoService = new ProdutoService(_produtoRepository); _pedidoItemService = new PedidoItemService(_pedidoItemRepository); _pedidoService = new PedidoService(_pedidoRepository); }
public async void DeletarItem(object sender, EventArgs e) { try { if (!CrossConnectivity.Current.IsConnected) { await DisplayAlert("Alerta!", "Sem conexão com à Internet.", "OK"); return; } var answer = await DisplayAlert("Alerta!", "Deseja excluir o item selecionado?", "Sim", "Não"); if (answer) { var item = (Xamarin.Forms.Button)sender; PedidoItemModel lst = (from itm in pItem.Items where itm.IdItem.ToString() == item.CommandParameter.ToString() select itm).FirstOrDefault <PedidoItemModel>(); //pItem.Items.Remove(lst); Item = new PedidoItemService(); var deletou = await Item.DeletaPedidoItem(Convert.ToInt32(item.CommandParameter)); List <PedidoItemModel> items = new List <PedidoItemModel>(); Item = new PedidoItemService(); items = await Item.BuscaItemPorIdPedido(GlobalVariables.GlobalPedido.IdPedido); if (items.Count > 0) { ped_items.Clear(); foreach (PedidoItemModel itm in items) { ped_items.Add(itm); } CarregaItensPedido(items); CalculaQtdItemPedido(); CalculaVlrPedido(); CalculaDescPedido(); CalculaTotalPedido(); } if (deletou > 0) { await DisplayAlert("Alerta!", "Item deletado com sucesso.", "OK"); } else { await DisplayAlert("Alerta!", "Falha ao excluir item. Tente novamente.", "OK"); } } } catch (Exception) { } }
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) { } }
private async void InserirItem(object sender, EventArgs e) { try { if (!CrossConnectivity.Current.IsConnected) { await DisplayAlert("Alerta!", "Sem conexão com à Internet.", "OK"); return; } if (quantidade == 0) { quantidade = 1; } ProdutosService prodService = new ProdutosService(); List <ProdutosModel> prod = new List <ProdutosModel>(); if (quantidade == 0) { PedidoItemService novoItem = new PedidoItemService(); var answer = await DisplayAlert("Alerta!", "Deseja excluir o item" + codigo + "? ", "Sim", "Não"); if (answer) { var deletou = await novoItem.DeletaPedidoItem(GlobalVariables.GlobalPedido.IdPedido, codigo); if (deletou > 0) { await DisplayAlert("Alerta!", "Item deletado com sucesso.", "OK"); } else { await DisplayAlert("Alerta!", "Falha ao excluir item. Tente novamente.", "OK"); } } ECcodigo.Text = ""; ECqtde.Text = ""; lblItemDigitado.Text = ""; ECcodigo.Focus(); return; } prod = await prodService.BuscaProdutosPorCodigo(codigo, GlobalVariables.campanha); if (prod != null && prod.Count > 0) { PedidoItemService novoItem = new PedidoItemService(); PedidoItemModel item = new PedidoItemModel(); Int32 existente = 0; Boolean novo = false; item.IdPedido = GlobalVariables.GlobalPedido.IdPedido; item.IdFornecedor = prod[0].IdFornecedor; item.IdProduto = prod[0].IdProduto; item.NomeProduto = prod[0].NomeProduto; item.CodigoProduto = prod[0].Codigo; item.Quantidade = quantidade; item.ValorProduto = prod[0].Preco; item.PercentualDesconto = (decimal)GlobalVariables.percDesconto; item.PercentualDescontoDist = prod[0].DescDist; item.ValorDesconto = item.ValorProduto * (item.PercentualDesconto / 100); item.ValorDescontoDist = item.ValorProduto * (item.PercentualDescontoDist / 100); item.Obs = ""; item.IdCampanha = GlobalVariables.campanha; existente = await novoItem.ExisteItemNoPedido(item.IdPedido, item.IdProduto); if (existente > 0) { this.IsBusy = true; item.IdItem = existente; await novoItem.AtualizaPedidoItem(item); ped_items.Add(item); this.IsBusy = false; } else { this.IsBusy = true; novo = await novoItem.InserePedidoItem(item); ped_items.Add(item); this.IsBusy = false; } if (existente > 0 || novo == true) { CalculaQtdItemPedido(); CalculaVlrPedido(); CalculaDescPedido(); CalculaTotalPedido(); ECcodigo.Text = ""; ECqtde.Text = ""; lblItemDigitado.Text = ""; ECcodigo.Focus(); List <PedidoItemModel> items = await Item.BuscaItemPorIdPedido(GlobalVariables.GlobalPedido.IdPedido); { if (items.Count > 0) { CarregaItensPedido(items); CalculaQtdItemPedido(); CalculaVlrPedido(); CalculaDescPedido(); CalculaTotalPedido(); } } } } else { ECcodigo.Text = ""; ECqtde.Text = ""; lblItemDigitado.Text = ""; ECcodigo.Focus(); } } catch (Exception) { } }
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) { } }