Beispiel #1
0
        /// <summary>
        /// evento que permite seleccionar una direccion de la lista y elegir la opcion de modificarlo o eliminarlo
        /// unicamente en android se hará uso del cuadro de diálogo personalizado ya que en iOS
        /// sus configuraciones nativas no lo requieren. Así mismo consume los servicios correspondientes.
        /// </summary>
        /// <param name="sender">objeto que hace referencia al evento</param>
        /// <param name="e">argumentos que son posibles de obtener apartir del objeto que hace llamada al evento</param>
        async void Agregar_Clicked(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(enCorreo.Text) || !Regex.Match(enCorreo.Text, "^(?(\")(\".+?(?<!\\\\)\"@)|(([0-9A-Za-z]((\\.(?!\\.))|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[0-9A-Za-z])@))(?(\\[)(\\[(\\d{1,3}\\.){3}\\d{1,3}\\])|(([0-9a-z][-\\w]*[0-9a-z]*\\.)+[a-z0-9][\\-a-z0-9]{0,22}[a-z0-9]))$").Success)
            {
                await DisplayAlert("Advertencia", "Introduzca un correo electrónico valido", "OK");
            }
            else
            {
                if (Application.Current.Properties.ContainsKey("token"))
                {
                    ClienteRest cliente = new ClienteRest();
                    var         inf     = await cliente.InfoUsuario <InfoUsuario>(Application.Current.Properties["token"] as string);

                    if (inf != null)
                    {
                        AgregarCorreo addemail = new AgregarCorreo();
                        addemail.persona = inf.persona;
                        addemail.email   = new Email
                        {
                            correoe = enCorreo.Text,
                            tipo    = "PERSONAL"
                        };
                        ClienteRest client = new ClienteRest();



                        client.POST(Constantes.URL_USUARIOS + "/email/agregar", addemail, 1);
                        MessagingCenter.Subscribe <ClienteRest>(this, "OK", (Sender) =>
                        {
                            DisplayAlert("Guardado", "¡Correo añadido con exito!", "OK");
                            Navigation.PopAsync();
                            MessagingCenter.Unsubscribe <ClienteRest>(this, "OK");
                        });

                        MessagingCenter.Subscribe <ClienteRest>(this, "error", (Sender) =>
                        {
                            DisplayAlert("Error", "¡No fué posible añadir el correo actual", "OK");
                            MessagingCenter.Unsubscribe <ClienteRest>(this, "error");
                        });
                    }
                }
            }
        }
        /// <summary>
        /// Este evento corresponde al boton agregar cuando se hace click al boton
        /// primero valida que todos los campos añadidos sean validos y una vez que todo sea correcto
        /// consume al servicio para añadir nueva informacion de facturacion.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        void Agregar_Clicked(object sender, System.EventArgs e)
        {
            facturacion.rfc            = enRFC.Text;
            facturacion.nomrazonSocial = enRazon.Text;



            ClienteRest client = new ClienteRest();

            if (!(string.IsNullOrEmpty(enRFC.Text)) && !(string.IsNullOrEmpty(enRazon.Text)) && pkCorreo.SelectedIndex > -1 && pkDireccion.SelectedIndex > -1)
            {
                if (!Regex.Match(enRFC.Text, "[A-Z,Ñ,&]{3,4}[0-9]{2}[0-1][0-9][0-3][0-9][A-Z,0-9]?[A-Z,0-9]?[0-9,A-Z]?").Success || enRFC.Text.Length < 12 || enRFC.Text.Length > 13)
                {
                    DisplayAlert("Advertencia", "Introduzca un RFC valido", "OK");
                }
                else
                {
                    client.POST(Constantes.URL_USUARIOS + "/datos-facturacion/agregar", facturacion, 1);
                }
            }
            else
            {
                DisplayAlert("Advertencia", "Llene y/o seleccione todos los campos", "OK");
            }


            MessagingCenter.Subscribe <ClienteRest>(this, "OK", (Sender) => {
                MessagingCenter.Unsubscribe <ClienteRest>(this, "OK");
                DisplayAlert("Guardado", "¡Información de facturación añadida con exito!", "OK");
                Navigation.PopAsync();
            });

            MessagingCenter.Subscribe <ClienteRest>(this, "error", (Sender) => {
                MessagingCenter.Unsubscribe <ClienteRest>(this, "error");
                DisplayAlert("Error", "¡No fue posible añadir la informació de facturación actual!", "OK");
                Navigation.PopAsync();
            });
        }
        /// <summary>
        /// evento del boton registrar valida que todos los campos ingresados sean correctos
        /// y en caso afirmativo consume al servicio de dar de alta un nuevo usuario
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        async void registrar_Clicked(object sender, System.EventArgs e)
        {
            bool a1 = false, a2 = false, a3 = false, a4 = false, a5 = false, a6 = false, a7 = false, a8 = false, a9 = false, a10 = false, a11 = true, a12 = false;
            bool comodin = true, comodin2 = true, com = false, com2 = false;

            if (!string.IsNullOrEmpty(enCiudad.Text))
            {
                if (!Regex.Match(enCiudad.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s0-9]+$").Success)
                {
                    enCiudad.ErrorText = "Introduza una ciudad valida";
                    await DisplayAlert("Advertencia", "Introduza una ciudad valida", "OK");

                    comodin = false;
                }
                else
                {
                    enCiudad.ErrorText = "";
                    comodin            = true;
                }
            }
            else
            {
                comodin = true;
            }

            if (!string.IsNullOrEmpty(enNumInt.Text))
            {
                if (!Regex.Match(enNumInt.Text, "^[a-zA-Z0-9/-]*$").Success)
                {
                    comodin2 = false;
                }
                else
                {
                    comodin2 = true;
                }
            }
            else
            {
                comodin2 = true;
            }



            if (!string.IsNullOrEmpty(enLADA2.Text))
            {
                if (enLADA2.Text.Length < 2)
                {
                    com = false;
                    await DisplayAlert("Advertencia", "LADA incorrecta", "OK");

                    enLADA2.ErrorText = "LADA";
                }
                else
                {
                    com = true;
                    enLADA2.ErrorText = "";
                }
            }
            else
            {
                com = false;
                enLADA2.ErrorText = "";
            }


            if (!string.IsNullOrEmpty(enCelular.Text))
            {
                if (enCelular.Text.Length < 7 || enCelular.Text.Length > 10)
                {
                    com2 = false;
                    enCelular.ErrorText = "Celular incorrecto";
                    await DisplayAlert("Advertencia", "Celular incorrecto", "OK");
                }
                else
                {
                    com2 = true;
                    enCelular.ErrorText = "";
                }
            }
            else
            {
                com2 = false;
                enCelular.ErrorText = "";
            }


            if (string.IsNullOrEmpty(enColonia.Text) || !Regex.Match(enColonia.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚüÜ\s0-9]+$").Success)
            {
                enColonia.ErrorText = "Introduzca un asentamiento valido";
                await DisplayAlert("Advertencia", "Introduzca un asentamiento valido", "OK");

                a1 = false;
            }
            else
            {
                enColonia.ErrorText = "";
                a1 = true;
            }

            if (ValidarVacio(enDomicilio.Text) || !Regex.Match(enDomicilio.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚüÜ\s0-9]+$").Success)
            {
                enDomicilio.ErrorText = "Introduzca una calle valida";
                await DisplayAlert("Advertencia", "Introduzca una calle valida", "OK");

                a2 = false;
            }
            else
            {
                enDomicilio.ErrorText = "";
                a2 = true;
            }
            if (ValidarVacio(enNumero.Text) || !Regex.Match(enNumero.Text, "^[a-zA-Z0-9/-]*$").Success)
            {
                lblnum.TextColor = Xamarin.Forms.Color.Red;
                a3 = false;
            }
            else
            {
                lblnum.TextColor = Xamarin.Forms.Color.Black;
                a3 = true;
            }

            if (ValidarVacio(enCod.Text) || enCod.Text.Length < 5)
            {
                lblCod.TextColor = Xamarin.Forms.Color.Red;
                a4 = false;
            }
            else
            {
                lblCod.TextColor = Xamarin.Forms.Color.Black;
                a4 = true;
            }


            if (ValidarVacio(enTipoAsentamiento.Text) || !Regex.Match(enTipoAsentamiento.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s0-9]+$").Success)
            {
                enTipoAsentamiento.ErrorText = "Introduzca un tipo valido";
                await DisplayAlert("Advertencia", "Introduzca un tipo valido", "OK");

                a5 = false;
            }
            else
            {
                enTipoAsentamiento.ErrorText = "";
                a5 = true;
            }

            if (ValidarVacio(enEstado.Text) || !Regex.Match(enEstado.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚÜü\s0-9]+$").Success)
            {
                enEstado.ErrorText = "Introduzca un estado valido";
                await DisplayAlert("Advertencia", "Introduzca un estado valido", "OK");

                a6 = false;
            }
            else
            {
                enEstado.ErrorText = "";
                a6 = true;
            }

            if (ValidarVacio(enPais.Text))
            {
                enPais.ErrorText = "Introduzca su país";
                await DisplayAlert("Advertencia", "Introduzca su país", "OK");

                a7 = false;
            }
            else
            {
                enPais.ErrorText = "";
                a7 = true;
            }
            if (ValidarVacio(enTelefono.Text) || enTelefono.Text.Length < 7 || enTelefono.Text.Length > 10)
            {
                await DisplayAlert("Sin número telefónico valido", "Deslice la pantalla para ver todas las opciones", "OK");

                enTelefono.ErrorText = "Introduzca un teléfono valido";
                a8 = false;
            }
            else
            {
                enTelefono.ErrorText = "";
                a8 = true;
            }

            if (ValidarVacio(enMunicipio.Text) || !Regex.Match(enMunicipio.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s0-9]+$").Success)
            {
                await DisplayAlert("Advertencia", "Introduzca un municipio valido", "OK");

                enMunicipio.ErrorText = "Introduzca un municipio valido";
                a9 = false;
            }
            else
            {
                enMunicipio.ErrorText = "";
                a9 = true;
            }

            if (ValidarVacio(enLADA.Text) || enLADA.Text.Length < 2)
            {
                await DisplayAlert("Advertencia", "LADA incorrecta", "OK");

                enLADA.ErrorText = "LADA";
                a10 = false;
            }
            else
            {
                enLADA.ErrorText = "";
                a10 = true;
            }

            if (cargaCP)
            {
                if (!(pkAsentamiento.SelectedIndex > -1))
                {
                    await DisplayAlert("Campo vacio", "seleccione su asentamiento", "ok");

                    a11 = false;
                }
                else
                {
                    a11 = true;
                }
            }

            if (a1 && a2 && a3 && a4 && a5 && a6 && a7 && a8 && a9 && a10 && comodin && comodin2 && a11)
            {
                var asentamiento =
                    user.direccion = new Direccion
                {
                    calle          = enDomicilio.Text,
                    numero         = enNumero.Text,
                    numeroInterior = enNumInt.Text,
                    tipo           = "DOMICILIO",

                    catalogoDir = new CatalogoDir
                    {
                        asentamiento     = (cargaCP)?pkAsentamiento.Items[pkAsentamiento.SelectedIndex]:enColonia.Text,
                        cp               = enCod.Text,
                        ciudad           = enCiudad.Text,
                        estado           = enEstado.Text,
                        municipio        = enMunicipio.Text,
                        tipoasentamiento = enTipoAsentamiento.Text,
                        pais             = enPais.Text
                    }
                };



                user.telefono = new List <Telefono>();


                user.telefono.Add(new Telefono
                {
                    telefono = enTelefono.Text,
                    lada     = enLADA.Text,
                    tipo     = "FIJO"
                });

                if (com && com2)
                {
                    user.telefono.Add(new Telefono
                    {
                        telefono = enCelular.Text,
                        lada     = enLADA2.Text,
                        tipo     = "MOVIL"
                    });
                }



                //System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(user));

                ClienteRest cliente = new ClienteRest();

                cliente.POST(Constantes.URL_USUARIOS + "/registrar?movil=true&tramitta=false", user, 1);


                MessagingCenter.Subscribe <ClienteRest>(this, "OK", async(Sender) =>
                {
                    await DisplayAlert("Guardado", "Usuario registrado con exito", "Ok");
                    await DisplayAlert("Información", "Verifique su correo electrónico para iniciar sesión", "Ok");
                    MessagingCenter.Unsubscribe <ClienteRest>(this, "OK");
                    await Navigation.PopToRootAsync();
                });
                MessagingCenter.Subscribe <ClienteRest>(this, "error", async(Sender) =>
                {
                    MessagingCenter.Unsubscribe <ClienteRest>(this, "error");
                    await DisplayAlert("Error", "No fue posible dar de alta al usuario, posiblemente que este correo ya esta registrado o el servidor esta fuera de línea", "Ok");
                    Application.Current.Properties["calle"]            = enDomicilio.Text;
                    Application.Current.Properties["numero"]           = enNumero.Text;
                    Application.Current.Properties["numeroInterior"]   = enNumInt.Text;
                    Application.Current.Properties["asentamiento"]     = (cargaCP) ? pkAsentamiento.Items[pkAsentamiento.SelectedIndex] : enColonia.Text;
                    Application.Current.Properties["cp"]               = enCod.Text;
                    Application.Current.Properties["ciudad"]           = enCiudad.Text;
                    Application.Current.Properties["estado"]           = enEstado.Text;
                    Application.Current.Properties["municipio"]        = enMunicipio.Text;
                    Application.Current.Properties["tipoAsentamiento"] = enTipoAsentamiento.Text;
                    Application.Current.Properties["pais"]             = enPais.Text;
                    Application.Current.Properties["telefono"]         = enTelefono.Text;
                    Application.Current.Properties["lada"]             = enLADA.Text;
                    Application.Current.Properties["celular"]          = enCelular.Text;
                    Application.Current.Properties["lada2"]            = enLADA2.Text;



                    await Application.Current.SavePropertiesAsync();
                });
                //await Navigation.PopToRootAsync();
            }
        }
        /// <summary>
        /// evento click del botón agregar para consumir al servicio de agregar un nuevo teléfono
        /// </summary>
        /// <param name="sender">objeto que hace referencia al evento</param>
        /// <param name="e">argumentos que son posibles de obtener apartir del objeto que hace llamada al evento</param>
        async void Agregar_Clicked(object sender, System.EventArgs e)
        {
            ClienteRest cliente = new ClienteRest();
            var         inf     = await cliente.InfoUsuario <InfoUsuario>(Application.Current.Properties["token"] as string);

            if (inf != null)
            {
                Modelos.ModificarTelefono modtel = new Modelos.ModificarTelefono();


                modtel.persona = inf.persona;
                bool auth = false, auth2 = false, auth3 = false;


                modtel.telefono = new Telefono
                {
                    tipo     = pkTipo.Items[pkTipo.SelectedIndex],
                    telefono = enTelefono.Text,
                    lada     = enLada.Text
                };

                ClienteRest client = new ClienteRest();
                if (!String.IsNullOrEmpty(enTelefono.Text) && !(enTelefono.Text.Length < 7) && !(enTelefono.Text.Length > 10))
                {
                    auth = true;
                }
                else
                {
                    auth = false;
                    await DisplayAlert("Error", "Teléfono Invalido", "ok");
                }


                if (!String.IsNullOrEmpty(enLada.Text) && !(enTelefono.Text.Length < 2))
                {
                    auth2 = true;
                }
                else
                {
                    auth2 = false;
                    await DisplayAlert("Error", "LADA incorrecta", "ok");
                }


                if (pkTipo.SelectedIndex > -1)
                {
                    auth3 = true;
                }
                else
                {
                    auth3 = false;
                    await DisplayAlert("Error", "Seleccione el tipo de teléfono", "ok");
                }

                if (auth && auth2 && auth3)
                {
                    client.POST(Constantes.URL_USUARIOS + "/telefono/agregar", modtel, 1);
                    MessagingCenter.Subscribe <ClienteRest>(this, "OK", (Sender) => {
                        DisplayAlert("Guardado", "¡Teléfono Añadido con Exito!", "OK");
                        MessagingCenter.Unsubscribe <ClienteRest>(this, "OK");
                        Navigation.PopAsync();
                    });

                    MessagingCenter.Subscribe <ClienteRest>(this, "error", (Sender) => {
                        DisplayAlert("Error", "¡No fué posible añadir el Teléfono!", "OK");
                        MessagingCenter.Unsubscribe <ClienteRest>(this, "error");
                    });
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// este método valida que los campos ingresados en las entradas sean correctos antes de consumir al servicio
        /// de añadir una nueva dirección, en caso contrario se notifica al usuario
        /// </summary>
        async void Añadir()
        {
            bool a1 = false, a2 = false, a3 = false, a4 = false, a5 = false, a6 = false, a7 = false;


            if (ValidarVacio(enCalle.Text) || !Regex.Match(enCalle.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚüÜ\s0-9]+$").Success)
            {
                await DisplayAlert("Campo no valida", "Introduza una calle válida", "Ok");

                a1 = false;
            }
            else
            {
                a1 = true;
            }

            if (ValidarVacio(enNumero.Text) || !Regex.Match(enNumero.Text, "^[a-zA-Z0-9/-]*$").Success)
            {
                await DisplayAlert("Campo no valido", "Introduza una número válido", "Ok");

                a2 = false;
            }
            else
            {
                a2 = true;
            }


            if (ValidarVacio(enCP.Text) || enCP.Text.Length < 5)
            {
                await  DisplayAlert("Campo no valido", "Introduza una código postal válido", "Ok");

                a3 = false;
            }
            else
            {
                a3 = true;
            }


            if (!(pkTipoAsentamiento.SelectedIndex > -1))
            {
                await DisplayAlert("Campo vacio", "selecciona un tipo de asentamiento", "ok");

                a4 = false;
            }
            else
            {
                a4 = true;
            }

            if (ValidarVacio(enMunicipio.Text) || !Regex.Match(enMunicipio.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s0-9]+$").Success)
            {
                await  DisplayAlert("Campo incorrecto", "Introduzca un municipio valido", "ok");

                a5 = false;
            }
            else
            {
                a5 = true;
            }

            if (ValidarVacio(enEstado.Text) || !Regex.Match(enEstado.Text, @"^[a-zA-ZñÑáéíóúÁÉÍÓÚÜü\s0-9]+$").Success)
            {
                await DisplayAlert("Campo vacio", "Introduzca un estado valido", "ok");

                a6 = false;
            }
            else
            {
                a6 = true;
            }
            if (!(pkAsentamiento.SelectedIndex > -1))
            {
                await DisplayAlert("Campo vacio", "seleccione su asentamiento", "ok");

                a7 = false;
            }
            else
            {
                a7 = true;
            }

            if (a1 && a2 && a3 && a4 && a5 && a6 && a7)
            {
                ClienteRest cliente = new ClienteRest();
                Modelos.AgregarDireccion agredire = new Modelos.AgregarDireccion();
                var inf = await cliente.InfoUsuario <InfoUsuario>(Application.Current.Properties["token"] as string);

                if (inf != null)
                {
                    agredire.persona = new Persona
                    {
                        id       = inf.persona.id,
                        nombre   = inf.persona.nombre,
                        apaterno = inf.persona.apaterno,
                        amaterno = inf.persona.amaterno,
                        curp     = inf.persona.curp,
                        edoCivil = inf.persona.edoCivil,
                        sexo     = inf.persona.sexo,
                        fechanac = inf.persona.fechanac
                    };


                    agredire.direccion = new Modelos.Direccion()
                    {
                        calle          = enCalle.Text,
                        numero         = enNumero.Text,
                        numeroInterior = enNumeroInterior.Text,
                        catalogoDir    = new CatalogoDir()
                        {
                            id               = (cargaCP)?cargaID.ToString():null,
                            asentamiento     = pkAsentamiento.Items[pkAsentamiento.SelectedIndex],
                            tipoasentamiento = pkTipoAsentamiento.Items[pkTipoAsentamiento.SelectedIndex],
                            cp               = enCP.Text,
                            ciudad           = enCiudad.Text,
                            municipio        = enMunicipio.Text,
                            estado           = enEstado.Text,
                            pais             = pkpais.Items[pkpais.SelectedIndex]
                        }
                    };
                }



                cliente.POST(Constantes.URL_USUARIOS + "/direccion/agregar", agredire, 1);

                MessagingCenter.Subscribe <ClienteRest>(this, "OK", (Sender) =>
                {
                    DisplayAlert("Guardado", "¡Direccion Añadida con Exito!", "OK");
                    Navigation.PopAsync();
                    MessagingCenter.Unsubscribe <ClienteRest>(this, "OK");
                });
                MessagingCenter.Subscribe <ClienteRest>(this, "error", (Sender) => {
                    DisplayAlert("Advertencia", "¡No fué posible añadir la dirección actual!", "error");
                    Navigation.PopAsync();
                    MessagingCenter.Unsubscribe <ClienteRest>(this, "error");
                });
            }
        }