コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["loginData"] == null)
            {
                Response.Redirect("Default.aspx");
            }


            //store data from sessions and string querries
            user = (User)Session["loginData"];              //user's details
            id   = Int32.Parse(Request.QueryString["id"]);  //reservation ID
            type = Request.QueryString["type"].ToString();  //type of session needed for writting to the database


            reservation = DBconnection.getReservation(id, type);


            if (type.Equals("Workshop"))
            {
                session = DBconnection.getWorkshop(reservation.SessionID);
            }
            else if (type.Equals("Class"))
            {
                session = DBconnection.getClass(reservation.SessionID);
            }


            Label2.Text = session.Title;
            Label3.Text = session.StartDate.ToShortDateString() + " " + session.Time.ToString();


            currentDate    = DateTime.Now;                                    //current date and time
            sessionDate    = session.StartDate.Date.Add(session.Time);        //store session's date and time in one DateTime object
            dateDifference = sessionDate.Subtract(currentDate);
            TimeSpan hours24     = new TimeSpan(24, 0, 0);                    //create a timespan of 24h
            int      compareTime = TimeSpan.Compare(dateDifference, hours24); //compare both dates



            if (compareTime == -1)
            {
                Label1.Text         = "You can cancel a session up to 24h before it is scheduled. We apologise for any inconvience";
                btn_confirm.Visible = false;
            }
            else
            {
                Label1.Text = "Are you sure you want to cancel the folloing session?";
            }
        }