Пример #1
0
        public IQueryable <AccountTreeViewItem> GetInactive(bool displayPublicName)
        {
            var financialAccountService = new FinancialAccountService(new Data.RockContext());

            IQueryable <FinancialAccount> qry;

            qry = Get().Where(f =>
                              f.ParentAccountId.HasValue == false);

            qry = qry
                  .Where(f => f.IsActive == false);

            var accountList = qry
                              .OrderBy(f => f.Order)
                              .ThenBy(f => f.Name)
                              .ToList();

            var accountTreeViewItems = accountList.Select(a => new AccountTreeViewItem
            {
                Id       = a.Id.ToString(),
                Name     = HttpUtility.HtmlEncode(displayPublicName ? a.PublicName : a.Name),
                GlCode   = a.GlCode,
                IsActive = a.IsActive,
                Path     = financialAccountService.GetDelimitedAccountHierarchy(a, FinancialAccountService.AccountHierarchyDirection.CurrentAccountToParent)
            }).ToList();

            var resultIds = accountList.Select(f => f.Id).ToList();

            var childrenList = Get()
                               .Where(f =>
                                      f.ParentAccountId.HasValue &&
                                      resultIds.Contains(f.ParentAccountId.Value))
                               .Select(f => f.ParentAccountId.Value)
                               .ToList();

            foreach (var accountTreeViewItem in accountTreeViewItems)
            {
                int accountId     = int.Parse(accountTreeViewItem.Id);
                int childrenCount = (childrenList?.Count(v => v == accountId)).GetValueOrDefault(0);

                accountTreeViewItem.HasChildren = childrenCount > 0;
                var lastChildId = (childrenList?.LastOrDefault()).GetValueOrDefault(0);

                if (accountTreeViewItem.HasChildren)
                {
                    accountTreeViewItem.CountInfo = childrenCount;
                    accountTreeViewItem.ParentId  = accountId.ToString();
                }

                accountTreeViewItem.IconCssClass = "fa fa-file-o";
            }

            return(accountTreeViewItems.AsQueryable());
        }
Пример #2
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            string searchTerm = PageParameter("SearchTerm");

            var accountService = new FinancialAccountService(new RockContext());
            var accounts       = new List <FinancialAccount>();

            var glCodeStart = searchTerm.LastIndexOf('(');

            if (glCodeStart > -1)
            {
                searchTerm = searchTerm.Substring(glCodeStart).Replace("(", "").Replace(")", "");
            }

            searchTerm = searchTerm.Trim();

            accounts = accountService.GetAccountsBySearchTerm(searchTerm)?.ToList();

            if (accounts?.Count == 1)
            {
                var pageService = new PageService(new RockContext());

                var queryParams = new Dictionary <string, string>();

                var accountId = accounts.First().Id;
                var parentIds = accountService.GetAllAncestorIds(accountId).Reverse()?.ToList();
                if (parentIds == null)
                {
                    parentIds = new List <int>();
                }
                queryParams.Add("AccountId", accountId.ToString());
                queryParams.Add("ExpandedIds", parentIds.Select(v => v.ToString()).JoinStrings(","));
                NavigateToPage(Rock.SystemGuid.Page.ACCOUNTS.AsGuid(), queryParams);
            }
            else
            {
                gAccounts.EntityTypeId = EntityTypeCache.Get <FinancialAccount>().Id;
                gAccounts.DataSource   = accounts?
                                         .Select(act => new
                {
                    act.Id,
                    Name        = act.Name,
                    PublicName  = act.PublicName.IsNullOrWhiteSpace() ? "" : act.PublicName,
                    GlCode      = act.GlCode,
                    AccountType = act.AccountTypeValue?.Value,
                    Description = act.Description,
                    Path        = accountService.GetDelimitedAccountHierarchy(act, FinancialAccountService.AccountHierarchyDirection.CurrentAccountToParent)?.Replace("^", " > ")
                })
                                         .ToList();

                gAccounts.DataBind();

                foreach (DataControlField dcf in gAccounts.Columns)
                {
                    var rtf = dcf as RockTemplateField;
                    var rtfAccountDescription = dcf as RockTemplateField;

                    if (rtf != null)
                    {
                        if (rtf.ID == "rtfAccountType")
                        {
                            rtf.Visible = this.GetAttributeValue(AttributeKey.ShowAccountType).AsBoolean();
                        }
                    }

                    if (rtfAccountDescription != null)
                    {
                        if (rtfAccountDescription.ID == "rtfAccountDescription")
                        {
                            rtfAccountDescription.Visible = this.GetAttributeValue(AttributeKey.ShowAccountDescription).AsBoolean();
                        }
                    }
                }
            }
        }