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; } }
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; } }
public EncFactura GetFactura(double pNumeroFactura) { EncFactura oFacturaEncabezado = new EncFactura(); DataSet ds = null; IDALHuesped _DALHuesped = new DALHuesped(); IDALTarjeta _DALTarjeta = new DALTarjeta(); IDALReservacion _DALReservacion = new DALReservacion(); IDALEncFactura _DALEncFactura = new DALEncFactura(); IBLLImpuesto _BLLImpuestotest = new BLLImpuesto(); SqlCommand command = new SqlCommand(); string sql = @""; sql = @"usp_SELECT_EncFactura_ByID"; try { command.Parameters.AddWithValue("@IDFactura", pNumeroFactura); 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) { DataRow dr = ds.Tables[0].Rows[0]; oFacturaEncabezado = new EncFactura() { IDFactura = double.Parse(dr["IDFactura"].ToString()), _Tarjeta = _DALTarjeta.GetTarjetaById(int.Parse(dr["IDTarjeta"].ToString())), Fecha = DateTime.Parse(dr["Fecha"].ToString()), EstadoFact = dr["EstadoFact"].ToString() }; foreach (var item in ds.Tables[0].Rows) { DetFactura oFacturaDetalle = new DetFactura(); oFacturaDetalle._EncFactura = _DALEncFactura.GetFactura(pNumeroFactura); oFacturaDetalle.Numero = int.Parse(dr["Numero"].ToString()); oFacturaDetalle.Precio = double.Parse(dr["Precio"].ToString()); oFacturaDetalle._Impuesto = _BLLImpuestotest.GetImpuesto(); // Enumerar la secuencia oFacturaDetalle._Reservacion = _DALReservacion.GetReserva(pNumeroFactura); // Agregar oFacturaEncabezado.AddDetalle(oFacturaDetalle); } } return(oFacturaEncabezado); } 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; } }