Beispiel #1
0
        protected void OnButtonNuevo(object sender, EventArgs e)
        {
            lblMsg.Text = lblError.Text = "";
            if (!ValidarCampos())
            {
                if (listaEntidades.SelectedValue == "-1")
                {
                    lblError.Text = "Debe seleccionar un valor de entidad para crear un nuevo registro.";
                }
                else
                {
                    lblError.Text = "No ha ingresado datos para crear.";
                }
            }
            else
            {
                ParametroSistema    daoPs = new ParametroSistema();
                ParametroSistemaDto ps    = daoPs.ObtenerValorParametroSistema(listaEntidades.SelectedValue.ToString());

                if (ps != null)
                {
                    Entidad    daoEnt  = new Entidad();
                    EntidadDto entInfo = new EntidadDto()
                    {
                        idEntidad = 0, codEntidad = Convert.ToInt32(ps.valorParametro), nombreEntidad = ps.descValorParametro, valorEntidad = txtEntidad.Text, descripcionEntidad = txtDescEntidad.Text
                    };
                    daoEnt.crearEntidad(entInfo, 1);
                    CargarGridInfoData();
                    txtDescEntidad.Text = txtEntidad.Text = "";
                    btnNuevo.Visible    = true;
                    btnEliminar.Visible = btnActualizar.Visible = false;
                    lblMsg.Text         = "Nuevo registro realizado con éxito.";
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Retrieves one record from DB.
        /// </summary>
        /// <param name="nombreParametro">Filter to use</param>
        /// <returns>NULL if no record found.</returns>
        public ParametroSistemaDto ObtenerValorParametroSistema(string nombreParametro)
        {
            SqlTransaction transaction = null;
            SqlDataReader  rdr         = null;
            HandleDatabase hdb         = null;

            try {
                ParametroSistemaDto r = null;
                hdb = new HandleDatabase(Settings.Connection);
                hdb.Open();
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@np";
                param.Value         = nombreParametro;
                param.SqlDbType     = SqlDbType.VarChar;
                string sql = "sp_obtenerValorParametroSistema @np";
                transaction = hdb.BeginTransaction("ObtenerValorParametroSistema");
                rdr         = hdb.ExecSelectSQLStmtAsReader(transaction, sql, param);
                if (rdr.HasRows)
                {
                    rdr.Read();
                    r = new ParametroSistemaDto()
                    {
                        idParametro        = Convert.ToInt32(rdr["idParametro"]),
                        nombreParametro    = rdr["nombreParametro"].ToString(),
                        valorParametro     = rdr["valorParametro"].ToString(),
                        descValorParametro = rdr["descValorParametro"].ToString(),
                        visible            = Convert.ToChar(rdr["visible"])
                    };
                }
                return(r);
            } catch (Exception) {
                return(null);
            } finally {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (transaction != null)
                {
                    transaction.Commit();
                }
                if (hdb != null)
                {
                    hdb.Close();
                }
            }
        }
        /// <summary>
        /// Retrieves one record from DB.
        /// </summary>
        /// <param name="nombreParametro">Filter to use</param>
        /// <returns>NULL if no record found.</returns>
        public ParametroSistemaDto getValorParametroSistema(string nombreParametro)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("getValorParametroSistema Starts");
            }
            SqlTransaction      transaction = null;
            SqlDataReader       rdr         = null;
            HandleDatabase      hdb         = null;
            ParametroSistemaDto r           = null;

            try {
                hdb = new HandleDatabase(Settings.Connection);
                hdb.Open();
                SqlParameter param = new SqlParameter()
                {
                    ParameterName = "@np", Value = nombreParametro, SqlDbType = SqlDbType.VarChar
                };
                string sql = "sp_obtenerValorParametroSistema @np";
                if (log.IsDebugEnabled)
                {
                    log.Debug("SQL=[" + sql + "]");
                    var paramValues = "ParameterName=[" + param.ParameterName + "], Value=[" + param.Value + "], SqlDbType=[" + param.SqlDbType + "]";
                    log.Debug("Parameter val=[" + paramValues + "]");
                }
                transaction = hdb.BeginTransaction("ObtenerValorParametroSistema");
                rdr         = hdb.ExecSelectSQLStmtAsReader(transaction, sql, param);
                if (rdr.HasRows)
                {
                    rdr.Read();
                    r = new ParametroSistemaDto()
                    {
                        idParametro        = Convert.ToInt32(rdr["idParametro"]),
                        nombreParametro    = rdr["nombreParametro"].ToString(),
                        valorParametro     = rdr["valorParametro"].ToString(),
                        descValorParametro = rdr["descValorParametro"].ToString(),
                        visible            = Convert.ToChar(rdr["visible"])
                    };
                }
            } catch (Exception ex) {
                if (log.IsFatalEnabled)
                {
                    log.Fatal("Exception occurred " + ex.Message);
                    log.Fatal("Exception trace=[" + ex.StackTrace + "]");
                    log.Fatal("Return null");
                }
                r = null;
            } finally {
                try {
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                    if (transaction != null)
                    {
                        transaction.Commit();
                    }
                    if (hdb != null)
                    {
                        hdb.Close();
                    }
                } catch (Exception e) {
                    if (log.IsFatalEnabled)
                    {
                        log.Fatal("Exception occurred " + e.Message);
                        log.Fatal("Exception trace=[" + e.StackTrace + "]");
                        log.Fatal("Return null");
                    }
                    r = null;
                }
            }
            if (log.IsDebugEnabled)
            {
                if (r == null)
                {
                    log.Debug("Result is NULL");
                }
                else
                {
                    log.Debug("Result sets to [" + r.ToString() + "]");
                }
                log.Debug("getValorParametroSistema Ends");
            }
            return(r);
        }
Beispiel #4
0
        /// <summary>
        /// Event fired to create a new record
        /// </summary>
        /// <param name="sender">object which fires the event</param>
        /// <param name="e">Event arguments</param>
        protected void OnButtonNuevo(object sender, EventArgs e)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("OnButtonNuevo Starts");
            }
            if (!ValidarCampos())
            {
                if (listaEntidades.SelectedValue == "-1")
                {
                    registerToastrMsg(MessageType.Warning, "Debe seleccionar un valor de entidad para crear un nuevo registro.");
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Must an entity value to work on");
                    }
                }
                else
                {
                    registerToastrMsg(MessageType.Error, "No ha ingresado datos para crear.");
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("No data input");
                    }
                }
            }
            else
            {
                ParametroSistema    daoPs = new ParametroSistema();
                ParametroSistemaDto ps    = daoPs.getValorParametroSistema(listaEntidades.SelectedValue.ToString());

                if (log.IsDebugEnabled)
                {
                    log.Debug("Record data to work on [" + listaEntidades.SelectedValue.ToString() + "]");
                }
                if (ps == null)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Record data not found");
                    }
                }
                if (ps != null)
                {
                    Entidad    daoEnt  = new Entidad();
                    EntidadDto entInfo = new EntidadDto()
                    {
                        idEntidad = 0, codEntidad = Convert.ToInt32(ps.valorParametro), nombreEntidad = ps.descValorParametro, valorEntidad = txtEntidad.Text, descripcionEntidad = txtDescEntidad.Text
                    };
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Record data [" + entInfo.ToString() + "]");
                    }
                    daoEnt.createEntidad(entInfo, 1);
                    CargarGridInfoData();
                    txtDescEntidad.Text = txtEntidad.Text = "";
                    btnNuevo.Visible    = true;
                    btnEliminar.Visible = btnActualizar.Visible = false;
                    registerToastrMsg(MessageType.Success, "Nuevo registro realizado con éxito.");
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("New record created");
                    }
                }
            }
            if (log.IsDebugEnabled)
            {
                log.Debug("OnButtonNuevo Ends");
            }
        }