Exemple #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            bool estaValidado = ValidarFormulario();

            if (!estaValidado)
            {
                return;
            }

            BancoBe registro = new BancoBe();

            if (codigoBanco.HasValue)
            {
                registro.CodigoBanco = codigoBanco.Value;
            }
            registro.Nombre = txtNombre.Text.Trim();

            bool seGuardoRegistro = bancoBl.GuardarBanco(registro);

            if (seGuardoRegistro)
            {
                DialogResult = MessageBox.Show("¡El registro se guardó correctamente!", "¡Bien hecho!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();
            }
            else
            {
                MessageBox.Show("¡Ocurrió un error! Contáctese con el administrador del sistema", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        public BancoBe ObtenerBanco(int codigoBanco, SqlConnection cn)
        {
            BancoBe item = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_banco_obtener", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoBanco", codigoBanco.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            item = new BancoBe();

                            if (dr.Read())
                            {
                                item.CodigoBanco = dr.GetData <int>("CodigoBanco");
                                item.Nombre      = dr.GetData <string>("Nombre");
                                item.FlagActivo  = dr.GetData <bool>("FlagActivo");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(item);
        }
Exemple #3
0
        public List <BancoBe> ListarComboBanco(SqlConnection cn)
        {
            List <BancoBe> lista = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_banco_listar_combo", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            lista = new List <BancoBe>();

                            while (dr.Read())
                            {
                                BancoBe item = new BancoBe();
                                item.CodigoBanco = dr.GetData <int>("CodigoBanco");
                                item.Nombre      = dr.GetData <string>("Nombre");
                                item.FlagActivo  = dr.GetData <bool>("FlagActivo");

                                lista.Add(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(lista);
        }
Exemple #4
0
        public bool GuardarBanco(BancoBe registro)
        {
            bool seGuardo = false;

            try
            {
                cn.Open();
                seGuardo = bancoDa.GuardarBanco(registro, cn);
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(seGuardo);
        }
Exemple #5
0
        public BancoBe ObtenerBanco(int codigoBanco)
        {
            BancoBe item = null;

            try
            {
                cn.Open();
                item = bancoDa.ObtenerBanco(codigoBanco, cn);
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(item);
        }
Exemple #6
0
        public bool CambiarFlagActivoBanco(BancoBe registro, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_banco_cambiar_flagactivo", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoBanco", registro.CodigoBanco.GetNullable());
                    cmd.Parameters.AddWithValue("@flagActivo", registro.FlagActivo.GetNullable());
                    cmd.Parameters.AddWithValue("@usuarioModi", registro.UsuarioModi.GetNullable());

                    int filasAfectadas = cmd.ExecuteNonQuery();

                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(seGuardo);
        }
Exemple #7
0
        private void mitToggleActivar_Click(object sender, EventArgs e)
        {
            MenuItem mitControl = (MenuItem)sender;
            dynamic  data       = (object)mitControl.Tag;

            DialogResult dr = MessageBox.Show($"¿Estás seguro que deseas {(data.FlagActivo ? "Inactivar" : "Activar")} el registro?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                BancoBe registro = new BancoBe();
                registro.CodigoBanco = data.CodigoBanco;
                registro.FlagActivo  = !data.FlagActivo;
                bool seGuardo = bancoBl.CambiarFlagActivoBanco(registro);
                if (seGuardo)
                {
                    MessageBox.Show($"Se cambió el estado del registro a {(registro.FlagActivo ? "Activo" : "Inactivo")}", "¡Bien hecho!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    BuscarBancos();
                }
                else
                {
                    MessageBox.Show("¡Ocurrió un error! Contáctese con el administrador del sistema", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #8
0
        public List <BancoBe> BuscarBanco(string nombre, bool flagActivo, SqlConnection cn)
        {
            List <BancoBe> resultados = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_banco_buscar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@nombre", nombre.GetNullable());
                    cmd.Parameters.AddWithValue("@flagActivo", flagActivo.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            resultados = new List <BancoBe>();

                            while (dr.Read())
                            {
                                BancoBe item = new BancoBe();
                                item.Fila        = dr.GetData <int>("Fila");
                                item.CodigoBanco = dr.GetData <int>("CodigoBanco");
                                item.Nombre      = dr.GetData <string>("Nombre");
                                item.FlagActivo  = dr.GetData <bool>("FlagActivo");

                                resultados.Add(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(resultados);
        }
Exemple #9
0
        void CargarBanco()
        {
            BancoBe item = bancoBl.ObtenerBanco(codigoBanco.Value);

            txtNombre.Text = item.Nombre;
        }