Ejemplo n.º 1
0
        private async Task SetAdminView(OauthResult oauth, List <Ticket> tickets = null)
        {
            try
            {
                TicketsTable.Children.Clear();
                if (tickets == null)
                {
                    var hoy    = DateTime.Now.AddDays(5).ToString("yyyy-MM-dd");
                    var pasado = DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd");
                    Result = await App.RestClient.Get <TicketsResult>(App.BaseUrl + "/Ticket/OfAdmin", new Dictionary <string, object>
                    {
                        { "fechainicial", pasado },
                        { "fechafinal", hoy }
                    });

                    if (Result != null && Result.Code == 100 && Result.Tickets != null && Result.Tickets.Count > 0) // mostramos las compras del usuario
                    {
                        tickets = Result.Tickets;
                        SetTicketsAdminView(tickets, true);
                    }
                    else
                    {
                        await DisplayAlert(App.AppName, "No encontramos información para tu usuario, intente más tarde...", "Aceptar");
                    }
                }
                else
                {
                    SetTicketsAdminView(tickets, false);
                }
            }
            catch
            {
                await DisplayAlert(App.AppName, "Verifica tu conexión a internet", "Aceptar");
            }
        }
Ejemplo n.º 2
0
 public static async void SetPreferences(OauthResult oauth)
 {
     if (oauth == null)
     {
         return;
     }
     Settings.Data.Replace = true;
     Settings.Data.Add("alias", oauth.Alias);
     Settings.Data.Add("correo", oauth.Correo);
     Settings.Data.Add("hasdirection", oauth.HasDirection);
     Settings.Data.Add("idperfil", oauth.IdPerfil);
     Settings.Data.Add("idusuario", oauth.IdUsuario);
     Settings.Data.Add("nombre", oauth.Nombre);
     Settings.Data.Add("apellido", oauth.Apellido);
     Settings.Data.Add("password", oauth.Password);
     Settings.Data.Add("telefono", oauth.Telefono);
     Settings.Data.Add("redtecnicos", oauth.RedTecnicos);
     Settings.Data.Add("customerid", oauth.CustomerId);
     if (oauth.HasDirection > 0 && oauth.Direction != null)
     {
         Settings.Data.Add("ciudad", oauth.Direction.Ciudad);
         Settings.Data.Add("codigopostal", oauth.Direction.CodigoPostal);
         Settings.Data.Add("direccion", oauth.Direction.Direccion);
         Settings.Data.Add("dnicuit", oauth.Direction.Dnicuit);
         Settings.Data.Add("empresa", oauth.Direction.Empresa);
         Settings.Data.Add("provincia", oauth.Direction.Provincia);
         await Settings.Data.SaveAsync();
     }
 }
Ejemplo n.º 3
0
 public TicketPage(OauthResult oauth, LogisticType type = LogisticType.Interior, List <Ticket> tickets = null)
 {
     Oauth = oauth;
     Type  = type;
     InitializeComponent();
     InitTicket(oauth, type, tickets);
 }
Ejemplo n.º 4
0
 private async Task GoToPage(OauthResult result)
 {
     if (result.IdPerfil == 4) // usuario final
     {
         await Navigation.PushAsync(new ProductsPage()
         {
             Title = App.AppName
         });
     }
     else
     {
         // no hacemos nada
     }
 }
