protected void Page_Load(object sender, EventArgs e)
    {
        sysManager = new SystemExerciseManager();
        routManager = new routineManager();
        logManager = new LoggedExerciseManager();

        lb = (ListBox)this.Parent.FindControl("lbRoutines");

        if (Session["loggedExerciseID"] != null)
        {
            loggedExerciseID = (int)Session["loggedExerciseID"];
        }

        if (!IsPostBack)
        {
            Session.Abandon();
            pnlSets.Visible = false;
        }

        if (lb != null && lb.SelectedIndex > -1)
        {
            routineID = Convert.ToInt32(lb.SelectedItem.Value);
            GridView1.DataSource = routManager.getLoggedExercises(userID, routineID);
            GridView1.DataBind();
            pnlSets.Visible = false;
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     manager = new routineManager();
     authenticated = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
     currentUser = authenticated ? HttpContext.Current.User.Identity.Name : "";
     cnr = LoginView1.FindControl("CreateNewRoutine") as ui_uc_CreateNewRoutine;
     if (authenticated && cnr != null)
     {
         cnr.userID = manager.getUserID(currentUser);
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlGenericControl li = (HtmlGenericControl)this.Page.Master.FindControl("Ulnav").FindControl("liuserRoutines");
        li.Attributes.Add("class", "active");

        manager = new routineManager();
        authenticated = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
        currentUser = authenticated ? HttpContext.Current.User.Identity.Name : "";
        if (authenticated)
        {
            cnr = LoginView1.FindControl("CreateNewRoutine") as ui_uc_CreateNewRoutine;
            dmr = LoginView1.FindControl("DeleteModifyRoutine") as ui_uc_DeleteModifyRoutine;
            crl = LoginView1.FindControl("ucCreateRoutineLog") as ui_uc_ucCreateRoutineLog;
            mdrl = LoginView1.FindControl("ucModifyDeleteRoutineLog") as ui_uc_ucModifyDeleteRoutineLog;
            mvRoutines = LoginView1.FindControl("mvRoutine") as MultiView;
            pnlButtons = LoginView1.FindControl("pnlButtons") as Panel;
            btnBack = LoginView1.FindControl("btnBack") as Button;
            lbRoutines = LoginView1.FindControl("lbRoutines") as ListBox;
            pnlRoutineList = LoginView1.FindControl("pnlRoutineList") as Panel;

        }
        if (!IsPostBack)
        {
            pnlRoutineList.Visible = false;
            if (authenticated)
            {
                pnlButtons.Visible = true;
                btnBack.Visible = false;
            }
        }

        if (authenticated && cnr != null)
        {
            cnr.userID = manager.getUserID(currentUser);
        }
        if (authenticated && dmr != null)
        {
            dmr.userID = manager.getUserID(currentUser);
        }
        if (authenticated && crl != null)
        {
            crl.userID = manager.getUserID(currentUser);
        }
        if (authenticated && mdrl != null)
        {
            mdrl.userID = manager.getUserID(currentUser);
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     manager = new routineManager();
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        sysManager = new SystemExerciseManager();
        routManager = new routineManager();

        if (Session["exercises"] == null)
        {
            exercises = new List<Exercise>();
            Session["exercises"] = exercises;
        }

        if (!IsPostBack)
        {
            lblUniqueName.Visible = false;
            pnlDescription.Visible = false;
            // full refresh of page will abandon current session
            Session.Abandon();
            lb = (ListBox)this.Parent.FindControl("lbRoutines");
            if (userID != null)
            {
                lb.DataSource = routManager.getUsersRoutines(userID).ToList();
                lb.DataTextField = "name";
                lb.DataValueField = "id";
                lb.DataBind();
            }

            // to get the id of the button so that enter = submit
            tbRoutineName.Attributes.Add("onKeyPress",
                 "doClick('" + btnConfirm.ClientID + "',event)");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        sysManager = new SystemExerciseManager();
        routManager = new routineManager();
        rbl = (RadioButtonList)this.Parent.FindControl("rblRoutines");
        if (!IsPostBack)
        {

        }
        if (rbl != null && rbl.SelectedIndex > -1)
        {
            GridView1.DataSource = routManager.getExerciseFromRoutine(Convert.ToInt32(rbl.SelectedItem.Value));
            GridView1.DataBind();
            Panel1.Visible = true;
            Panel1.Enabled = true;
            //Response.Write(rbl.SelectedIndex + " item: " + rbl.SelectedItem);

            // to get the id of the button so that enter = submit
            tbRoutineName.Attributes.Add("onKeyPress",
                 "doClick('" + btnConfirm.ClientID + "',event)");
        }
    }
    //protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        Control control = e.Row.Cells[2].Controls[0];
    //        LiteralControl wc = (LiteralControl)control;
    //        Control control2 = e.Row.Cells[0].Controls[0];
    //        WebControl wc2 = (WebControl)control2;
    //        LinkButton lb = (LinkButton)wc2;
    //        wc.Text = lb.Text;
    //    }
    //}
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ';' });
        lblResultModify.Text = "";
        lblMuscleGroupsModify.Text = "";
        lblExercisesInRoutine.Text = "";
           if(commandArgs.Count() > 1)
           modifyExercise = Convert.ToBoolean(commandArgs[1]);

        modifyItemID = Convert.ToInt32(commandArgs[0]);

        if (e.CommandName == "del")
        {

            hideModifyForm();
            if (scheduleManager.deletecheduledItem(Convert.ToInt32(commandArgs[0]), Convert.ToBoolean(commandArgs[1]), userID))
            {
                lblResultModify.Text = "Modified your item!";
                pnlModifyItem.Visible = false;
                populateRemoveItems();
            }

            else
                lblResultModify.Text = "Somthing went worng!";

        }

        if (e.CommandName == "modify" || e.CommandName == "info")
        {
            if (e.CommandName == "modify")
            {
                pnlModifyStartTime.Visible = true;
                scheduledItem selectedItem = scheduleManager.getScheduledItemByID(modifyItemID, modifyExercise);
                DateTime itemStartTime = selectedItem.startTime;
                tbDateModify.Text = itemStartTime.Date.ToString("MM/dd/yyyy");
                for (int i = 0; i < ddlModifyItems.Items.Count; i++)
                {
                    if (ddlModifyItems.Items[i].Text == selectedItem.itemName)
                    {
                        ddlModifyItems.SelectedIndex = i;
                        break;
                    }
                }
                //Select the dropdownlist for Hour based on the selected item
                for (int i = 0; i < ddlHoursModify.Items.Count; i++)
                {
                    if (Convert.ToInt32(ddlHoursModify.Items[i].Text) == Convert.ToInt32(itemStartTime.ToString("hh")))
                    {
                        ddlHoursModify.SelectedIndex = i;
                        break;
                    }
                }
                //Select the dropdownlist for the minute based on the selected item
                for (int i = 0; i < ddlMinutesModify.Items.Count; i++)
                {
                    if (Convert.ToInt32(ddlMinutesModify.Items[i].Text) == Convert.ToInt32(itemStartTime.ToString("mm")))
                    {
                        ddlMinutesModify.SelectedIndex = i;
                        break;
                    }
                }
                //select the dropdownlist for the AM or PM for the selected item
                if (itemStartTime.ToString("tt") == "AM")
                {
                    ddlAmPmModify.SelectedIndex = 0;
                }
                else
                {
                    ddlAmPmModify.SelectedIndex = 1;
                }
                if (Convert.ToBoolean(commandArgs[1]))
                {
                    listBoxExercisesForRoutineModify.Visible = false;
                    lblExercisesforroutine.Visible = false;
                    pnlExercisesInRoutine.Visible = false;
                    pnlEquipmentMuscle.Visible = true;
                    Exercise exercise = exerciseManager.getExerciseByScheduledItem(Convert.ToInt32(modifyItemID));
                    ddlModifyItems.DataSource = exerciseManager.getExercises();
                    ddlModifyItems.DataBind();
                    lblEquipmentModify.Text = exercise.equipment;
                    lblNameModify.Text = exercise.name;
                    if (exercise != null)
                        if (exercise.description != null)
                            lblDescriptionModify.Text = exercise.description;
                        else
                        {
                            lblDescriptionModify.Text = "None";
                        }

                    lblMuscleGroupsModify.Text = "";
                    String[] muscles = exerciseManager.splitMuscleGroups(exercise.muscleGroups);
                    foreach (var item in muscles)
                    {
                        if (item != "")
                            lblMuscleGroupsModify.Text += "- " + item + "<br/>";
                    }
                    //lblDescriptionModify.Text = itemStartTime.Date.ToString("MM/dd/yyyy");

                }

            //User selected a scheduled Routine
                else
                {
                    Routine routine = routineManager.getRoutineByScheduledItem(Convert.ToInt32(commandArgs[0]));
                    ddlModifyItems.DataSource = routineManager.getUsersRoutines(userID);
                    ddlModifyItems.DataBind();
                    lblEquipmentModify.Visible = false;
                    pnlEquipmentMuscle.Visible = false;
                    lblDescriptionModify.Text = "";
                    ICollection<Exercise> exercisesInRoutine = routineManager.getExerciseFromRoutine(routine.id);
                    foreach (var item in exercisesInRoutine)
                    {
                        lblExercisesInRoutine.Text += "-" + item.name + "<br />";
                    }
                    lblDescriptionModify.Text = "None";
                    pnlEquipmentMuscle.Visible = false;
                    ddlModifyItems_indexChanged(sender, e);
                    pnlExercisesInRoutine.Visible = true;
                    listBoxExercisesForRoutineModify.Visible = true;
                    lblExercisesforroutine.Visible = true;
                }
            }

            pnlModifyItem.Visible = true;
            btnModify.Visible = true;
            ddlModifyItems.Visible = true;
            lblEquipmentModify.Visible = true;

            //User selected a scheduled Exercise

            if (e.CommandName == "info")
            {
                pnlModifyStartTime.Visible = false;
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = GridViewScheduledItems.Rows[index];
                Control control = row.Cells[0].Controls[0];
                WebControl wc = (WebControl)control;
                LinkButton lb = (LinkButton)wc;

                if (lb.Text.Contains("[E] "))
                {
                    listBoxExercisesForRoutineModify.Visible = false;
                    lblExercisesforroutine.Visible = false;
                    pnlExercisesInRoutine.Visible = false;
                    pnlEquipmentMuscle.Visible = true;
                    lnkVideoModify.Visible = true;
                    Exercise selectedExercise = sysExerciseManager.getExercise(lb.Text.Substring(4, lb.Text.Length - 4));

                    lblDescriptionModify.Text = selectedExercise.description;
                    lblNameModify.Text = selectedExercise.name;
                    lnkVideoModify.PostBackUrl = selectedExercise.videoLink;
                    String[] muscles = exerciseManager.splitMuscleGroups(selectedExercise.muscleGroups);
                    foreach (var item in muscles)
                    {
                        if (item != "")
                            lblMuscleGroupsModify.Text += "- " + item + "<br/>";
                    }
                    lblEquipmentModify.Text = selectedExercise.equipment;
                }

                else if (lb.Text.Contains("[R] "))
                {
                    pnlExercisesInRoutine.Visible = true;
                    routineManager routineManager = new routineManager();
                    routineManager.setUserID(userID);
                    Routine selectedRoutine = routineManager.getRoutineByName(lb.Text.Substring(4, lb.Text.Length - 4));
                    ICollection<Exercise> exercisesInRoutine = routineManager.getExerciseFromRoutine(selectedRoutine.id);
                    foreach (var item in exercisesInRoutine)
                    {
                        lblExercisesInRoutine.Text += "-" + item.name + "<br />";
                    }
                    lblDescriptionModify.Text = "None";
                    lblNameModify.Text = selectedRoutine.name;
                    lnkVideoModify.Visible = false;
                    pnlEquipmentMuscle.Visible = false;
                }

                /*if (Convert.ToBoolean(commandArgs[1]))
                {
                    Exercise exercise = exerciseManager.getExerciseByScheduledItem(Convert.ToInt32(modifyItemID));
                    ddlModifyItems.DataSource = exerciseManager.getExercises();
                    ddlModifyItems.DataBind();
                    lblEquipmentModify.Text = exercise.equipment;
                    if (exercise != null)
                        if (exercise.description != null)
                            lblDescriptionModify.Text = exercise.description;
                        else
                        {
                            lblDescriptionModify.Text = "None";
                        }

                    String[] muscles = exerciseManager.splitMuscleGroups(exercise.muscleGroups);
                    foreach (var item in muscles)
                    {
                        if (item != "")
                            lblMuscleGroupsModify.Text += "- " + item + "<br/>";
                    }
                    //lblDescriptionModify.Text = itemStartTime.Date.ToString("MM/dd/yyyy");

                }

                //User selected a scheduled Routine
                else
                {
                    Routine routine = routineManager.getRoutine(Convert.ToInt32(commandArgs[0]));
                    ddlModifyItems.DataSource = routineManager.getUsersRoutines(userID);
                    ddlModifyItems.DataBind();
                    lblEquipmentModify.Visible = false;
                    pnlEquipmentMuscle.Visible = false;
                    lblDescriptionModify.Text = "";
                }

                */
            }

        }
    }