Esempio n. 1
0
        async void ActualizarTapped(object sender, System.EventArgs e)
        {
            try
            {
                CuentaManager cuentaManager     = new CuentaManager();
                Cuenta        cuentaActualizada = new Cuenta();

                string moneda = string.Empty;

                switch (pkrMoneda.SelectedItem.ToString())
                {
                case "Colones":
                    moneda = "COL";
                    break;

                case "Dólares":
                    moneda = "DOL";
                    break;

                default:
                    moneda = "EUR";
                    break;
                }

                Cuenta cuenta = new Cuenta()
                {
                    CUE_CODIGO      = Convert.ToInt32(txtCodigo.Text),
                    USU_CODIGO      = App.usuarioActual.USU_CODIGO,
                    CUE_DESCRIPCION = txtDescripcion.Text,
                    CUE_MONEDA      = moneda,
                    CUE_SALDO       = Convert.ToDecimal(txtSaldo.Text),
                    CUE_ESTADO      = pkrEstado.SelectedItem.ToString().Substring(0, 1)
                };

                cuentaActualizada = await cuentaManager.Actualizar(cuenta);

                await DisplayAlert("Actualizar",
                                   "Cuenta actualizada correctamente",
                                   "Ok", "Cancel");
            }
            catch (Exception ex)
            {
                await DisplayAlert("Actualizar",
                                   "Error" + ex.Message,
                                   "Ok", "Cancel");
            }
        }
        async private void ActualizarCuenta_Clicked(object sender, EventArgs e)
        {
            if (Dispositivo.ValidarConexionInternet())
            {
                if (ValidarCamposEditar())
                {
                    CuentaManager eCuentaManager   = new CuentaManager();
                    Cuenta        eCuentaIngresada = new Cuenta();
                    Cuenta        eCuenta          = new Cuenta()
                    {
                        CUE_CODIGO      = int.Parse(txtCodigo.Text),
                        CUE_DESCRIPCION = txtDescripcionMOD.Text,
                        CUE_MONEDA      = txtMonedaMOD.Text,
                        CUE_ESTADO      = txtEstadoMOD.Text,
                        CUE_SALDO       = Convert.ToDecimal(txtSaldoMOD.Text),
                        USU_CODIGO      = App.UsuarioActual.USU_CODIGO
                    };

                    eCuentaIngresada = await eCuentaManager.Actualizar(eCuenta);

                    if (eCuentaIngresada != null)
                    {
                        txtMonedaMOD.Text      = string.Empty;
                        txtDescripcionMOD.Text = string.Empty;
                        txtEstadoMOD.Text      = string.Empty;
                        txtSaldoMOD.Text       = string.Empty;
                        txtCodigo.Text         = string.Empty;

                        await DisplayAlert("Información", "Cuenta Actualizada Correctamente", "Ok");
                    }
                    else
                    {
                        await DisplayAlert("Alerta", "La cuenta no pudo ser actualizada, favor validar", "Ok");
                    }
                }
                else
                {
                }
            }
            else
            {
                await DisplayAlert("Banco Económico", "No existe conexión a Internet", "Ok");
            }
        }
        async void AgregarTapped(object sender, System.EventArgs e)
        {
            try
            {
                int    cuentaorigen   = pkrCuentas.SelectedIndex;
                int    cuentadestino  = pkrCuentasDestino.SelectedIndex;
                string monto          = txtMonto.Text;
                bool   BCuentaOrigen  = true;
                bool   BCuentaDestino = true;

                if (cuentaorigen == -1)
                {
                    BCuentaOrigen = false;
                    await DisplayAlert("Alerta", "Debes seleccionar una cuenta de origen.", "OK");
                }
                if (cuentadestino == -1)
                {
                    BCuentaDestino = false;
                    await DisplayAlert("Alerta", "Debes seleccionar una cuenta de destino.", "OK");
                }

                if (BCuentaOrigen && BCuentaDestino)
                {
                    if (cuentaorigen != cuentadestino)
                    {
                        int imonto = int.Parse(monto);

                        if (imonto > 0)
                        {
                            if (cuentaList[cuentaorigen].CUE_SALDO > imonto)
                            {
                                if (cuentaList[cuentaorigen].CUE_MONEDA.Equals(cuentaList[cuentadestino].CUE_MONEDA))
                                {
                                    Cuenta cuentaOrigen = new Cuenta()
                                    {
                                        USU_CODIGO = App.usuarioActual.USU_CODIGO,
                                        CUE_MONEDA = cuentaList[cuentaorigen].CUE_MONEDA,
                                        CUE_SALDO  = cuentaList[cuentaorigen].CUE_SALDO - int.Parse(monto),
                                    };
                                    Cuenta cuentaDestino = new Cuenta()
                                    {
                                        USU_CODIGO = App.usuarioActual.USU_CODIGO,
                                        CUE_MONEDA = cuentaList[cuentaorigen].CUE_MONEDA,
                                        CUE_SALDO  = cuentaList[cuentaorigen].CUE_SALDO + int.Parse(monto),
                                    };

                                    Transferencia transferencia = new Transferencia()
                                    {
                                        TRA_CODIGO         = App.usuarioActual.USU_CODIGO,
                                        TRA_CUENTA_ORIGEN  = ((Cuenta)pkrCuentas.SelectedItem).CUE_CODIGO,
                                        TRA_CUENTA_DESTINO = ((Cuenta)pkrCuentasDestino.SelectedItem).CUE_CODIGO,
                                        TRA_FECHA          = DateTime.Now,
                                        TRA_MONTO          = Convert.ToDecimal(txtMonto.Text),
                                        TRA_ESTADO         = "A"
                                    };

                                    bool respuesta = await DisplayAlert("Agregar transferencia", "", "Agregar", "Cancelar");

                                    if (respuesta)
                                    {
                                        //Agregar la transferencia.
                                        transferencia = await transferenciaManager.AgregarTransferencia(transferencia);

                                        cuentaOrigen = await cuentaManager.Actualizar(cuentaOrigen);

                                        cuentaDestino = await cuentaManager.Actualizar(cuentaDestino);

                                        await DisplayAlert("Mensaje", "Transferencia agregada correctamente", "Aceptar");
                                    }
                                }
                                else
                                {
                                    await DisplayAlert("Atencion", "Monedas no son iguales", "Aceptar");
                                }
                            }
                            else
                            {
                                await DisplayAlert("Atencion", "Monto insuficiente", "Aceptar");
                            }
                        }
                        else
                        {
                            await DisplayAlert("Atencion", "Monto debe ser mayor a cero", "Aceptar");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Atencion", "Cuentas iguales", "Aceptar");
                    }
                }
                else
                {
                    await DisplayAlert("Atencion", "Revise sus de datos", "Aceptar");
                }
            }
            catch (System.Exception ex)
            {
                await DisplayAlert("Transferencias1",
                                   "Error " + ex.Message,
                                   "Ok", "Cancel");
            }
        }