Ejemplo n.º 5
0
        private async void InitTicket(OauthResult oauth, LogisticType type, List <Ticket> tickets)
        {
            if (oauth != null)
            {
                if (oauth.IdPerfil == 4) // cliente
                {
                    if (ToolbarItems.Count == 0)
                    {
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Refrescar", Order = ToolbarItemOrder.Primary, Priority = 1, Command = new Command(Refresh)
                        });
                    }
                    await SetClientView(oauth);
                }
                else if (oauth.IdPerfil == 1) // administrador
                {
                    await SetAdminView(oauth, tickets);

                    if (ToolbarItems.Count == 0)
                    {
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Refrescar", Order = ToolbarItemOrder.Primary, Priority = 1, Command = new Command(Refresh)
                        });
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Buscar", Order = ToolbarItemOrder.Secondary, Priority = 0, Command = new Command(FindTicket)
                        });
                    }
                }
                else if (oauth.IdPerfil == 2) // repartidor
                {
                    if (ToolbarItems.Count == 0)
                    {
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Refrescar", Order = ToolbarItemOrder.Primary, Priority = 1, Command = new Command(Refresh)
                        });
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Capital Federal", Order = ToolbarItemOrder.Secondary, Priority = 0, Command = new Command <LogisticType>(ChangePage), CommandParameter = LogisticType.Capital
                        });
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Interior", Order = ToolbarItemOrder.Secondary, Priority = 0, Command = new Command <LogisticType>(ChangePage), CommandParameter = LogisticType.Interior
                        });
                        ToolbarItems.Add(new ToolbarItem {
                            Text = "Buscar", Order = ToolbarItemOrder.Secondary, Priority = 0, Command = new Command(FindTicket)
                        });
                    }
                    await SetLocalView(oauth, type, tickets);
                }
            }
        }
Ejemplo n.º 6
0
 public UserProfilePage(OauthResult oauth)
 {
     InitializeComponent();
     _oauth = oauth;
     StackUser.BindingContext = _oauth;
     if (_oauth.Direction != null)
     {
         StackDirection.BindingContext = _oauth.Direction;
         StackDirection.IsVisible      = true;
         BtnDireccion.Text             = "Actualizar dirección";
     }
     _tickets = new ObservableCollection <Ticket>();
     ListOfPurchases.ItemsSource = _tickets;
     _cards = new ObservableCollection <Openpay.Card>();
     ListOfCards.ItemsSource = _cards;
 }
