コード例 #1
0
        public DataView GetFlagForGrid()
        {
            try
            {
                _slcApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());

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

                Temp[] _temp = null;
                Temp[] _tempForStaff = null;
                JArray _homeLinks = (JArray) Session["HomeLinks"];
                String UserCustomLink = _slcApi.GetCustomLink(_homeLinks);

                String EducationOrganizationId = Session["EducationOrganizationId"].ToString();

                if (_user.IsAdminUser)
                {
                    // get all the flags from organization by admin user specific
                    _temp = _slcApi.GetFlagListByEducationOrganization(_user, EducationOrganizationId);
                    ListItem[] _schoolList = null;

                    _schoolList = GetSchoolList();

                    _tempForStaff = _slcApi.GetFlagListOfStaffForAdminUser(_user, EducationOrganizationId, _schoolList);

                    if (_tempForStaff.Any())
                    {
                        if (_temp != null)
                        {
                            Temp[] _tempNew = _temp;
                            _temp = new Temp[_tempNew.Count() + _tempForStaff.Count()];

                            for (int i = 0; i < _tempNew.Count(); i++)
                            {
                                _temp[i] = new Temp();
                                _temp[i] = _tempNew[i];
                            }
                            int j = 0;
                            for (int i = _tempNew.Count(); i < _tempNew.Count() + _tempForStaff.Count(); i++)
                            {
                                _temp[i] = new Temp();
                                _temp[i] = _tempForStaff[j];
                                j++;
                            }
                        }
                        else
                            _temp = _tempForStaff;
                    }
                }
                else
                {
                    // get all the flags from custom and organization for normal users i.e public flag
                    _temp = _slcApi.GetFlagListByEducationOrganization(null, EducationOrganizationId);
                }

                Temp[] _newTemp = null;
                Temp _ownTemp = null;

                if (_temp != null)
                {
                    _newTemp = new Temp[_temp.Count() + 1];
                    for (int i = 0; i < _temp.Count(); i++)
                    {
                        _newTemp[i] = new Temp();
                        _newTemp[i] = _temp[i];
                    }

                    _ownTemp = _slcApi.GetCustomForStaff(UserCustomLink);
                    _newTemp[_temp.Count()] = new Temp();
                    _newTemp[_temp.Count()] = _ownTemp;
                }
                else
                {
                    // to get the flags from user custom, private for admin users
                    _ownTemp = _slcApi.GetCustomForStaff(UserCustomLink);
                    _newTemp = new Temp[1];
                    _newTemp[0] = new Temp();
                    _newTemp[0] = _ownTemp;
                }

                DataTable dt = new DataTable("blablaTable");
                dt.Columns.Add("FlagId", typeof (int));
                dt.Columns.Add("FlagName", typeof (string));
                dt.Columns.Add("FlagDescription", typeof (string));
                dt.Columns.Add("Keyword", typeof (string));
                dt.Columns.Add("IsPublic", typeof (bool));
                dt.Columns.Add("IsFavorite", typeof (bool));
                dt.Columns.Add("CreatedDate", typeof (DateTime));
                dt.Columns.Add("Type", typeof (string));

                dt.Columns.Add("IsAdmin", typeof (string));
                dt.Columns.Add("UserId", typeof (string));

                for (int i = 0; i < _newTemp.Count(); i++)
                {
                    if (_newTemp[i] != null)
                    {
                        FlagCls[] _flagCls = _newTemp[i].FlagList;
                        AggregateCls[] _aggregateFlagCls = _newTemp[i].AggregateFlagList;

                        if (_flagCls != null)
                        {
                            for (int j = 0; j < _flagCls.Count(); j++)
                            {
                                if (_flagCls[j].IsDeleted == false)
                                    dt.Rows.Add(new Object[] {_flagCls[j].FlagId, _flagCls[j].FlagName, _flagCls[j].FlagDescription, _flagCls[j].FlagKeyword, _flagCls[j].IsPublic, _flagCls[j].IsFavorite, _flagCls[j].CreatedDate, "Flag", _newTemp[i].IsAdmin, _newTemp[i].UserId});
                            }
                        }

                        if (_aggregateFlagCls != null)
                        {
                            for (int j = 0; j < _aggregateFlagCls.Count(); j++)
                            {
                                if (_aggregateFlagCls[j].IsDeleted == false)
                                    dt.Rows.Add(new Object[] {_aggregateFlagCls[j].AggregateFlagId, _aggregateFlagCls[j].AggregateFlagName, _aggregateFlagCls[j].AggregateFlagDescription, _aggregateFlagCls[j].Keyword, _aggregateFlagCls[j].IsPublic, _aggregateFlagCls[j].IsFavorite, _aggregateFlagCls[j].CreatedDate, "AggregateFlag", _newTemp[i].IsAdmin, _newTemp[i].UserId});
                            }
                        }

                    }
                }

                return dt.DefaultView;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
コード例 #2
0
        protected void gridViewFlag_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            #region Grid Operation Edit, Delete, Update, Favorite

            _slcApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());

            if (e.CommandName == "CmdDelete")
            {
                try
                {
                    int RowIndex = Int32.Parse(e.CommandArgument.ToString());
                    int FlagID = Convert.ToInt16(gridViewFlag.DataKeys[RowIndex].Value.ToString());

                    _user = (User) Session["UserDetail"];
                    IList<Flag> _flag = (IList<Flag>) _sqlHelper.GetFlag(FlagID);

                    if (_user.ExternalId == _flag[0].UserId)
                    {

                        _sqlHelper.DeleteFlag(FlagID);

                        JArray _links = (JArray) Session["HomeLinks"];

                        String UserCustomLink = _slcApi.GetCustomLink(_links);
                        String EducationOrganizationId = Session["EducationOrganizationId"].ToString();

                        String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                        String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                        bool IsAdminUser = (AdminUser == "True");

                        String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                        bool IsPublic = (IsPublicFag == "True");

                        FlagCls[] _flagCls = new FlagCls[1];
                        _flagCls[0] = new FlagCls();
                        _flagCls[0].FlagId = _flag[0].FlagId;
                        _flagCls[0].FlagName = _flag[0].FlagName;
                        _flagCls[0].FlagDescription = _flag[0].FlagDescription;
                        _flagCls[0].FlagKeyword = _flag[0].Keyword;
                        _flagCls[0].IsPublic = _flag[0].IsPublic;
                        _flagCls[0].IsFavorite = _flag[0].IsFavorite;
                        _flagCls[0].IsDeleted = true;
                        _flagCls[0].ConditionId = _flag[0].ConditionId;
                        _flagCls[0].DataElementId = _flag[0].DataElementId;
                        _flagCls[0].ValueSet1 = _flag[0].ValueSet1;
                        _flagCls[0].ValueSet2 = _flag[0].ValueSet2;
                        _flagCls[0].UserId = _flag[0].UserId;
                        _flagCls[0].CreatedBy = _flag[0].CreatedBy;
                        _flagCls[0].CreatedDate = _flag[0].CreatedDate;
                        _flagCls[0].ModifiedBy = _user.ExternalId;
                        _flagCls[0].ModifiedDate = DateTime.Now;

                        _slcApi.UpateFlag(FlagID, UserCustomLink, EducationOrganizationId, IsAdminUser, IsPublic, UserId, _flagCls, _user);

                        LoadFlagGrid();
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else if (e.CommandName == "CmdFavorite")
            {
                try
                {
                    _user = (User) Session["UserDetail"];

                    int RowIndex = Int32.Parse(e.CommandArgument.ToString());
                    int FlagID = Convert.ToInt16(gridViewFlag.DataKeys[RowIndex].Value.ToString());

                    _sqlHelper.FavoriteFlag(FlagID, _user.ExternalId);
                    _user = (User) Session["UserDetail"];

                    JArray _links = (JArray) Session["HomeLinks"];

                    String UserCustomLink = _slcApi.GetCustomLink(_links);
                    String EducationOrganizationId = Session["EducationOrganizationId"].ToString();

                    String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                    String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                    bool IsAdminUser = AdminUser == "True";

                    String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                    bool IsPublic = IsPublicFag == "True";

                    IList<Flag> _flag = _sqlHelper.GetFlag(FlagID);

                    FlagCls[] _flagCls = new FlagCls[1];
                    _flagCls[0] = new FlagCls();
                    _flagCls[0].FlagId = _flag[0].FlagId;
                    _flagCls[0].FlagName = _flag[0].FlagName;
                    _flagCls[0].FlagDescription = _flag[0].FlagDescription;
                    _flagCls[0].FlagKeyword = _flag[0].Keyword;
                    _flagCls[0].IsPublic = _flag[0].IsPublic;
                    _flagCls[0].IsFavorite = _flag[0].IsFavorite;
                    //_flagCls[0].IsDeleted =(bool) _flag[0].IsDeleted;
                    _flagCls[0].ConditionId = _flag[0].ConditionId;
                    _flagCls[0].DataElementId = _flag[0].DataElementId;
                    _flagCls[0].ValueSet1 = _flag[0].ValueSet1;
                    _flagCls[0].ValueSet2 = _flag[0].ValueSet2;
                    _flagCls[0].UserId = _flag[0].UserId;
                    _flagCls[0].CreatedBy = _flag[0].CreatedBy;
                    _flagCls[0].CreatedDate = _flag[0].CreatedDate;
                    _flagCls[0].ModifiedBy = _user.ExternalId;
                    _flagCls[0].ModifiedDate = DateTime.Now;

                    _slcApi.UpateFlag(FlagID, UserCustomLink, EducationOrganizationId, IsAdminUser, IsPublic, UserId, _flagCls, _user);

                    UpdateMasterFlagList();

                    LoadFlagGrid();

                }
                catch (Exception ex)
                {
                }
            }
            else if (e.CommandName == "CmdCopyFlag")
            {
                try
                {
                    int FlagID = Int32.Parse(e.CommandArgument.ToString());
                    Session.Add("CopyFlag", FlagID);
                    Response.Redirect("CopyFlag.aspx");
                }
                catch (Exception ex)
                {
                }
            }
            else if (e.CommandName == "CmdEditFlag")
            {
                try
                {
                    int RowIndex = Int32.Parse(e.CommandArgument.ToString());
                    int FlagId = Convert.ToInt16(gridViewFlag.DataKeys[RowIndex].Value.ToString());
                    String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                    String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                    bool IsAdminUser = (AdminUser == "True");

                    String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                    bool IsPublic = (IsPublicFag == "True");

                    String FlagType = gridViewFlag.Rows[RowIndex].Cells[7].Text;

                    Session.Add("CustomUserId", UserId);
                    Session.Add("CustomIsPublic", IsPublic);
                    Session.Add("CustomFlagType", FlagType);
                    Session.Add("CustomIsAdminUser", IsAdminUser);
                    Session.Add("EditFlag", FlagId);
                    Response.Redirect("EditFlag.aspx");
                }
                catch (Exception Ex)
                {
                }
            }
            else if (e.CommandName == "CmdCopyAggregateFlag")
            {
                try
                {
                    int AggregateFlagID = Int32.Parse(e.CommandArgument.ToString());
                    Session.Add("CopyAggregateFlag", AggregateFlagID);
                    Response.Redirect("CopyAggregateFlag.aspx");
                }
                catch (Exception ex)
                {
                }
            }
            else if (e.CommandName == "CmdEditAggregateFlag")
            {
                try
                {
                    int RowIndex = Int32.Parse(e.CommandArgument.ToString());
                    int AggregateFlagID = Convert.ToInt16(gridViewFlag.DataKeys[RowIndex].Value.ToString());
                    String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                    String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                    bool IsAdminUser = (AdminUser == "True");

                    String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                    bool IsPublic = (IsPublicFag == "True");

                    String FlagType = gridViewFlag.Rows[RowIndex].Cells[7].Text;

                    Session.Add("CustomUserId", UserId);
                    Session.Add("CustomIsPublic", IsPublic);
                    Session.Add("CustomFlagType", FlagType);
                    Session.Add("CustomIsAdminUser", IsAdminUser);
                    Session.Add("EditAggregateFlag", AggregateFlagID);

                    Response.Redirect("EditAggregateFlag.aspx");
                }
                catch (Exception Ex)
                {
                }
            }
            else if (e.CommandName == "CmdFavoriteAggregateFlag")
            {
                try
                {
                    int RowIndex = Int32.Parse(e.CommandArgument.ToString());
                    int AggregateFlagID = Convert.ToInt16(gridViewFlag.DataKeys[RowIndex].Value.ToString());

                    _user = (User) Session["UserDetail"];
                    _sqlHelper.AggregatetFavoriteFlag(AggregateFlagID, _user.ExternalId);

                    JArray _links = (JArray) Session["HomeLinks"];

                    String UserCustomLink = _slcApi.GetCustomLink(_links);
                    String EducationOrganizationId = Session["EducationOrganizationId"].ToString();

                    String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                    String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                    bool IsAdminUser = (AdminUser == "True");

                    String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                    bool IsPublic = (IsPublicFag == "True");

                    AggregateCls[] _aggregateCls = new AggregateCls[1];

                    IList<AggregateFlag> _aggregateFlag = _sqlHelper.GetAggregateFlag(AggregateFlagID);

                    _aggregateCls[0] = new AggregateCls();
                    _aggregateCls[0].AggregateFlagId = _aggregateFlag[0].AggregateFlagId;
                    _aggregateCls[0].AggregateFlagDescription = _aggregateFlag[0].AggregateFlagDescription;
                    _aggregateCls[0].AggregateFlagName = _aggregateFlag[0].AggregateFlagName;
                    _aggregateCls[0].Keyword = _aggregateFlag[0].Keyword;

                    _aggregateCls[0].IsPublic = _aggregateFlag[0].IsPublic;
                    _aggregateCls[0].IsFavorite = _aggregateFlag[0].IsFavorite;
                    _aggregateCls[0].UserId = _aggregateFlag[0].UserId;
                    _aggregateCls[0].CreatedBy = _aggregateFlag[0].CreatedBy;
                    _aggregateCls[0].ModifiedBy = _user.ExternalId;
                    _aggregateCls[0].CreatedDate = _aggregateFlag[0].CreatedDate;
                    _aggregateCls[0].ModifiedDate = DateTime.Now;

                    int[] flagId = _sqlHelper.GetAllFlagIdOfAggregateFlagByAggregateFlagId(AggregateFlagID);
                    FlagForAggregate[] _flagForAggregateList = new FlagForAggregate[flagId.Count()];
                    for (int j = 0; j < flagId.Count(); j++)
                    {
                        _flagForAggregateList[j] = new FlagForAggregate();

                        _flagForAggregateList[j].AggregateFlagId = _aggregateFlag[0].AggregateFlagId;
                        _flagForAggregateList[j].FlagId = flagId[j];
                        _flagForAggregateList[j].CreatedBy = _aggregateFlag[0].CreatedBy;
                        _flagForAggregateList[j].CreatedDate = _aggregateFlag[0].CreatedDate;
                        _flagForAggregateList[j].ModifiedBy = _aggregateFlag[0].ModifiedBy;
                        _flagForAggregateList[j].ModifiedDate = _aggregateFlag[0].ModifiedDate;

                    }

                    _aggregateCls[0].FlagForAggregate = _flagForAggregateList;

                    _slcApi.UpateAggregateFlag(AggregateFlagID, UserCustomLink, EducationOrganizationId, IsAdminUser, IsPublic, UserId, _aggregateCls, _user);

                    UpdateMasterFlagList();

                    LoadFlagGrid();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else if (e.CommandName == "CmdDeleteAggregateFlag")
            {
                try
                {
                    int RowIndex = Int32.Parse(e.CommandArgument.ToString());
                    int AggregateFlagID = Convert.ToInt16(gridViewFlag.DataKeys[RowIndex].Value.ToString());

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

                    AggregateCls[] _aggregateCls = new AggregateCls[1];

                    IList<AggregateFlag> _aggregateFlag = _sqlHelper.GetAggregateFlag(AggregateFlagID);

                    if (_user.ExternalId == _aggregateFlag[0].UserId)
                    {
                        if (_sqlHelper.DeleteAggregateFlag(AggregateFlagID))
                        {
                            // deleted successfully

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

                            JArray _links = (JArray) Session["HomeLinks"];

                            String UserCustomLink = _slcApi.GetCustomLink(_links);
                            String EducationOrganizationId = Session["EducationOrganizationId"].ToString();

                            String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                            String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                            bool IsAdminUser = (AdminUser == "True");

                            String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                            bool IsPublic = (IsPublicFag == "True");

                            _aggregateCls[0] = new AggregateCls();
                            _aggregateCls[0].AggregateFlagId = _aggregateFlag[0].AggregateFlagId;
                            _aggregateCls[0].AggregateFlagDescription = _aggregateFlag[0].AggregateFlagDescription;
                            _aggregateCls[0].AggregateFlagName = _aggregateFlag[0].AggregateFlagName;
                            _aggregateCls[0].Keyword = _aggregateFlag[0].Keyword;
                            _aggregateCls[0].IsDeleted = true;
                            _aggregateCls[0].IsPublic = _aggregateFlag[0].IsPublic;
                            _aggregateCls[0].IsFavorite = _aggregateFlag[0].IsFavorite;
                            _aggregateCls[0].UserId = _aggregateFlag[0].UserId;
                            _aggregateCls[0].CreatedBy = _aggregateFlag[0].CreatedBy;
                            _aggregateCls[0].ModifiedBy = _user.ExternalId;
                            _aggregateCls[0].CreatedDate = _aggregateFlag[0].CreatedDate;
                            _aggregateCls[0].ModifiedDate = DateTime.Now;

                            int[] flagId = _sqlHelper.GetAllFlagIdOfAggregateFlagByAggregateFlagId(AggregateFlagID);
                            FlagForAggregate[] _flagForAggregateList = new FlagForAggregate[flagId.Count()];

                            for (int j = 0; j < flagId.Count(); j++)
                            {
                                _flagForAggregateList[j] = new FlagForAggregate();

                                _flagForAggregateList[j].AggregateFlagId = _aggregateFlag[0].AggregateFlagId;
                                _flagForAggregateList[j].FlagId = flagId[j];
                                _flagForAggregateList[j].CreatedBy = _aggregateFlag[0].CreatedBy;
                                _flagForAggregateList[j].CreatedDate = _aggregateFlag[0].CreatedDate;
                                _flagForAggregateList[j].ModifiedBy = _aggregateFlag[0].ModifiedBy;
                                _flagForAggregateList[j].ModifiedDate = _aggregateFlag[0].ModifiedDate;
                            }

                            _aggregateCls[0].FlagForAggregate = _flagForAggregateList;

                            _slcApi.UpateAggregateFlag(AggregateFlagID, UserCustomLink, EducationOrganizationId, IsAdminUser, IsPublic, UserId, _aggregateCls, _user);

                            LoadFlagGrid();
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else if (e.CommandName == "CmdRunFlag")
            {
                //Session.Add("ResultPage", true);
                int RowIndex = Convert.ToInt16(e.CommandArgument);
                int FlagId = Convert.ToInt16(gridViewFlag.Rows[RowIndex].Cells[8].Text);
                String FlagType = gridViewFlag.Rows[RowIndex].Cells[7].Text;
                Session.Add("FlagId", FlagId);
                Session.Add("FlagType", FlagType);

                String UserId = gridViewFlag.Rows[RowIndex].Cells[10].Text;
                String AdminUser = gridViewFlag.Rows[RowIndex].Cells[9].Text;

                bool IsAdminUser = (AdminUser == "True");

                String IsPublicFag = gridViewFlag.Rows[RowIndex].Cells[4].Text;
                bool IsPublic = (IsPublicFag == "True");

                FlagType = gridViewFlag.Rows[RowIndex].Cells[7].Text;

                Session.Add("CustomUserId", UserId);
                Session.Add("CustomIsPublic", IsPublic);
                Session.Add("CustomFlagType", FlagType);
                Session.Add("CustomIsAdminUser", IsAdminUser);
                Session.Add("EditFlag", FlagId);

                Response.Redirect("Result.aspx");
            }

            #endregion
        }