Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GuestTicketsSize.Attributes.Add("readonly", "readonly");
            if (!IsPostBack)
            {
                if (Global.CurrentPerson == null || string.IsNullOrEmpty(Request.QueryString["Series"]))
                {
                    Response.Redirect("Index.aspx");
                }

                SeriesId            = long.Parse(Request.QueryString["Series"]);
                SeriesIdField.Value = SeriesId.ToString();

                checkIfTicketsAlreadyPurchased(SeriesId);

                DataTable                  eventTable    = new DataTable();
                List <Models.Event>        eventModel    = new List <Models.Event>();
                DataTable                  requestsTable = new DataTable();
                List <Models.GroupRequest> requestsModel = new List <Models.GroupRequest>();

                using (OracleConnection objConn = new OracleConnection(Global.ConnectionString))
                {
                    try
                    {
                        // Set up the getEvent command
                        var eventCommand = new OracleCommand("TICKETS_QUERIES.getEvent", objConn)
                        {
                            BindByName = true, CommandType = CommandType.StoredProcedure
                        };
                        eventCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                        eventCommand.Parameters.Add("p_SeriesId", OracleDbType.Int64, SeriesId, ParameterDirection.Input);

                        // Set up the getGroupRequestsForEvent command
                        var requestsCommand = new OracleCommand("TICKETS_QUERIES.getGroupForEvent", objConn)
                        {
                            BindByName = true, CommandType = CommandType.StoredProcedure
                        };
                        requestsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                        requestsCommand.Parameters.Add("p_SeriesId", OracleDbType.Int64, SeriesId, ParameterDirection.Input);
                        requestsCommand.Parameters.Add("p_PersonId", OracleDbType.Int64, Global.CurrentPerson.person_id, ParameterDirection.Input);

                        // Execute the queries and auto map the results to models
                        objConn.Open();
                        var eventAdapter = new OracleDataAdapter(eventCommand);
                        eventAdapter.Fill(eventTable);
                        eventModel = Mapper.DynamicMap <IDataReader, List <Models.Event> >(eventTable.CreateDataReader());

                        var requestsAdapter = new OracleDataAdapter(requestsCommand);
                        requestsAdapter.Fill(requestsTable);
                        requestsModel = Mapper.DynamicMap <IDataReader, List <Models.GroupRequest> >(requestsTable.CreateDataReader());
                    }
                    catch (Exception)
                    {
                        Response.Redirect("Index.aspx");
                    }

                    objConn.Close();
                }

                // Fill list dropdowns with data from the database
                if (eventModel.Count > 0)
                {
                    var currentEvent = eventModel.FirstOrDefault();
                    BuildingKey            = currentEvent.building_key;
                    Building               = currentEvent.building;
                    BuildingKeyField.Value = BuildingKey.ToString();

                    EventName.Text        = currentEvent.name;
                    EventDescription.Text = currentEvent.description;
                    EventLocation.Text    = currentEvent.building;
                    EventPrice.Text       = "$" + currentEvent.regular_price;
                    EventPrimePrice.Text  = "$" + currentEvent.prime_price;

                    eventModel.ForEach(ed => ed.friendly_date = ed.event_datetime.ToString("dddd, MMMM d - h:mm tt"));
                    EventDateDropDown.DataTextField           = "friendly_date";
                    EventDateDropDown.DataValueField          = "event_id";
                    EventDateDropDown.DataSource = eventModel;
                    EventDateDropDown.DataBind();
                }

                if (requestsModel.Count > 0)
                {
                    AlreadyPurchasedTickets = requestsModel.FirstOrDefault().guest_tickets + 1;
                    GroupSize.Text          = AlreadyPurchasedTickets.ToString();
                    GuestTicketsSize.Text   = "0";
                    if (Request.QueryString["Error"] != null)
                    {
                        Error.Text    = "Those seats are no longer available. Please pick new seats.";
                        Error.Visible = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GuestTicketsSize.Attributes.Add("readonly", "readonly");
            FacultyTicketsSize.Attributes.Add("readonly", "readonly");

            if (!IsPostBack)
            {
                if (Global.CurrentPerson == null || string.IsNullOrEmpty(Request.QueryString["Series"]))
                {
                    Response.Redirect("Index.aspx");
                }

                SeriesId            = long.Parse(Request.QueryString["Series"]);
                SeriesIdField.Value = SeriesId.ToString();

                checkIfTicketsAlreadyPurchased(SeriesId);

                DataTable                  eventTable    = new DataTable();
                List <Models.Event>        eventModel    = new List <Models.Event>();
                DataTable                  requestsTable = new DataTable();
                List <Models.GroupRequest> requestsModel = new List <Models.GroupRequest>();
                DataTable                  seasonsTable  = new DataTable();
                List <Models.Season>       seasonsModel  = new List <Models.Season>();

                using (OracleConnection objConn = new OracleConnection(Global.ConnectionString))
                {
                    // Set up the getEvent command
                    var eventCommand = new OracleCommand("TICKETS_QUERIES.getEvent", objConn)
                    {
                        BindByName = true, CommandType = CommandType.StoredProcedure
                    };
                    eventCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                    eventCommand.Parameters.Add("p_SeriesId", OracleDbType.Int64, SeriesId, ParameterDirection.Input);

                    // Set up the getGroupRequestsForEvent command
                    var requestsCommand = new OracleCommand("TICKETS_QUERIES.getGroupForEvent", objConn)
                    {
                        BindByName = true, CommandType = CommandType.StoredProcedure
                    };
                    requestsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                    requestsCommand.Parameters.Add("p_SeriesId", OracleDbType.Int64, SeriesId, ParameterDirection.Input);
                    requestsCommand.Parameters.Add("p_PersonId", OracleDbType.Int64, Global.CurrentPerson.person_id, ParameterDirection.Input);

                    // Set up the getSeasonTickets command
                    var seasonsCommand = new OracleCommand("TICKETS_QUERIES.getSeasonTickets", objConn)
                    {
                        BindByName = true, CommandType = CommandType.StoredProcedure
                    };
                    seasonsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                    seasonsCommand.Parameters.Add("p_PersonId", OracleDbType.Int64, Global.CurrentPerson.person_id, ParameterDirection.Input);

                    try
                    {
                        // Execute the queries and auto map the results to models
                        objConn.Open();
                        var eventAdapter = new OracleDataAdapter(eventCommand);
                        eventAdapter.Fill(eventTable);
                        eventModel = Mapper.DynamicMap <IDataReader, List <Models.Event> >(eventTable.CreateDataReader());

                        var requestsAdapter = new OracleDataAdapter(requestsCommand);
                        requestsAdapter.Fill(requestsTable);
                        requestsModel = Mapper.DynamicMap <IDataReader, List <Models.GroupRequest> >(requestsTable.CreateDataReader());

                        var seasonsAdapter = new OracleDataAdapter(seasonsCommand);
                        seasonsAdapter.Fill(seasonsTable);
                        seasonsModel = Mapper.DynamicMap <IDataReader, List <Models.Season> >(seasonsTable.CreateDataReader());
                    }
                    catch (Exception)
                    {
                        // This shouldn't happen, redirect them back to the event chosing page
                        Response.Redirect("Index.aspx");
                    }

                    objConn.Close();
                }

                // Fill list dropdowns with data from the database
                if (eventModel.Count > 0)
                {
                    var currentEvent = eventModel.FirstOrDefault();
                    BuildingKey            = currentEvent.building_key;
                    Building               = currentEvent.building;
                    BuildingKeyField.Value = BuildingKey.ToString();

                    EventName.InnerHtml   = currentEvent.name;
                    EventDescription.Text = currentEvent.description;
                    EventLocation.Text    = currentEvent.building;
                    EventPrice.Text       = "$" + currentEvent.regular_price;
                    EventPrimePrice.Text  = "$" + currentEvent.prime_price;

                    eventModel.ForEach(ed => ed.friendly_date = ed.event_datetime.ToString("dddd, MMMM d - h:mm tt"));
                    EventDateDropDown.DataTextField           = "friendly_date";
                    EventDateDropDown.DataValueField          = "event_id";
                    EventDateDropDown.DataSource = eventModel;
                    EventDateDropDown.DataBind();

                    if (seasonsModel.Count > 0)
                    {
                        var season = seasonsModel.Where(s => s.season_id == currentEvent.season_id).FirstOrDefault();
                        if (season != null)
                        {
                            seasonTicketsAmount = season.ticket_count;
                        }
                    }
                }

                if (requestsModel.Count > 0)
                {
                    GuestTickets     = requestsModel.FirstOrDefault().guest_tickets;
                    FacultyTickets   = requestsModel.FirstOrDefault().faculty_tickets;
                    RequestedTickets = requestsModel.Where(ticket => ticket.requested_id != 0).Count();
                    if (RequestedTickets == 0)
                    {
                        requestsModel.Clear();
                    }

                    var error = "";
                    if ((error = Request.QueryString["Error"]) != null)
                    {
                        if (error.Equals("1"))
                        {
                            Error.Text    = "Those seats are no longer available. Please pick new seats.";
                            Error.Visible = true;
                        }
                        else if (error.Equals("2"))
                        {
                            Error.Text    = "Could not buy extra tickets, try again later.";
                            Error.Visible = true;
                        }
                        else if (error.Equals("3"))
                        {
                            Error.Text    = "You may not have more than 10 members in your group (including yourself).";
                            Error.Visible = true;
                        }
                    }
                }

                TotalSize = GuestTickets + FacultyTickets + RequestedTickets + 1;
                if (TotalSize > 10)
                {
                    TotalSize = 10;
                }

                GroupSize.Value      = TotalSize.ToString();
                GroupList.DataSource = requestsModel;
                GroupList.DataBind();
            }
        }