Example #1
0
        public string AministrarUsuarios(Models.Usuarios.Usuarios.clsUsuario obclsUsuarios, int inOpcion)
        {
            try
            {
                _SqlConnection = new SqlConnection(stConexion);
                _SqlConnection.Open();

                _SqlCommand             = new SqlCommand("Usuarios.spAdministrarUsuarios", _SqlConnection);
                _SqlCommand.CommandType = CommandType.StoredProcedure;

                _SqlCommand.Parameters.Add(new SqlParameter("@Codigo", obclsUsuarios.inCodigo));
                _SqlCommand.Parameters.Add(new SqlParameter("@Nombre", obclsUsuarios.stNombre));
                _SqlCommand.Parameters.Add(new SqlParameter("@Apellido", obclsUsuarios.stApellido));
                _SqlCommand.Parameters.Add(new SqlParameter("@Email", obclsUsuarios.stEmail));
                _SqlCommand.Parameters.Add(new SqlParameter("@Usuario", obclsUsuarios.stUsuario));
                _SqlCommand.Parameters.Add(new SqlParameter("@Password", obclsUsuarios.stPassword));
                _SqlCommand.Parameters.Add(new SqlParameter("@perfCodigo", obclsUsuarios.obclsPerfiles.inCodigo));
                _SqlCommand.Parameters.Add(new SqlParameter("@nOpcion", inOpcion));

                _SqlParameter = new SqlParameter();
                _SqlParameter.ParameterName = "@cMensaje";
                _SqlParameter.SqlDbType     = SqlDbType.VarChar;
                _SqlParameter.Size          = 50;
                _SqlParameter.Direction     = ParameterDirection.Output;

                _SqlCommand.Parameters.Add(_SqlParameter);
                _SqlCommand.ExecuteNonQuery();

                return(_SqlParameter.Value.ToString());
            }
            catch (Exception ex) { throw ex; }
            finally { _SqlConnection.Close(); }
        }
        public bool ValidarPaginas(Models.Usuarios.Usuarios.clsUsuario obclsUsuario, int inPagina)
        {
            try
            {
                DataSet dsConsulta = new DataSet();

                _SqlConnection = new SqlConnection(stConexion);
                _SqlConnection.Open();

                _SqlCommand             = new SqlCommand("Seguridad.spValidarPaginas", _SqlConnection);
                _SqlCommand.CommandType = CommandType.StoredProcedure;

                _SqlCommand.Parameters.Add(new SqlParameter("@Perfil", obclsUsuario.obclsPerfiles.inCodigo));
                _SqlCommand.Parameters.Add(new SqlParameter("@Pagina", inPagina));

                _SqlCommand.ExecuteNonQuery();

                _SqlDataAdapter = new SqlDataAdapter(_SqlCommand);
                _SqlDataAdapter.Fill(dsConsulta);

                if (dsConsulta.Tables[0].Rows.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex) { throw ex; }
            finally { _SqlConnection.Close(); }
        }
Example #3
0
        /// <summary>
        /// CONSULTA USUARIO
        /// </summary>
        /// <param name="obclsUsuario"></param>
        /// <returns></returns>
        public DataSet ConsultarUsuarioCorreo(Models.Usuarios.Usuarios.clsUsuario obclsUsuario)
        {
            try
            {
                DataSet dsConsulta = new DataSet();

                _SqlConnection = new SqlConnection(stConexion);
                _SqlConnection.Open();

                _SqlCommand             = new SqlCommand("Usuarios.spConsultarCorreo", _SqlConnection);
                _SqlCommand.CommandType = CommandType.StoredProcedure;

                _SqlCommand.Parameters.Add(new SqlParameter("@correo", obclsUsuario.stEmail));
                _SqlCommand.Parameters.Add(new SqlParameter("@usuario", obclsUsuario.stUsuario));

                _SqlCommand.ExecuteNonQuery();

                _SqlDataAdapter = new SqlDataAdapter(_SqlCommand);
                _SqlDataAdapter.Fill(dsConsulta);

                return(dsConsulta);
            }
            catch (Exception ex) { throw ex; }
            finally { _SqlConnection.Close(); }
        }
Example #4
0
        protected void btnEnvPass_Click(object sender, EventArgs e)
        {
            try
            {
                string contraseña = " ";

                string stServidor = ConfigurationManager.AppSettings["stServidor"].ToString();
                string stUsuario  = ConfigurationManager.AppSettings["stUsuario"].ToString();
                string stPassword = ConfigurationManager.AppSettings["stPassword"].ToString();
                string stPuerto   = ConfigurationManager.AppSettings["stPuerto"].ToString();

                Controllers.Usuarios.ForgotPass.ForgotPassController obForgotPass = new Controllers.Usuarios.ForgotPass.ForgotPassController();

                Models.Usuarios.Usuarios.clsUsuario obclsCorreo = new Models.Usuarios.Usuarios.clsUsuario
                {
                    stUsuario = txtUsuario.Text,
                    stEmail   = txtEmail.Text
                };

                DataSet dsConsulta = obForgotPass.ConsultarUsuarioCorreo(obclsCorreo);

                if (dsConsulta.Tables[0].Rows.Count > 0)
                {
                    contraseña = dsConsulta.Tables[0].Rows[0]["usuPassword"].ToString();

                    obForgotPass.envioEmail(stServidor,
                                            stUsuario,
                                            stPassword,
                                            true, true,
                                            stUsuario,
                                            txtEmail.Text,
                                            "Recuperacion Contraseña UTAP",
                                            "Su contraseña es: " + contraseña,
                                            0, 3,
                                            stPuerto);

                    ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Correcto!', 'Se envio Correo con exito!', 'success') </script>");

                    txtUsuario.Text = string.Empty;
                    txtEmail.Text   = string.Empty;
                }
                else
                {
                    throw new Exception("el usuario o correo ingresados no se encuentran registrados");
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + ex.Message + "!', 'error') </script>");
                txtUsuario.Text = string.Empty;
                txtEmail.Text   = string.Empty;
            }
        }
        protected void gvwDatos_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int inIndice = Convert.ToInt32(e.CommandArgument);

                if (e.CommandName.Equals("Editar"))
                {
                    lblOpcion.Text = "2";
                    //Accede al control web dentro de una grid

                    lblCodUsuario.Text = ((Label)gvwDatos.Rows[inIndice].FindControl("lblCodigo")).Text;

                    txtNombre.Text            = gvwDatos.Rows[inIndice].Cells[1].Text;
                    txtApellido.Text          = gvwDatos.Rows[inIndice].Cells[2].Text;
                    txtCorreo.Text            = gvwDatos.Rows[inIndice].Cells[3].Text;
                    txtUsuario.Text           = gvwDatos.Rows[inIndice].Cells[4].Text;
                    txtPassword.Text          = ((Label)gvwDatos.Rows[inIndice].FindControl("lblPassword")).Text;
                    txtPassword.Enabled       = false;
                    ddlPerfiles.SelectedValue = ((Label)gvwDatos.Rows[inIndice].FindControl("lblPerfil")).Text;
                }
                else if (e.CommandName.Equals("Eliminar"))
                {
                    lblOpcion.Text = "3";

                    Models.Usuarios.Usuarios.clsUsuario obclsUsuario = new Models.Usuarios.Usuarios.clsUsuario
                    {
                        inCodigo      = Convert.ToInt32(((Label)gvwDatos.Rows[inIndice].FindControl("lblCodigo")).Text),
                        stNombre      = string.Empty,
                        stApellido    = string.Empty,
                        stEmail       = string.Empty,
                        stUsuario     = string.Empty,
                        stPassword    = string.Empty,
                        obclsPerfiles = new Models.Usuarios.Perfiles.clsPerfiles
                        {
                            inCodigo = 0
                        }
                    };

                    Controllers.Usuarios.Usuarios.UsuariosController obUsuariosController = new Controllers.Usuarios.Usuarios.UsuariosController();

                    ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('successful!', '" + obUsuariosController.AministrarUsuarios(obclsUsuario, Convert.ToInt32(lblOpcion.Text)) + "!', 'success') </script>");

                    lblOpcion.Text = string.Empty;

                    getUsuarios();
                }
            }
            catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + ex.Message + "!', 'error') </script>"); }
        }
Example #6
0
        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrEmpty(txtEmail.Text))
                {
                    stMensaje += "Ingrese Email, ";
                }
                if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    stMensaje += "Ingrese Password,";
                }

                if (!string.IsNullOrEmpty(stMensaje))
                {
                    throw new Exception(stMensaje.TrimEnd(','));
                }

                Controllers.Usuarios.Login.LoginController obLoginController = new Controllers.Usuarios.Login.LoginController();

                //definicion objeto
                Models.Usuarios.Usuarios.clsUsuario obclsUsuario = new Models.Usuarios.Usuarios.clsUsuario
                {
                    stEmail    = txtEmail.Text,
                    stPassword = txtPassword.Text
                };

                DataSet dsConsulta = obLoginController.ConsultarAutenticacionUsuario(obclsUsuario);

                if (dsConsulta.Tables[0].Rows.Count > 0)
                {
                    Session["Perfil"] = dsConsulta.Tables[0].Rows[0]["perfCodigo"];
                    Response.Redirect("../../Home.aspx");
                }
                else
                {
                    throw new Exception("Usuario o password incorrecto");
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + ex.Message + "!', 'error') </script>");
            }
        }
        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrEmpty(txtCodigo.Text))
                {
                    stMensaje += "Ingrese Codigo, ";
                }

                if (!string.IsNullOrEmpty(stMensaje))
                {
                    throw new Exception(stMensaje.TrimEnd(','));
                }

                Models.Usuarios.Usuarios.clsUsuario obclsUsuarios = new Models.Usuarios.Usuarios.clsUsuario
                {
                    inCodigo = Convert.ToInt32(txtCodigo.Text)
                };

                Controllers.Usuarios.Usuarios.UsuariosController obUsuariosController = new Controllers.Usuarios.Usuarios.UsuariosController();

                DataSet dsConsulta = obUsuariosController.ConsultarCodUsuarios(obclsUsuarios);

                if (dsConsulta.Tables[0].Rows.Count > 0)
                {
                    gvwDatos.DataSource = dsConsulta;
                }
                else
                {
                    gvwDatos.DataSource = null;
                }

                txtCodigo.Text = string.Empty;

                gvwDatos.DataBind();
            }
            catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + ex.Message + "!', 'error') </script>"); }
        }
