예제 #1
0
        private void btnAceptarSalir(object sender, DialogClickEventArgs e)
        {
            try
            {
                clsLogin objCierreSesion = new clsLogin();
                objCierreSesion.su_fechaFin = DateTime.Now.ToString("dd/MM/yyyy");
                objCierreSesion.su_horaFin  = DateTime.Now.ToString("hh:mm");
                objCierreSesion.su_IDSesion = stIdSesion;
                var stCierreSesion = JsonConvert.SerializeObject(objCierreSesion);

                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                string urlCierreSesion = "http://DCWebApi.somee.com/api/LoginController/RegistrarCierreSesion?stObj=" + stCierreSesion;
                HttpResponseMessage responseCierreSesion = client.GetAsync(urlCierreSesion).Result;
                if (responseCierreSesion.IsSuccessStatusCode)
                {
                    string ResultadoCierreSesion = JsonConvert.DeserializeObject(responseCierreSesion.Content.ReadAsStringAsync().Result).ToString();
                    if (ResultadoCierreSesion == "1")
                    {
                        // FinishAffinity();
                        StartActivity(typeof(ActivityLogin));
                        Finish();
                    }
                    else
                    {
                        StartActivity(typeof(ActivityLogin));
                        Finish();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
예제 #2
0
        private void Btnlogin1_Click(object sender, EventArgs e)
        {
            try
            {
                progressDialog.SetMessage("Iniciado sesión");
                //muestras el ProgressDialog
                progressDialog.Indeterminate = true;
                progressDialog.SetCancelable(false);
                progressDialog.Show();

                if (t1.Text != "" && t2.Text != "")
                {
                    clsLogin objlogin = new clsLogin();
                    objlogin.usu_username   = t1.Text;
                    objlogin.usu_password   = t2.Text;
                    objlogin.su_fechaInicio = DateTime.Now.ToString("dd/MM/yyyy");
                    objlogin.su_horaInicio  = DateTime.Now.ToString("hh:mm");
                    var        Json   = JsonConvert.SerializeObject(objlogin);
                    HttpClient client = new HttpClient();

                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    string url = "http://DCWebApi.somee.com/api/LoginController/ValidarSesion?stObj=" + Json;
                    HttpResponseMessage response = client.GetAsync(url).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        var ResultadoLogin = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);

                        JObject   o         = JObject.Parse(ResultadoLogin.ToString());
                        clsSesion ObjSesion = new clsSesion();
                        ObjSesion.usu_IDRol     = o["usu_IDRol"].ToString();
                        ObjSesion.usu_username  = o["usu_username"].ToString();
                        ObjSesion.usu_IDUsuario = o["usu_IDUsuario"].ToString();
                        ObjSesion.usu_password  = o["usu_password"].ToString();
                        ObjSesion.usu_nombre    = o["usu_nombre"].ToString();
                        ObjSesion.usu_apellido  = o["usu_apellido"].ToString();
                        ObjSesion.usu_dni       = o["usu_dni"].ToString();
                        ObjSesion.usu_telefono  = o["usu_telefono"].ToString();
                        ObjSesion.usu_email     = o["usu_email"].ToString();
                        string valorAreaServicio = o["usu_IDAreaServicio"].ToString();

                        ObjSesion.usu_IDSesion = o["usu_IDSesion"].ToString();

                        if (valorAreaServicio != null)
                        {
                            ObjSesion.usu_IDAreaServicio = o["usu_IDAreaServicio"].ToString();
                            ObjSesion.usu_arServNombre   = o["usu_areaServicio"].ToString();
                        }
                        if (ObjSesion.usu_IDRol != "" && ObjSesion.usu_username != "")
                        {
                            Intent secondActivityIntentParcelable = new Intent(this, typeof(ActivityMenu));
                            secondActivityIntentParcelable.PutExtra("usuarioNombre", ObjSesion.usu_username);
                            secondActivityIntentParcelable.PutExtra("usuarioId", ObjSesion.usu_IDUsuario);
                            secondActivityIntentParcelable.PutExtra("usuarioIdRol", ObjSesion.usu_IDRol.ToString());
                            secondActivityIntentParcelable.PutExtra("NombreCompleto", ObjSesion.usu_nombre + " " + ObjSesion.usu_apellido);
                            secondActivityIntentParcelable.PutExtra("email", ObjSesion.usu_email);
                            secondActivityIntentParcelable.PutExtra("telefono", ObjSesion.usu_telefono);
                            secondActivityIntentParcelable.PutExtra("CodigoReclamo", "0");
                            secondActivityIntentParcelable.PutExtra("idAreaServicio", ObjSesion.usu_IDAreaServicio.ToString());
                            secondActivityIntentParcelable.PutExtra("AreaServicioNombre", ObjSesion.usu_arServNombre.ToString());
                            secondActivityIntentParcelable.PutExtra("password", ObjSesion.usu_password);
                            secondActivityIntentParcelable.PutExtra("nombre", ObjSesion.usu_nombre);
                            secondActivityIntentParcelable.PutExtra("apellido", ObjSesion.usu_apellido);
                            secondActivityIntentParcelable.PutExtra("dni", ObjSesion.usu_dni);
                            secondActivityIntentParcelable.PutExtra("IDSesion", ObjSesion.usu_IDSesion);
                            StartActivity(secondActivityIntentParcelable);
                            //Finish();

                            // progressDialog.Dismiss();
                            new Handler().PostDelayed(() =>
                            {
                                progressDialog.Dismiss();
                            }, 3000);
                        }
                    }
                }
                else
                {
                    AlertDialog ad = new AlertDialog.Builder(this).Create();
                    ad.SetTitle("Error al ingresar");
                    ad.SetMessage("Por favor ingrese su Usuario y Contraseña!");
                    ad.SetButton("Ok", (g, h) => { });
                    ad.Show();
                    t1.Text = "";
                    t2.Text = "";

                    new Handler().PostDelayed(() =>
                    {
                        progressDialog.Dismiss();
                    }, 1000);
                }
                //Finish();
            }
            catch (SoapException ex)
            {
            }
            catch (Exception ex)
            {
                AlertDialog ad = new AlertDialog.Builder(this).Create();
                ad.SetTitle("Error");
                ad.SetMessage("Por favor verifique usuario y contraseña!");
                ad.SetButton("Ok", (g, h) => { });
                ad.Show();
                t1.Text = "";
                t2.Text = "";

                new Handler().PostDelayed(() =>
                {
                    progressDialog.Dismiss();
                }, 1000);
            }
        }