Exemplo n.º 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;
            }
        }
Exemplo n.º 2
0
        public bool Login(string pUsuario, string pContrasena)
        {
            StringBuilder conexion = new StringBuilder();

            try
            {
                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(pUsuario, pContrasena)))
                {
                    // Si esto da error es porque el usuario no existe!
                }

                return(true);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));

                _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;
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        public List <SysUser> GetSysUserByFilter(string pDescripcion)
        {
            DataSet        ds      = null;
            SqlCommand     command = new SqlCommand();
            List <SysUser> lista   = new List <SysUser>();
            string         sql     = @" select * from  [SysUser] where [Login] like @Login";

            try
            {
                // Pasar Parámetro
                command.Parameters.AddWithValue("@Login", pDescripcion);
                command.CommandText = sql;
                command.CommandType = CommandType.Text;

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

                // Si devolvió valores
                if (ds.Tables[0].Rows.Count > 0)
                {
                    // Itetarar en las filas
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        SysUser oSysUser = new SysUser()
                        {
                            Login    = (dr["Login"].ToString()),
                            Password = (dr["Password"].ToString()),
                            IdRol    = (int)(dr["IdRol"]),
                            IDUser   = (int)(dr["IDUser"])
                        };

                        lista.Add(oSysUser);
                    }
                }

                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;
            }
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
0
        public List <SysUserRolDTO> GetAllSysUser()
        {
            DataSet ds = null;
            List <SysUserRolDTO> lista   = new List <SysUserRolDTO>();
            SqlCommand           command = new SqlCommand();

            string sql = @"usp_SELECT_SysUser_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)
                    {
                        SysUserRolDTO oSysUserRolDTO = new SysUserRolDTO()
                        {
                            Login    = (dr["Login"].ToString()),
                            Password = (dr["Password"].ToString()),
                            Id       = double.Parse(dr["IdRol"].ToString()),
                            //Descripcion = (dr["Descripcion"].ToString()),
                            IDUser = (int)(dr["IDUser"])
                        };

                        lista.Add(oSysUserRolDTO);
                    }
                }

                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;
            }
        }
Exemplo n.º 7
0
        public List <HabitacionDTO> GetAllHabitacion()
        {
            DataSet ds = null;
            List <HabitacionDTO> lista   = new List <HabitacionDTO>();
            SqlCommand           command = new SqlCommand();

            string sql = @"usp_SELECT_Habitacion_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)
                    {
                        HabitacionDTO oHabitacionDTO = new HabitacionDTO()
                        {
                            NUM         = double.Parse(dr["NUM"].ToString()),
                            Descripcion = dr["Descripcion"].ToString(),
                            Foto        = (byte[])dr["Foto"],
                            Estado      = (int)dr["Estado"],
                            Precio      = double.Parse(dr["Precio"].ToString())
                        };

                        lista.Add(oHabitacionDTO);
                    }
                }

                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;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Metodo que busca si el mensajero tiene alguna factura en la base de datos
        /// </summary>
        /// <param name="IdMensajero">Mensajero al que se le va a buscar</param>
        /// <returns>Retorna una factura de las que el mensajero tenga</returns>
        public EncabezadoFactura ObtenerFacturaByIDMensajero(string IdMensajero)
        {
            EncabezadoFactura oEncabezado   = new EncabezadoFactura();
            IConexion         conexion      = new Conexion();
            IDALCliente       _DALCliente   = new DALCliente();
            IDALMensajero     _DALMensajero = new DALMensajero();
            IDALTarjeta       _DALTarjeta   = new DALTarjeta();
            DataSet           ds            = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("select * from EncFactura where IDMensajero = @IdMensajero", conn);
                    cmd.Parameters.AddWithValue("@IdMensajero", IdMensajero);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];

                        oEncabezado.IDEncFactura = dr["IDEncFactura"].ToString();
                        oEncabezado.Fecha        = Convert.ToDateTime(dr["Fecha"].ToString());
                        oEncabezado.oCliente     = _DALCliente.BuscarClienteID(dr["IDCliente"].ToString());
                        oEncabezado.oMensajero   = _DALMensajero.BuscarMensajeroID(dr["IDMensajero"].ToString());
                        oEncabezado.XML          = dr["XML"].ToString();
                        oEncabezado.oTarjeta     = _DALTarjeta.GetTarjetID(dr["IDTarjeta"].ToString());
                    }
                    else
                    {
                        oEncabezado = null;
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(oEncabezado);
        }
Exemplo n.º 9
0
        public Habitacion UpdateHabitacion(Habitacion pHabitacion)
        {
            Habitacion oHabitacion = null;
            string     sql         = @"usp_UPDATE_Habitacion";



            SqlCommand command = new SqlCommand();
            double     rows    = 0;

            try
            {
                // Pasar parámetros
                command.Parameters.AddWithValue("@NUM", pHabitacion.NUM);
                command.Parameters.AddWithValue("@Descripcion", pHabitacion.Descripcion);
                command.Parameters.AddWithValue("@Foto", pHabitacion.Foto.ToArray());
                command.Parameters.AddWithValue("Estado", pHabitacion.Estado);
                command.Parameters.AddWithValue("Precio", pHabitacion.Precio);

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


                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    rows = db.ExecuteNonQuery(command, IsolationLevel.ReadCommitted);
                }

                // Si devuelve filas quiere decir que se salvo entonces extraerlo
                if (rows > 0)
                {
                    oHabitacion = GetHabitacionById(pHabitacion.NUM);
                }

                return(oHabitacion);
            }
            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;
            }
        }
Exemplo n.º 10
0
        public Habitacion GetHabitacionById(double pId)
        {
            DataSet    ds          = null;
            Habitacion oHabitacion = null;
            string     sql         = @"Select * from [Habitacion] where NUM = @NUM";

            SqlCommand command = new SqlCommand();

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

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

                // Si retornó valores
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //Extraer la primera fila, como se buscó por Id entonces solo una debe devolver
                    DataRow dr = ds.Tables[0].Rows[0];
                    oHabitacion = new Habitacion()
                    {
                        NUM         = double.Parse(dr["NUM"].ToString()),
                        Descripcion = dr["Descripcion"].ToString(),
                        Foto        = (byte[])dr["Foto"],
                        Estado      = (int)dr["Estado"],
                        Precio      = double.Parse(dr["Precio"].ToString())
                    };
                }

                return(oHabitacion);
            }
            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;
            }
        }
Exemplo n.º 11
0
        public SysUser GetSysUserById(double pId)
        {
            DataSet       ds       = null;
            SysUser       oSysUser = null;
            SysUserRolDTO DTO      = new SysUserRolDTO();
            string        sql      = @" select * from  [SysUser] where IDUser = @IDUser";

            SqlCommand command = new SqlCommand();

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

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

                // Si retornó valores
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //Extraer la primera fila, como se buscó por Id entonces solo una debe devolver
                    DataRow dr = ds.Tables[0].Rows[0];
                    oSysUser = new SysUser()
                    {
                        Login    = (dr["Login"].ToString()),
                        Password = (dr["Password"].ToString()),
                        IdRol    = (int)(dr["IdRol"]),
                        IDUser   = (int)(dr["IDUser"])
                    };
                }

                return(oSysUser);
            }
            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;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Método que busca mensajeros por ID en la base de datos
        /// </summary>
        /// <param name="IDMensajero">ID dej mensajero</param>
        /// <returns>Retorna el mensajero que se encuentre en la base de datos</returns>
        public Mensajero BuscarMensajeroID(string IDMensajero)
        {
            Mensajero oMensajero = new Mensajero();
            IConexion conexion   = new Conexion();
            DataTable dt         = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("select * from [Mensajero] where IDMensajero= @IDMensajero", conn);
                    cmd.Parameters.AddWithValue("@IDMensajero", IDMensajero);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        oMensajero.IDMensajero = dt.Rows[0][0].ToString();
                        oMensajero.Nombre      = dt.Rows[0][1].ToString();
                        oMensajero.Apellidos   = dt.Rows[0][2].ToString();
                        oMensajero.Sexo        = dt.Rows[0][3].ToString();
                        oMensajero.Foto        = (byte[])(dt.Rows[0][4]);
                        oMensajero.Correo      = dt.Rows[0][5].ToString();
                        oMensajero.Activo      = (Boolean)dt.Rows[0][6];
                        oMensajero.Telefono    = dt.Rows[0][7].ToString();
                    }
                    else
                    {
                        oMensajero = null;
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(oMensajero);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Metodo que busca el cliente por ID
        /// </summary>
        /// <param name="IDCliente">ID del cliente</param>
        /// <returns>Retorna el cliente encontrado</returns>
        public Cliente BuscarClienteID(string IDCliente)
        {
            Cliente   oCliente = new Cliente();
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("select * from [Cliente] where IDCliente= @IDCliente", conn);
                    cmd.Parameters.AddWithValue("@IDCliente", IDCliente);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        oCliente.IDCliente         = dt.Rows[0][0].ToString();
                        oCliente.Nombre            = dt.Rows[0][1].ToString();
                        oCliente.Apellidos         = dt.Rows[0][2].ToString();
                        oCliente.CorreoElectronico = dt.Rows[0][3].ToString();
                        oCliente.Activo            = Convert.ToBoolean(dt.Rows[0][4]);
                        oCliente.Telefono          = dt.Rows[0][5].ToString();
                        oCliente.Direccion         = dt.Rows[0][6].ToString();
                        oCliente.Provincia         = dt.Rows[0][7].ToString();
                    }
                    else
                    {
                        oCliente = null;
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(oCliente);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Método que busca mensajeros por filtro
        /// </summary>
        /// <param name="flitro">filtro</param>
        /// <returns>Retorna una lista de mensajeros que cumplan con el filtro</returns>
        public List <Mensajero> BuscarMensajeroByFilter(string flitro)
        {
            List <Mensajero> _ListMensajero = new List <Mensajero>();
            IConexion        conexion       = new Conexion();
            DataSet          dt             = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand(@"PA_BuscarMensajeroByFilter", conn);
                    cmd.Parameters.AddWithValue("@Filtro", flitro);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Tables[0].Rows)
                        {
                            Mensajero oMensajero = new Mensajero();
                            oMensajero.IDMensajero = dr["IDMensajero"].ToString();
                            oMensajero.Nombre      = dr["Nombre"].ToString();
                            oMensajero.Apellidos   = dr["Apellidos"].ToString();
                            oMensajero.Foto        = (byte[])dr["Foto"];

                            _ListMensajero.Add(oMensajero);
                        }
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListMensajero);
        }
