/// <summary>
        /// ENVIA UN EMAIL
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                ILogicaEmails le = FabricaLogica.getLogicaEmails();
                SiteAlumno m = Master;
                if (m != null && m.USUARIO_LOGUEADO != null)
                {
                    Alumno a = m.USUARIO_LOGUEADO;

                    Entidades.Email newEmail = new Entidades.Email
                                                   {
                                                       CUERPO = txtContenido.Text,
                                                       FECHA = DateTime.Now,
                                                       ASUNTO = txtAsunto.Text
                                                   };
                    Alumno destinatario = new Alumno {NOMBRE_USUARIO = txtPara.Text};

                    //le.AgregarEmail(txtAsunto.Text, txtContenido.Text, a, txtPara.Text);
                    le.AgregarEmail(newEmail, a, destinatario);
                    Response.Redirect("~/AdminAlumno/home.aspx");
                }
            }
            catch (Exception ex)
            {
                lblInfo.Text = ex.Message;
            }
        }
        protected void ddlFolders_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ILogicaEmails le = FabricaLogica.getLogicaEmails();
                Carpeta current = (Carpeta)Session["Carpeta"];
                if (current != null)
                {
                    //le.MoverEmail(Convert.ToInt32(Session["EmailId"]), current.NUMERO_CARPETA, Convert.ToInt32(ddlFolders.SelectedValue));

                    Entidades.Email email = new Entidades.Email();
                    email.NUMERO_EMAIL = Convert.ToInt32(Session["EmailId"]);
                    Carpeta cdestino = new Carpeta();
                    cdestino.NUMERO_CARPETA = Convert.ToInt32(ddlFolders.SelectedValue);
                    le.MoverEmail(email, current, cdestino);

                    lblInfo.Text = "El email se movio a la carpeta " + ddlFolders.SelectedItem.Text;
                }

            }
            catch (Exception ex)
            {
                lblInfo.Text = ex.Message;
            }
        }
        /// <summary>
        /// ELIMINA UN EMAIL DE LA BASE DE DATOS
        /// </summary>
        /// <param name="NumeroEmail"></param>
        public void EliminarEmail(Email e, Carpeta c)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand cmd = Conexion.GetCommand("spEliminarEmail", conexion, CommandType.StoredProcedure);

            SqlParameter _numeroEmail = new SqlParameter("@NumeroMail", e.NUMERO_EMAIL);
            SqlParameter _numeroCarpeta = new SqlParameter("@NumeroCarpeta", c.NUMERO_CARPETA);

            cmd.Parameters.Add(_numeroEmail);
            cmd.Parameters.Add(_numeroCarpeta);

            try
            {
                conexion.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                conexion.Close();
            }
        }
        /// <summary>
        /// Lista los emails del sistema
        /// </summary>
        /// <param name="numeroCarpeta"></param>
        public List<Email> ListarEmails(int numeroCarpeta)
        {
            List<Email> _listaEmail = new List<Email>();

            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand cmd = Conexion.GetCommand("spListarMails", conexion, CommandType.StoredProcedure);

            SqlParameter _numeroCarpeta = new SqlParameter("@NumeroCarpeta", numeroCarpeta);
            //SqlParameter _Retorno = new SqlParameter("@Retorno", SqlDbType.Int);
            //_Retorno.Direction = ParameterDirection.ReturnValue;

            //int oAfectados = -1;

            cmd.Parameters.Add(_numeroCarpeta);

            SqlDataReader _Reader;
            try
            {
                conexion.Open();
                cmd.ExecuteNonQuery();
                _Reader = cmd.ExecuteReader();
                string _asunto, _cuerpo, _nombreDestinatario, _nombreRemitente, _apellidoRem,
                    _apellidoDest, _nombreUsuarioRem, _nombreUsuarioDest;
                bool _leido;

                while (_Reader.Read())
                {
                    _asunto = (string)_Reader["Asunto"];
                    _cuerpo = (string)_Reader["Cuerpo"];
                    _leido = (bool)_Reader["Leido"];
                    _nombreRemitente = (string)_Reader["NombreRemitente"];
                    _nombreDestinatario = (string)_Reader["NombreDestinatario"];
                    _apellidoRem = (string)_Reader["ApellidoRemitente"];
                    _apellidoDest = (string)_Reader["ApellidoDestinatario"];
                    _nombreUsuarioRem = (string)_Reader["NombreUsuarioRemitente"];
                    _nombreUsuarioDest = (string)_Reader["NombreUsuarioDestinatario"];

                    Email e = new Email(0, 0, 0, _asunto, _leido, _cuerpo, _nombreRemitente, _nombreDestinatario, _apellidoRem, _apellidoDest,
                        _nombreUsuarioDest, _nombreUsuarioRem);

                    _listaEmail.Add(e);
                }
                _Reader.Close();
            }
            catch
            {
                throw new ErrorBaseDeDatos(); //Acá van las excepciones según @retorno
            }
            finally
            {
                conexion.Close();
            }

            return _listaEmail;
        }
        //public void AgregarEmail(string asunto, string cuerpo, Alumno Remitente, string userNameDestinatario)
        public void AgregarEmail(Email newEmail, Alumno remitente, Alumno destinatario)
        {
            try
            {
                //PRIMERO VALIDAMOS QUE EL DESTINATARIO EXISTA
                //--------------------------------------------
                ServicioRemoting.ServicioAlumno _objServicioA = new ServicioRemoting.ServicioAlumno();

                //OBTENERMOS EL USUARIO DESTINATARIO
                //destinatario = lusuario.getAlumno(destinatario.NOMBRE_USUARIO);
                destinatario = _objServicioA.Buscar(destinatario);
                if (destinatario != null)
                {
                    //OBTENGO LA CARPETA INBOX POR DEFECTO DEL DESTINATARIO
                    //------------------------------------------------------
                    LogicaCarpetas lcarpeta = LogicaCarpetas.GetInstancia();
                    //Carpeta InboxDest = lcarpeta.getInboxFolder(destinatario.CI);
                    Carpeta InboxDest = lcarpeta.getInboxFolder(destinatario);

                    //Carpeta SentFolder = lcarpeta.getSentFolder(Remitente.CI);
                    Carpeta SentFolder = lcarpeta.getSentFolder(remitente);

                    //Email e = new Email(null, asunto, false, cuerpo, SentFolder, InboxDest, DateTime.Now);
                    newEmail.CARPETA_DESTINATARIO = InboxDest;
                    newEmail.CARPETA_REMITENTE = SentFolder;
                    ServicioRemoting.ServicioEmails _objServicioE = new ServicioRemoting.ServicioEmails();

                    //GUARDAMOS EL NUEVO EMAIL EN LA BASE DE DATOS
                    //--------------------------------------------
                    _objServicioE.NuevoEmail(newEmail);
                }
                else
                    //CREAR EXCEPCION PERSONALIZADA AQUI!! ***********************************
                    throw new Exception("Usuario destinatario no valido. El usuario no existe en el sistema.");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void EmailListRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            try
            {
                ILogicaEmails le = FabricaLogica.getLogicaEmails();
                if (e.CommandName.ToUpper() == "VER")
                {
                    //OBTENEMOS EL EMAIL
                    //------------------
                    if (Session["EmailId"] == null)
                    {
                        Session.Add("EmailId", e.CommandArgument);
                    }
                    else
                    {
                        Session["EmailId"] = e.CommandArgument;
                    }
                    //MARCAR EMAIL COMO LEIDO
                    //-----------------------
                    //le.MarcarEmailLeido(Convert.ToInt32(e.CommandArgument), CARPETA.NUMERO_CARPETA);
                    Entidades.Email email = new Entidades.Email {NUMERO_EMAIL = Convert.ToInt32(e.CommandArgument)};
                    le.MarcarEmailLeido(email, CARPETA);

                    Response.Redirect("~/AdminAlumno/Email.aspx", false);
                }
                else if (e.CommandName.ToUpper() == "ELIMINAR")
                {
                    //le.EliminarEmail(Convert.ToInt32(e.CommandArgument), CARPETA.NUMERO_CARPETA, ((Alumno)Session["Usuario"]).CI);
                    Entidades.Email email = new Entidades.Email {NUMERO_EMAIL = Convert.ToInt32(e.CommandArgument)};
                    CARPETA.USUARIO = ((Alumno)Session["Usuario"]);
                    le.EliminarEmail(email, CARPETA);
                    lblInfo.Text = "Email eliminado";
                }
            }
            catch (Exception ex)
            {
                lblInfo.Text = ex.Message;
            }
        }
        //public void EliminarEmail(int numeroEmail, int NumeroCarpeta, int ciAlumno)
        /// <summary>
        /// ENVIA UN EMAIL A LA CARPETA DE PAPELERA
        /// ELIMINA UN EMAIL COMPLETAMENTE SI SE ENCUENTRA EN LA CARPETA PAPELERA
        /// </summary>
        /// <param name="e"></param>
        /// <param name="carpeta"></param>
        public void EliminarEmail(Email e, Carpeta carpeta)
        {
            try
            {
                ServicioRemoting.ServicioEmails _objServicioE = new ServicioRemoting.ServicioEmails();
                ServicioRemoting.ServicioCarpeta _objServicioC = new ServicioRemoting.ServicioCarpeta();
                //IPersistenciaCarpetas pc = FabricaPersistencia.getPersistenciaCarpetas();
                //Carpeta c = pc.BuscarCarpetaAlumno(ciAlumno, NumeroCarpeta);
                Carpeta c = _objServicioC.BuscarCarpetaAlumno(carpeta);
                if (c != null && c.NOMBRE_CARPETA.ToUpper() != "PAPELERA")
                {
                    //Carpeta papelera = pc.BuscarCarpetaSistemaAlumno(ciAlumno, "Papelera");
                    carpeta.NOMBRE_CARPETA = "Papelera";
                    Carpeta papelera = _objServicioC.BuscarCarpetaSistemaAlumno(carpeta);

                    if (papelera != null)
                    {
                        //pe.MoverEmail(numeroEmail, NumeroCarpeta, papelera.NUMERO_CARPETA);
                        _objServicioE.MoverEmail(e, carpeta, papelera);

                    }
                    else
                    {
                        throw new Exception("No se encontro la carpeta papelera del usuario");
                    }
                }
                else
                {
                    //pe.EliminarEmail(numeroEmail, NumeroCarpeta);
                    _objServicioE.EliminarEmail(e, carpeta);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 //public Email GetEmail(int numeroEmail)
 public Email GetEmail(Email e)
 {
     try
     {
         IPersistenciaEmails pe = FabricaPersistencia.getPersistenciaEmails();
         return pe.GetEmail(e);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public Email GetEmail(Email e)
 {
     ILogicaEmails le = FabricaLogica.getLogicaEmails();
     return le.GetEmail(e);
 }
 public void EliminarEmail(Email e, Carpeta carpeta)
 {
     ILogicaEmails le = FabricaLogica.getLogicaEmails();
     le.EliminarEmail(e, carpeta);
 }
 public void AgregarEmail(Email newEmail, Alumno remitente, Alumno destinatario)
 {
     ILogicaEmails le = FabricaLogica.getLogicaEmails();
     le.AgregarEmail(newEmail, remitente, destinatario);
 }
 public void MoverEmail(Email e, Carpeta carpetaActual, Carpeta carpetaDestino)
 {
     ILogicaEmails le = FabricaLogica.getLogicaEmails();
     le.MoverEmail(e, carpetaActual, carpetaDestino);
 }
        //public void MarcarEmailLeido(int NumeroEmail, int numeroCarpeta)
        public void MarcarEmailLeido(Email e, Carpeta c)
        {
            try
            {
                ServicioRemoting.ServicioEmails _objServicioE = new ServicioRemoting.ServicioEmails();

                _objServicioE.MarcarEmailLeido(e, c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Lista los emails del sistema
        /// </summary>
        /// <param name="numeroCarpeta"></param>a
        public List<Email> ListarEmailsEnviados(Carpeta c)
        {
            List<Email> _listaEmail = new List<Email>();

            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand cmd = Conexion.GetCommand("spListarMailsEnviados", conexion, CommandType.StoredProcedure);

            SqlParameter _numeroCarpeta = new SqlParameter("@NumeroCarpeta", c.NUMERO_CARPETA);

            cmd.Parameters.Add(_numeroCarpeta);

            SqlDataReader _Reader;
            try
            {
                conexion.Open();
                cmd.ExecuteNonQuery();
                _Reader = cmd.ExecuteReader();
                string _asunto, _cuerpo, _nombreDestinatario, _nombreRemitente, _apellidoRem,
                    _apellidoDest, _nombreUsuarioRem, _nombreUsuarioDest, _nombreCarpetaRem, _nombreCarpetaDest;
                bool _leido;
                int _numeroEmail;
                int _numCarpetaRem, _numCarpetaDest;
                //Usuario _usuarioRemitente, _usuarioDestinatario;
                Alumno _usuarioRemitente, _usuarioDestinatario;

                Carpeta _carpetaRemitente, _carpetaDestinatario;
                DateTime _fecha;

                while (_Reader.Read())
                {
                    _asunto = (string)_Reader["Asunto"];
                    _cuerpo = (string)_Reader["Cuerpo"];
                    _leido = (bool)_Reader["Leido"];
                    _numeroEmail = (int)_Reader["NumeroMail"];
                    _nombreRemitente = (string)_Reader["NombreRemitente"];
                    _nombreDestinatario = (string)_Reader["NombreDestinatario"];
                    _apellidoRem = (string)_Reader["ApellidoRemitente"];
                    _apellidoDest = (string)_Reader["ApellidoDestinatario"];
                    _nombreUsuarioRem = (string)_Reader["NombreUsuarioRemitente"];
                    _nombreUsuarioDest = (string)_Reader["NombreUsuarioDestinatario"];
                    _numCarpetaDest = (int)_Reader["NumeroCarpetaDest"];
                    _numCarpetaRem = (int)_Reader["NumeroCarpetaRem"];
                    _nombreCarpetaRem = (string)_Reader["NombreCarpetaRem"];
                    _nombreCarpetaDest = (string)_Reader["NombreCarpetaDest"];
                    _fecha = (DateTime)_Reader["Fecha"];

                    //_usuarioRemitente = new Usuario(0, _nombreUsuarioRem, _nombreRemitente, _apellidoRem, "");
                    _usuarioRemitente = new Alumno
                                            {
                                                NOMBRE_USUARIO = _nombreUsuarioRem,
                                                NOMBRE = _nombreRemitente,
                                                APELLIDO = _apellidoRem
                                            };

                    _carpetaRemitente = new Carpeta(_usuarioRemitente, _numCarpetaRem, _nombreCarpetaRem);
                    //_usuarioDestinatario = new Usuario(0, _nombreUsuarioDest, _nombreDestinatario, _apellidoDest, "");
                    _usuarioDestinatario = new Alumno
                    {
                        NOMBRE_USUARIO = _nombreUsuarioDest,
                        NOMBRE = _nombreDestinatario,
                        APELLIDO = _apellidoDest
                    };

                    _carpetaDestinatario = new Carpeta(_usuarioDestinatario, _numCarpetaDest, _nombreCarpetaDest);

                    Email e = new Email(_numeroEmail, _asunto, _leido, _cuerpo, _carpetaRemitente, _carpetaDestinatario, _fecha);

                    _listaEmail.Add(e);
                }
                _Reader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:ListarEmailsEnviados" + ex.Message);
            }
            finally
            {
                conexion.Close();
            }

            return _listaEmail;
        }
        /// <summary>
        /// Ingresa un nuevo email en el sistema
        /// </summary>
        /// <param name="e"></param>
        public void NuevoEmail(Email e)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand cmd = Conexion.GetCommand("spNuevoEmail", conexion, CommandType.StoredProcedure);

            SqlParameter _ciR = new SqlParameter("@ciR", e.CARPETA_REMITENTE.USUARIO.CI);
            SqlParameter _ciD = new SqlParameter("@ciD", e.CARPETA_DESTINATARIO.USUARIO.CI);
            SqlParameter _numCarpetaRem = new SqlParameter("@NumCarpetaR", e.CARPETA_REMITENTE.NUMERO_CARPETA);
            SqlParameter _numCarpetaDest = new SqlParameter("@NumCarpetaD", e.CARPETA_DESTINATARIO.NUMERO_CARPETA);
            SqlParameter _Asunto = new SqlParameter("@Asunto", e.ASUNTO);
            SqlParameter _Cuerpo = new SqlParameter("@Cuerpo", e.CUERPO);
            SqlParameter _Leido = new SqlParameter("@Leido", e.LEIDO);
            SqlParameter _Fecha = new SqlParameter("@Fecha", e.FECHA);

            cmd.Parameters.Add(_ciR);
            cmd.Parameters.Add(_ciD);
            cmd.Parameters.Add(_numCarpetaRem);
            cmd.Parameters.Add(_numCarpetaDest);
            cmd.Parameters.Add(_Asunto);
            cmd.Parameters.Add(_Cuerpo);
            cmd.Parameters.Add(_Leido);
            cmd.Parameters.Add(_Fecha);

            try
            {
                conexion.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                conexion.Close();
            }
        }
 public void AgregarEmail(Email e)
 {
     IPersistenciaEmails a = FabricaPersistencia.getPersistenciaEmails();
     //a.AgregarArticulo(A);
 }
 //public void MoverEmail(int numeroEmail, int NumeroCarpetaActual, int numeroCarpetaDestino)
 public void MoverEmail(Email e, Carpeta carpetaActual, Carpeta carpetaDestino)
 {
     try
     {
         ServicioRemoting.ServicioEmails _objServicioE = new ServicioRemoting.ServicioEmails();
         _objServicioE.MoverEmail(e, carpetaActual, carpetaDestino);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        //public void MarcarEmailLeido(int NumeroEmail, int numeroCarpeta)
        public void MarcarEmailLeido(Email e, Carpeta c)
        {
            try
            {
                IPersistenciaEmails pe = FabricaPersistencia.getPersistenciaEmails();

                pe.MarcarEmailLeido(e, c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    int emailId;
                    if (Int32.TryParse(Convert.ToString(Session["EmailId"]), out emailId))
                    {
                        txtFrom.Visible = true;
                        lblFrom.Visible = true;

                        //CARGAMOS LA INFORMACION DEL EMAIL PARA SER VISUALIZADA.
                        //-------------------------------------------------------
                        btnAceptar.Visible = false;
                        ILogicaEmails le = FabricaLogica.getLogicaEmails();

                        //Entidades.Email email = le.GetEmail(emailId);

                        Entidades.Email email = new Entidades.Email {NUMERO_EMAIL = emailId};
                        email = le.GetEmail(email);

                        if (email != null)
                        {
                            Header.HEADER_TEXT = "Email enviado " + email.FECHA.ToShortDateString() + " a las " +
                                                 email.FECHA.ToShortTimeString();

                            txtFrom.Text = email.CARPETA_REMITENTE.USUARIO.NOMBRE + " " +
                                           email.CARPETA_REMITENTE.USUARIO.APELLIDO;
                            txtPara.Text = email.CARPETA_DESTINATARIO.USUARIO.NOMBRE + " " +
                                           email.CARPETA_DESTINATARIO.USUARIO.APELLIDO;
                            txtAsunto.Text = email.ASUNTO;
                            txtContenido.Text = email.CUERPO;

                            //bindeamos las posibles carpetas de destino
                            // a mover
                            ILogicaCarpetas lc = FabricaLogica.getLogicaCarpetas();
                            ddlFolders.DataSource = lc.ListarCarpetas((Alumno)Session["Usuario"]);
                            ddlFolders.DataBind();
                            lblMover.Visible = true;
                            ddlFolders.Visible = true;
                        }
                        else
                        {
                            lblInfo.Text = "No se encontro la informacion del email";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblInfo.Text = ex.ToString();
            }
        }
 //public void MoverEmail(int numeroEmail, int NumeroCarpetaActual, int numeroCarpetaDestino)
 public void MoverEmail(Email e, Carpeta carpetaActual, Carpeta carpetaDestino)
 {
     try
     {
         IPersistenciaEmails pe = FabricaPersistencia.getPersistenciaEmails();
         pe.MoverEmail(e, carpetaActual, carpetaDestino);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public void MarcarEmailLeido(Email e, Carpeta c)
 {
     ILogicaEmails le = FabricaLogica.getLogicaEmails();
     le.MarcarEmailLeido(e, c);
 }
        /// <summary>
        /// Ingresa un nuevo email en el sistema
        /// </summary>
        /// <param name="u"></param>
        public void NuevoEmail(Email e)
        {
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand cmd = Conexion.GetCommand("spAltaAlumno", conexion, CommandType.StoredProcedure);

            //SqlParameter _codigo = new SqlParameter("@cod", A.Codigo);
            //SqlParameter _nombre = new SqlParameter("@nom", A.Nombre);
            //SqlParameter _precio = new SqlParameter("@pre", A.Precio);
            SqlParameter _Retorno = new SqlParameter("@Retorno", SqlDbType.Int);
            _Retorno.Direction = ParameterDirection.ReturnValue;

            //int oAfectados = -1;

            //oComando.Parameters.Add(_codigo);
            //oComando.Parameters.Add(_nombre);
            //oComando.Parameters.Add(_precio);
            //oComando.Parameters.Add(_Retorno);

            try
            {
                conexion.Open();
                cmd.ExecuteNonQuery();
                //oAfectados = (int)oComando.Parameters["@Retorno"].Value;
                //if (oAfectados == -1)
                //    throw new Exception("El codigo de articulo ya existe");
            }
            catch
            {
                throw new ErrorBaseDeDatos(); //Acá van las excepciones según @retorno
            }
            finally
            {
                conexion.Close();
            }
        }
 //public Email GetEmail(int numeroEmail)
 public Email GetEmail(Email e)
 {
     try
     {
         ServicioRemoting.ServicioEmails _objServicioE = new ServicioRemoting.ServicioEmails();
         return _objServicioE.GetEmail(e);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// OBTIENE UN EMAIL DE LA BASE DE DATOS
        /// </summary>
        /// <param name="numeroEmail"></param>
        /// <returns></returns>
        public Email GetEmail(Email e)
        {
            Email EmailRetorno = new Email();
            SqlConnection conexion = new SqlConnection(Conexion.Cnn);
            SqlCommand cmd = Conexion.GetCommand("spGetmail", conexion, CommandType.StoredProcedure);
            SqlParameter _numeroEmail = new SqlParameter("@NumeroMail", e.NUMERO_EMAIL);

            cmd.Parameters.Add(_numeroEmail);

            SqlDataReader _Reader;
            try
            {
                conexion.Open();
                _Reader = cmd.ExecuteReader();

                string _asunto, _cuerpo, _nombreDestinatario, _nombreRemitente, _apellidoRem,
                    _apellidoDest, _nombreUsuarioRem, _nombreUsuarioDest, _nombreCarpetaRem, _nombreCarpetaDest;
                bool _leido;
                int _numCarpetaRem, _numCarpetaDest;
                //Usuario _usuarioRemitente, _usuarioDestinatario;
                Alumno _usuarioRemitente, _usuarioDestinatario;

                Carpeta _carpetaRemitente, _carpetaDestinatario;
                DateTime _fecha;

                while (_Reader.Read())
                {
                    _asunto = (string)_Reader["Asunto"];
                    _cuerpo = (string)_Reader["Cuerpo"];
                    _leido = (bool)_Reader["Leido"];
                    _nombreRemitente = (string)_Reader["NombreRemitente"];
                    _nombreDestinatario = (string)_Reader["NombreDestinatario"];
                    _apellidoRem = (string)_Reader["ApellidoRemitente"];
                    _apellidoDest = (string)_Reader["ApellidoDestinatario"];
                    _nombreUsuarioRem = (string)_Reader["NombreUsuarioRemitente"];
                    _nombreUsuarioDest = (string)_Reader["NombreUsuarioDestinatario"];
                    _numCarpetaDest = (int)_Reader["NumeroCarpetaDest"];
                    _numCarpetaRem = (int)_Reader["NumeroCarpetaRem"];
                    _nombreCarpetaRem = (string)_Reader["NombreCarpetaRem"];
                    _nombreCarpetaDest = (string)_Reader["NombreCarpetaDest"];
                    _fecha = (DateTime)_Reader["Fecha"];

                    //_usuarioRemitente = new Usuario(0, _nombreUsuarioRem, _nombreRemitente, _apellidoRem, "");
                    _usuarioRemitente = new Alumno
                    {
                        NOMBRE_USUARIO = _nombreUsuarioRem,
                        NOMBRE = _nombreRemitente,
                        APELLIDO = _apellidoRem
                    };
                    _carpetaRemitente = new Carpeta(_usuarioRemitente, _numCarpetaRem, _nombreCarpetaRem);
                    //_usuarioDestinatario = new Usuario(0, _nombreUsuarioDest, _nombreDestinatario, _apellidoDest, "");
                    _usuarioDestinatario = new Alumno
                    {
                        NOMBRE_USUARIO = _nombreUsuarioDest,
                        NOMBRE = _nombreDestinatario,
                        APELLIDO = _apellidoDest
                    };
                    _carpetaDestinatario = new Carpeta(_usuarioDestinatario, _numCarpetaDest, _nombreCarpetaDest);

                    EmailRetorno = new Email(e.NUMERO_EMAIL, _asunto, _leido, _cuerpo, _carpetaRemitente, _carpetaDestinatario,_fecha);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                conexion.Close();
            }

            return EmailRetorno;
        }
        private static void verificarCantidadStock(int Bodega, int Articulo, int IdEmpresa)
        {
            Documento DocumentoOrden = new Documento();
            DocumentoDetalle DetalleDocumento = new DocumentoDetalle();
                try
                {
                    //lectorSQL = AccesoDatosCV.verificarCantidadArticulo(Bodega, Articulo, IdEmpresa, (int)datosActuales.Get("idmoneda"), (int)datosActuales.Get("socio"));

                        DataAccess da = new DataAccess();
                        DataSet lectorSQL2 = da.ExecuteQuery("SP_VERIFICAR_CANTIDAD_ARTICULO", new List<SqlParameter>()
                        {
                            new SqlParameter("@IdBodega",Bodega),
                            new SqlParameter("@IdArticulo",Articulo),
                            new SqlParameter("@IdEmpresa",IdEmpresa),
                            new SqlParameter("@IdMoneda",(int)datosActuales.Get("idmoneda")),
                            new SqlParameter("@IdSocio",(int)datosActuales.Get("socio"))

                        });

                        if (lectorSQL2.Tables.Count == 6)
                        {
                            DocumentoOrden.TipoDocumento = OrdenCompra;
                            DetalleDocumento.NumeroDocumento = (int)lectorSQL2.Tables[5].Rows[0].ItemArray[0];
                            DocumentoOrden.Fecha1 = (DateTime)lectorSQL2.Tables[5].Rows[0].ItemArray[1];
                            DocumentoOrden.TotalAI = (Decimal)lectorSQL2.Tables[5].Rows[0].ItemArray[5];
                            DetalleDocumento.Descripcion = (String)lectorSQL2.Tables[5].Rows[0].ItemArray[2];
                            DetalleDocumento.Cantidad = (int)lectorSQL2.Tables[5].Rows[0].ItemArray[3];
                            DetalleDocumento.Precio = (Decimal)lectorSQL2.Tables[5].Rows[0].ItemArray[4];
                            Email email = new Email();
                            email.EnviarCorreo((String)lectorSQL2.Tables[5].Rows[0].ItemArray[6], DocumentoOrden, DetalleDocumento);

                        }
                        else
                            banderaError = 1;

                }
                catch (Exception ex) { return; }
        }