Exemplo n.º 1
0
        //change session's status
        protected void btn_status_Click(object sender, EventArgs e)
        {
            //check if a session has been selected before proceeding
            if (Session["selectedRow"] == null)
            {
                HttpContext.Current.Response.Write("<script>alert('Please select a session to be modyfied first!')</script>");  //error message
            }
            else
            {
                //get the current status of a selected session from the database
                string currentStatus = DBconnection.getStatus(Session["selectedRow"].ToString(), DropDownList1.SelectedValue);
                string updatedStatus = "something went wrong";

                //set status to the opposite [Active = Cancelled/Cancelled = Active]
                if (currentStatus.Equals("Active"))
                {
                    updatedStatus = "Cancelled";
                }
                else if (currentStatus.Equals("Cancelled"))
                {
                    updatedStatus = "Active";
                }
                else
                {
                    return;
                }
                //update status in the database
                DBconnection.changeStatus(DropDownList1.SelectedValue, updatedStatus, Session["selectedRow"].ToString());

                //clear gridview selection and reset data
                GridView1.SelectedIndex = -1;
                Session["selectedRow"]  = null;
                refreshTable();
                HttpContext.Current.Response.Write("<script>alert('Session has been set to " + updatedStatus + ".')</script>"); //conrimation message
            }
        }