Esempio n. 1
0
        //DataBind TimeSlotDropDown with TimeSlots and FieldTrips
        private void BindTimeSlots()
        {
            //Look for Field Trips to fill Time Slot DropDown
            SqlConnection con = new SqlConnection
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()
            };

            SqlDataAdapter adapter = new SqlDataAdapter();

            con.Open();

            SqlDataAdapter getFieldTrips = new SqlDataAdapter("Select Location From FieldTrips where CONVERT(DATE, StartTime) = @CurrentDate",
                                                              ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

            getFieldTrips.SelectCommand.Parameters.AddWithValue("@CurrentDate", Calendar.SelectedDate.Date);
            DataTable dt = new DataTable();

            getFieldTrips.Fill(dt);

            //Add regular time slots if no fieldtrips
            if (dt.Rows.Count == 0)
            {
                SqlDataAdapter getTimeSlots = new SqlDataAdapter("Select Location From TimeSlots order by StartTime",
                                                                 ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
                getTimeSlots.Fill(dt);
            }

            TimeSlotDropDown.DataSource    = dt;
            TimeSlotDropDown.DataTextField = "Location";
            TimeSlotDropDown.DataBind();
        }
        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection
                                     ("Server=DESKTOP-41H50KG\\SQLEXPRESS; Database=clubone; Uid=20201113; password=123456");

            conn.Open();
            SqlCommand cmd1 = new
                              SqlCommand("select BookingFacility.bfID, Facility.fName, BookingFacility.days, BookingFacility.timeSlot from BookingFacility, Facility where userID=@UID and BookingFacility.facilityID = Facility.fID and BookingFacility.bfID = @BFID", conn);

            cmd1.Parameters.AddWithValue("@UID", Session["user_id"]);
            cmd1.Parameters.AddWithValue("@BFID", ListBox1.SelectedValue);
            SqlDataAdapter adapter1      = new SqlDataAdapter(cmd1);
            DataTable      dt_facilities = new DataTable();

            adapter1.Fill(dt_facilities);

            SqlCommand selectTimeSlot = new
                                        SqlCommand("select * from TimeSlots", conn);
            SqlDataAdapter adapter2    = new SqlDataAdapter(selectTimeSlot);
            DataTable      dt_timeslot = new DataTable();

            adapter2.Fill(dt_timeslot);

            TimeSlotDropDown.DataSource = dt_timeslot;
            TimeSlotDropDown.DataBind();
            TimeSlotDropDown.DataTextField  = "timeSlot";
            TimeSlotDropDown.DataValueField = "timeSlot";
            TimeSlotDropDown.DataBind();

            Username.Text = (String)Session["username"];
            Facility.Text = Convert.ToString(dt_facilities.Rows[0]["fName"]);
            DaysDropDown.SelectedValue     = (String)dt_facilities.Rows[0]["days"];
            TimeSlotDropDown.SelectedValue = (String)dt_facilities.Rows[0]["timeSlot"];
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user_id"] == null)
            {
                Response.Redirect("Login.aspx");
            }

            SqlConnection conn = new SqlConnection
                                     ("Server=DESKTOP-41H50KG\\SQLEXPRESS; Database=clubone; Uid=20201113; password=123456");

            conn.Open();

            Username.Text = (String)Session["username"];
            SqlCommand selectFacilities = new
                                          SqlCommand("select * from Facility where availability = 1", conn);
            SqlDataAdapter adapter1      = new SqlDataAdapter(selectFacilities);
            DataTable      dt_facilities = new DataTable();

            adapter1.Fill(dt_facilities);

            //FacilitiesDropDown.DataSource = dt_facilities;
            //FacilitiesDropDown.DataBind();
            //FacilitiesDropDown.DataTextField = "fName";
            //FacilitiesDropDown.DataValueField = "fID";
            //FacilitiesDropDown.DataBind();
            facilityName.Text = Request.QueryString["fName"];

            SqlCommand selectTimeSlot = new
                                        SqlCommand("select * from TimeSlots", conn);
            SqlDataAdapter adapter2    = new SqlDataAdapter(selectTimeSlot);
            DataTable      dt_timeslot = new DataTable();

            adapter2.Fill(dt_timeslot);

            TimeSlotDropDown.DataSource = dt_timeslot;
            TimeSlotDropDown.DataBind();
            TimeSlotDropDown.DataTextField  = "timeSlot";
            TimeSlotDropDown.DataValueField = "timeSlot";
            TimeSlotDropDown.DataBind();
        }
        protected void initialize()
        {
            SqlConnection conn = new SqlConnection
                                     ("Server=DESKTOP-41H50KG\\SQLEXPRESS; Database=clubone; Uid=20201113; password=123456");

            conn.Open();

            SqlCommand selectTimeSlot = new
                                        SqlCommand("select * from TimeSlots", conn);
            SqlDataAdapter adapter1    = new SqlDataAdapter(selectTimeSlot);
            DataTable      dt_timeslot = new DataTable();

            adapter1.Fill(dt_timeslot);

            SqlCommand cmd2 = new
                              SqlCommand("select BookingFacility.bfID, Facility.fName, BookingFacility.days, BookingFacility.timeSlot from BookingFacility, Facility where userID=@UID and BookingFacility.facilityID = Facility.fID and BookingFacility.status = @S", conn);

            cmd2.Parameters.AddWithValue("@UID", Session["user_id"]);
            cmd2.Parameters.AddWithValue("@S", "Pending");
            SqlDataAdapter adapter2      = new SqlDataAdapter(cmd2);
            DataTable      dt_facilities = new DataTable();

            adapter2.Fill(dt_facilities);

            ListBox1.DataSource = dt_facilities;
            ListBox1.DataBind();
            ListBox1.DataTextField  = "fName";
            ListBox1.DataValueField = "bfID";
            ListBox1.DataBind();

            TimeSlotDropDown.DataSource = dt_timeslot;
            TimeSlotDropDown.DataBind();
            TimeSlotDropDown.DataTextField  = "timeSlot";
            TimeSlotDropDown.DataValueField = "timeSlot";
            TimeSlotDropDown.DataBind();
        }