Mini Kabibi Habibi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DevExpress.Web.ASPxTreeView;
using System.Configuration;
using System.Globalization;
using DevExpress.Web.ASPxNavBar;
public static class UIUtils {
public static void CreateAccountsNavBar(ASPxNavBar nbAccounts) {
var accounts = DataProvider.Instance.GetAccounts();
var cashGroup = nbAccounts.Groups.Add("Cash & Checking");
var creditGroup = nbAccounts.Groups.Add("Credit Cards");
var loansGroup = nbAccounts.Groups.Add("Loans");
var assetsGroup = nbAccounts.Groups.Add("Assets");
foreach (var acc in accounts) {
var item = new NavBarItem(acc.Title, string.Format("account_{0}", acc.ID)) { DataItem = acc };
if (acc.Category == AccountCategory.Cash)
cashGroup.Items.Add(item);
else if (acc.Category == AccountCategory.Credit)
creditGroup.Items.Add(item);
else if (acc.Category == AccountCategory.Loans)
loansGroup.Items.Add(item);
else if (acc.Category == AccountCategory.Assets)
assetsGroup.Items.Add(item);
}
cashGroup.Expanded = true;
creditGroup.Expanded = true;
assetsGroup.Expanded = true;
loansGroup.Expanded = true;
}
public static void CreateAllAccountsNavBar(ASPxNavBar nbAccounts) {
var accounts = DataProvider.Instance.GetAccounts();
var accGroup = nbAccounts.Groups.Add("Accounts");
foreach (var acc in accounts)
accGroup.Items.Add(new NavBarItem(acc.Title, String.Format("account_{0}", acc.ID)) { DataItem = acc });
if (accGroup.Items.Count > 1)
accGroup.Items.Insert(0, new NavBarItem("All Accounts", "allAccounts") { DataItem = new { Description = String.Format("{0} accounts", accGroup.Items.Count) } });
}
public static string GetBudgetProgressBarInnerText(decimal budgetAmount, decimal spentAmount) {
if(budgetAmount == 0)
return string.Format("{0} of an unestimated budget. Set the Amount value.", spentAmount.AsCurrency());
return string.Format("{0} of an estimated {1}", spentAmount.AsCurrency(), budgetAmount.AsCurrency());
}
public static string GetBudgetProgressBarClassName(int spentAmountPercent) {
return spentAmountPercent > 90 && spentAmountPercent < 100 ? "orange" : spentAmountPercent >= 100 ? "red" : "";
}
}