Example #1
0
        public List <Huesped> GetAllHuesped()
        {
            DataSet        ds      = null;
            List <Huesped> lista   = new List <Huesped>();
            SqlCommand     command = new SqlCommand();
            IDALPais       _Pais   = new DALPais();

            string sql = @"usp_SELECT_Huesped_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)
                    {
                        Huesped oHuesped = new Huesped();
                        oHuesped.ID        = (int)dr["ID"];
                        oHuesped.Nombre    = dr["Nombre"].ToString();
                        oHuesped.Apellido1 = dr["Apellido1"].ToString();
                        oHuesped.Apellido2 = dr["Apellido2"].ToString();
                        oHuesped.Telefono  = dr["Telefono"].ToString();
                        oHuesped.Correo    = dr["Correo"].ToString();
                        oHuesped._Pais     = _Pais.GetPaisById(Double.Parse(dr["IDPais"].ToString()));
                        lista.Add(oHuesped);
                    }
                }

                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;
            }
        }
Example #2
0
        public Huesped GetHuespedById(double pIdHuesped)
        {
            DataSet    ds       = null;
            Huesped    oHuesped = new Huesped();
            SqlCommand command  = new SqlCommand();

            IDALPais _DALPais = new DALPais();


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

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

                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)
                    {
                        oHuesped.ID        = (int)dr["ID"];
                        oHuesped.Nombre    = dr["Nombre"].ToString();
                        oHuesped.Apellido1 = dr["Apellido1"].ToString();
                        oHuesped.Apellido2 = dr["Apellido2"].ToString();
                        oHuesped.Telefono  = dr["Telefono"].ToString();
                        oHuesped.Correo    = dr["Correo"].ToString();
                        oHuesped._Pais     = _DALPais.GetPaisById(Double.Parse(dr["IDPais"].ToString()));
                    }
                }

                return(oHuesped);
            }
            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;
            }
        }