Ejemplo n.º 7
0
        private async void CheckPermissions()
        {
            if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android)
            {
                bool success = false;
                Dictionary <Permission, PermissionStatus> permissions = new Dictionary <Permission, PermissionStatus>();
                try
                {
                    permissions = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location, Permission.Phone, Permission.Storage);

                    success = true;
                }
                catch (Exception ex)
                {
#if DEBUG
                    throw ex;
#endif
                    success = false;
                }

                if (permissions[Permission.Location] == PermissionStatus.Granted)
                {
                    ActivityGPS();
                }
                else
                {
                    try
                    {
                        var locationrequest = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

                        if (locationrequest[Permission.Location] == PermissionStatus.Granted)
                        {
                            ActivityGPS();
                        }
                    }
                    catch { }
                }

                if (permissions.Count(e => e.Value == PermissionStatus.Granted) == permissions.Count)
                {
                }
                else
                {
                    var permisos = permissions.Where(e => e.Value != PermissionStatus.Granted).Select(e => e.Key).ToArray();
                    try
                    {
                        permissions = await CrossPermissions.Current.RequestPermissionsAsync(permisos);

                        success = true;
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        throw ex;
#endif
                        success = false;
                    }
                }
            }
            else if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
            {
                ActivityGPS();
            }

            ActivityGPS();

            App.Instance   = this;
            App.RestClient = new RestForms();
            ShopList       = new List <ShopItem>();

            if (Settings.Data.Count > 0)
            {
                string alias        = Settings.Data.Get <string>("alias");
                string correo       = Settings.Data.Get <string>("correo");
                int    hasdirection = Settings.Data.Get <int>("hasdirection");
                int    idperfil     = Settings.Data.Get <int>("idperfil");
                int    idusuario    = Settings.Data.Get <int>("idusuario");
                string nombre       = Settings.Data.Get <string>("nombre");
                string apellido     = Settings.Data.Get <string>("apellido");
                string password     = Settings.Data.Get <string>("password");
                string telefono     = Settings.Data.Get <string>("telefono");
                int    redtecnicos  = Settings.Data.Get <int>("redtecnicos");
                string customerid   = Settings.Data.Get <string>("customerid");

                OauthResult result = new OauthResult
                {
                    IdUsuario    = idusuario,
                    Alias        = alias,
                    Correo       = correo,
                    HasDirection = hasdirection,
                    IdPerfil     = idperfil,
                    Nombre       = nombre,
                    Apellido     = apellido,
                    Password     = password,
                    Telefono     = telefono,
                    CustomerId   = customerid,
                    RedTecnicos  = redtecnicos,
                };

                if (hasdirection > 0)
                {
                    Direction direction = new Direction();
                    direction.Ciudad       = Settings.Data.Get <string>("ciudad");
                    direction.CodigoPostal = Settings.Data.Get <string>("codigopostal");
                    direction.Direccion    = Settings.Data.Get <string>("direccion");
                    direction.Dnicuit      = Settings.Data.Get <string>("dnicuit");
                    direction.Empresa      = Settings.Data.Get <string>("empresa");
                    direction.Provincia    = Settings.Data.Get <string>("provincia");
                    result.Direction       = direction;
                }

                App.Oauth = result;

                if (result.IdPerfil == 4) // usuario final
                {
                    var navigationpage = new NavigationPage(new ProductsPage())
                    {
                        BarBackgroundColor = Color.FromHex("#8ea226"),
                        BarTextColor       = Color.White
                    };
                    MainPage = navigationpage;
                    return;
                }
                else
                {
                }
            }

            if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
            {
                var navigationpage = new NavigationPage(new ProductsPage())
                {
                    BarBackgroundColor = Color.FromHex("#8ea226"),
                    BarTextColor       = Color.White
                };
                MainPage = navigationpage;
            }
            else
            {
                var navigationpage = new NavigationPage(new LoginPage())
                {
                    BarBackgroundColor = Color.FromHex("#8ea226"),
                    BarTextColor       = Color.White
                };
                MainPage = navigationpage;
            }
        }
Ejemplo n.º 8
0
        private async void BtnLogin_Clicked(object sender, EventArgs e)
        {
            BtnLogin.IsEnabled = false;
            var alias    = BoxUser.Text ?? "";
            var password = BoxPassword.Text ?? "";

            if (CrossConnectivity.Current.IsConnected)
            {
                if (!string.IsNullOrEmpty(alias) && !string.IsNullOrEmpty(password))
                {
                    try
                    {
                        OauthResult result = await App.RestClient.Post <OauthResult>(App.BaseUrl + "/User/Oauth", new Dictionary <string, object>
                        {
                            { "alias", alias },
                            { "password", password }
                        });

                        if (result != null)
                        {
                            if (result.Code == 100)
                            {
                                DirectionResult direction = await App.RestClient.Get <DirectionResult>(App.BaseUrl + "/Direction/Get/" + result.IdUsuario, new Dictionary <string, object> {
                                });

                                App.Oauth          = result;
                                App.Oauth.Alias    = alias;
                                App.Oauth.Password = password;
                                if (direction != null)
                                {
                                    if (direction.Direccion != null)
                                    {
                                        App.Oauth.Direction = direction.Direccion;
                                    }
                                }
                                App.SetPreferences(App.Oauth);
                                await GoToPage(result);
                            }
                            else
                            {
                                await DisplayAlert(App.AppName, result.Message, "Aceptar");
                            }
                        }
                        else
                        {
                            await DisplayAlert(App.AppName, "No es posible acceder, intente más tarde", "Aceptar");
                        }
                    }
                    catch
                    {
                        await DisplayAlert(App.AppName, "No es posible acceder, intente más tarde", "Aceptar");
                    }
                }
                else
                {
                    await DisplayAlert(App.AppName, "Introduce los datos que se te piden", "Aceptar");
                }
            }
            else
            {
                await DisplayAlert(App.AppName, "Asegurate de tener conexión a internet", "Aceptar");
            }
            BtnLogin.IsEnabled = true;
        }
