public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { report.output_error = null; var ignored = base.OnCreateView(inflater, container, savedInstanceState); View self = inflater.Inflate(Resource.Layout.CommonReportOutput, null); if (!report.getFillCommonInfo(self, true, false, ref report.output_error)) { reportErrorGoBack(report.output_error); return(self); } TableLayout table = self.FindViewById <TableLayout>(Resource.Id.tbReporte); // Asegura que ningun parametro este vacío if (String.IsNullOrEmpty(report.input_oficina)) { reportErrorGoBack("El campo de oficina no puede ser vacío"); return(self); } // Consulta // Cambiar las fechas al formato admitido por la BD string fecha_inicio = report.input_fecha_inicio.ToString("yyyyMMdd"); string fecha_fin = report.input_fecha_fin.ToString("yyyyMMdd"); string codigoNotificador = ""; if (report.loggin_supervisor) { try { Helpers.SQLiteConeccion dbConeccion; dbConeccion = new Helpers.SQLiteConeccion(); dbConeccion.consultaDatos( "SELECT CodigoNotificador FROM OficialesNotificadores WHERE NombreCompleto = '" + report.input_notificador + "'", this.Context, ref codigoNotificador); } catch (Exception) { reportErrorGoBack("No fue posible obtener la información requerida para le reporte (ID)"); return(self); } } string query = @"https://pjgestionnotificacionmovilservicios.azurewebsites.net/api/Reportes/NotificacionesCompletadasPorNotificador" + "?PCodOficina=" + report.input_oficina + "&PCodNotificador=" + (report.loggin_supervisor ? codigoNotificador : report.loggin_usuario) + "&PFecha1=" + fecha_inicio + "&PFecha2=" + fecha_fin; // Verificar si la conección a internet esta disponible if (!coneccionInternet.verificaConeccion(this.Context)) { ReportUtils.alertNoInternetMessage(this.Context); } WebRequest request = HttpWebRequest.Create(query); request.ContentType = "application/json"; request.Method = "GET"; string content = ""; Console.Out.WriteLine("--XDEBUG " + query); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode); reportErrorGoBack("No fue posible obtener la información requerida para le reporte"); return(self); } using (StreamReader reader = new StreamReader(response.GetResponseStream())) { content = reader.ReadToEnd(); if (string.IsNullOrWhiteSpace(content)) { Console.Out.WriteLine("fzeledon -- Response contained empty body..."); reportErrorGoBack("Los valores de entrada de la consulta no generaron resultado"); return(self); } try { var jsonParsed = JArray.Parse(content); if (jsonParsed.Count != 2) // Esperamos 2 resultados unicamente { reportErrorGoBack("La información obtenida para le informe no puede ser procesada"); return(self); } ReportUtils.agregarFilaATabla(new string[] { "Notificador", report.input_notificador, "" }, Activity, table); ReportUtils.agregarFilaATabla(new string[] { "", "Cantidad", "Porcentaje" }, Activity, table); int total_positivas = 0; int total_negativas = 0; int i = 0; for (i = 0; i < jsonParsed.Count; ++i) { int total_diligencias = jsonParsed[i].Value <int>("Total"); bool diligenciada = jsonParsed[i].Value <bool>("Diligenciada"); if (diligenciada) { total_positivas += total_diligencias; } else { total_negativas += total_diligencias; } } int gran_total = total_positivas + total_negativas; ReportUtils.agregarFilaATabla(new string[] { "Positivas:", total_positivas.ToString(), (100.0 * total_positivas / gran_total).ToString("N3") + "%" }, Activity, table); ReportUtils.agregarFilaATabla(new string[] { "Negativas", total_negativas.ToString(), (100.0 * total_negativas / gran_total).ToString("N3") + "%" }, Activity, table); ReportUtils.agregarFilaATabla(new string[] { "Total:", (gran_total).ToString() }, Activity, table); } catch (Exception ex) { Console.WriteLine("Error descargando datos de usuario: " + ex.ToString()); reportErrorGoBack("Error descargando datos de usuario"); return(self); } } } Button btnGen = self.FindViewById <Button>(Resource.Id.btnRegresarNotificacionesEnviadas); btnGen.Click += (sender, e) => { report.output_error = null; Fragment frag = report.getInputReportFragment(); FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, frag).Commit(); }; return(self); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { report.output_error = null; var ignored = base.OnCreateView(inflater, container, savedInstanceState); View self = inflater.Inflate(Resource.Layout.CommonReportOutput, null); if (!report.getFillCommonInfo(self, true, false, ref report.output_error)) { reportErrorGoBack(report.output_error); return(self); } TableLayout table = self.FindViewById <TableLayout>(Resource.Id.tbReporte); // Asegura que ningun parametro este vacío if (String.IsNullOrEmpty(report.input_oficina)) { reportErrorGoBack("El campo de oficina no puede ser vacío"); return(self); } // Consulta // Cambiar las fechas al formato admitido por la BD string fecha_jornada = report.input_fecha_jornada.ToString("yyyyMMdd"); string codigoNotificador = ""; try { Helpers.SQLiteConeccion dbConeccion; dbConeccion = new Helpers.SQLiteConeccion(); dbConeccion.consultaDatos( "SELECT CodigoNotificador FROM OficialesNotificadores WHERE NombreCompleto = '" + report.input_notificador + "'", this.Context, ref codigoNotificador); } catch (Exception) { reportErrorGoBack("No fue posible obtener la información requerida para le reporte (ID)"); return(self); } string query = @"https://pjgestionnotificacionmovilservicios.azurewebsites.net/api/Reportes/NotificacionesPendientesJornada" + "?PCodOficina=" + report.input_oficina + "&PCodNotificador=" + codigoNotificador + "&PFechaJornada=" + fecha_jornada; // Verificar si la conección a internet esta disponible if (!coneccionInternet.verificaConeccion(this.Context)) { ReportUtils.alertNoInternetMessage(this.Context); } WebRequest request = HttpWebRequest.Create(query); request.ContentType = "application/json"; request.Method = "GET"; string content = ""; Console.Out.WriteLine("--XDEBUG " + query); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode); reportErrorGoBack("No fue posible obtener la información requerida para le reporte"); return(self); } using (StreamReader reader = new StreamReader(response.GetResponseStream())) { content = reader.ReadToEnd(); if (string.IsNullOrWhiteSpace(content)) { Console.Out.WriteLine("fzeledon -- Response contained empty body..."); reportErrorGoBack("Los valores de entrada de la consulta no generaron resultado"); return(self); } try { var jsonParsed = JArray.Parse(content); if (jsonParsed.Count <= 0) // Esperamos al menos un resultado { reportErrorGoBack("La información obtenida para le informe no puede ser procesada"); return(self); } // Por cada despacho encontrada ReportUtils.agregarFilaATabla(new string[] { "Notificando", "Expediente", "Fecha de resolución", "Justificación" }, Activity, table); int i = 0; for (i = 0; i < jsonParsed.Count; ++i) { string notificando = jsonParsed[i].Value <string>("Notificando"); string expediente = jsonParsed[i].Value <string>("Expediente"); string resolicion = jsonParsed[i].Value <string>("FechaResolucion"); string justificacion = "No disponible"; // FIXME no existia el campo en la consulta DateTime date_resolucion = DateTime.Parse(resolicion); resolicion = date_resolucion.ToString("dd-MMM-yyyy"); ReportUtils.agregarFilaATabla(new string[] { notificando, expediente, resolicion, justificacion }, Activity, table); // FIXME. Son demasiadas las respuestas, filtrar por pagina o preguntar como proceder if (i > 200) { break; } } ReportUtils.agregarFilaATabla(new string[] { "Total:", i.ToString(), "", "" }, Activity, table); } catch (Exception ex) { Console.WriteLine("Error descargando datos de usuario: " + ex.ToString()); reportErrorGoBack("Error descargando datos de usuario"); return(self); } } } Button btnGen = self.FindViewById <Button>(Resource.Id.btnRegresarNotificacionesEnviadas); btnGen.Click += (sender, e) => { report.output_error = null; Fragment frag = report.getInputReportFragment(); FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, frag).Commit(); }; return(self); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { report.output_error = null; var ignored = base.OnCreateView(inflater, container, savedInstanceState); View self = inflater.Inflate(Resource.Layout.CommonReportOutput, null); if (!report.getFillCommonInfo(self, true, false, ref report.output_error)) { reportErrorGoBack(report.output_error); return(self); } TableLayout table = self.FindViewById <TableLayout>(Resource.Id.tbReporte); // Asegura que ningun parametro este vacío if (String.IsNullOrEmpty(report.input_oficina)) { reportErrorGoBack("El campo de oficina no puede ser vacío"); return(self); } // Consulta // Cambiar las fechas al formato admitido por la BD string fecha_inicio = report.input_fecha_inicio.ToString("yyyyMMdd"); string fecha_fin = report.input_fecha_fin.ToString("yyyyMMdd"); string query = @"https://pjgestionnotificacionmovilservicios.azurewebsites.net/api/Reportes/NotificacionesEnviadasADespachos" + "?PCodOficina=" + report.input_oficina + "&PCodDespacho=" + // FIXME "&PFecha1=" + fecha_inicio + "&PFecha2=" + fecha_fin; // Verificar si la conección a internet esta disponible if (!coneccionInternet.verificaConeccion(this.Context)) { ReportUtils.alertNoInternetMessage(this.Context); } WebRequest request = HttpWebRequest.Create(query); request.ContentType = "application/json"; request.Method = "GET"; string content = ""; Console.Out.WriteLine("--XDEBUG " + query); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode); reportErrorGoBack("No fue posible obtener la información requerida para le reporte"); return(self); } using (StreamReader reader = new StreamReader(response.GetResponseStream())) { content = reader.ReadToEnd(); if (string.IsNullOrWhiteSpace(content)) { Console.Out.WriteLine("fzeledon -- Response contained empty body..."); reportErrorGoBack("Los valores de entrada de la consulta no generaron resultado"); return(self); } try { var jsonParsed = JArray.Parse(content); if ((jsonParsed.Count % 2) == 1) // Esperamos un número par de elementos del array { reportErrorGoBack("La información obtenida para le informe no puede ser procesada"); return(self); } Dictionary <string, int> despacho_deligencia_true = new Dictionary <string, int>(); Dictionary <string, int> despacho_deligencia_false = new Dictionary <string, int>(); Dictionary <string, string> despacho_nombre = new Dictionary <string, string>(); for (int i = 0; i < jsonParsed.Count; ++i) { string codigo = jsonParsed[i].Value <string>("Codigo"); despacho_nombre[codigo] = jsonParsed[i].Value <string>("Descripcion"); if (jsonParsed[i].Value <Boolean>("Diligenciada")) { despacho_deligencia_true[codigo] = jsonParsed[i].Value <int>("Total"); } else { despacho_deligencia_false[codigo] = jsonParsed[i].Value <int>("Total"); } } // Por cada despacho encontrada TableLayout.LayoutParams layoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MatchParent, TableLayout.LayoutParams.WrapContent); foreach (string codigo in despacho_nombre.Keys) { // Cantidad int total_cantidad = despacho_deligencia_true[codigo] + despacho_deligencia_false[codigo]; // Crea las columnas TextView nombre_label = new TextView(Activity); nombre_label.Text = "Nombre del despacho"; TextView text_nombre = new TextView(Activity); text_nombre.Text = despacho_nombre[codigo]; // FIXME. Buscar una mejor manera de acomodar los nombres largos if (despacho_nombre[codigo].Length > 20) { text_nombre.Text = despacho_nombre[codigo].Substring(0, 20); } TextView pad = new TextView(Activity); pad.Text = ""; TextView pad2 = new TextView(Activity); pad.Text = ""; TextView positivas = new TextView(Activity); positivas.Text = "Positivas"; TextView negativas = new TextView(Activity); negativas.Text = "Negativas"; TextView total = new TextView(Activity); total.Text = "Total"; TextView cantidad = new TextView(Activity); cantidad.Text = "Cantidad"; TextView porcentaje = new TextView(Activity); porcentaje.Text = "Porcentaje"; TextView text_positivas_cantidad = new TextView(Activity); text_positivas_cantidad.Text = despacho_deligencia_true[codigo].ToString(); TextView text_negativas_cantidad = new TextView(Activity); text_negativas_cantidad.Text = despacho_deligencia_false[codigo].ToString(); TextView text_positivas_porcentaje = new TextView(Activity); text_positivas_porcentaje.Text = (100.0 * despacho_deligencia_true[codigo] / total_cantidad).ToString("N3") + '%'; TextView text_negativas_porcentaje = new TextView(Activity); text_negativas_porcentaje.Text = (100.0 * despacho_deligencia_false[codigo] / total_cantidad).ToString("N3") + '%'; TextView text_total_cantidad = new TextView(Activity); text_total_cantidad.Text = total_cantidad.ToString(); // La Fila Nombre TableRow filaNombre = new TableRow(Activity); //Se instancia la nueva fila filaNombre.LayoutParameters = layoutParams; //Se agregan los tamaños del layout filaNombre.AddView(nombre_label); filaNombre.AddView(text_nombre); filaNombre.SetPadding(15, 15, 15, 15); filaNombre.SetBackgroundColor(Android.Graphics.Color.Argb(50, 1, 0, 5)); // La file de nombre de columnas TableRow filaNombreColumnas = new TableRow(Activity); //Se instancia la nueva fila filaNombreColumnas.LayoutParameters = layoutParams; //Se agregan los tamaños del layout filaNombreColumnas.AddView(pad2); filaNombreColumnas.AddView(cantidad); filaNombreColumnas.AddView(porcentaje); filaNombreColumnas.SetPadding(15, 15, 15, 15); filaNombreColumnas.SetBackgroundColor(Android.Graphics.Color.Argb(30, 1, 0, 5)); // La Fila positivas TableRow filaPositivas = new TableRow(Activity); //Se instancia la nueva fila filaPositivas.LayoutParameters = layoutParams; //Se agregan los tamaños del layout filaPositivas.AddView(positivas); filaPositivas.AddView(text_positivas_cantidad); filaPositivas.AddView(text_positivas_porcentaje); filaPositivas.SetPadding(15, 15, 15, 15); // La Fila negativas TableRow filaNegativa = new TableRow(Activity); //Se instancia la nueva fila filaNegativa.LayoutParameters = layoutParams; //Se agregan los tamaños del layout filaNegativa.AddView(negativas); filaNegativa.AddView(text_negativas_cantidad); filaNegativa.AddView(text_negativas_porcentaje); filaNegativa.SetPadding(15, 15, 15, 15); // La Fila total TableRow filatotal = new TableRow(Activity); //Se instancia la nueva fila filatotal.LayoutParameters = layoutParams; //Se agregan los tamaños del layout filatotal.AddView(total); filatotal.AddView(text_total_cantidad); filatotal.AddView(pad); filatotal.SetPadding(15, 15, 15, 15); // Agregar a la tabla table.AddView(filaNombre); table.AddView(filaNombreColumnas); table.AddView(filaPositivas); table.AddView(filaNegativa); table.AddView(filatotal); } } catch (Exception ex) { Console.WriteLine("Error descargando datos de usuario: " + ex.ToString()); reportErrorGoBack("Error descargando datos de usuario"); return(self); } } } Button btnGen = self.FindViewById <Button>(Resource.Id.btnRegresarNotificacionesEnviadas); btnGen.Click += (sender, e) => { report.output_error = null; Fragment frag = report.getInputReportFragment(); FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, frag).Commit(); }; return(self); }