protected void DeleteLinkButton_Click(object sender, EventArgs e)
 {
     TeamBL teamBL = new TeamBL();
     Int64 teamid = Convert.ToInt64(Session["EditTeamID"]);
     teamBL.DeactivateTeam(teamid);
     Session["EditTeamID"] = 0;
     this.TeamsGridView.DataBind();
     this.TeamsGridView.SelectedIndex = -1;
     this.MiniTeamFormView.DataBind();
     upListView.Update();
     miniDetails.Update();
     EditLinkButton.Visible = false;
     ModalPopButton2.Visible = false;
     DeleteLinkButton.Visible = false;
        // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "GoToTab(2);", true);
 }
        protected void TeamsDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            TeamBL teamBL = new TeamBL();
            Int64 id = 0;
            string value = Convert.ToString(Session["NewTeam"]);
            if (value != "")
                id = int.Parse(value);

            if (id > 0)
            {
                Label2.Text = "Success !</br> <p>Team information has been saved successfully</p>";
                UpdatePanel2.Update();
                UsersDetailsView.DataBind();
                UpdatePanel3.Update();
            }
            else
            {
                Label2.Text = "Error !</br> <p>Team information did not save.</p>";
                UpdatePanel2.Update();
            }
        }
        protected void TeamSetTextBox_Load(object sender, EventArgs e)
        {
            TeamBL teamBL = new TeamBL();
            string teamsetname = Convert.ToString(Session["EditTeamSetName"]);
            if (teamsetname != null)
            {
                TextBox pe = (TextBox)TeamsDetailsView.FindControl("TeamSetTextBox");
                pe.Text = teamsetname;

            }
        }
        protected void TeamsDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            Int64 userid = Convert.ToInt32(HttpContext.Current.Session["UserID"]);
            int teamsetid = Convert.ToInt32(HttpContext.Current.Session["EditTeamSetID"]);

            e.NewValues["ModifiedBy"] = userid;
            e.NewValues["ModifiedTime"] = DateTime.Now;
            e.NewValues["TeamSetID"] = teamsetid;

               Int64 teamid = Convert.ToInt64(Session["EditTeamID"]);
               TeamBL teamBL = new TeamBL();
               teamBL.SetTeamSetIDinUsers(teamid, teamsetid);
        }
        protected void Submit_Click(object sender, EventArgs e)
        {
            TeamBL teamBL = new TeamBL();
            string teamsetname = "";
            int teamsetid = 0;

            if (TeamSetNameTextBox.Text!="")
            {
                var tset = teamBL.SetTeamSets(TeamSetNameTextBox.Text);
                teamsetname = tset.ElementAt(0).TeamSetName;
                teamsetid = tset.ElementAt(0).TeamSetID;
                Session["EditTeamSetName"] = teamsetname;
                Session["EditTeamSetID"] = teamsetid;

                if (teamsetname != null)
                {
                    TextBox pe = TeamsDetailsView.FindControl("TeamSetTextBox") as TextBox;
                    pe.Text = teamsetname;
                }

                this.TeamSetsGridView.DataBind();

                TeamSetNameTextBox.Text = "";

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "CloseModals(['BodyContent_ModalPanel1','BodyContent_Panel291']);", true);
            }
        }
        protected void SelectTeamSets_Command(object sender, CommandEventArgs e)
        {
            string val = e.CommandArgument.ToString();
            int teamsetid = Convert.ToInt32(val);
            //int test = teamBL.TeamSetTeamSetID(teamsetid);
            TeamBL teamBL = new TeamBL();
            string teamsetname = teamBL.GetTeamSetNameByID(teamsetid);
            Session["EditTeamSetName"] = teamsetname;
            Session["EditTeamSetID"] = teamsetid;
            if (teamsetname != null)
            {
                TextBox pe = TeamsDetailsView.FindControl("TeamSetTextBox") as TextBox;
                pe.Text = teamsetname;

            }

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "CloseModals(['BodyContent_ModalPanel1','BodyContent_Panel291']);", true);
        }
        protected void SelectLinkButton_Command(object sender, CommandEventArgs e)
        {
            string value = e.CommandArgument.ToString();
            string[] all = { "" };
            all = value.Split(':');
            Session["EditTeamID"] = all[0];
            Session["EditTeamSetID"] = all[1];

            long teamid = Convert.ToInt64(Session["EditTeamID"]);
            string name = "";
            TeamBL teamBL = new TeamBL();
            var team = teamBL.GetTeamsByID(teamid);
            name = team.ElementAt(0).Name;

            if (name == "Global")
            {
                EditLinkButton.Visible = false;
                ModalPopButton2.Visible = true;
                DeleteLinkButton.Visible = false;
            }
            else
            {
                EditLinkButton.Visible = true;
                ModalPopButton2.Visible = true;
                DeleteLinkButton.Visible = true;
            }

            int gindex = Convert.ToInt32(TeamsGridView.SelectedIndex);
            if (gindex > -1)
            {

                LinkButton nlbtn = TeamsGridView.Rows[gindex].FindControl("SelectLinkButton") as LinkButton;
                nlbtn.CssClass = "";
            }
            LinkButton lbtn = sender as LinkButton;
            lbtn.CssClass = "active";
            miniDetails.Update();
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            TeamBL teamBL = new TeamBL();
            Int64 teamid = Convert.ToInt64(Session["EditTeamID"]);

            foreach (GridViewRow gvrow in TeamMemberGridView.Rows)
            {

                CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete");
                if (chkdelete.Checked)
                {
                    Int64 userid = Convert.ToInt64(TeamMemberGridView.DataKeys[gvrow.RowIndex].Value);
                    teamBL.UsersSetTeamID(userid, teamid);

                }
            }

            this.TeamsGridView.DataBind();
            this.MiniTeamFormView.DataBind();
            this.SelectedTeamGridView.DataBind();
            this.TeamMemberGridView.DataBind();
            upListView.Update();
            miniDetails.Update();
        }