Ejemplo n.º 9
0
        private async Task SetClientView(OauthResult oauth)
        {
            try
            {
                TicketsTable.Children.Clear();
                Result = await App.RestClient.Get <TicketsResult>(App.BaseUrl + "/Ticket/OfClient?idusuario=" + oauth.IdUsuario, new Dictionary <string, object> {
                });

                if (Result != null && Result.Code == 100 && Result.Tickets != null && Result.Tickets.Count > 0) // mostramos las compras del usuario
                {
                    var tickets = Result.Tickets;

                    TicketsTable.RowDefinitions.Add(new RowDefinition {
                        Height = 40
                    });

                    Label pedido = new Label {
                        Text = "Pedido"
                    };
                    Label estatus = new Label {
                        Text = "Estatus"
                    };
                    Label monto = new Label {
                        Text = "Monto"
                    };
                    Label comprobante = new Label {
                        Text = "Subir recibos"
                    };

                    SetRowAndColumn(pedido, estatus, monto, comprobante, null, 0, null);
                    int row = 1;
                    foreach (var ticket in tickets)
                    {
                        pedido = new Label {
                            Text = ticket.IdTicket.ToString()
                        };
                        string state = "Subir baucher";
                        if (ticket.Baucher == null)
                        {
                            state = "Subir baucher";
                        }
                        else if (ticket.Baucher != null && ticket.Verificado.Equals("0"))
                        {
                            state = "En revisión";
                        }
                        else if (ticket.Baucher != null && ticket.Verificado.Equals("1") && ticket.Paqueteria == null)
                        {
                            state = "Verificado";
                        }
                        else
                        {
                            state = "Enviado";
                        }
                        estatus = new Label {
                            Text = state
                        };

                        monto = new Label {
                            Text = "$" + ticket.Total
                        };

                        ticket.Pedido  = pedido;
                        ticket.Estatus = estatus;
                        ticket.Monto   = monto;

                        StackLayout layoutbuttons = new StackLayout {
                            Orientation = StackOrientation.Horizontal
                        };
                        Image camera = new Image {
                            Source = "camera.png", WidthRequest = 25, HeightRequest = 25, Margin = new Thickness(5)
                        };
                        if (!state.Equals("Subir baucher"))
                        {
                            camera.Source = "document.png";
                        }

                        if (ticket.Baucher == null)
                        {
                            camera.GestureRecognizers.Add(new TapGestureRecognizer()
                            {
                                Command = new Command <Ticket>(AddBaucher), CommandParameter = ticket
                            });
                        }
                        else
                        {
                            camera.GestureRecognizers.Add(new TapGestureRecognizer()
                            {
                                Command = new Command <Ticket>(ViewBaucher), CommandParameter = ticket
                            });
                        }
                        ticket.BtnCamara = camera;
                        Image air = new Image {
                            Source = "map.png", WidthRequest = 25, HeightRequest = 25, Margin = new Thickness(5)
                        };
                        air.GestureRecognizers.Add(new TapGestureRecognizer()
                        {
                            Command = new Command <Ticket>(ViewPaqueteria), CommandParameter = ticket
                        });
                        layoutbuttons.Children.Add(camera);
                        layoutbuttons.Children.Add(air);
                        SetRowAndColumn(pedido, estatus, monto, null, layoutbuttons, row, ticket);
                        row++;
                    }
                }
                else
                {
                    await DisplayAlert(App.AppName, "No encontramos información para tu usuario, intenta más tarde...", "Aceptar");
                }
            }
            catch
            {
                await DisplayAlert(App.AppName, "Verifica tu conexión a internet", "Aceptar");
            }
        }
Ejemplo n.º 10
0
 private void InfoClient(OauthResult oauth)
 {
 }