public VM_AddBudget(Action <VM_BudgetItem> action = null) { ModelNew = new VM_BudgetItem(new BudgetItem()); BudgetGroups = BudgetGroup.GetAll(); _budgetVars = BudgetVar.GetAll(); _updateAction = action; }
private void Initialize() { // 所有预算和所有变量 var list = BudgetGroup.GetAll(); var budgetVars = BudgetVar.GetAll(); BudgetItems = new ObservableCollection <VM_BudgetItem>(); foreach (var itemGroup in list) { if (itemGroup.BudgetItems == null) { continue; } foreach (var item in itemGroup.BudgetItems) { var vb = new VM_BudgetItem(item) { GroupName = itemGroup.Name }; BudgetItems.Add(vb); var expression = item.Expression; budgetVars.ForEach(bv => { if (expression.Contains(bv.Name)) { expression = expression.Replace(bv.Name, bv.GetQuantities()); } }); try { vb.QuantitieString = string.Format(item.Format, Convert.ToDouble(new System.Data.DataTable().Compute(expression, null)) * item.Ratio); } catch (Exception ex) { vb.QuantitieString = "计算出错"; } } } collectionView = CollectionViewSource.GetDefaultView(BudgetItems); collectionView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName")); }
public VM_AddGroup() { _budgetGroupList = BudgetGroup.GetAll(); }
public VM_EditGroup() { var list = BudgetGroup.GetAll(); BudgetGroups = new ObservableCollection <VM_BudgetGroup>(list.Select(b => new VM_BudgetGroup(b)).ToList()); }