示例#1
0
        protected void _btnExportarExcel_Click(object sender, EventArgs e)
        {
            List <List <string> > contenido = new List <List <string> >();
            List <string>         fila      = new List <string>();

            string[] badChars  = { "&#225;", "&#233;", "&#237;", "&#243;", "&#250;", "&#241;" };
            string[] goodChars = { "á", "é", "í", "ó", "ú", "ñ" };
            foreach (GridViewRow r in _gvwEventos.Rows)
            {
                for (int i = 0; i < r.Cells.Count; i++)
                {
                    string text = r.Cells[i].Text;
                    for (int k = 0; k < badChars.Length; k++)           // Limpiar caracteres
                    {
                        text = text.Replace(badChars[k], goodChars[k]); // Quitar tildes u caracteres especiales del nombre
                    }
                    fila.Add(text);
                }
                contenido.Add(fila);
                fila = new List <string>();
            }

            ReporteExcel report = new ReporteExcel();

            SpreadsheetGear.IWorkbook workbook = report.generarReporte("Bitacora " + _txtFechaConsulta.Text.Replace('/', '-'), new List <string> {
                "Fecha", "Operador", "Evento"
            }, contenido);

            Thread STAThread = new Thread(() =>
            {
                // Stream the Excel spreadsheet to the client in a format
                // compatible with Excel 97/2000/XP/2003/2007/2010.
                Response.Clear();
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + "Bitacora " + _txtFechaConsulta.Text + ".xls");
                workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.Excel8);
                Response.End();
            });

            STAThread.SetApartmentState(ApartmentState.STA);
            STAThread.Start();
            STAThread.Join();
        }
