示例#1
0
 public void Baja(Admin unAdmin)
 {
     SqlConnection _cnn = new SqlConnection(Conexion.Cnn);
     SqlCommand comando = new SqlCommand("BAJA_ADMINISTRADOR", _cnn);
     comando.CommandType = System.Data.CommandType.StoredProcedure;
     comando.Parameters.AddWithValue("@CI", unAdmin.CI);
     SqlParameter Retorno = new SqlParameter("@Retorno", System.Data.SqlDbType.Int);
     Retorno.Direction = System.Data.ParameterDirection.ReturnValue;
     comando.Parameters.Add(Retorno);
     try
     {
         _cnn.Open();
         comando.ExecuteNonQuery();
         if ((int)Retorno.Value == -1)
             throw new Exception("No Existe el Usuario");
         else if ((int)Retorno.Value == -2)
             throw new Exception("Error Al Eliminar El Administrador");
         else if ((int)Retorno.Value == -3)
             throw new Exception("Error AL Eliminar El Usuario");
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         _cnn.Close();
     }
 }
示例#2
0
        public void Alta(Admin unAdmin)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand comando = new SqlCommand("REG_ADMINISTRADOR", conexion);
            comando.CommandType = System.Data.CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@CI", unAdmin.CI);
            comando.Parameters.AddWithValue("@NOMBRE", unAdmin.NOM_COMPLETO);
            comando.Parameters.AddWithValue("@USUARIO", unAdmin.USUARIO);
            comando.Parameters.AddWithValue("@PASS", unAdmin.PASS);
            comando.Parameters.AddWithValue("@ESTADISTICAS", unAdmin.ESTADISTICAS);
            SqlParameter Retorno = new SqlParameter("@Retorno", SqlDbType.Int);
            Retorno.Direction = ParameterDirection.ReturnValue;
            comando.Parameters.Add(Retorno);
            try
            {
                conexion.Open();
                comando.ExecuteNonQuery();

                if ((int)Retorno.Value == -1)
                    throw new Exception("Ya existe ese usuario/cedula");
                else if ((int)Retorno.Value == -2)
                    throw new Exception("Error al registrar el empleado.");
                else if ((int)Retorno.Value == -3)
                    throw new Exception("Error en el cargo");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
            }
        }
示例#3
0
        public Admin Logueo(string pUsuario, string pPass)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            Admin UnAdmin = null;

            SqlCommand comando = new SqlCommand("LOGUEO_ADMINISTRADOR", conexion);
            comando.CommandType = CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@USUARIO", pUsuario);
            comando.Parameters.AddWithValue("@PASS", pPass);

            try
            {
                conexion.Open();
                SqlDataReader dr = comando.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    UnAdmin = new Admin((int)dr["CI"], (string)dr["NOMBRE"],
                        (string)dr["USUARIO"], (string)dr["PASS"], (bool)dr["ESTADISTICAS"]);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
            }
            return UnAdmin;
        }
示例#4
0
 public void Modificar(Admin unAdmin)
 {
     SqlConnection conexion = new SqlConnection(Conexion.Cnn);
     SqlCommand comando = new SqlCommand("MOD_ADMINISTRADOR", conexion);
     comando.CommandType = System.Data.CommandType.StoredProcedure;
     comando.Parameters.AddWithValue("@CI", unAdmin.CI);
     comando.Parameters.AddWithValue("@NOMBRE", unAdmin.NOM_COMPLETO);
     comando.Parameters.AddWithValue("@USUARIO", unAdmin.USUARIO);
     comando.Parameters.AddWithValue("@PASS", unAdmin.PASS);
     comando.Parameters.AddWithValue("@ESTADISTICAS", unAdmin.ESTADISTICAS);
     SqlParameter Retorno = new SqlParameter("@Retorno", System.Data.SqlDbType.Int);
     Retorno.Direction = System.Data.ParameterDirection.ReturnValue;
     comando.Parameters.Add(Retorno);
     try
     {
         conexion.Open();
         comando.ExecuteNonQuery();
         if ((int)Retorno.Value == -1)
             throw new Exception("No Existe el Usuario");
         else if ((int)Retorno.Value == -2)
             throw new Exception("Error Al Modificar El Usuario");
         else if ((int)Retorno.Value == -3)
             throw new Exception("Error AL Modificar El Administrador");
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         conexion.Close();
     }
 }
示例#5
0
        public Admin Buscar(int pCi)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            Admin unAdmin = null;
            SqlCommand comando = new SqlCommand("BUSCAR_ADMIN", conexion);
            comando.CommandType = System.Data.CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@CI", pCi);

            try
            {
                conexion.Open();
                SqlDataReader dr = comando.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    unAdmin = new Admin(pCi, (string)dr["NOMBRE"],
                        (string)dr["USUARIO"], (string)dr["PASS"], (bool)dr["ESTADISTICAS"]);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
            }
            return unAdmin;
        }