Example #8
0
        protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrEmpty(txtNombre.Text))
                {
                    stMensaje += "Ingrese Nombre, ";
                }
                if (string.IsNullOrEmpty(txtApellido.Text))
                {
                    stMensaje += "Ingrese Apellido,";
                }
                if (string.IsNullOrEmpty(txtEmail.Text))
                {
                    stMensaje += "Ingrese Email,";
                }
                if (string.IsNullOrEmpty(txtUsuario.Text))
                {
                    stMensaje += "Ingrese Usuario,";
                }
                if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    stMensaje += "Ingrese Password,";
                }

                if (!string.IsNullOrEmpty(stMensaje))
                {
                    throw new Exception(stMensaje.TrimEnd(','));
                }

                Controllers.Usuarios.Registro.RegistroController obRegistroController = new Controllers.Usuarios.Registro.RegistroController();

                //Definicion Objeto
                Models.Usuarios.Usuarios.clsUsuario obclsUsuario = new Models.Usuarios.Usuarios.clsUsuario
                {
                    stNombre      = txtNombre.Text,
                    stApellido    = txtApellido.Text,
                    stEmail       = txtEmail.Text,
                    stUsuario     = txtUsuario.Text,
                    stPassword    = txtPassword.Text,
                    obclsPerfiles = new Models.Usuarios.Perfiles.clsPerfiles {
                        inCodigo = 3
                    }
                };

                string respuesta = obRegistroController.InserarUsuario(obclsUsuario);

                if (respuesta.Equals("Usted se a registrado correctamente"))
                {
                    txtNombre.Text   = string.Empty;
                    txtApellido.Text = string.Empty;
                    txtEmail.Text    = string.Empty;
                    txtUsuario.Text  = string.Empty;
                    txtPassword.Text = string.Empty;

                    ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Buen Trabajo!', '" + respuesta + "!', 'success') </script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + respuesta + "!', 'error') </script>");
                    txtUsuario.Text = string.Empty;
                }
            }
            catch (Exception ex)
            { ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + ex.Message + "!', 'error') </script>"); }
        }
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrEmpty(txtNombre.Text))
                {
                    stMensaje += "Ingrese Nombre, ";
                }
                if (string.IsNullOrEmpty(txtApellido.Text))
                {
                    stMensaje += "Ingrese Apellido,";
                }
                if (string.IsNullOrEmpty(txtCorreo.Text))
                {
                    stMensaje += "Ingrese Correo, ";
                }
                if (string.IsNullOrEmpty(txtUsuario.Text))
                {
                    stMensaje += "Ingrese Usuario,";
                }
                if (lblOpcion.Text != "2" && string.IsNullOrEmpty(txtPassword.Text))
                {
                    stMensaje += "Ingrese Contraseña, ";
                }

                if (!string.IsNullOrEmpty(stMensaje))
                {
                    throw new Exception(stMensaje.TrimEnd(','));
                }

                codigo = 0;
                if (lblOpcion.Text == "2")
                {
                    codigo = Convert.ToInt32(lblCodUsuario.Text);
                }
                ;

                Models.Usuarios.Usuarios.clsUsuario obclsUsuario = new Models.Usuarios.Usuarios.clsUsuario
                {
                    inCodigo      = codigo,
                    stNombre      = txtNombre.Text,
                    stApellido    = txtApellido.Text,
                    stEmail       = txtCorreo.Text,
                    stUsuario     = txtUsuario.Text,
                    stPassword    = txtPassword.Text,
                    obclsPerfiles = new Models.Usuarios.Perfiles.clsPerfiles
                    {
                        inCodigo = Convert.ToInt32(ddlPerfiles.SelectedValue)
                    }
                };

                Controllers.Usuarios.Usuarios.UsuariosController obUsuariosController = new Controllers.Usuarios.Usuarios.UsuariosController();

                if (string.IsNullOrEmpty(lblOpcion.Text))
                {
                    lblOpcion.Text = "1";
                }

                ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('successful!', '" + obUsuariosController.AministrarUsuarios(obclsUsuario, Convert.ToInt32(lblOpcion.Text)) + "!', 'success') </script>");

                txtNombre.Text      = string.Empty;
                txtApellido.Text    = string.Empty;
                txtCorreo.Text      = string.Empty;
                txtUsuario.Text     = string.Empty;
                txtPassword.Enabled = true;
                txtPassword.Text    = string.Empty;

                getUsuarios();
            }
            catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('Error!', '" + ex.Message + "!', 'error') </script>"); }
        }