public inBloomCustom(String accessToken)
 {
     AccessToken = accessToken;
     _authenticateUser = new AuthenticateUser();
     _slcApi = new inBloomApi(accessToken);
     _sqlHelper = new SqlHelper();
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session[SessionEnum.AccessToken.ToString()] != null)
                {
                    _inBloomApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());
                    _sqlHelper = new SqlHelper();

                    _user = (User)Session["UserDetail"];
                    //Label lbl = (Label)Master.FindControl("lblUser");
                    lblUser.Text = _user.FullName;

                    _user = _inBloomApi.UserDetails();

                    if (_user == null)
                        Response.Redirect("Search.aspx");
                    else
                        if (Session["UserDetail"] == null)
                        {
                            Session.Add("UserDetail", _user);
                        }

                    if (!IsPostBack)
                    {
                        DropDownListSection.Items.Clear();
                        GetFlag();

                        if (Session["FlagId"] == null && Session["FlagType"] == null)
                        {
                        }
                        else
                        {
                            String SelectFlag = Session["FlagId"].ToString() + "_" + Session["FlagType"].ToString();
                            DropDownListSection.SelectedValue = SelectFlag;
                        }
                    }

                    if (Session["Success"] != null)
                    {
                        //lblSuccess.Text = Session["Success"].ToString();
                        hdnFieldMessage.Value = Session["Success"].ToString();
                        Session["Success"] = null;

                    }
                    else
                    {
                        hdnFieldMessage.Value = "";
                    }

                    if (!IsPostBack)
                    {

                        if (_user.IsAdminUser || IsLeader())
                        {
                            GetDistrictList();
                        }
                        else
                        {
                            DropDownListDistrict.Visible = false;
                            LabelDistrict.Visible = false;
                        }

                        //|| IsLeader() need to add
                        if (IsEducator())
                        {
                            dropDownListStaff.Visible = false;
                            LabelStaff.Visible = false;
                        }

                        if (Session["School"] == null)
                        {
                            GetSchoolList();
                        }
                        else
                        {
                            try
                            {
                                DropDownListSchool.Items.Clear();
                                School school = (School)Session["School"];
                                DropDownListSchool.Items.AddRange(school.GetSchoolList());
                                DropDownListSchool.SelectedValue = Session[SessionEnum.SchoolId.ToString()].ToString();
                            }
                            catch (Exception Ex)
                            {
                            }
                        }

                        if (Session["Staff"] == null)
                        {
                            if (!IsEducator())
                                GetStaffList();
                        }
                        else
                            if (!IsEducator())
                            {
                                dropDownListStaff.Items.Clear();
                                Staff staff = (Staff)Session["Staff"];
                                dropDownListStaff.Items.AddRange(staff.GetStaffList());
                                dropDownListStaff.SelectedValue = Session[SessionEnum.StaffID.ToString()].ToString();
                            }

                        if (Session["Course"] == null)
                        {
                            GetCourseListNew();
                            //GetCourseList();
                        }
                        else
                        {
                            try
                            {
                                Course course = (Course)Session["Course"];
                                ListItem[] _courseList = course.GetCourseList();
                                //DropDownListCourse.Items.AddRange(course.GetCourseList());
                                for (int i = 0; i < _courseList.Count(); i++)
                                {
                                    if (_courseList[i] != null)
                                        DropDownListCourse.Items.Add(_courseList[i]);
                                }
                                DropDownListCourse.SelectedValue = Session[SessionEnum.CourseId.ToString()].ToString();
                            }
                            catch (Exception Ex)
                            {
                            }
                        }

                        if (Session["Section"] == null)
                        {
                            GetSectionListNew();
                            //GetSectionList();
                        }
                        else
                        {
                            try
                            {
                                Section section = (Section)Session["Section"];
                                ListItem[] _listSection = section.GetSectionList();
                                if (_listSection != null)
                                {
                                    for (int Index = 0; Index < _listSection.Length; Index++)
                                    {
                                        if (_listSection[Index] != null)
                                        {
                                            DropDownListSection.Items.Add(new ListItem(_listSection[Index].Text, _listSection[Index].Value.ToString()));
                                        }
                                    }

                                }

                                DropDownListSection.SelectedValue = Session[SessionEnum.SectionId.ToString()].ToString();
                            }
                            catch (Exception Ex)
                            {
                            }
                        }

                        try
                        {
                            Session.Add(SessionEnum.SchoolId.ToString(), DropDownListSchool.SelectedValue);
                            Session.Add(SessionEnum.CourseId.ToString(), DropDownListCourse.SelectedValue);
                            Session.Add(SessionEnum.SectionId.ToString(), DropDownListSection.SelectedValue);
                            Session.Add(SessionEnum.StaffID.ToString(), dropDownListStaff.SelectedValue);
                        }
                        catch (Exception Ex)
                        {
                        }

                    }

                }
                else
                {
                    Response.Redirect("Search.aspx");
                }
            }
            catch (Exception ex)
            {
                throw;
                //Response.Redirect("Search.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _sqlHelper = new SqlHelper();

            try
            {
                _inBloomApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());
            }
            catch (Exception Ex)
            {
                Response.Redirect("Search.aspx");
            }

            if (!IsPostBack)
            {
                if (Session["CopyAggregateFlag"] != null)
                {
                    _aggregateFlagId = Convert.ToInt16(Session["CopyAggregateFlag"].ToString());

                    IList<AggregateFlag> _AggregateFlag = _sqlHelper.GetAggregateFlag(_aggregateFlagId);

                    txtFlagName.Text = _AggregateFlag[0].AggregateFlagName;
                    txtDescription.Text = _AggregateFlag[0].AggregateFlagDescription;
                    txtFlag.Text = _AggregateFlag[0].Keyword;

                    _user = (User)Session["UserDetail"];
                    if (_user == null)
                    {
                        Session[SessionEnum.AccessToken.ToString()] = null;
                        Response.Redirect("Search.aspx");
                    }
                    else
                    {
                        if (_user.IsAdminUser)
                        {
                            String IsPublic = _AggregateFlag[0].IsPublic.ToString();
                            if (IsPublic == "True")
                            {
                                radioFlagType.SelectedIndex = 0;
                            }
                            else
                            {
                                radioFlagType.SelectedIndex = 1;
                            }
                        }
                        else
                        {
                            PanelFlagType.Visible = false;
                        }

                        _user = (User)Session["UserDetail"];
                        //gridStudentInfo.DataSource = _sqlHelper.GetFlagList(_user.ExternalId);
                        //gridStudentInfo.DataBind();

                        IList<Flag> _flagForGrid = _sqlHelper.GetFlagList(_user.ExternalId);
                        IList<Flag> _flagListTemp = null;

                        String EducationOrganizationId = Session["EducationOrganizationId"].ToString();
                        String[] AdminUserId = _inBloomApi.GetAdminIdByEducationOrganizationId(EducationOrganizationId);
                        if (AdminUserId != null)
                        {
                            for (int i = 0; i < AdminUserId.Count(); i++)
                            {
                                _flagListTemp = _sqlHelper.GetPublicFlagListForAdmin(AdminUserId[i]);
                                if (_flagForGrid == null)
                                {
                                    _flagForGrid = _flagListTemp;
                                }
                                else
                                {
                                    for (int j = 0; j < _flagListTemp.Count; j++)
                                    {
                                        _flagForGrid.Add(_flagListTemp[j]);
                                    }

                                }
                            }
                        }

                        gridStudentInfo.DataSource = _flagForGrid;
                        gridStudentInfo.DataBind();

                        // add to listbox
                        IList<Flag> _flag = _sqlHelper.GetFlagAddedForInAggregate(_aggregateFlagId);
                        for (int i = 0; i < _flag.Count; i++)
                        {
                            int FlagId = _flag[i].FlagId;
                            String FlagName = _flag[i].FlagName;

                            lstcategory.Items.Add(new ListItem(FlagName, FlagId.ToString()));
                        }

                        foreach (GridViewRow row in gridStudentInfo.Rows)
                        {
                            int FlagId = Convert.ToInt16(row.Cells[4].Text);
                            for (int i = 0; i < _flag.Count; i++)
                            {
                                if (_flag[i].FlagId == FlagId)
                                {
                                    row.Visible = false;
                                    break;
                                }
                            }
                        }
                    }

                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _sqlHelper = new SqlHelper();

            try
            {
                _inBloomApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());
            }
            catch (Exception Ex)
            {
                Response.Redirect("Search.aspx");
            }

            if (!IsPostBack)
            {

                 _user = (User)Session["UserDetail"];

                 if (_user == null)
                 {
                     Session[SessionEnum.AccessToken.ToString()] = null;
                     Response.Redirect("Search.aspx");
                 }
                 else
                 {
                     //gridStudentInfo.DataSource = _sDACEntities.Flags;
                     //gridStudentInfo.DataSource = _sqlHelper.GetFlagList(_user.ExternalId);
                     //gridStudentInfo.DataBind();

                     IList<Flag> _flag = _sqlHelper.GetFlagList(_user.ExternalId);

                     IList<Flag> _flagListTemp = null;

                     String EducationOrganizationId = Session["EducationOrganizationId"].ToString();
                     String[] AdminUserId = _inBloomApi.GetAdminIdByEducationOrganizationId(EducationOrganizationId);
                     if (AdminUserId != null)
                     {
                         for (int i = 0; i < AdminUserId.Count(); i++)
                         {
                             _flagListTemp = _sqlHelper.GetPublicFlagListForAdmin(AdminUserId[i]);
                             if (_flag == null)
                             {
                                 _flag = _flagListTemp;
                             }
                             else
                             {
                                 for (int j = 0; j < _flagListTemp.Count; j++)
                                 {
                                     _flag.Add(_flagListTemp[j]);
                                 }

                             }
                         }
                     }

                     gridStudentInfo.DataSource = _flag;

                     gridStudentInfo.DataBind();

                     if (_user.IsAdminUser)
                     {
                     }
                     else
                     {
                         PanelFlagType.Visible = false;
                     }

                 }

            }

            String script = "function abc() {" +

                         "var count = 0;" +
                         "$('#lstcategory option').each(function (e) {" +
                             "count = count + 1;" +
                         "});" +

                         "$('#gridStudentInfo tr input:checkbox').each(function () {" +

                             "if (this.checked) {" +
                                 "count = count + 1;" +
                             "}" +

                         "});" +

                         "if (count > 5) {" +

                             "DisplayErrorPopup('You can select only 5 flags.');" +
                             "return false;" +
                         "}" +

                         "return true;" +

                     "}";

            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), Guid.NewGuid().ToString(), script, true);
        }