Exemplo n.º 15
0
        public SysUser UpdateSysUser(SysUser pSysUser)
        {
            SysUser oSysUser = null;
            string  sql      = @"usp_UPDATE_SysUser";



            SqlCommand command = new SqlCommand();
            double     rows    = 0;

            try
            {
                // Pasar parámetros
                command.Parameters.AddWithValue("@Login", pSysUser.Login);
                command.Parameters.AddWithValue("@Password", pSysUser.Password);
                command.Parameters.AddWithValue("@IdRol", pSysUser.IdRol);
                command.Parameters.AddWithValue("@IDUser", pSysUser.IDUser);
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;


                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    rows = db.ExecuteNonQuery(command, IsolationLevel.ReadCommitted);
                }

                // Si devuelve filas quiere decir que se salvo entonces extraerlo
                if (rows > 0)
                {
                    oSysUser = GetSysUserById(pSysUser.IDUser);
                }

                return(oSysUser);
            }
            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;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Método que muestra clientes por un filtro
        /// </summary>
        /// <param name="descripcion">Filtro por el que se buscaran los clientes</param>
        /// <returns>Retorna una lista de los clientes que cumplan con el filtro</returns>
        public List <Cliente> MostrarClientesByFilter(string descripcion)
        {
            List <Cliente> _ListCliente = new List <Cliente>();
            IConexion      conexion     = new Conexion();
            DataSet        dt           = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand(@"PA_BuscarClienteByFilter", conn);
                    cmd.Parameters.AddWithValue("@Filtro", descripcion);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Tables[0].Rows)
                        {
                            Cliente oCliente = new Cliente();
                            oCliente.IDCliente = dr["IDCliente"].ToString();
                            oCliente.Nombre    = dr["Nombre"].ToString();
                            oCliente.Apellidos = dr["Apellidos"].ToString();
                            oCliente.Provincia = dr["Provincia"].ToString();

                            _ListCliente.Add(oCliente);
                        }
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListCliente);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Metodo que muestra los mensajeros que hay en la base de datos
        /// </summary>
        /// <returns>Retorna una lista con la información</returns>
        public List <Mensajero> MostrarMensajeros()
        {
            IConexion        conexion        = new Conexion();
            List <Mensajero> _ListMensajeros = new List <Mensajero>();
            DataSet          dt = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand     cmd = new SqlCommand("select * from [Mensajero]", conn);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    foreach (DataRow dr in dt.Tables[0].Rows)
                    {
                        Mensajero oMensajero = new Mensajero();
                        oMensajero.IDMensajero = dr["IDMensajero"].ToString();
                        oMensajero.Nombre      = dr["Nombre"].ToString();
                        oMensajero.Apellidos   = dr["Apellidos"].ToString();
                        oMensajero.Sexo        = dr["Sexo"].ToString();
                        oMensajero.Foto        = (byte[])dr["Foto"];
                        oMensajero.Correo      = dr["CorreoElectronico"].ToString();
                        oMensajero.Activo      = Convert.ToBoolean(dr["Activo"].ToString());
                        oMensajero.Telefono    = dr["Telefono"].ToString();

                        _ListMensajeros.Add(oMensajero);
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListMensajeros);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Metodo que Inserta un cliente a la base de datos
        /// </summary>
        /// <param name="oCliente">Cliente a insertar</param>
        /// <returns>retorna una string con el resultado del storedProcedure</returns>
        public Cliente InsertarCliente(Cliente oCliente)
        {
            string    client   = "";
            Cliente   vCliente = new Cliente();
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    string     query = @"PA_InsertarCliente";
                    SqlCommand comm  = new SqlCommand(query, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@IDCliente", oCliente.IDCliente);
                    comm.Parameters.AddWithValue("@Nombre", oCliente.Nombre);
                    comm.Parameters.AddWithValue("@Apellidos", oCliente.Apellidos);
                    comm.Parameters.AddWithValue("@Telefono", oCliente.Telefono);
                    comm.Parameters.AddWithValue("@CorreoElectronico", oCliente.CorreoElectronico);
                    comm.Parameters.AddWithValue("@Provincia", oCliente.Provincia);
                    comm.Parameters.AddWithValue("@Direccion", oCliente.Direccion);
                    comm.Parameters.AddWithValue("@Activo", oCliente.Activo);
                    SqlDataReader reader = comm.ExecuteReader();
                    while (reader.Read())
                    {
                        client = oCliente.IDCliente;
                    }
                    return(this.BuscarClienteID(oCliente.IDCliente));
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Metodo que obtiene los clientes que hay en la base de datos
        /// </summary>
        /// <returns>retorna un dataTable con la información</returns>
        public List <Cliente> MostrarClientes()
        {
            List <Cliente> _ListCliente = new List <Cliente>();
            IConexion      conexion     = new Conexion();
            DataSet        dt           = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand     cmd = new SqlCommand("select * from [Cliente]", conn);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    foreach (DataRow dr in dt.Tables[0].Rows)
                    {
                        Cliente oCliente = new Cliente();
                        oCliente.IDCliente         = dr["IDCliente"].ToString();
                        oCliente.Nombre            = dr["Nombre"].ToString();
                        oCliente.Apellidos         = dr["Apellidos"].ToString();
                        oCliente.CorreoElectronico = dr["CorreoElectronico"].ToString();
                        oCliente.Activo            = Convert.ToBoolean(dr["Activo"].ToString());
                        oCliente.Telefono          = dr["Telefono"].ToString();
                        oCliente.Direccion         = dr["Direccion"].ToString();
                        oCliente.Provincia         = dr["Provincia"].ToString();

                        _ListCliente.Add(oCliente);
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListCliente);
        }
Exemplo n.º 20
0
        public Huesped UpdateHuesped(Huesped pHuesped)
        {
            Huesped    _Huesped = null;
            string     sql      = @"usp_UPDATE_Huesped";
            SqlCommand cmd      = new SqlCommand();
            double     rows     = 0;

            try
            {
                cmd.Parameters.AddWithValue("@ID", pHuesped.ID);
                cmd.Parameters.AddWithValue("@Nombre", pHuesped.Nombre);
                cmd.Parameters.AddWithValue("@Apellido1", pHuesped.Apellido1);
                cmd.Parameters.AddWithValue("@Apellido2", pHuesped.Apellido2);
                cmd.Parameters.AddWithValue("@Telefono", pHuesped.Telefono);
                cmd.Parameters.AddWithValue("@Correo", pHuesped.Correo);
                cmd.Parameters.AddWithValue("@IDPais", pHuesped._Pais.ID);
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.StoredProcedure;


                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    rows = db.ExecuteNonQuery(cmd, IsolationLevel.ReadCommitted);
                }

                // Si devuelve filas quiere decir que se salvo entonces extraerlo
                if (rows > 0)
                {
                    _Huesped = GetHuespedById(pHuesped.ID);
                }

                return(_Huesped);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                msg.AppendFormat("SQL             {0}\n", cmd.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;
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Metodo que inserta un mensajero a la base de datos
        /// </summary>
        /// <param name="oMensajero">Mensajero a insertar en la base de datos</param>
        /// <returns>Retorna una string con la respuesta del storedProcedure</returns>
        public Mensajero InsertarMensajero(Mensajero oMensajero)
        {
            string    client   = "";
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    string     query = @"PA_InsertarMensajero";
                    SqlCommand comm  = new SqlCommand(query, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@IDMensajero", oMensajero.IDMensajero);
                    comm.Parameters.AddWithValue("@Nombre", oMensajero.Nombre);
                    comm.Parameters.AddWithValue("@Apellidos", oMensajero.Apellidos);
                    comm.Parameters.AddWithValue("@Sexo", oMensajero.Sexo);
                    comm.Parameters.AddWithValue("@foto", oMensajero.Foto);
                    comm.Parameters.AddWithValue("@Correo", oMensajero.Correo);
                    comm.Parameters.AddWithValue("@Activo", oMensajero.Activo);
                    comm.Parameters.AddWithValue("@Telefono", oMensajero.Telefono);
                    SqlDataReader reader = comm.ExecuteReader();
                    while (reader.Read())
                    {
                        client = oMensajero.IDMensajero;
                    }
                    return(this.BuscarMensajeroID(oMensajero.IDMensajero));
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Metodo que verifica si la contraseña y el usuario son corrector para permitir o denegar acceso
        /// </summary>
        /// <param name="user">Nombre de Usuario</param>
        /// <param name="pass">Contraseña</param>
        /// <returns>Retorna una string con la respuesta del storedprocedure</returns>
        public Usuario Login(string pass, string login)
        {
            Usuario   oUsuario = new Usuario();
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("PA_SELECT_Seguridad_ByID", conn);
                    cmd.Parameters.AddWithValue("@NombreUsuario", login);
                    cmd.Parameters.AddWithValue("@Contrasena", pass);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        oUsuario.Login       = dt.Rows[0][0].ToString();
                        oUsuario.Password    = dt.Rows[0][1].ToString();
                        oUsuario.TipoUsuario = dt.Rows[0][2].ToString();
                    }
                    else
                    {
                        oUsuario = null;
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(oUsuario);
        }
Exemplo n.º 23
0
        public Pais GetPaisById(double pId)
        {
            DataSet    ds      = null;
            Pais       oPais   = new Pais();
            SqlCommand command = new SqlCommand();

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

            try
            {
                command.Parameters.AddWithValue("@ID", pId);
                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)
                    {
                        oPais.ID      = (int)dr["ID"];
                        oPais.Detalle = dr["Detalle"].ToString();
                    }
                }

                return(oPais);
            }
            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;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Método que obtiene el impuesto de la base de datos
        /// </summary>
        /// <returns>Retorna el impuesto que hay en la base de datos</returns>
        public List <Impuesto> ObtenerImpuesto()
        {
            List <Impuesto> _ListImpuesto = new List <Impuesto>();
            IConexion       conexion      = new Conexion();
            DataSet         dt            = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand(@"PA_MostrarImpuesto", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Tables[0].Rows)
                        {
                            Impuesto _Impuesto = new Impuesto();
                            _Impuesto.Valor        = Convert.ToDouble(dr["Cantidad"].ToString());
                            _Impuesto.TipoImpuesto = dr["TipoImpuesto"].ToString();

                            _ListImpuesto.Add(_Impuesto);
                        }
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListImpuesto);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Método que obtiene la tarjeta por ID
        /// </summary>
        /// <param name="id">ID de la tarjeta</param>
        /// <returns>Retorna la tarjeta que se encontró</returns>
        public Tarjeta GetTarjetID(string id)
        {
            Tarjeta   oTarjeta = new Tarjeta();
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("select * from [Tarjeta] where IDTarjeta = @IDTarjeta", conn);
                    cmd.Parameters.AddWithValue("@IDTarjeta", id);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        oTarjeta.IDTarjeta   = dt.Rows[0][0].ToString();
                        oTarjeta.Descripcion = dt.Rows[0][1].ToString();
                    }
                    else
                    {
                        oTarjeta = null;
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(oTarjeta);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Método que agrega un usuario a la base de datos
        /// </summary>
        /// <param name="pUsuario">Usuario que se va a agregar</param>
        /// <returns>Retorna el usuario que se agregó</returns>
        public Usuario AgregarUsuario(Usuario pUsuario)
        {
            string    client   = "";
            Usuario   oUsuario = new Usuario();
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    string     query = @"PA_INSERT_Seguridad";
                    SqlCommand comm  = new SqlCommand(query, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@NombreUsuario", pUsuario.Login);
                    comm.Parameters.AddWithValue("@Contrasena", pUsuario.Password);
                    comm.Parameters.AddWithValue("@TipoUsuario", pUsuario.TipoUsuario);
                    SqlDataReader reader = comm.ExecuteReader();
                    while (reader.Read())
                    {
                        client = pUsuario.Login;
                    }
                    oUsuario = this.SelectUsuarioXID(pUsuario.Password, pUsuario.Login);
                    return(oUsuario);
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Método que obtiene los precios de envio de la base de datos
        /// </summary>
        /// <returns>Retorna una lista con los precios</returns>
        public List <EnvioPaquete> ListaPrecios()
        {
            List <EnvioPaquete> _ListPrecios = new List <EnvioPaquete>();
            IConexion           conexion     = new Conexion();
            DataSet             dt           = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand     cmd = new SqlCommand("select * from [EnvioPaquete]", conn);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    foreach (DataRow dr in dt.Tables[0].Rows)
                    {
                        EnvioPaquete EnvioPaquete = new EnvioPaquete();

                        EnvioPaquete.TipoEnvio        = dr["TipoEnvio"].ToString();
                        EnvioPaquete.PrecioRango      = Convert.ToDouble(dr["PrecioRango"].ToString());
                        EnvioPaquete.KilometroInicial = Convert.ToInt32(dr["KilometroInicial"].ToString());
                        EnvioPaquete.KilometroFinal   = Convert.ToInt32(dr["KilometroFinal"].ToString());
                        _ListPrecios.Add(EnvioPaquete);
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListPrecios);
        }
Exemplo n.º 28
0
        public List <Pais> GetAllPais()
        {
            IDataReader reader  = null;
            List <Pais> lista   = new List <Pais>();
            SqlCommand  command = new SqlCommand();

            string sql = @"usp_SELECT_Pais_All";

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


            try
            {
                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    reader = db.ExecuteReader(command);

                    while (reader.Read())
                    {
                        Pais oPais = new Pais();
                        oPais.ID      = int.Parse(reader["ID"].ToString());
                        oPais.Detalle = reader["Detalle"].ToString();
                        lista.Add(oPais);
                    }
                }

                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;
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Método que obtiene todas las tarjetas de la base de datos
        /// </summary>
        /// <returns>Retorna una lista con las tarjetas que hay en la base de datos</returns>
        public List <Tarjeta> GetAllTarjeta()
        {
            List <Tarjeta> _ListTarjeta = new List <Tarjeta>();
            IConexion      conexion     = new Conexion();
            DataSet        dt           = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("PA_MostrarTarjetas", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    foreach (DataRow dr in dt.Tables[0].Rows)
                    {
                        Tarjeta oTarjeta = new Tarjeta();
                        oTarjeta.IDTarjeta   = dr["IDTarjeta"].ToString();
                        oTarjeta.Descripcion = dr["Descripcion"].ToString();

                        _ListTarjeta.Add(oTarjeta);
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(_ListTarjeta);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Metodo que actualiza un valor en la base de datos con el parametro recibido
        /// </summary>
        /// <param name="oEnvio">Parametro que actualizará en la base de datos</param>
        /// <returns>Retorna una string con la respuesta del storedProcedure</returns>
        public EnvioPaquete ActualizarPrecioEnvio(EnvioPaquete oEnvio)
        {
            string    client   = "";
            IConexion conexion = new Conexion();
            DataTable dt       = new DataTable();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    string     query = @"PA_ModificarPrecio";
                    SqlCommand comm  = new SqlCommand(query, conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@TipoEnvio", oEnvio.TipoEnvio);
                    comm.Parameters.AddWithValue("@Precio", oEnvio.PrecioRango);
                    comm.Parameters.AddWithValue("@KilometroInicial", oEnvio.KilometroInicial);
                    comm.Parameters.AddWithValue("@KilometroFinal", oEnvio.KilometroFinal);
                    SqlDataReader reader = comm.ExecuteReader();
                    while (reader.Read())
                    {
                        client = oEnvio.TipoEnvio;
                    }
                    return(this.MostrarXID(oEnvio.TipoEnvio));
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _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;
                }
                finally
                {
                    conn.Close();
                }
            }
        }