Exemple #1
0
        public bool ListadoParaCombos(CategoriaDeCuentaEN oRegistroEN, DatosDeConexionEN oDatos)
        {
            try
            {
                Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos));
                Cnn.Open();

                Comando             = new MySqlCommand();
                Comando.Connection  = Cnn;
                Comando.CommandType = CommandType.Text;

                Consultas           = string.Format(@"select idCategoriaDeCuenta,cc.idGrupoDeCuentas, DescCategoriaDeCuenta, gc.DescGrupoDeCuentas, 
                cc.IdUsuarioDeCreacion, cc.FechaDeCreacion, cc.IdUsuarioDeModificacion, cc.FechaDeModificacion 
                from categoriadecuenta as cc
                inner join grupodecuentas as gc on gc.idGrupoDeCuentas = cc.idGrupoDeCuentas
                where idCategoriaDeCuenta > 0 {0} {1}; ", oRegistroEN.Where, oRegistroEN.OrderBy);
                Comando.CommandText = Consultas;

                Adaptador = new MySqlDataAdapter();
                DT        = new DataTable();

                Adaptador.SelectCommand = Comando;
                Adaptador.Fill(DT);

                return(true);
            }
            catch (Exception ex)
            {
                this.Error = ex.Message;

                return(false);
            }
            finally
            {
                if (Cnn != null)
                {
                    if (Cnn.State == ConnectionState.Open)
                    {
                        Cnn.Close();
                    }
                }

                Cnn       = null;
                Comando   = null;
                Adaptador = null;
            }
        }
        private void tsbSeleccionarTodos_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                tsbSeleccionarTodos.Checked = !tsbMarcarTodos.Checked;
                if (tsbSeleccionarTodos.Checked == true)
                {
                    tsbSeleccionarTodos.Image = Properties.Resources.unchecked16x16;
                }
                else
                {
                    tsbSeleccionarTodos.Image = Properties.Resources.checked16x16;
                }

                int a = 0;
                this.Cursor = Cursors.WaitCursor;
                if (dgvLista.Rows.Count > 0)
                {
                    foreach (DataGridViewRow Fila in dgvLista.Rows)
                    {
                        if (Convert.ToBoolean(Fila.Cells["Seleccionar"].Value) == true)
                        {
                            a++;
                            Array.Resize(ref oCategoriaDeCuenta, a);

                            oCategoriaDeCuenta[a - 1] = new CategoriaDeCuentaEN();
                            oCategoriaDeCuenta[a - 1].idCategoriaDeCuenta   = Convert.ToInt32(Fila.Cells["idCategoriaDeCuenta"].Value);
                            oCategoriaDeCuenta[a - 1].DescCategoriaDeCuenta = Fila.Cells["DescCategoriaDeCuenta"].Value.ToString();
                            oCategoriaDeCuenta[a - 1].oGrupoDeCuentasEN.idGrupoDeCuentas   = Convert.ToInt32(Fila.Cells["idGrupoDeCuentas"].Value.ToString());
                            oCategoriaDeCuenta[a - 1].oGrupoDeCuentasEN.DescGrupoDeCuentas = Fila.Cells["DescGrupoDeCuentas"].Value.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Seleccionar los registros", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally {
                AgregarRegistrosAlDTUsuario();
                this.Cursor = Cursors.Default;
                this.Close();
            }
        }
Exemple #3
0
        private CategoriaDeCuentaEN InformacionDelRegistro()
        {
            CategoriaDeCuentaEN oRegistroEN = new CategoriaDeCuentaEN();

            oRegistroEN.idCategoriaDeCuenta   = Convert.ToInt32((txtIdentificador.Text.Length > 0 ? txtIdentificador.Text : "0"));
            oRegistroEN.DescCategoriaDeCuenta = txtDescCategoriaDeCuenta.Text.Trim();
            oRegistroEN.oGrupoDeCuentasEN.idGrupoDeCuentas   = Convert.ToInt32(cmbGrupoDeCuenta.SelectedValue);
            oRegistroEN.oGrupoDeCuentasEN.DescGrupoDeCuentas = cmbGrupoDeCuenta.Text.Trim();

            //partes generales.
            oRegistroEN.oLoginEN                = Program.oLoginEN;
            oRegistroEN.IdUsuarioDeCreacion     = Program.oLoginEN.idUsuario;
            oRegistroEN.IdUsuarioDeModificacion = Program.oLoginEN.idUsuario;
            oRegistroEN.FechaDeCreacion         = System.DateTime.Now;
            oRegistroEN.FechaDeModificacion     = System.DateTime.Now;

            return(oRegistroEN);
        }
        public bool Eliminar(CategoriaDeCuentaEN oREgistroEN, DatosDeConexionEN oDatos)
        {
            if (string.IsNullOrEmpty(oREgistroEN.idCategoriaDeCuenta.ToString()) || oREgistroEN.idCategoriaDeCuenta == 0)
            {
                this.Error = @"Se debe de seleccionar un elemento de la lista";
                return(false);
            }

            if (oCategoriaDeCuentaAD.Eliminar(oREgistroEN, oDatos))
            {
                Error = string.Empty;
                return(true);
            }
            else
            {
                Error = oCategoriaDeCuentaAD.Error;
                return(false);
            }
        }
        private void LLenarListado()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                CategoriaDeCuentaEN oRegistrosEN = new CategoriaDeCuentaEN();
                CategoriaDeCuentaLN oRegistrosLN = new CategoriaDeCuentaLN();

                oRegistrosEN.Where = WhereDinamico();

                if (oRegistrosLN.Listado(oRegistrosEN, Program.oDatosDeConexion))
                {
                    dgvLista.Columns.Clear();
                    System.Diagnostics.Debug.Print(oRegistrosLN.TraerDatos().Rows.Count.ToString());

                    if (ActivarFiltros == true)
                    {
                        dgvLista.DataSource = AgregarColumnaSeleccionar(oRegistrosLN.TraerDatos());
                    }
                    else
                    {
                        dgvLista.DataSource = oRegistrosLN.TraerDatos();
                    }

                    FormatearDGV();
                    this.dgvLista.ClearSelection();

                    tsbNoRegistros.Text = "No. Registros: " + oRegistrosLN.TotalRegistros().ToString();
                }
                else
                {
                    throw new ArgumentException(oRegistrosLN.Error);
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Llenar listado de registro en la lista", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        private void LLenarCategoriasParaLasCuentas()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                CategoriaDeCuentaEN oRegistroEN = new CategoriaDeCuentaEN();
                CategoriaDeCuentaLN oRegistroLN = new CategoriaDeCuentaLN();

                oRegistroEN.Where = "";

                if (Controles.IsNullOEmptyElControl(chkGrupoDeCuentas) == false && Controles.IsNullOEmptyElControl(cmbGruposDeCuentas) == false)
                {
                    oRegistroEN.Where += string.Format(" and cc.idGrupoDeCuentas = {0} ", cmbGruposDeCuentas.SelectedValue);
                }

                oRegistroEN.OrderBy = "";

                if (oRegistroLN.ListadoParaCombos(oRegistroEN, Program.oDatosDeConexion))
                {
                    cmbCategoriaDeCuentas.DataSource    = oRegistroLN.TraerDatos();
                    cmbCategoriaDeCuentas.DisplayMember = "DescCategoriaDeCuenta";
                    cmbCategoriaDeCuentas.ValueMember   = "idCategoriaDeCuenta";
                    cmbCategoriaDeCuentas.SelectedIndex = -1;
                }
                else
                {
                    throw new ArgumentException(oRegistroLN.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Información de la categoria asociada a grupos", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        public bool ValidarRegistroDuplicado(CategoriaDeCuentaEN oRegistroEN, DatosDeConexionEN oDatos, string TipoDeOperacion)
        {
            try
            {
                Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos));
                Cnn.Open();

                Comando             = new MySqlCommand();
                Comando.Connection  = Cnn;
                Comando.CommandType = CommandType.Text;

                switch (TipoDeOperacion.Trim().ToUpper())
                {
                case "AGREGAR":

                    Consultas = @"SELECT CASE WHEN EXISTS(SELECT idCategoriaDeCuenta FROM CategoriaDeCuenta WHERE upper(trim(DescCategoriaDeCuenta)) = upper(@DescCategoriaDeCuenta) and idGrupoDeCuentas = @idGrupoDeCuentas) THEN 1 ELSE 0 END AS 'RES'";
                    Comando.Parameters.Add(new MySqlParameter("@DescCategoriaDeCuenta", MySqlDbType.VarChar, oRegistroEN.DescCategoriaDeCuenta.Trim().Length)).Value = oRegistroEN.DescCategoriaDeCuenta.Trim();
                    Comando.Parameters.Add(new MySqlParameter("@idGrupoDeCuentas", MySqlDbType.Int32)).Value = oRegistroEN.oGrupoDeCuentasEN.idGrupoDeCuentas;

                    break;

                case "ACTUALIZAR":

                    Consultas = @"SELECT CASE WHEN EXISTS(SELECT idCategoriaDeCuenta FROM CategoriaDeCuenta WHERE upper(trim(DescCategoriaDeCuenta)) = upper(@DescCategoriaDeCuenta) and idGrupoDeCuentas = @idGrupoDeCuentas <> @idCategoriaDeCuenta) THEN 1 ELSE 0 END AS 'RES'";
                    Comando.Parameters.Add(new MySqlParameter("@DescCategoriaDeCuenta", MySqlDbType.VarChar, oRegistroEN.DescCategoriaDeCuenta.Trim().Length)).Value = oRegistroEN.DescCategoriaDeCuenta.Trim();
                    Comando.Parameters.Add(new MySqlParameter("@idGrupoDeCuentas", MySqlDbType.Int32)).Value    = oRegistroEN.oGrupoDeCuentasEN.idGrupoDeCuentas;
                    Comando.Parameters.Add(new MySqlParameter("@idCategoriaDeCuenta", MySqlDbType.Int32)).Value = oRegistroEN.idCategoriaDeCuenta;

                    break;

                default:
                    throw new ArgumentException("La aperación solicitada no esta disponible");
                }

                Comando.CommandText = Consultas;

                Adaptador = new MySqlDataAdapter();
                DT        = new DataTable();

                Adaptador.SelectCommand = Comando;
                Adaptador.Fill(DT);

                if (Convert.ToInt32(DT.Rows[0]["RES"].ToString()) > 0)
                {
                    DescripcionDeOperacion = string.Format("Ya existe información del Registro dentro de nuestro sistema: {0} {1}", Environment.NewLine, InformacionDelRegistro(oRegistroEN));
                    this.Error             = DescripcionDeOperacion;
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                this.Error = ex.Message;

                DescripcionDeOperacion = string.Format("Se produjo el seguiente error: '{2}' al validar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message);
                //oTransaccionesAD.Agregar(oRegistroEN.oLoginEN.idUsuario, oRegistroEN.oLoginEN.NumeroIP, oRegistroEN.idCategoriaDeCuenta, "VALIDAR", "ERROR AL VALIDAR LA INFORMACIÓN DE LA CATEGORIA DE LA CUENTA", "ERROR", DescripcionDeOperacion, oRegistroEN.oLoginEN.idUsuario, oDatos);

                return(false);
            }
            finally
            {
                if (Cnn != null)
                {
                    if (Cnn.State == ConnectionState.Open)
                    {
                        Cnn.Close();
                    }
                }

                Cnn              = null;
                Comando          = null;
                Adaptador        = null;
                oTransaccionesAD = null;
            }
        }
        public bool Agregar(CategoriaDeCuentaEN oRegistroEN, DatosDeConexionEN oDatos)
        {
            try
            {
                Cnn = new MySqlConnection(TraerCadenaDeConexion(oDatos));
                Cnn.Open();

                Comando             = new MySqlCommand();
                Comando.Connection  = Cnn;
                Comando.CommandType = CommandType.Text;

                Consultas = @"                
                insert into categoriadecuenta
                (idCategoriaDeCuenta, DescCategoriaDeCuenta, IdUsuarioDeCreacion, FechaDeCreacion, IdUsuarioDeModificacion, FechaDeModificacion, idGrupoDeCuentas)
                values
                (IdentificadorDeCategoriaDeCuenta(), @DescCategoriaDeCuenta, @IdUsuarioDeCreacion, current_timestamp(), @IdUsuarioDeModificacion, current_timestamp(), @idGrupoDeCuentas);

                Select max(idCategoriaDeCuenta) from categoriadecuenta order by idCategoriaDeCuenta desc;";

                Comando.CommandText = Consultas;

                Comando.Parameters.Add(new MySqlParameter("@DescCategoriaDeCuenta", MySqlDbType.VarChar, oRegistroEN.DescCategoriaDeCuenta.Trim().Length)).Value = oRegistroEN.DescCategoriaDeCuenta.Trim();
                Comando.Parameters.Add(new MySqlParameter("@idGrupoDeCuentas", MySqlDbType.Int32)).Value        = oRegistroEN.oGrupoDeCuentasEN.idGrupoDeCuentas;
                Comando.Parameters.Add(new MySqlParameter("@IdUsuarioDeCreacion", MySqlDbType.Int32)).Value     = oRegistroEN.oLoginEN.idUsuario;
                Comando.Parameters.Add(new MySqlParameter("@IdUsuarioDeModificacion", MySqlDbType.Int32)).Value = oRegistroEN.oLoginEN.idUsuario;


                Adaptador = new MySqlDataAdapter();
                DT        = new DataTable();

                Adaptador.SelectCommand = Comando;
                Adaptador.Fill(DT);

                oRegistroEN.idCategoriaDeCuenta = Convert.ToInt32(DT.Rows[0].ItemArray[0].ToString());

                DescripcionDeOperacion = string.Format("El registro fue Insertado Correctamente. {0} {1}", Environment.NewLine, InformacionDelRegistro(oRegistroEN));

                //oTransaccionesAD.Agregar(oRegistroEN.oLoginEN.idUsuario, oRegistroEN.oLoginEN.NumeroIP,oRegistroEN.idCategoriaDeCuenta, "AGREGAR", "INFORMACIÓN DE LA CATEGORIA DE CUENTAS AGREGADA CORRECTAMENTE", "CORRECTA", DescripcionDeOperacion, oRegistroEN.oLoginEN.idUsuario, oDatos);

                return(true);
            }
            catch (Exception ex)
            {
                this.Error = ex.Message;

                DescripcionDeOperacion = string.Format("Se produjo el seguiente error: '{2}' al insertar el registro. {0} {1} ", Environment.NewLine, InformacionDelRegistro(oRegistroEN), ex.Message);
                //oTransaccionesAD.Agregar(oRegistroEN.oLoginEN.idUsuario, oRegistroEN.oLoginEN.NumeroIP, oRegistroEN.idCategoriaDeCuenta, "AGREGAR", "ERROR AL AGREGAR LA INFORMACIÓN DE LA CATEGORIA DE CUENTAS", "ERROR", DescripcionDeOperacion, oRegistroEN.oLoginEN.idUsuario, oDatos);

                return(false);
            }
            finally {
                if (Cnn != null)
                {
                    if (Cnn.State == ConnectionState.Open)
                    {
                        Cnn.Close();
                    }
                }

                Cnn              = null;
                Comando          = null;
                Adaptador        = null;
                oTransaccionesAD = null;
            }
        }
Exemple #9
0
        private void tsbEliminar_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                if (LosDatosIngresadosSonCorrectos())
                {
                    if (txtIdentificador.Text.Length == 0 || txtIdentificador.Text == "0")
                    {
                        MessageBox.Show("No se puede continuar. Ha ocurrido un error y el registro no ha sido cargado correctamente.", OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }


                    if (MessageBox.Show("¿Está seguro que desea eliminar el registro?", "Eliminar la Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }

                    CategoriaDeCuentaEN oRegistroEN = InformacionDelRegistro();
                    CategoriaDeCuentaLN oRegistroLN = new CategoriaDeCuentaLN();

                    if (oRegistroLN.ValidarSiElRegistroEstaVinculado(oRegistroEN, Program.oDatosDeConexion, "ELIMINAR"))
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show(oRegistroLN.Error, this.OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    if (oRegistroLN.Eliminar(oRegistroEN, Program.oDatosDeConexion))
                    {
                        txtIdentificador.Text     = oRegistroEN.idCategoriaDeCuenta.ToString();
                        ValorLlavePrimariaEntidad = oRegistroEN.idCategoriaDeCuenta;

                        EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Eliminar");

                        oRegistroEN = null;
                        oRegistroLN = null;

                        this.Cursor = Cursors.Default;

                        if (CerrarVentana == true)
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        throw new ArgumentException(oRegistroLN.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Eliminar la información del registro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Exemple #10
0
        private void tsbActualizar_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                if (LosDatosIngresadosSonCorrectos())
                {
                    if (txtIdentificador.Text.Length == 0 || txtIdentificador.Text == "0")
                    {
                        MessageBox.Show("No se puede continuar. Ha ocurrido un error y el registro no ha sido cargado correctamente.", OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }


                    if (MessageBox.Show("¿Está seguro que desea aplicar los cambios al registro seleccionado?", "Actualizar la Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }

                    CategoriaDeCuentaEN oRegistroEN = InformacionDelRegistro();
                    CategoriaDeCuentaLN oRegistroLN = new CategoriaDeCuentaLN();

                    if (oRegistroLN.ValidarSiElRegistroEstaVinculado(oRegistroEN, Program.oDatosDeConexion, "ACTUALIZAR"))
                    {
                        if (PermitirModificarRegistrosVinculados == true && AplicarCambio == true)
                        {
                            if (MessageBox.Show(string.Format("¿Está seguro que desea guardar los cambios en el registro seleccionado ya que este se encuentra asociado a otras Entidades de manera interna? {0} {1}", System.Environment.NewLine, oRegistroLN.Error), "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) == System.Windows.Forms.DialogResult.No)
                            {
                                this.Cursor = Cursors.Default;
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show(oRegistroLN.Error, this.OperacionARealizar, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.Cursor = Cursors.Default;
                            return;
                        }
                    }

                    if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "ACTUALIZAR"))
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show(oRegistroLN.Error, "Actualizar la información", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (oRegistroLN.Actualizar(oRegistroEN, Program.oDatosDeConexion))
                    {
                        txtIdentificador.Text     = oRegistroEN.idCategoriaDeCuenta.ToString();
                        ValorLlavePrimariaEntidad = oRegistroEN.idCategoriaDeCuenta;

                        EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Actualizar");

                        oRegistroEN = null;
                        oRegistroLN = null;

                        this.Cursor = Cursors.Default;

                        if (CerrarVentana == true)
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        throw new ArgumentException(oRegistroLN.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Actualizar la información del registro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }