private void PopulateAccountTypes() { this.DropAccountType.Items.Clear(); for (int i = 1; i < 5; ++i) { FinancialAccountType t = ((FinancialAccountType[])Enum.GetValues(typeof(FinancialAccountType)))[i]; this.DropAccountType.Items.Add(new ListItem(t.ToString(), t.ToString())); } }
private string GetAccountsRecurse(FinancialAccountType accountType, int rootNodeId) { List <string> childStrings = new List <string>(); if (!this._hashedAccounts.ContainsKey(rootNodeId)) { return(string.Empty); } if (this._hashedAccounts[rootNodeId].Count == 1) { // No children return(string.Empty); } IOrderedEnumerable <FinancialAccount> childAccountsSorted = this._hashedAccounts[rootNodeId].OrderBy(account => account.Name);; foreach (FinancialAccount account in childAccountsSorted) { if (account.Identity == rootNodeId || account.AccountType != accountType || account.Identity == _resultAccountId) { continue; } string ownerString = " "; if (account.AccountType == FinancialAccountType.Income || account.AccountType == FinancialAccountType.Cost) { if (account.OwnerPersonId != 0) { // TODO: add zoom, write capability ownerString = "<span style=\\\"padding-" + _nearEdge + ":20px;background-repeat:no-repeat;background-position:center " + _nearEdge + ";background-image:url('" + account.Owner.GetSecureAvatarLink(16) + "')\\\">" + JsonSanitize(Server.HtmlEncode(account.Owner.Canonical)) + "</span>"; } else { // TODO: add write capability ownerString = "<span style=\\\"padding-" + _nearEdge + ":20px;background-repeat:no-repeat;background-position:center " + _nearEdge + ";background-image:url('/Images/Icons/iconshock-warning-16x12px.png')\\\">" + JsonSanitize(Server.HtmlEncode(Global.Global_NoOwner)) + "</span>"; } } string grandChildren = GetAccountsRecurse(accountType, account.Identity); if (!string.IsNullOrEmpty(grandChildren)) { grandChildren = ",\"state\":\"closed\",\"children\":[" + grandChildren + "]"; } string editString = String.Format( "<img class='IconEdit' accountId='{0}{1}' height='16' width='24' src='/Images/Icons/iconshock-wrench-128x96px-centered.png' />", accountType.ToString().Substring(0, 1), account.Identity); childStrings.Add('{' + String.Format( "\"id\":\"{0}\",\"accountName\":\"{1}\",\"owner\":\"{2}\",\"balance\":\"{3}\",\"budget\":\"{4}\",\"action\":\"{5}\",\"inactive\":\"{6}\"", account.Identity, JsonSanitize(account.Name), ownerString, this._hashedAccounts[account.Identity].Count > 1 ? JsonDualString(account.Identity, this._treeBalanceLookup[account.Identity], this._singleBalanceLookup[account.Identity]) : (this._singleBalanceLookup[account.Identity] / 100.0).ToString("N0", CultureInfo.CurrentCulture), account.AccountType == FinancialAccountType.Income || account.AccountType == FinancialAccountType.Cost ? this._hashedAccounts[account.Identity].Count > 1 ? (JsonDualString(account.Identity, this._treeBudgetLookup[account.Identity], this._singleBudgetLookup[account.Identity])) : (this._singleBudgetLookup[account.Identity] / 100.0).ToString("N0", CultureInfo.CurrentCulture) : string.Empty, editString, account.Active? "false":"true" // reverses condition on purpose ) + grandChildren + '}'); } return(String.Join(",", childStrings.ToArray())); }
private string GetAccountsRecurse(FinancialAccountType accountType, int rootNodeId) { List <string> childStrings = new List <string>(); if (!_hashedAccounts.ContainsKey(rootNodeId)) { return(string.Empty); } if (_hashedAccounts [rootNodeId].Count == 1) { // No children return(string.Empty); } foreach (FinancialAccount account in _hashedAccounts[rootNodeId]) { if (account.Identity == rootNodeId || account.AccountType != accountType) { continue; } string ownerString = " "; if (account.AccountType == FinancialAccountType.Income || account.AccountType == FinancialAccountType.Cost) { if (account.OwnerPersonId != 0) { // TODO: add zoom, write capability ownerString = "<span style=\\\"padding-left:20px;background-repeat:no-repeat;background-image:url('" + account.Owner.GetSecureAvatarLink(16) + "')\\\">" + JsonSanitize(Server.HtmlEncode(account.Owner.Canonical)) + "</span>"; } else { // TODO: add write capability ownerString = "<span style=\\\"padding-left:20px;background-repeat:no-repeat;background-position:center left;background-image:url('/Images/Icons/iconshock-warning-16x12px.png')\\\">" + JsonSanitize(Server.HtmlEncode(Resources.Global.Global_NoOwner)) + "</span>"; } } string grandChildren = GetAccountsRecurse(accountType, account.Identity); if (!string.IsNullOrEmpty(grandChildren)) { grandChildren = ",\"state\":\"closed\",\"children\":[" + grandChildren + "]"; } string editString = String.Format("<img class=\\\"IconEdit\\\" accountId=\\\"{0}{1}\\\" src=\\\"/Images/Icons/iconshock-wrench-16px.png\\\" />", accountType.ToString().Substring(0, 1), account.Identity); childStrings.Add('{' + String.Format("\"id\":\"{0}\",\"accountName\":\"{1}\",\"owner\":\"{2}\",\"balance\":\"{3}\",\"budget\":\"{4}\",\"action\":\"{5}\"", account.Identity, Server.HtmlEncode(JsonSanitize(account.Name)), ownerString, _hashedAccounts[account.Identity].Count > 1 ? JsonDualString(account.Identity, _treeBalanceLookup[account.Identity], _singleBalanceLookup[account.Identity]) : (_singleBalanceLookup [account.Identity] / 100.0).ToString("N0"), account.AccountType == FinancialAccountType.Income || account.AccountType == FinancialAccountType.Cost? _hashedAccounts[account.Identity].Count > 1 ? (JsonDualString(account.Identity, _treeBudgetLookup[account.Identity], _singleBudgetLookup[account.Identity])) : (_singleBudgetLookup[account.Identity] / 100.0).ToString("N0") : string.Empty, editString ) + grandChildren + '}'); } return(String.Join(",", childStrings.ToArray())); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; FinancialAccountType accountType = (FinancialAccountType)(Enum.Parse(typeof(FinancialAccountType), Request.QueryString["AccountType"])); string accountsJson = string.Empty; int excludeId = -1; string excludeIdString = Request.QueryString["ExcludeId"]; if (!String.IsNullOrEmpty(excludeIdString)) { excludeId = Int32.Parse(excludeIdString); } // Get accounts FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization, accountType); // Build tree (there should be a template for this) Dictionary <int, List <FinancialAccount> > treeMap = new Dictionary <int, List <FinancialAccount> >(); foreach (FinancialAccount account in accounts) { if (account.Identity == excludeId) { continue; } if (!treeMap.ContainsKey(account.ParentIdentity)) { treeMap[account.ParentIdentity] = new List <FinancialAccount>(); } treeMap[account.ParentIdentity].Add(account); } if (treeMap.ContainsKey(0)) { accountsJson = RecurseTreeMap(treeMap, 0); } accountsJson = "[{\"id\":\"0\",\"text\":\"" + JsonSanitize(Resources.Global.ResourceManager.GetString("Financial_" + accountType.ToString())) + "\",\"state\":\"open\",\"children\":" + accountsJson + "}]"; Response.Output.WriteLine(accountsJson); Response.End(); }