protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable eventTypeNamesTable = new DataTable(); DataTable buildingsTable = new DataTable(); DataTable seasonsTable = new DataTable(); List <EventType> eventTypes = new List <EventType>(); List <Building> buildings = new List <Building>(); List <Season> seasons = new List <Season>(); using (OracleConnection objConn = new OracleConnection(Global.ConnectionString)) { // Set up the eventTypes command var eventTypesCommand = new OracleCommand("TICKETS_QUERIES.getEventTypeNames", objConn) { BindByName = true, CommandType = CommandType.StoredProcedure }; eventTypesCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue); // Set up the buildings command var buildingsCommand = new OracleCommand("TICKETS_QUERIES.getBuildingNames", objConn) { BindByName = true, CommandType = CommandType.StoredProcedure }; buildingsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue); // Set up the seasons command var seasonsCommand = new OracleCommand("TICKETS_QUERIES.getSeasonNames", objConn) { BindByName = true, CommandType = CommandType.StoredProcedure }; seasonsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue); try { // Execute the queries and auto map the results to models objConn.Open(); var eventTypesAdapter = new OracleDataAdapter(eventTypesCommand); var buildingAdapter = new OracleDataAdapter(buildingsCommand); var seasonsAdapter = new OracleDataAdapter(seasonsCommand); eventTypesAdapter.Fill(eventTypeNamesTable); buildingAdapter.Fill(buildingsTable); seasonsAdapter.Fill(seasonsTable); eventTypes = Mapper.DynamicMap <IDataReader, List <EventType> >(eventTypeNamesTable.CreateDataReader()); buildings = Mapper.DynamicMap <IDataReader, List <Building> >(buildingsTable.CreateDataReader()); seasons = Mapper.DynamicMap <IDataReader, List <Season> >(seasonsTable.CreateDataReader()); } catch (Exception ex) { Response.Redirect("Index.aspx"); } objConn.Close(); } // Fill list dropdowns with data from the database if (eventTypes.Count > 0) { EventType.DataTextField = "name"; EventType.DataValueField = "event_type_id"; EventType.DataSource = eventTypes; EventType.DataBind(); } if (buildings.Count > 0) { LocationDropDown.DataTextField = "description"; LocationDropDown.DataValueField = "building_key"; LocationDropDown.DataSource = buildings; LocationDropDown.DataBind(); } if (seasons.Count > 0) { SeasonDropDown.DataTextField = "name"; SeasonDropDown.DataValueField = "season_id"; SeasonDropDown.DataSource = seasons; SeasonDropDown.DataBind(); } SeasonDropDown.Items.Insert(0, new ListItem("No Season", "-1")); SeasonDropDown.Items.Insert(1, new ListItem("Add New Season", "-1")); SeasonDropDown.ClearSelection(); SeasonDropDown.SelectedIndex = 0; } }
protected void Page_Load(object sender, EventArgs e) { if (string.IsNullOrEmpty(Request.QueryString["Series"])) { Response.Redirect("Index.aspx"); } // Get the seriesId and picture name from the button long seriesId; seriesId = long.Parse(Request.QueryString["Series"]); DataTable eventTable = new DataTable(); DataTable eventTypeNamesTable = new DataTable(); DataTable buildingsTable = new DataTable(); DataTable seasonsTable = new DataTable(); List <Models.Event> events = new List <Models.Event>(); List <EventType> eventTypes = new List <EventType>(); List <Building> buildings = new List <Building>(); List <Season> seasons = new List <Season>(); using (OracleConnection objConn = new OracleConnection(Global.ConnectionString)) { var eventCommand = new OracleCommand("TICKETS_QUERIES.getEvent", objConn); var eventTypesCommand = new OracleCommand("TICKETS_QUERIES.getEventTypeNames", objConn); var buildingsCommand = new OracleCommand("TICKETS_QUERIES.getBuildingNames", objConn); try { eventCommand.BindByName = true; eventCommand.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 eventTypes command eventTypesCommand.BindByName = true; eventTypesCommand.CommandType = CommandType.StoredProcedure; eventTypesCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue); // Set up the buildings command buildingsCommand.BindByName = true; buildingsCommand.CommandType = CommandType.StoredProcedure; buildingsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue); // Set up the seasons command var seasonsCommand = new OracleCommand("TICKETS_QUERIES.getSeasonNames", objConn) { BindByName = true, CommandType = CommandType.StoredProcedure }; seasonsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue); // Execute the queries and auto map the results to models objConn.Open(); var eventAdapter = new OracleDataAdapter(eventCommand); var eventTypesAdapter = new OracleDataAdapter(eventTypesCommand); var buildingAdapter = new OracleDataAdapter(buildingsCommand); var seasonsAdapter = new OracleDataAdapter(seasonsCommand); eventAdapter.Fill(eventTable); eventTypesAdapter.Fill(eventTypeNamesTable); buildingAdapter.Fill(buildingsTable); seasonsAdapter.Fill(seasonsTable); events = Mapper.DynamicMap <IDataReader, List <Models.Event> >(eventTable.CreateDataReader()); eventTypes = Mapper.DynamicMap <IDataReader, List <EventType> >(eventTypeNamesTable.CreateDataReader()); buildings = Mapper.DynamicMap <IDataReader, List <Building> >(buildingsTable.CreateDataReader()); seasons = Mapper.DynamicMap <IDataReader, List <Season> >(seasonsTable.CreateDataReader()); } catch (Exception ex) { Response.Redirect("Index.aspx"); } objConn.Close(); } // Fill list dropdowns with data from the database if (eventTypes.Count > 0) { EventType.DataTextField = "name"; EventType.DataValueField = "event_type_id"; EventType.DataSource = eventTypes; EventType.DataBind(); } if (buildings.Count > 0) { LocationDropDown.DataTextField = "description"; LocationDropDown.DataValueField = "building_key"; LocationDropDown.DataSource = buildings; LocationDropDown.DataBind(); } if (seasons.Count > 0) { SeasonDropDown.DataTextField = "name"; SeasonDropDown.DataValueField = "season_id"; SeasonDropDown.DataSource = seasons; SeasonDropDown.DataBind(); } SeasonDropDown.Items.Insert(0, new ListItem("No Season", "-1")); SeasonDropDown.Items.Insert(1, new ListItem("Add New Season", "-1")); SeasonDropDown.ClearSelection(); SeasonDropDown.SelectedIndex = 0; var currentEvent = events.FirstOrDefault(); image = currentEvent.event_picture; EventType.SelectedValue = currentEvent.event_type.ToString(); EventNameInput.Text = currentEvent.name; DescriptionInput.Text = currentEvent.description; EventDate.Text = currentEvent.event_datetime.ToString("dd-MMM-yy hh:mm tt"); // format: 'DD-MMM-YY hh:mm A' LocationDropDown.SelectedValue = currentEvent.building_key.ToString(); RegularPrice.Text = currentEvent.regular_price.ToString(); PrimePrice.Text = currentEvent.prime_price.ToString(); lowestId = (int)currentEvent.event_id; foreach (var a in events) { if (lowestId > (int)a.event_id) { lowestId = (int)a.event_id; } } }