public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var      ignored             = base.OnCreateView(inflater, container, savedInstanceState);
            View     self                = inflater.Inflate(Resource.Layout.CommonReportInput, null);
            TextView info                = self.FindViewById <TextView>(Resource.Id.textViewReportInputInfo);
            Spinner  spinner_oficina     = self.FindViewById <Spinner>(Resource.Id.spinnerInputOficina);
            Spinner  spinner_despacho    = self.FindViewById <Spinner>(Resource.Id.spinnerInputDespacho);
            Spinner  spinner_notificador = self.FindViewById <Spinner>(Resource.Id.spinnerInputNotificador);
            TextView fecha_inicio        = self.FindViewById <TextView>(Resource.Id.textViewInputFechaInicio);
            TextView fecha_fin           = self.FindViewById <TextView>(Resource.Id.textViewInputFechaFin);
            TextView fecha_jornada       = self.FindViewById <TextView>(Resource.Id.textViewInputFechaJornada);

            // Oculta/Muestra los parametros de entrada que no corresponden al
            // reporte/perfil de usuario
            bool es_supervisor = false;

            try
            {
                string es_supervisor_str = "False";
                Helpers.SQLiteConeccion dbConeccion;
                dbConeccion = new Helpers.SQLiteConeccion();
                dbConeccion.consultaDatos("SELECT Supervisor FROM OficialNotificador", this.Activity, ref es_supervisor_str);
                es_supervisor = (String.Compare("True", es_supervisor_str, true) == 0);
            }
            catch (Exception e)
            {
                //Se guarda el error en el log de errores
                Logs.saveLogError("NotificacionesEnviadasADespachoInputReport.OnCreateView " + e.Message + " " + e.StackTrace);
                //Se muestra un mensaje informando el error
                Toast.MakeText(this.Context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
            }

            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputOficina).Visibility      = sel_oficina ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputNotificador).Visibility  = (sel_notificador && es_supervisor) ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputDespacho).Visibility     = sel_despacho ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputFechaInicio).Visibility  = sel_fecha_inicio ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputFechaFin).Visibility     = sel_fecha_fin ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputFechaJornada).Visibility = sel_fecha_jornada ? ViewStates.Visible : ViewStates.Gone;

            // Cargar los valores que se tengan del ultimo reporte
            fecha_inicio.Text  = report.input_fecha_inicio.ToString("yyyy-MMM-dd");
            fecha_fin.Text     = report.input_fecha_fin.ToString("yyyy-MMM-dd");
            fecha_jornada.Text = report.input_fecha_jornada.ToString("yyyy-MMM-dd");

            // FIXME: Poner el mensaje de error en un mejor lugar
            if (String.IsNullOrEmpty(report.output_error))
            {
                info.Text = "Datos de entrada para Reporte: " + report.ToString();
            }
            else
            {
                info.Text           = report.output_error;
                report.output_error = null;
            }

            // Accion para el botón de generar reporte
            Button btnGen = self.FindViewById <Button>(Resource.Id.btnGenerarReporte);

            btnGen.Click += (sender, e) => {
                Fragment frag = report.getOutputReportFragment();
                // Asigna los parámetros de entrada (las fechas se assignan en OnDateSet)
                report.input_oficina  = "0534"; // FIXME. El valor esta harc
                report.input_despacho = (string)spinner_despacho.SelectedItem;
                if (sel_notificador)
                {
                    if (es_supervisor)
                    {
                        report.input_notificador = (string)spinner_notificador.SelectedItem;
                    }
                    else
                    {
                        try
                        {
                            Helpers.SQLiteConeccion dbConeccion;
                            dbConeccion = new Helpers.SQLiteConeccion();
                            dbConeccion.consultaDatos("SELECT NombreCompleto FROM OficialNotificador", this.Activity, ref report.input_notificador);
                        }
                        catch (Exception ex)
                        {
                            //Se guarda el error en el log de errores
                            Logs.saveLogError("NotificacionesEnviadasADespachoInputReport.OnCreateView " + ex.Message + " " + ex.StackTrace);
                            //Se muestra un mensaje informando el error
                            Toast.MakeText(this.Context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
                            report.input_notificador = "";
                        }
                    }
                }

                FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, frag).Commit();
            };

            // Spinner con oficinas
            if (sel_oficina)
            {
                Android.Widget.ArrayAdapter <String> ad;
                ad = new Android.Widget.ArrayAdapter <String>(
                    this.Context, Android.Resource.Layout.SimpleSpinnerItem,
                    new string[] { Fragments.FragmentLogin.codOficina, "0534" }); // FIXME El valor de la oficina esta hardcoded
                spinner_oficina.Adapter = ad;
            }

            // Spinner con notificadores
            if (sel_notificador && es_supervisor)
            {
                try
                {
                    Helpers.SQLiteConeccion dbConeccion;
                    dbConeccion = new Helpers.SQLiteConeccion();
                    dbConeccion.setAdaptadorCombo("SELECT NombreCompleto FROM OficialesNotificadores", this.Activity, ref spinner_notificador);
                }
                catch (Exception e)
                {
                    //Se guarda el error en el log de errores
                    Logs.saveLogError("FragmentMap.cargarComboNotificador " + e.Message + " " + e.StackTrace);
                    //Se muestra un mensaje informando el error
                    Toast.MakeText(this.Context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
                }
            }

            // Spinner con despachos
            if (sel_despacho)
            {
                Android.Widget.ArrayAdapter <String> adapter;
                adapter = new Android.Widget.ArrayAdapter <String>(
                    this.Context, Android.Resource.Layout.SimpleSpinnerItem,
                    new string[] { Fragments.FragmentLogin.codOficina, "0163" }); // FIXME El valor del despacho esta hardcoded
                spinner_despacho.Adapter = adapter;
            }

            // Fecha inicio
            if (sel_fecha_inicio)
            {
                DatePickerDialogFragment fecha_inicio_picker = new DatePickerDialogFragment(Activity, DateTime.Now, this, "inicio");
                fecha_inicio.Click += (sender, args) =>
                {
                    fecha_inicio_picker.Show(FragmentManager, null);
                };
            }

            // Fecha fin
            if (sel_fecha_fin)
            {
                DatePickerDialogFragment fecha_fin_picker = new DatePickerDialogFragment(Activity, DateTime.Now, this, "fin");
                fecha_fin.Click += (sender, args) =>
                {
                    fecha_fin_picker.Show(FragmentManager, null);
                };
            }

            // Fecha jornada
            if (sel_fecha_jornada)
            {
                DatePickerDialogFragment fecha_jornada_picker = new DatePickerDialogFragment(Activity, DateTime.Now, this, "jornada");
                fecha_jornada.Click += (sender, args) =>
                {
                    fecha_jornada_picker.Show(FragmentManager, null);
                };
            }

            return(self);
        }
Beispiel #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment

            View ubicacion = inflater.Inflate(Resource.Layout.fragmentMap, container, false);

            ((Activities.MainActivity)Activity).habilitarMenuLateral(true);
            ((Activities.MainActivity)Activity).cambiarTituloAplicacion("Rutas Notificadores");

            TextView txt = ubicacion.FindViewById <TextView>(Resource.Id.textView9);

            Button btnSiguiente = ubicacion.FindViewById <Button>(Resource.Id.btnSiguiente);

            btnSiguiente.Click += BtnSiguiente_Click;//Se crea el evento click

            cargarComboNotificador(this.Activity, ubicacion);

            Spinner notificador = ubicacion.FindViewById <Spinner>(Resource.Id.spnNotificador);

            notificador.ItemSelected += Notificador_ItemSelected;

            if (!(FragmentLogin.supervisor.Equals("true") || FragmentLogin.supervisor.Equals("True")))
            {
                txt.Visibility         = ViewStates.Invisible;
                notificador.Visibility = ViewStates.Invisible;
            }
            else
            {
                notificador.Visibility = ViewStates.Visible;
                txt.Visibility         = ViewStates.Visible;
                dbConeccion.setAdaptadorCombo("SELECT NombreCompleto || '-' || CodigoNotificador FROM OficialesNotificadores", Activity, ref notificador);
                notificador.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Notificador_ItemSelected1);
            }

            posiciones.Clear();
            listaPosiciones.Clear();
            ManejoBaseDatos.Abrir();
            if (FragmentLogin.supervisor.Equals("true", StringComparison.Ordinal) || FragmentLogin.supervisor.Equals("True", StringComparison.Ordinal))
            {
                ICursor cursor = ManejoBaseDatos.Seleccionar("SELECT googleMapsX,googleMapsY,RolNocturno FROM Notificaciones WHERE Estado='AsignarParaNotificar'");
                if (cursor.MoveToFirst())
                {
                    listaPosiciones = new List <KeyValuePair <LatLng, bool> >();
                    KeyValuePair <LatLng, bool> posicion;

                    do
                    {
                        Console.WriteLine("Pares: " + cursor.GetString(0) + " " + cursor.GetString(1));

                        double latitudeM  = double.Parse(cursor.GetString(0), EnglishCulture);
                        double longitudeM = double.Parse(cursor.GetString(1), EnglishCulture);
                        //Se obtiene el valor del rol nocturno
                        string rol = cursor.GetString(2);
                        //Si es verdadero el check se marca y si no, se deja sin marcar
                        bool rolNocturno = rol == "True" || rol == "true" ? true : false;

                        posicion = new KeyValuePair <LatLng, bool>(new LatLng(latitudeM, longitudeM), rolNocturno);
                        listaPosiciones.Add(posicion);

                        posiciones.Add(new LatLng(latitudeM, longitudeM));
                        // 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));
                        //codNotificacion.Add(cursor.GetString(2));
                    } while (cursor.MoveToNext());
                }
                cursor.Close();
                ManejoBaseDatos.Cerrar();
            }
            else
            {
                string  codigoNotificador = FragmentLogin.codNotificador;
                ICursor cursor            = ManejoBaseDatos.Seleccionar("SELECT googleMapsX,googleMapsY,RolNocturno FROM Notificaciones WHERE Estado='Notificandose' and CodNotificador = '" + codigoNotificador + "'");
                if (cursor.MoveToFirst())
                {
                    listaPosiciones = new List <KeyValuePair <LatLng, bool> >();
                    KeyValuePair <LatLng, bool> posicion;

                    do
                    {
                        NumberFormatInfo provider = new NumberFormatInfo();
                        provider.NumberDecimalSeparator = ".";

                        double latitudeM  = Convert.ToDouble(cursor.GetString(0), provider);
                        double longitudeM = Convert.ToDouble(cursor.GetString(1), provider);
                        //Se obtiene el valor del rol nocturno
                        string rol = cursor.GetString(2);
                        //Si es verdadero el check se marca y si no, se deja sin marcar
                        bool rolNocturno = rol == "True" || rol == "true" ? true : false;

                        Console.WriteLine("latitudeM: " + latitudeM.ToString());
                        Console.WriteLine("longitudeM: " + longitudeM.ToString());

                        posicion = new KeyValuePair <LatLng, bool>(new LatLng(latitudeM, longitudeM), rolNocturno);
                        listaPosiciones.Add(posicion);

                        posiciones.Add(new LatLng(latitudeM, longitudeM));
                    } while (cursor.MoveToNext());
                }
                cursor.Close();
                ManejoBaseDatos.Cerrar();
            }

            ((Activities.MainActivity)Activity).IniciarFragmentoMapa(Resource.Id.map);//Se inicia el mapa en el fragmento
            return(ubicacion);
        }