private bool SubirNotificacionRechazada()
        {
            List <int>    listaCodigoNotificacion = new List <int>();
            List <string> listaCodigoNotificador  = new List <string>();
            List <string> motivo = new List <string>();
            List <string> listaCodigoReferencia = new List <string>();

            if (coneccionInternet.verificaConeccion(ApplicationContext))
            {
                if (!ManejoBaseDatos.DataBaseOpen())
                {
                    ManejoBaseDatos.Abrir();
                    string  consulta = "Select CodNotificador from Notificaciones WHERE PendienteSubir='S' AND Estado='ResultadoEnCorreccion'";
                    ICursor cursor   = ManejoBaseDatos.Seleccionar(consulta);
                    if (cursor.MoveToFirst())
                    {
                        do
                        {
                            listaCodigoNotificador.Add(cursor.GetString(0));
                        }while (cursor.MoveToNext());
                    }
                    cursor.Close();
                    ManejoBaseDatos.Cerrar();

                    if (listaCodigoNotificador.Count > 0 && !ManejoBaseDatos.DataBaseOpen())
                    {
                        foreach (var codigoNotificador in listaCodigoNotificador)
                        {
                            //tengo por notificador la lista de notificaciones en estado ResultadoEnCorreccion
                            //db = SQLiteDatabase.OpenDatabase(dbPath, null, DatabaseOpenFlags.OpenReadwrite);
                            consulta = "Select CodigoNotificacion,Motivo,CodReferencia from Notificaciones WHERE PendienteSubir='S' AND Estado='ResultadoEnCorreccion' AND CodNotificador='" + codigoNotificador + "'";
                            //cursor = db.RawQuery(consulta, null);
                            ManejoBaseDatos.Abrir();
                            ICursor mCursor = ManejoBaseDatos.Seleccionar(consulta);
                            if (mCursor.MoveToFirst())
                            {
                                Log.Debug(TAG, "Subiendo notificacion RECHAZADA at {0}.", DateTime.UtcNow);
                                do
                                {
                                    //agrego los diferentes codigos de notificaciones pendientes de subir para un notificador en especifico
                                    listaCodigoNotificacion.Add(Convert.ToInt32(mCursor.GetString(0)));
                                    motivo.Add(mCursor.GetString(1));
                                    listaCodigoReferencia.Add(mCursor.GetString(2));
                                }while (mCursor.MoveToNext());
                            }
                            mCursor.Close();
                            ManejoBaseDatos.Cerrar();
                            //
                            int counter = 0;
                            //Por cada codigo de notificacion creo un webRequest con su respectivo cuerpo de Json
                            foreach (var codigoNotificacion in listaCodigoNotificacion)
                            {
                                try
                                {
                                    DateTime      localDate       = DateTime.Now;
                                    string        output          = localDate.ToString("o");
                                    RechazarActas actasRechazadas = new RechazarActas()
                                    {
                                        Fecha              = output,
                                        OficialSupervisor  = FragmentLogin.codNotificador,
                                        OficialNotificador = codigoNotificador,
                                        CodOficina         = FragmentLogin.codOficina,
                                        Notificaciones     = new List <ClassNotificaciones>()
                                        {
                                            new ClassNotificaciones()
                                            {
                                                CodNotificacion = codigoNotificacion,
                                                CodReferencia   = Convert.ToInt32(listaCodigoReferencia[counter])
                                            }
                                        },
                                        Motivo = motivo[counter]
                                    };
                                    string request = @"https://pjgestionnotificacionmovilservicios.azurewebsites.net/api/ActaNotificacion/RechazarActasNotificacion";
                                    string json    = Newtonsoft.Json.JsonConvert.SerializeObject(actasRechazadas);
                                    Console.WriteLine("Json: " + json);
                                    var httpWebRequest = (HttpWebRequest)WebRequest.Create(request);
                                    httpWebRequest.ContentType = "application/json";
                                    httpWebRequest.Method      = "POST";

                                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                                    {
                                        streamWriter.Write(json);
                                        streamWriter.Flush();
                                        streamWriter.Close();
                                    }

                                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                                    {
                                        var result = streamReader.ReadToEnd();
                                        Console.WriteLine("RESULTADO POST: " + result);

                                        if (result.Equals("true", StringComparison.Ordinal) || result.Equals("True", StringComparison.Ordinal))
                                        {
                                            //db = SQLiteDatabase.OpenDatabase(dbPath, null, DatabaseOpenFlags.OpenReadwrite);
                                            //db.ExecSQL(@"UPDATE Notificaciones SET PendienteSubir='N' WHERE CodigoNotificacion=" + codigoNotificacion + " ");
                                            //db.Close();
                                            ManejoBaseDatos.Abrir();
                                            ManejoBaseDatos.ActualizarMultiples("UPDATE Notificaciones SET PendienteSubir='N' WHERE CodigoNotificacion=" + codigoNotificacion + "");
                                            ManejoBaseDatos.Cerrar();
                                        }
                                    }
                                    counter = counter + 1;
                                }
                                catch (Exception ex) { Console.WriteLine("Error subiendo datos para ResultadoEnCorreccion: " + ex.ToString()); }
                            }
                            listaCodigoNotificacion.Clear();
                            motivo.Clear();
                            listaCodigoReferencia.Clear();
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                    //
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        private bool ReasignarNotificacion()
        {
            List <string> listaCodigoNotificacion = new List <string>();
            List <string> listaCodigoNotificador  = new List <string>();

            if (!ManejoBaseDatos.DataBaseOpen())
            {
                ManejoBaseDatos.Abrir();
                string  query  = "Select CodNotificador,CodigoNotificacion from Notificaciones WHERE Reasignar='S'";
                ICursor cursor = ManejoBaseDatos.Seleccionar(query);

                if (cursor.MoveToFirst())
                {
                    do
                    {
                        listaCodigoNotificador.Add(cursor.GetString(0));
                        listaCodigoNotificacion.Add(cursor.GetString(1));
                    }while (cursor.MoveToNext());
                }

                cursor.Close();
                ManejoBaseDatos.Cerrar();

                int counter = 0;
                if (coneccionInternet.verificaConeccion(ApplicationContext))
                {
                    foreach (var codigoNotificacion in listaCodigoNotificacion)
                    {
                        try
                        {
                            string request        = @"https://pjgestionnotificacionmovilservicios.azurewebsites.net/api/OficialNotificador/ReasignarNotificacion?PCodSupervisor=" + FragmentLogin.codNotificador + "&PCodlNotificador=" + listaCodigoNotificador[counter] + "&PCodNotificacion=" + codigoNotificacion + "&PFecha=20160915";
                            var    httpWebRequest = (HttpWebRequest)WebRequest.Create(request);
                            httpWebRequest.ContentType   = "application/json";
                            httpWebRequest.Method        = "POST";
                            httpWebRequest.ContentLength = 0;
                            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                            {
                                var result = streamReader.ReadToEnd();
                                Console.WriteLine("Resultado:" + result);

                                if (result.Equals("true", StringComparison.Ordinal) || result.Equals("True", StringComparison.Ordinal))
                                {
                                    ManejoBaseDatos.Abrir();
                                    //CAMBIAR ESTE QUERY A UN SOLO STRING
                                    //ManejoBaseDatos.Actualizar("Notificaciones", "Reasignar", "'N'", "WHERE CodigoNotificacion=" + codigoNotificacion + "");
                                    ManejoBaseDatos.ActualizarMultiples("UPDATE Notificaciones SET Reasignar='N' WHERE CodigoNotificacion=" + codigoNotificacion + "");
                                    ManejoBaseDatos.Cerrar();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error Re-asignando notificacion: " + ex.ToString());
                            //return false;
                        }
                        counter = counter + 1;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        private bool ActualizarPosicionMaps()
        {
            if (!ManejoBaseDatos.DataBaseOpen())
            {
                if (coneccionInternet.verificaConeccion(ApplicationContext))
                {
                    List <string> data            = new List <string>();
                    List <string> codNotificacion = new List <string>();
                    string        consulta        = "Select Provincia,Canton,Distrito,CodigoNotificacion from Notificaciones WHERE CalcularPosicion='S'";
                    ManejoBaseDatos.Abrir();
                    ICursor cursor = ManejoBaseDatos.Seleccionar(consulta);
                    if (cursor.MoveToFirst())
                    {
                        do
                        {
                            // se agregan a la lista los diferentes elementos a los cuales se les va a calcular la posicion
                            data.Add("Costa Rica," + cursor.GetString(0) + "," + cursor.GetString(1) + "," + cursor.GetString(2));
                            codNotificacion.Add(cursor.GetString(3));
                        } while (cursor.MoveToNext());
                    }
                    cursor.Close();
                    ManejoBaseDatos.Cerrar();

                    if (data.Count >= 0)
                    {
                        int counter = 0;
                        foreach (var item in data)
                        {
                            //Console.WriteLine("string buscar " + item);
                            List <string> tempCoordenas = new List <string>();
                            tempCoordenas = Helper.obtenerCoordenadas(item);


                            if (tempCoordenas.Count >= 0)
                            {
                                //Console.WriteLine("Coordenadas " + tempCoordenas[0] + "," + tempCoordenas[1]);
                                //db = SQLiteDatabase.OpenDatabase(dbPath, null, DatabaseOpenFlags.OpenReadwrite);
                                //db.ExecSQL(@"UPDATE Notificaciones SET googleMapsX=" + tempCoordenas[0] + ", googleMapsY=" + tempCoordenas[1] + ", CalcularPosicion='N' WHERE CodigoNotificacion =" + codNotificacion[counter] + " ");
                                //db.Close();
                                ManejoBaseDatos.Abrir();
                                //ManejoBaseDatos.Actualizar("Notificaciones", "googleMapsX", tempCoordenas[0], " WHERE CodigoNotificacion =" + codNotificacion[counter] + "");
                                //ManejoBaseDatos.Actualizar("Notificaciones", "googleMapsY", tempCoordenas[1], " WHERE CodigoNotificacion =" + codNotificacion[counter] + "");
                                //ManejoBaseDatos.Actualizar("Notificaciones", "CalcularPosicion", "'N'", " WHERE CodigoNotificacion =" + codNotificacion[counter] + "");
                                ManejoBaseDatos.ActualizarMultiples("UPDATE Notificaciones SET googleMapsX=" + tempCoordenas[0] + ", googleMapsY=" + tempCoordenas[1] + ", CalcularPosicion='N' WHERE CodigoNotificacion =" + codNotificacion[counter] + "");
                                ManejoBaseDatos.Cerrar();
                            }
                            counter = counter + 1;
                        }
                        Console.WriteLine("Posiciones guardadas");
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }