예제 #1
0
    protected void RadGrid1ItemCommand(object sender, GridCommandEventArgs e)
    {
        ((IFeedback)Page.Master).HideFeedback();

        if (e.CommandName == "view")
        {
            GridDataItem item       = (GridDataItem)e.Item;
            var          lnkbtnView = (LinkButton)e.Item.FindControl("imgBtnView");
            AuditManager.Audit(Page.User.Identity.Name, item["Id"].Text, AuditRecord.AuditAction.Viewed);
            Navigation.Communication_NewsViewItem(lnkbtnView.CommandArgument.ToString(CultureInfo.InvariantCulture)).Redirect(this);
        }
        else if (e.CommandName == "editVersion")
        {
            //edit link to be be the VersionID
            VersionItem versionByItem = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());
            string      groupId       = string.Empty;
            if (versionByItem != null)
            {
                groupId = versionByItem.GroupId;
                string versionId = (VersionManager.GetVersionByGroupId(groupId)).Id;

                string checkedoutUser = VersionManager.GetCheckedOutUser(groupId);
                if ((!string.IsNullOrEmpty(checkedoutUser)) && (checkedoutUser != Page.User.Identity.Name))
                {
                    ((IFeedback)Page.Master).SetError(GetType(), "Unable to edit: News Item is checked out to " + checkedoutUser);
                }
                else
                {
                    //perform checkout by the user here
                    VersionManager.CheckOutVersion(versionId, Page.User.Identity.Name);
                    Navigation.Communication_NewsEditItem(versionId).Redirect(this);
                }
            }
            else //for existing announcements which dont have a version
            {
                //create a version out of the existing announcement

                string itemId        = e.CommandArgument.ToString();
                string VersionNumber = VersionManager.GetVersionNumber(VersionType.New, string.Empty);

                VersionManager.CreateVersionItem(new VersionItem()
                {
                    ItemId        = itemId,
                    GroupId       = itemId,
                    VersionNumber = VersionNumber,
                    DateCreated   = DateTime.Now,
                    Comments      = string.Empty,
                    ModifiedBy    = Utilities.GetUserName(Page.User.Identity.Name)
                });

                //get the version by itemId and then check out.
                string versionId = VersionManager.GetVersionByItemId(itemId).Id;


                VersionManager.CheckOutVersion(versionId, Utilities.GetUserName(Page.User.Identity.Name));

                Navigation.Communication_NewsEditItem(versionId).Redirect(this);
            }
        }
        else if (e.CommandName == "delete")
        {
            Item   itemToDelete         = NewsManager.GetItem(e.CommandArgument.ToString());
            string itemNameBeforeDelete = itemToDelete.Title;
            string groupID = VersionManager.GetVersionByItemId(itemToDelete.Id).GroupId;

            string checkedoutUser = VersionManager.GetCheckedOutUser(groupID);
            if ((!string.IsNullOrEmpty(checkedoutUser)) && (checkedoutUser != Page.User.Identity.Name))
            {
                ((IFeedback)Page.Master).SetError(GetType(), "Unable to delete: News Item is checked out to " + checkedoutUser);
            }
            else
            {
                string itemIdBeforeDelete = itemToDelete.Category.Id;
                NewsManager.DeleteItemByGroup(groupID);

                //Controls_TreeView tree = (Controls_TreeView)this.Parent.FindControl("tree1");
                //tree.PopulateTreeView<Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), false, false, string.Empty);
                //tree.RebindNode(itemIdBeforeDelete, false);

                ((IFeedback)Page.Master).ShowFeedback(BusiBlocksConstants.Blocks.Administration.ShortName, itemToDelete.GetType().Name, Feedback.Actions.Deleted, itemNameBeforeDelete);
            }
        }
        else if (e.CommandName == RadGrid.FilterCommandName)
        {
            Pair filterPair           = (Pair)e.CommandArgument;
            List <NewsGridItem> items = new List <NewsGridItem>();

            switch (filterPair.Second.ToString())
            {
            case "Category":
                TextBox tbPattern = (e.Item as GridFilteringItem)["Category"].Controls[0] as TextBox;
                FilterExpression = tbPattern.Text;
                BindWithFilter(items);
                RadGridManage.DataBind();
                if (!string.IsNullOrEmpty(FilterExpression))
                {
                    var foundNews  = NewsManager.GetCategoryByLikeName(FilterExpression.Split(',').First(), true);
                    int foundCount = foundNews.Count;
                    if (foundCount > 0)
                    {
                        //Controls_TreeView tree = (Controls_TreeView)this.Parent.FindControl("tree1");
                        //tree.PopulateTreeView<Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), false, false, string.Empty);
                        //string selectedNode = (foundNews.FirstOrDefault()).Id;
                        //tree.RebindNode(selectedNode, true);
                    }
                }
                break;

            default:
                break;
            }
        }
        else if (e.CommandName == "approveItem")
        {
            VersionItem versionByItem = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());
            string      groupId       = string.Empty;
            if (versionByItem != null)
            {
                groupId = versionByItem.GroupId;

                string checkedoutUser = VersionManager.GetCheckedOutUser(groupId);
                if ((!string.IsNullOrEmpty(checkedoutUser)) && (checkedoutUser != Page.User.Identity.Name))
                {
                    ((IFeedback)Page.Master).SetError(GetType(), "Unable to approve: News Item is checked out to " + checkedoutUser);
                }
                else
                {
                    string versionId = (VersionManager.GetVersionByGroupId(groupId)).Id;
                    Navigation.Communication_NewsViewItemApproval(versionId).Redirect(this);
                }
            }
            else
            {
                Navigation.Communication_NewsViewItemApproval(e.CommandArgument.ToString()).Redirect(this);
            }
        }
        else if (e.CommandName == "checkinItem")
        {
            VersionManager.CheckInVersion(e.CommandArgument.ToString());
            Navigation.Communication_News().Redirect(this);
        }
        else if (e.CommandName == "viewStatus")
        {
            // Navigate to the user view status page and pass the item id
            VersionItem versionByItem = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());
            if (versionByItem != null)
            {
                Navigation.Communication_UserViewStatus(versionByItem.ItemId, versionByItem.Id).Redirect(this);
            }
        }
        //else if (e.CommandName == "UsersViewed")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Viewed, totalUsers, publishedIds);

        //    foreach (User user in usersViewed)
        //        personsViewed.Add(user.Person.Id);

        //    Session["personList"] = personsViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
        //else if (e.CommandName == "UsersNotViewed")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsNotViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Viewed, totalUsers, publishedIds);

        //    foreach (User user in totalUsers)
        //        if (!usersViewed.Contains(user))
        //            personsNotViewed.Add(user.Person.Id);

        //    Session["personList"] = personsNotViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
        //else if (e.CommandName == "UsersAcked")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Acknowledged, totalUsers, publishedIds);

        //    foreach (User user in usersViewed)
        //        personsViewed.Add(user.Person.Id);

        //    Session["personList"] = personsViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
        //else if (e.CommandName == "UsersNotAcked")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsNotViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Acknowledged, totalUsers, publishedIds);

        //    foreach (User user in totalUsers)
        //        if (!usersViewed.Contains(user))
        //            personsNotViewed.Add(user.Person.Id);

        //    Session["personList"] = personsNotViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
    }
예제 #2
0
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType != GridItemType.Footer && e.Item.ItemType != GridItemType.Header)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item            = (GridDataItem)e.Item;
                LinkButton   latestVersionId = (LinkButton)item.FindControl("lnkEditItem");
                LinkButton   lnkBtnDelete    = (LinkButton)item.FindControl("lnkDeleteClient");
                LinkButton   lnkBtnCheckIn   = (LinkButton)item.FindControl("lnkBtnCheckIn");

                Label       lblCheckedOut = (Label)item.FindControl("lblCheckedOut");
                VersionItem versionByItem = VersionManager.GetVersionByItemId(latestVersionId.CommandArgument.ToString());

                lnkBtnCheckIn.Visible = false;
                //if the Version/item is not checked out - check using the groupId of those versions and return user who has checkedout.
                if (versionByItem != null)
                {
                    Item   NewsItem           = NewsManager.GetItem(versionByItem.ItemId);
                    string checkedOutUsername = VersionManager.GetCheckedOutUser(versionByItem.GroupId);                                                        //username for comparison puposes
                    string checkedOutName     = (!string.IsNullOrEmpty(checkedOutUsername)) ? Utilities.GetDisplayUserName(checkedOutUsername) : string.Empty;; //full name for display purpose.

                    HyperLink lnkVersion = (HyperLink)item["Version"].Controls[0];                                                                              //accessing link
                    lnkVersion.Text = versionByItem.VersionNumber;                                                                                              //add version number here

                    //display check out to string to other users if item is checked out by the user.
                    string username = Page.User.Identity.Name;

                    if (!string.IsNullOrEmpty(checkedOutUsername) && (username.ToLower() != checkedOutUsername.ToLower() && username != "admin"))
                    {
                        latestVersionId.Visible = false;
                        lnkBtnDelete.Visible    = false;
                        lblCheckedOut.Text      = CheckOutString + checkedOutName + ")";
                        lnkVersion.NavigateUrl  = null;
                    }
                    else
                    {
                        latestVersionId.Visible = true;
                        lnkBtnDelete.Visible    = true;
                        lnkVersion.NavigateUrl  = Navigation.Communication_NewsVersionHistory(versionByItem.GroupId).GetServerUrl(true); //link to version history page
                        //if user is same as owner and item is not checked out.
                        if (!string.IsNullOrEmpty(checkedOutUsername))
                        {
                            lnkBtnCheckIn.Visible = true;
                            if (checkedOutUsername.ToLower() != "admin" && username == "admin")
                            {
                                latestVersionId.Visible = false;
                                lnkBtnDelete.Visible    = false;
                                lblCheckedOut.Text      = CheckOutString + checkedOutName + ")";
                            }
                        }
                    }

                    // todo fix this defect

                    if (SecurityHelper.CanUserEdit(Page.User.Identity.Name, item["CategoryId"].Text) == true)
                    {
                        if (string.IsNullOrEmpty(checkedOutUsername))
                        {
                            AddApproverButton(versionByItem.Id, versionByItem.ItemId, item);
                        }
                    }
                    else if (SecurityHelper.CanUserContribute(Page.User.Identity.Name, item["CategoryId"].Text) == true)
                    {
                        if (Page.User.Identity.Name.ToLower().Equals(item["Owner"].Text.ToLower()))
                        {
                            if (string.IsNullOrEmpty(checkedOutUsername))
                            {
                                AddApproverButton(versionByItem.Id, versionByItem.ItemId, item);
                            }
                        }
                        else
                        {
                            latestVersionId.Visible = false;
                            lnkBtnDelete.Visible    = false;
                        }
                    }
                    else
                    {
                        latestVersionId.Visible = false;
                        lnkBtnDelete.Visible    = false;
                    }
                }
                //disabling the view link and columns text to empty if the item hasn't been published once.
                if (item["PubStatus"].Text != "Published")
                {
                    CheckPublished(item);
                }
            }
        }
    }