konste22

Code Behind

Oct 18th, 2013
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.12 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Drawing;
  9. using iTextSharp.text;
  10. using iTextSharp.text.pdf;
  11. using iTextSharp.text.html.simpleparser;
  12. using System.Configuration;
  13. using System.Web;
  14.  
  15. public partial class aSelectEventExport : System.Web.UI.Page
  16. {
  17.     int RowCount;
  18.  
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         int rigRedirect;
  22.  
  23.         if (Session["UserID"] == null)
  24.         {
  25.             Session.Abandon();
  26.             Response.Redirect("EventLogin.aspx");
  27.         }
  28.  
  29.         else
  30.         {
  31.             rigRedirect = (int)(Session["Rights"]);
  32.  
  33.             if (Session["UserID"] == null && rigRedirect != 6 && rigRedirect != 1)
  34.             {
  35.                 Session.Abandon();
  36.                 Response.Redirect("EventLogin.aspx");
  37.             }
  38.             else if (rigRedirect != 6 && rigRedirect != 1)
  39.             {
  40.                 Session.Abandon();
  41.                 Response.Redirect("EventLogin.aspx");
  42.             }
  43.             else
  44.             {
  45.                 Label1.Text = "Welcome " + Session["Fname"] + " " + Session["Lname"];
  46.  
  47.             }
  48.         }
  49.     }
  50.  
  51.     public override void VerifyRenderingInServerForm(Control control)
  52.     {
  53.         /*Verifies that the control is rendered */
  54.     }
  55.  
  56.  
  57.     protected void SearchEvent_Click(object sender, EventArgs e)
  58.     {
  59.  
  60.         SqlDataSource1.FilterExpression = "Event_Name LIKE '%" + txtSearchEvent.Text + "%' or Event_Desc LIKE '%" + txtSearchEvent.Text + "%'";
  61.        
  62.         GridView1.DataBind();
  63.         RowCount = GridView1.Rows.Count;
  64.         txtSearchEvent.Text = "";
  65.  
  66.     }
  67.  
  68.     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  69.     {
  70.         int eventid;
  71.         eventid = Convert.ToInt32(GridView1.SelectedDataKey.Value);
  72.  
  73.         String strCon = ConfigurationManager.ConnectionStrings["CME_RFID"].ConnectionString;
  74.         DataTable dtExport = new DataTable();
  75.         String strSQL = "SELECT PersonID, Person_Last, Person_First, Person_Title, Life_Number, Event_Name, EventID, CME_Event_Track_ID FROM CME_RFIDReader.vAttendanceList WHERE EventID = " + eventid;
  76.  
  77.         SqlConnection connect = new SqlConnection(strCon);
  78.         SqlCommand command = new SqlCommand(strSQL, connect);
  79.  
  80.         SqlDataAdapter adExport = new SqlDataAdapter(command);
  81.  
  82.         adExport.Fill(dtExport);
  83.  
  84.      exportSpreadsheet(dtExport, "ExportReport");
  85.  
  86.     }
  87.  
  88.  
  89.     public void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  90.     {
  91.         GridView1.EditIndex = e.NewEditIndex;
  92.         ((TemplateField)GridView1.Columns[2]).EditItemTemplate = null;
  93.         //GridView1.DataBind();
  94.         Session["SelecetedRowIndex"] = e.NewEditIndex;
  95.     }
  96.  
  97.  
  98.     public static void exportSpreadsheet(DataTable dtTable, String strName)
  99.     {
  100.         HttpContext context = HttpContext.Current;
  101.         context.Response.Clear();
  102.  
  103.  
  104.         foreach (DataColumn column in dtTable.Columns)
  105.         {
  106.             context.Response.Write(column.ColumnName + ",");
  107.         }
  108.         context.Response.Write(Environment.NewLine);
  109.         foreach (DataRow drRow in dtTable.Rows)
  110.         {
  111.             for (int i = 0; i < dtTable.Columns.Count; i++)
  112.             {
  113.                 context.Response.Write(drRow[i].ToString().Replace(",", string.Empty) + ",");
  114.             }
  115.             context.Response.Write(Environment.NewLine);
  116.         }
  117.         context.Response.ContentType = "text/csv";
  118.         context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + strName + ".csv");
  119.         context.Response.End();
  120.     }
  121.  
  122.     protected void btnLogOff_Click(object sender, EventArgs e)
  123.     {
  124.         Session.Abandon();
  125.         Session.RemoveAll();
  126.         Response.Redirect("~/EventLogin.aspx");
  127.     }
  128.  
  129.     protected void btnMenu_Click(object sender, EventArgs e)
  130.     {
  131.         Response.Redirect("~/EventSysMenu.aspx");
  132.     }
  133.  
  134.     protected void bShowAll_Click(object sender, EventArgs e)
  135.     {
  136.         SqlDataSource1.FilterExpression = null;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment