Exemple #1
0
        public List <Reservacion> GetAllReservacion()
        {
            DataSet            ds      = null;
            List <Reservacion> lista   = new List <Reservacion>();
            SqlCommand         command = new SqlCommand();

            IDALHabitacion _DALHabitacion = new DALHabitacion();
            IDALHuesped    _DALHuesped    = new DALHuesped();

            string sql = @"usp_SELECT_Reservacion_All";

            try
            {
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;

                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    ds = db.ExecuteReader(command, "query");
                }

                // Si devolvió filas
                if (ds.Tables[0].Rows.Count > 0)
                {
                    // Iterar en todas las filas y Mapearlas
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        Reservacion oReservacion = new Reservacion()
                        {
                            ID          = double.Parse(dr["ID"].ToString()),
                            _Huesped    = _DALHuesped.GetHuespedById(double.Parse(dr["IDHuesped"].ToString())),
                            _Habitacion = _DALHabitacion.GetHabitacionById(double.Parse(dr["NUMHabitacion"].ToString())),
                            CheckIN     = (DateTime)dr["CheckIN"],
                            CheckOUT    = (DateTime)dr["CheckOUT"],
                            CantDias    = (int)dr["CantDias"],
                            Subtotal    = double.Parse(dr["Subtotal"].ToString())
                        };

                        lista.Add(oReservacion);
                    }
                }

                return(lista);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                msg.AppendFormat("SQL             {0}\n", command.CommandText);
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er));
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
        }
Exemple #2
0
        public Reservacion GetReserva(double pNumeroReserva)
        {
            Reservacion oReservacion = new Reservacion();
            DataSet     ds           = null;

            IDALHabitacion _DALHabitacion = new DALHabitacion();
            IDALHuesped    _DALHuesped    = new DALHuesped();

            SqlCommand command = new SqlCommand();

            string sql = @" ";


            sql = @"select * from [Reservacion] where ID = @ID";

            try
            {
                command.CommandText = sql;
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@ID", pNumeroReserva);

                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    ds = db.ExecuteReader(command, "query");
                }

                // Si devolvió filas
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    oReservacion = new Reservacion()
                    {
                        ID          = (int)dr["ID"],
                        _Huesped    = _DALHuesped.GetHuespedById(double.Parse(dr["IDHuesped"].ToString())),
                        _Habitacion = _DALHabitacion.GetHabitacionById(double.Parse(dr["NUMHabitacion"].ToString())),
                        CheckIN     = (DateTime)(dr["CheckIN"]),
                        CheckOUT    = (DateTime)(dr["CheckIN"]),
                        CantDias    = (int)dr["CantDias"],
                        Subtotal    = double.Parse(dr["Subtotal"].ToString())
                    };

                    foreach (var item in ds.Tables[0].Rows)
                    {
                        oReservacion.ID          = double.Parse(dr["ID"].ToString());
                        oReservacion._Huesped    = _DALHuesped.GetHuespedById(double.Parse(dr["IDHuesped"].ToString()));
                        oReservacion._Habitacion = _DALHabitacion.GetHabitacionById(double.Parse(dr["NUMHabitacion"].ToString()));
                        oReservacion.CheckIN     = (DateTime)(dr["CheckIN"]);
                        oReservacion.CheckOUT    = (DateTime)(dr["CheckOUT"]);
                        oReservacion.CantDias    = double.Parse(dr["CantDias"].ToString());
                        oReservacion.Subtotal    = double.Parse(dr["Subtotal"].ToString());
                    }
                }

                return(oReservacion);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                msg.AppendFormat("SQL             {0}\n", command.CommandText);
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er));
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
        }