Example #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string idUsuario = lblUsuario.Text.Split('-')[0].Trim();
            string id        = ((Label)Master.FindControl("lblUsuario")).Text;

            try
            {
                if (validarControlesInsertar())
                {
                    if (idUsuario.Equals(string.Empty))
                    {
                        throw new Exception("Seleccione un usuario!");
                    }

                    usuarioL = new UsuariosLN();
                    DataSet dsResultado = usuarioL.IngresarCargoUsuario(int.Parse(idUsuario), int.Parse(dropUnidad.SelectedValue), int.Parse(dropDependencia.SelectedValue), int.Parse(dropTipoUsuario.SelectedValue), id);

                    if (bool.Parse(dsResultado.Tables[0].Rows[0]["ERRORES"].ToString()))
                    {
                        throw new Exception(dsResultado.Tables[0].Rows[0]["MSG_ERROR"].ToString());
                    }

                    usuarioL.gridCargoUsuario(gridCargo, int.Parse(idUsuario));

                    lblSuccess.Text = "El registro fue ingresado correctamente";
                    lblError.Text   = string.Empty;
                }
            }
            catch (Exception ex)
            {
                string mensaje = "Error al ingresar el registro: " + ex.Message;
                if (ex.Message.Equals("Seleccione un usuario!"))
                {
                    mensaje = "Seleccione un usuario!";
                }

                lblError.Text   = mensaje;
                lblSuccess.Text = string.Empty;
            }
            lblErrorM.Text   = string.Empty;
            lblSuccessM.Text = string.Empty;
        }