示例#2
0
        /// <summary>
        /// Método que se encarga de cargar una imagen en memoria cargada en el componente Input para carga de archivos
        /// </summary>
        /// <returns>Retorna uan arreglo de bytes con la imagen</returns>

        protected void _btnConsultar_Click(object sender, EventArgs e)
        {
            Usuario user     = null;
            int     contador = 0;

            _controladorSGC             = new ControladorSGC();
            _imgMensajeBusqueda.Visible = false;
            _lblMensajeBusqueda.Visible = false;

            _sesion       = new Sesion();
            _cookieActual = _sesion.verificarValidez(Request.Cookies["PS"]);
            if (_cookieActual == null) // Si la cookie expira redirecciona a la pantalla de Login
            {
                Response.Redirect("../Autentificacion/Login.aspx");
            }
            else // Volver a crear la cookie en el cliente, con el nuevo tiempo de expiración
            {
                Response.SetCookie(_cookieActual);
            }

            // Verificar que se haya selecionado un criterio de búsqueda
            if (_ddlCriterio.SelectedIndex == 0)
            { //
                _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png";
                _lblMensajeBusqueda.Text     = "Debe seleccionar un criterio de búsqueda";
                _imgMensajeBusqueda.Visible  = true;
                _lblMensajeBusqueda.Visible  = true;
                return;
            }
            if (_ddlCriterio.SelectedIndex == 3) //si el criterio seleccionado es por rango de fechas
            {
                // Verificar que los campos de la busqueda estén llenos
                if ((_txtValor2.Text.Equals("")) || (_txtValor3.Text.Equals("")))
                {
                    _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png";
                    _lblMensajeBusqueda.Text     = "Debe ingresar fechas para la busqueda";
                    _imgMensajeBusqueda.Visible  = true;
                    _lblMensajeBusqueda.Visible  = true;
                    return;
                }
                else
                {
                    DateTime fechaInicial = DateTime.ParseExact(_txtValor2.Text, "dd/MM/yyyy", null);
                    DateTime fechaFinal   = DateTime.ParseExact(_txtValor3.Text, "dd/MM/yyyy", null);
                    try
                    {
                        List <List <string> > contenido = _controladorSGC.crearArchivoUsuariosPorFecha(fechaInicial, fechaFinal);

                        string nombreArchivo = "Cuentas entre " + fechaInicial.Date.Day.ToString() + "-" + fechaInicial.Month.ToString() + "-" + fechaInicial.Year.ToString() + " y " + fechaFinal.Day.ToString() + "-" + fechaFinal.Month.ToString() + "-" + fechaFinal.Year.ToString();

                        ReporteExcel report = new ReporteExcel();

                        SpreadsheetGear.IWorkbook workbook = report.generarReporte(nombreArchivo, new List <string> {
                            "Login", "Carrera", "Fecha de Creación"
                        }, contenido);

                        Thread STAThread = new Thread(() =>
                        {
                            // Stream the Excel spreadsheet to the client in a format
                            // compatible with Excel 97/2000/XP/2003/2007/2010.
                            Response.Clear();
                            Response.ContentType = "application/vnd.ms-excel";
                            Response.AddHeader("Content-Disposition", "attachment; filename=" + nombreArchivo + ".xls");
                            workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.Excel8);
                            Response.End();
                        });

                        STAThread.SetApartmentState(ApartmentState.STA);
                        STAThread.Start();
                        STAThread.Join();
                    }
                    catch (Exception ex)
                    {
                        _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png";
                        _lblMensajeBusqueda.Text     = ex.Message;
                        _imgMensajeBusqueda.Visible  = true;
                        _lblMensajeBusqueda.Visible  = true;
                    }
                }
            }
            else
            {
                // Verificar que los campos de la busqueda estén llenos
                if (_txtValor.Text.Equals(""))
                {
                    _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png";
                    _lblMensajeBusqueda.Text     = "Debe ingresar algún valor para la busqueda";
                    _imgMensajeBusqueda.Visible  = true;
                    _lblMensajeBusqueda.Visible  = true;
                    return;
                }
                // El criterio seleccionado es "Login"
                if (_ddlCriterio.SelectedIndex == 1)
                {
                    user = _controladorSGC.buscarUsuario(_txtValor.Text, true); // Login
                }
                if (_ddlCriterio.SelectedIndex == 2)
                {
                    user = _controladorSGC.buscarUsuario(_txtValor.Text, false); //Carnet
                    _lblUsuario.Visible = true;
                    _txtUsuario.Visible = true;
                }


                // Se actualiza el contenido de la interfaz
                if (user != null)
                {
                    _txtCarnet.Text    = user.Carnet;
                    _txtNombre.Text    = user.Nombre;
                    _txtPApellido.Text = user.Apellidos.Split(' ')[0];
                    _txtSApellido.Text = user.Apellidos.Split(' ')[1];
                    _txtTelefono.Text  = user.TelefonoCasa;
                    _txtCelular.Text   = user.TelefonoCelular;
                    _txtCorreo.Text    = user.Correo;
                    _txtUsuario.Text   = user.UID;

                    foreach (ListItem carrera in _ddlCarrera.Items)
                    {
                        if (carrera.Text == user.Carrera)
                        {
                            _ddlCarrera.SelectedIndex = contador;
                        }
                        else
                        {
                            contador++;
                        }
                    }

                    if (user.Grupo == "Estudiante")
                    {
                        _rblUsarios.SelectedIndex = 0;
                    }
                    else
                    {
                        _rblUsarios.SelectedIndex = 1;
                    }


                    _imgMensajeBusqueda.Visible = false;
                    _lblMensajeBusqueda.Visible = false;
                    _bntModificar.Enabled       = true;
                    _lblMensaje.Visible         = false;
                    _imgMensaje.Visible         = false;

                    _upConsultaUsuario.Update();
                }
                else
                {
                    _imgMensajeBusqueda.ImageUrl = "../Imagenes/Error.png";
                    _lblMensajeBusqueda.Text     = "Usuario no encontrado";
                    _imgMensajeBusqueda.Visible  = true;
                    _lblMensajeBusqueda.Visible  = true;

                    _txtCarnet.Text           = "";
                    _txtNombre.Text           = "";
                    _txtPApellido.Text        = "";
                    _txtSApellido.Text        = "";
                    _txtTelefono.Text         = "";
                    _txtCelular.Text          = "";
                    _txtCorreo.Text           = "";
                    _txtPassword.Text         = "";
                    _txtCPassword.Text        = "";
                    _ddlCarrera.SelectedIndex = 0;
                    //if(_rblUsarios.SelectedItem.Selected)
                    //      _rblUsarios.SelectedItem.Selected = false;
                    _bntModificar.Enabled = false;
                }
            }
        }