Exemple #1
0
        internal static void ActualizarCon(Juegos pJue, Contestada pCon, SqlTransaction pTransaccion)
        {
            SqlCommand comando = new SqlCommand("GUARDAR_CONTESTADAS", pTransaccion.Connection);
            comando.CommandType = System.Data.CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@ID_JUEGO", pJue.ID_JUEGO);
            comando.Parameters.AddWithValue("@ID_PREG", pCon.UNA_PRE.ID_PREG);
            comando.Parameters.AddWithValue("@CONTESTADA", pCon.CORRECTA);

            SqlParameter _ParmRetorno = new SqlParameter("@Retorno", SqlDbType.Int);
            _ParmRetorno.Direction = ParameterDirection.ReturnValue;
            comando.Parameters.Add(_ParmRetorno);

            try
            {
                comando.Transaction = pTransaccion;
                comando.ExecuteNonQuery();

                int _Codcomp = Convert.ToInt32(_ParmRetorno.Value);
                if (_Codcomp == -1)
                    throw new Exception("El juego no existe");
                else if (_Codcomp == -2)
                    throw new Exception("La pregunta no existe");
                else if (_Codcomp == -3)
                    throw new Exception("Error al actualizar contestadas.");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
 void IWCFsem.AltaJuego(Juegos pJuego)
 {
     try
     {
         FabricaLogica.GetLogicaJuego().Alta(pJuego);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
        public void Alta(Juegos pJuego)
        {
            List<Juegos> listjue = ListarJuegos();

            pJuego.ID_JUEGO = listjue.Count();

            SqlConnection _cnn = new SqlConnection(Conexion.Cnn);

            SqlCommand _comando = new SqlCommand("REG_JUEGO", _cnn);
            _comando.CommandType = System.Data.CommandType.StoredProcedure;
            _comando.Parameters.AddWithValue("@CI", pJuego.JUGADOR.CI);

            SqlParameter _ParmRetorno = new SqlParameter("@Retorno", SqlDbType.Int);
            _ParmRetorno.Direction = ParameterDirection.ReturnValue;
            _comando.Parameters.Add(_ParmRetorno);

            SqlTransaction _miTransaccion = null;

            try
            {
                _cnn.Open();

                _miTransaccion = _cnn.BeginTransaction();

                _comando.Transaction = _miTransaccion;
                _comando.ExecuteNonQuery();

                int _Codcomp = Convert.ToInt32(_ParmRetorno.Value);
                if (_Codcomp == -1)
                    throw new Exception("Usuario no habilitado para jugar");
                else if (_Codcomp == -2)
                    throw new Exception("El usurio tiene juegos pendientes");
                else if (_Codcomp == -3)
                    throw new Exception("Error al crear el juego");

                foreach (Contestada unaC in pJuego.LIST_CON)
                {
                    Persistencia.Clases_de_trabajo.PerContestada.RegPreg(unaC, _miTransaccion);
                }

                _miTransaccion.Commit();
            }
            catch (Exception ex)
            {
                _miTransaccion.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                _cnn.Close();
            }
        }
Exemple #4
0
        public Juegos Buscar_Juego(int pId)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            Juegos unJuego = null;
            Jugador unJugador = null;
            List<Contestada> listCon = null;
            SqlCommand comando = new SqlCommand("BUSCAR_JUEGO", conexion);
            comando.CommandType = System.Data.CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@ID_JUEGO", pId);

            try
            {
                conexion.Open();
                SqlDataReader dr = comando.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    unJugador = PerFabrica.GetPerJugador().Buscar(Convert.ToInt32(dr["CI"]));
                    listCon = Persistencia.Clases_de_trabajo.PerContestada.ContestadasXJuego(Convert.ToInt32(dr["ID_JUEGO"]));
                    unJuego = new Juegos(Convert.ToInt32(dr["ID_JUEGO"]), unJugador, Convert.ToDateTime(dr["FECHA_INICIO"]), Convert.ToInt32(dr["MOVIMIENTOS"]), listCon);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
            }
            return unJuego;
        }
Exemple #5
0
 private List<Juegos> ListarJuegos()
 {
     List<Juegos> lista = new List<Juegos>();
     SqlConnection conexion = new SqlConnection(Conexion.Cnn);
     SqlCommand comando = new SqlCommand("LISTAR_JUEGOS", conexion);
     comando.CommandType = System.Data.CommandType.StoredProcedure;
     Juegos _juego = null;
     try
     {
         conexion.Open();
         SqlDataReader dr = comando.ExecuteReader();
         if (dr.HasRows)
         {
             while (dr.Read())
             {
                 _juego = new Juegos(Convert.ToInt32(dr["ID_JUEGO"]), PerJugador.GetInstancia().Buscar(Convert.ToInt32(dr["CI"])), Convert.ToDateTime(dr["FECHA_INICIO"]),
                 Convert.ToInt32(dr["MOVIMIENTOS"]), PerContestada.ListarPreguntasXJuego(Convert.ToInt32(dr["ID_JUEGO"])));
                 lista.Add(_juego);
             }
         }
         dr.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         conexion.Close();
     }
     return lista;
 }
Exemple #6
0
 public List<Juegos> ListarJuegosXJugador(Jugador UnJug)
 {
     List<Juegos> lista = new List<Juegos>();
     SqlConnection conexion = new SqlConnection(Conexion.Cnn);
     SqlCommand comando = new SqlCommand("ESTADISTICA_X_JUGADOR", conexion);
     comando.CommandType = System.Data.CommandType.StoredProcedure;
     Juegos juego = null;
     comando.Parameters.AddWithValue("@CI", UnJug.CI);
     try
     {
         conexion.Open();
         SqlDataReader dr = comando.ExecuteReader();
         if (dr.HasRows)
         {
             UnJug = PerJugador.GetInstancia().Buscar(UnJug.CI);
             while (dr.Read())
             {
                 juego = new Juegos((int)dr["ID_JUEGO"], PerJugador.GetInstancia().Buscar((int)dr["CI"]), Convert.ToDateTime(dr["FECHA_INICIO"]),
                 (int)dr["MOVIMIENTOS"], PerContestada.ListarPreguntasXJuego((int)dr["ID_JUEGO"]));
                 juego.F_FIN = Convert.ToDateTime(dr["FECHA_FIN"]);
                 lista.Add(juego);
             }
         }
         dr.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         conexion.Close();
     }
     return lista;
 }
Exemple #7
0
        public void GuardarJuego(Juegos pJuego)
        {
            SqlConnection _cnn = new SqlConnection(Conexion.Cnn);

            SqlCommand _comando = new SqlCommand("GUARDAR_JUEGO", _cnn);
            _comando.CommandType = System.Data.CommandType.StoredProcedure;
            _comando.Parameters.AddWithValue("@ID_JUEGO", pJuego.ID_JUEGO);
            _comando.Parameters.AddWithValue("@MOVIMIENTOS", pJuego.MOVS);

            SqlParameter _ParmRetorno = new SqlParameter("@Retorno", SqlDbType.Int);
            _ParmRetorno.Direction = ParameterDirection.ReturnValue;
            _comando.Parameters.Add(_ParmRetorno);

            SqlTransaction _miTransaccion = null;

            try
            {
                _cnn.Open();

                _miTransaccion = _cnn.BeginTransaction();

                _comando.Transaction = _miTransaccion;
                _comando.ExecuteNonQuery();

                int _Codcomp = Convert.ToInt32(_ParmRetorno.Value);
                if (_Codcomp == -1)
                    throw new Exception("El juego no existe");
                else if (_Codcomp == -2)
                    throw new Exception("Error al actualizar el juego");

                foreach (Contestada unaC in pJuego.LIST_CON)
                {
                    Persistencia.Clases_de_trabajo.PerContestada.ActualizarCon(pJuego, unaC, _miTransaccion);
                }

                _miTransaccion.Commit();
            }
            catch (Exception ex)
            {
                _miTransaccion.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                _cnn.Close();
            }
        }
Exemple #8
0
        public void FinalizarJuego(Juegos pJuego)
        {
            SqlConnection _cnn = new SqlConnection(Conexion.Cnn);

            SqlCommand _comando = new SqlCommand("FINALIZAR_JUEGO", _cnn);
            _comando.CommandType = System.Data.CommandType.StoredProcedure;
            _comando.Parameters.AddWithValue("@ID_JUEGO", pJuego.ID_JUEGO);
            _comando.Parameters.AddWithValue("@FECHA_FIN", DateTime.Now);

            SqlParameter _ParmRetorno = new SqlParameter("@Retorno", SqlDbType.Int);
            _ParmRetorno.Direction = ParameterDirection.ReturnValue;
            _comando.Parameters.Add(_ParmRetorno);

            try
            {
                _cnn.Open();
                _comando.ExecuteNonQuery();

                int _Codcomp = Convert.ToInt32(_ParmRetorno.Value);
                if (_Codcomp == -1)
                    throw new Exception("El juego no existe");
                else if (_Codcomp == -2)
                    throw new Exception("Error al actualizar el juego");

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                _cnn.Close();
            }
        }
Exemple #9
0
 public void GuardarJuego(Juegos pJuego)
 {
     PerFabrica.GetPerJuego().GuardarJuego(pJuego);
 }
Exemple #10
0
 public void FinalizarJuego(Juegos pJuego)
 {
     PerFabrica.GetPerJuego().FinalizarJuego(pJuego);
 }
Exemple #11
0
 public void Alta(Juegos pJuego)
 {
     PerFabrica.GetPerJuego().Alta(pJuego);
 }
Exemple #12
0
 void IWCFsem.FinalizarJuego(Juegos pJuego)
 {
     try
     {
         FabricaLogica.GetLogicaJuego().FinalizarJuego(pJuego);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }