Beispiel #1
0
        //manejador del botón guardar
        private async void ButGuardar_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(LblNombres.Text) &&
                    PkrNumeroMedidor.SelectedItem != null &&
                    !string.IsNullOrWhiteSpace(txtConsumo.Text)    //validación de no nulos
                    )
                {
                    if (txtCedula.Text.Length == 10 &&
                        Obj.Actual > 0)//validación cedula con 10 caracteres
                    {
                        if (txtCedula.TextColor == Color.Green &&
                            txtLecturaActual.TextColor == Color.Green
                            )                                        //Validacíon formato correcto
                        {
                            CtrlLectura manager = new CtrlLectura(); //instancia de clase control
                            var         res     = "";
                            if (opc)
                            {
                                var ObjLecturaInsert = await manager.InsertAsync(Obj);//llamada a método que inserta un nuevo registro

                                if (ObjLecturaInsert != null)
                                {
                                    Obj        = ObjLecturaInsert.First(); //asignación de objeto local con datos recién ingresados
                                    txtId.Text = Obj.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(Obj);//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)
            {
                await DisplayAlert("Mensaje", e1.Message, "ok");
            }
        }
Beispiel #2
0
        //manejador del botón guardar
        private async void ButGuardar_Clicked(object sender, EventArgs e)
        {
            try
            {
                var res = "";
                if (ObjLectura.Observacion == null)
                {
                    ObjLectura.Observacion = "s/n";
                }
                if (ObjLectura.Image == null)
                {
                    ObjLectura.StrImagen = "";
                }


                if (!string.IsNullOrWhiteSpace(LblNombres.Text) &&
                    !string.IsNullOrWhiteSpace(lblNumero.Text) &&
                    !string.IsNullOrWhiteSpace(txtConsumo.Text)    //validación de no nulos
                    )
                {
                    if (txtCedula.Text.Length == 10 &&
                        ObjLectura.Actual >= 0)//validación cedula con 10 caracteres
                    {
                        ObjLectura.Calcular();
                        if (ObjLectura.Consumo >= 0)
                        {
                            string ObjLecturaGuardada = null;                             //declaramos una variable tipo string, que se inicializa en nulo
                            if (nuevo)                                                    //si nuevo es verdadero, entonces haga la linea 217, caso contrario haga 219
                            {
                                ObjLecturaGuardada = await manager.SaveAsync(ObjLectura); //llamada a método que inserta un nuevo registro
                            }
                            else
                            {
                                ObjLecturaGuardada = await manager.UpdateAsync(ObjLectura);
                            }
                            if (ObjLecturaGuardada != null)
                            {
                                res = ObjLecturaGuardada;//respuesta positiva
                            }
                            else
                            {
                                res = null;//respuesta negativa si no se realizó correctamente
                            }
                        }
                        else
                        {
                            await DisplayAlert("Mensaje", "El consumo no puede ser negativo", "ok");

                            res = null;
                        }
                    }
                    else
                    {
                        await DisplayAlert("Mensaje", "Faltan Datos Necesarios", "ok");

                        res = null;
                    }
                }
                else
                {
                    await DisplayAlert("Mensaje", "Faltan Datos", "ok");

                    res = null;
                }

                if (res != null)
                {
                    await DisplayAlert("Mensaje", "Datos guardados correctamente", "ok");

                    ButGuardar.IsEnabled = false;
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Mensaje", ex.Message, "ok");
            }
        }