//maneja la seleccion de un medidor del listado para crear una nueva lectura private async void listView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { try { CtrlMedidor Manager = new CtrlMedidor(); //declarando una variable de la clase control medidor e intanciandola Object ObjFila = e.SelectedItem; //asignar el objeto seleccionado a la variable de tipo object var json = JsonConvert.SerializeObject(ObjFila); //declaramos una variable json, y serializo el objeto fila ClsMedidor ObjMedidor = JsonConvert.DeserializeObject <ClsMedidor>(json); //transformamos ese json con jsonConver a un cls medidor var consulta = await Manager.Consultar(ObjMedidor.Id); //en esta variable vamos a cargar lo que me trae del metodo consultar de la clase medidor por id ObjMedidor = consulta.First(); //aqui tenemos todos los datos cargados de mi clase medidor CtrlLectura ObjCtrlLectura = new CtrlLectura(); //declamos una varible de tipo ctrllectura e intanciamos para usar sus metdos var LecturaMes = await ObjCtrlLectura.GetLecturaMedidorAsync(DateTime.Today, ObjMedidor.Id); if (LecturaMes == null) { await((NavigationPage)this.Parent).PushAsync(new PagIngresoLectura(ObjMedidor, true)); //mostrar el formulario Ingresos de lecturas con los datos cargados para modificar o eliminar } else { var resp = await DisplayAlert("Mensaje", "Desea Modificar", "si", "no"); if (resp) { await((NavigationPage)this.Parent).PushAsync(new PagIngresoLectura(LecturaMes, "edit")); //mostrar la vista para modificar una lectura con los datos cargados } } } catch (Exception ex) { await DisplayAlert("Mensaje", ex.Message, "ok"); } }
ClsMedidor ObjMedidor; //instancia de la clase Clsmedidor public PagAdminMedidor(ClsMedidor ObjMedidor, bool opc) //constructor { InitializeComponent(); this.opc = opc; //variable que define si se está agregando un nuevo o modificando un existente this.ObjMedidor = ObjMedidor; //asigna la variable del parámetro con la variable local. BindingContext = this.ObjMedidor; //indica que la vista se relacionará con los valores del objeto }
//manejador del botón agregar private void BtnAgregar_Clicked(object sender, EventArgs e) { ClsMedidor Obj = new ClsMedidor(); //nueva instancia de clase clsmedidor Obj.FechaIngreso = DateTime.Now; //asigna fecha actual Obj.FechaModificacion = DateTime.Now; ((NavigationPage)this.Parent).PushAsync(new Vista.PagAdminMedidor(Obj, true)); //mostrar la vista adminmedidor con campos vacíos para ingresar nuevo }
//maneja el evento item selected de la lista de objetos private async void lstMedidores_ItemSelected(object sender, SelectedItemChangedEventArgs e) { ClsMedidor Obj = e.SelectedItem as ClsMedidor; //asignar el objeto seleccionado a la variable obj CtrlPersona ObjCtrl = new CtrlPersona(); //nueva instancia del controlador var ConsCtrl = await ObjCtrl.ConsultarId(Obj.IdPersona); //consulta la persona por id Obj.ObjPersona = ConsCtrl.First(); //asigna persona al objeto medidor await((NavigationPage)this.Parent).PushAsync(new PagAdminMedidor(Obj, false)); //mostrar la vista adminmedidor con los datos cargados para modificar o eliminar }
//manejador del botón asignar medidor private void ButAsignaMedidor_Clicked(object sender, EventArgs e) { ClsMedidor Obj = new ClsMedidor { ObjPersona = ObjPersona, FechaIngreso = DateTime.Now, FechaModificacion = DateTime.Now }; ((NavigationPage)this.Parent).PushAsync(new Vista.PagAdminMedidor(Obj, true)); }
//método que invoca al script que elimina registros en la tabla lectura de la base de datos public async Task <string> DeleteAsync(ClsMedidor Objeto) { Url = "http://" + Servidor + "/applecturas/logica/medidor/delete.php?" + "id=" + Objeto.Id; HttpClient client = getCliente(); var resp = await client.GetAsync(Url); if (resp.IsSuccessStatusCode) { return(await resp.Content.ReadAsStringAsync()); } return("false"); }
public PagIngresoLectura(ClsMedidor Obj, bool nuevo)//constructor para ingresar nuevo { InitializeComponent(); this.nuevo = nuevo; //asignación de variable local this.ObjMedidor = Obj; //asignación de objeto local lblCodigo.Text = this.ObjMedidor.Codigo; lblNumero.Text = this.ObjMedidor.Numero; this.ObjLectura = new ClsLectura(); this.ObjLectura.Created_at = DateTime.Now; //asigna fecha actual this.ObjLectura.Updated_at = DateTime.Now; this.ObjLectura.Fecha = DateTime.Today; //asignación de fecha actual this.ObjLectura.Medidor_id = this.ObjMedidor.Id; BindingContext = this.ObjLectura; //indica que la vista se relacionará con los valores del objeto this.ObjLectura.Localizar(); }
//método que invoca al script php que actualiza un registro en la base de datos tabla medidor public async Task <string> UpdateAsync(ClsMedidor Objeto) { Url = "http://" + Servidor + "/applecturas/logica/medidor/update.php?" + "codigo=" + Objeto.Codigo + "&numero=" + Objeto.Numero + "&idpersona=" + Objeto.ObjPersona.Id + "&estado=" + Objeto.Estado + "&id=" + Objeto.Id; HttpClient client = getCliente(); var resp = await client.GetAsync(Url); if (resp.IsSuccessStatusCode) { return(await resp.Content.ReadAsStringAsync()); } return("false"); }
//método que invoca al script que realiza la inserción de registros en la base de datos en la tabla medidor public async Task <IEnumerable <ClsMedidor> > InsertAsync(ClsMedidor Objeto) { Url = "http://" + Servidor + "/applecturas/logica/medidor/insert.php?" + "codigo=" + Objeto.Codigo + "&numero=" + Objeto.Numero + "&idpersona=" + Objeto.ObjPersona.Id; HttpClient client = getCliente(); var resp = await client.GetAsync(Url); if (resp.IsSuccessStatusCode) { string content = await resp.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <IEnumerable <ClsMedidor> >(content)); } return(Enumerable.Empty <ClsMedidor>()); }
//controlador del selector de medidores private async void PkrNumeroMedidor_SelectedIndexChanged(object sender, EventArgs e) { ClsMedidor ObjMedidor = PkrNumeroMedidor.SelectedItem as ClsMedidor; //asignar nueva instancia de clase medidor según el objeto seleccionado ObjMedidor.ObjPersona = ObjPersona; //asignar objeto persona a objeto medidor Obj.ObjMedidor = ObjMedidor; //asignar variable local con objeto seleccionado CtrlLectura ObjCtrlLectura = new CtrlLectura(); //instancia de clase lectura var ConsLectura = await ObjCtrlLectura.ConsultarAnterior(ObjMedidor.Id); //consulta de lectura anterior if (ConsLectura != null) //si la lectura anterior no es nulo { if (ConsLectura.Count() != 0) { ClsLectura ObjLecturaAnterior = ConsLectura.First(); //asignar lectura anterior a objeto lectura anterior Obj.Anterior = ObjLecturaAnterior.Actual; //asignar campo anterior en objeto lectura según lectura del objeto lectura anterior TxtAnterior.Text = Obj.Anterior.ToString(); //mostrar lectura anterior en caja de texto } else { Obj.Anterior = 0;//en caso que no haya lectura anterior parte de 0 TxtAnterior.Text = "0"; } } }
public Task <int> SaveMedidorAsync(ClsMedidor medidor) //método asíncrono que guarda un nuevo registro en la tabla ClsMedidor, recibe como parametro un objeto de la clase ClsMedidor { return(_database.InsertAsync(medidor)); //invocación al método Insert en la tabla ClsMedidor enviando el objeto de la clase ClsMedidor, devuelve cero si la operación fracasó. }
protected override async void OnAppearing()//se ejecuta cuando se muestra esta interfaz { base.OnAppearing(); this.ObjUsuario = App.Current.Properties["ObjUsuario"] as ClsUsuario;//recuperar objeto guardado en propieades de la aplicación ObjLectura.User_id = ObjUsuario.Id; try { manager = new CtrlLectura(); //instancia de clase control lectura if (nuevo) //cuando se está creando una lectura nueva { this.ObjCtrlPersona = new CtrlPersona(); //instancia la variable en objeto de la clase control persona (abonado) var ListPersona = await ObjCtrlPersona.ConsultarId(this.ObjMedidor.Persona_id); if (ListPersona.Count() > 0) { this.ObjPersona = ListPersona.First(); LblNombres.Text = this.ObjPersona.Nombre + " " + this.ObjPersona.Apellido; txtCedula.Text = this.ObjPersona.Cedula; } var LecturaAnterior = await manager.ConsultarAnterior(this.ObjMedidor.Id); if (LecturaAnterior.Count == 1) { ClsLectura ObjLecAnterior = LecturaAnterior.First(); TxtAnterior.Text = ObjLecAnterior.Actual.ToString(); ObjLectura.Anterior = ObjLecAnterior.Actual; } } else { if (opc == "ver") { //cuando se está consultando una lectura ButGuardar.IsVisible = false; } this.ObjCtrlPersona = new CtrlPersona(); CtrlMedidor ObjCtrlMedidor = new CtrlMedidor(); var ListMedidor = await ObjCtrlMedidor.Consultar(this.ObjLectura.Medidor_id); if (ListMedidor.Count() == 1) { this.ObjMedidor = ListMedidor.First(); var ListPersona = await ObjCtrlPersona.ConsultarId(this.ObjMedidor.Persona_id); if (ListPersona.Count() == 1) { this.ObjPersona = ListPersona.First(); LblNombres.Text = this.ObjPersona.Nombre + " " + this.ObjPersona.Apellido; txtCedula.Text = this.ObjPersona.Cedula; txtConsumo.Text = this.ObjLectura.Consumo.ToString(); TxtObservacion.Text = this.ObjLectura.Observacion; TxtAnterior.Text = ObjLectura.Anterior.ToString(); lblCodigo.Text = ObjMedidor.Codigo.ToString(); lblNumero.Text = ObjMedidor.Numero.ToString(); if (ObjLectura.Image != null) { Imagen.Source = ObjLectura.Image; } } } } recuperarpolitica(); } catch (Exception ex) { await DisplayAlert("Mensaje", ex.Message, "ok"); } }
private async void ButGuardar_Clicked(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(txtNumero.Text) && !string.IsNullOrWhiteSpace(txtCodigo.Text) && !string.IsNullOrWhiteSpace(txtidPersona.Text) //validación de no nulos ) { if (ObjMedidor.Numero.Length > 0 && ObjMedidor.Codigo.Length > 0 && ObjMedidor.ObjPersona.Id > 0)//validación de no vacío { if (txtNumero.TextColor == Color.Green && txtCodigo.TextColor == Color.Green && txtidPersona.TextColor == Color.Green//validación de formato correcto ) { CtrlMedidor manager = new CtrlMedidor();//instancia de clase control var res = ""; if (opc) { var varObjeto = await manager.InsertAsync(ObjMedidor);//llmada a método que inserta un nuevo registro if (varObjeto != null) { ObjMedidor = varObjeto.First(); //asignación de objeto local con datos recién ingresados txtId.Text = ObjMedidor.Id.ToString(); //mostrar id del registro creado res = "Ok"; //respuesta positiva } else { res = null;//respuesta negativa si no se realizó correctamente } } else { res = await manager.UpdateAsync(ObjMedidor);//llamada al método actualizar } if (res != null) { await DisplayAlert("Mensaje", "Datos Guardados Correctamente", "ok"); } else { await DisplayAlert("Mensaje", "No se guardó la información, vuelva a intentar más tarde", "ok"); } } else { await DisplayAlert("Mensaje", "Los campos de color rojo tienen formato incorrecto", "ok"); } } else { await DisplayAlert("Mensaje", "Faltan Datos Necesarios", "ok"); } } else { await DisplayAlert("Mensaje", "Faltan Datos", "ok"); } } catch (Exception e1)//control de errores { await DisplayAlert("Mensaje", e1.Message, "ok"); } }