private void RefreshFilters() { if (RCs == null || InOuts == null || TransportCompanies == null || Notes == null) { return; } SelectedRC = RCs.First(); SelectedInOut = InOuts.First(); SelectedTransportCompany = TransportCompanies.First(); SelectedNote = Notes.First(); Filter(); BC.DataContext.Configuration.AutoDetectChangesEnabled = false; RCs.Clear(); var rcEmpty = new DirectoryRC { Name = null }; RCs.Add(rcEmpty); foreach (var rc in Costs.Select(c => c.DirectoryRC).Distinct()) { RCs.Add(rc); } InOuts.Clear(); InOuts.Add(""); if (Costs.Any(c => c.IsIncoming)) { InOuts.Add("Приход"); } if (Costs.Any(c => !c.IsIncoming)) { InOuts.Add("Расход"); } TransportCompanies.Clear(); var transportCompanyEmpty = new DirectoryTransportCompany { Name = null }; TransportCompanies.Add(transportCompanyEmpty); foreach (var transportCompany in Costs.Select(c => c.DirectoryTransportCompany).Where(t => t != null).Distinct()) { TransportCompanies.Add(transportCompany); } Notes.Clear(); var noteEmpty = new DirectoryNote { Description = null }; Notes.Add(noteEmpty); foreach (var masNotes in Costs.Select(c => c.CurrentNotes.Select(n => n.DirectoryNote))) { foreach (var note in masNotes) { if (!Notes.Contains(note)) { Notes.Add(note); } } } OrderNotes(); BC.DataContext.Configuration.AutoDetectChangesEnabled = true; }
public MonthCostsViewModel() { var firstWorkingArea = Screen.AllScreens[0].WorkingArea; MaxHeightForm = firstWorkingArea.Height - 100; _isNotTransportOnly = Privileges.HasAccess(UserPrivileges.CostsVisibility_IsNotTransportOnly); Costs = new ObservableCollection <InfoCost>(); Years = new ObservableCollection <int>(BC.GetInfoCostYears()); if (Years.Any()) { SelectedYear = Years.Last(); } IncomingsAndExpenses = new ObservableCollection <IncomingAndExpense>(); IncomingsAndExpenses.Add(new IncomingAndExpense()); ShowDayCostsCommand = new RelayCommand(ShowDayCosts); FilterCommand = new RelayCommand(FilterShow); ReturnCommand = new RelayCommand(Return); ReturnName = "Компенсация"; ReturnVisibility = Visibility.Collapsed; ReturnButtonVisibility = _isNotTransportOnly ? Visibility.Visible : Visibility.Collapsed; VisibilityCash = _isNotTransportOnly ? Visibility.Visible : Visibility.Collapsed; BC.DataContext.Configuration.AutoDetectChangesEnabled = false; CostItems = new ObservableCollection <DirectoryCostItem>(BC.GetDirectoryCostItems()); var costItemEmpty = new DirectoryCostItem { Name = null }; CostItems.Insert(0, costItemEmpty); InOuts = new ObservableCollection <string> { "", "Приход", "Расход" }; SelectedInOut = InOuts.First(); TransportCompanies = new ObservableCollection <DirectoryTransportCompany>(BC.GetDirectoryTransportCompanies()); var transportCompanyEmpty = new DirectoryTransportCompany { Name = null }; TransportCompanies.Insert(0, transportCompanyEmpty); SelectedTransportCompany = TransportCompanies.First(); Notes = new ObservableCollection <DirectoryNote>(BC.GetDirectoryNotes().ToList()); var noteEmpty = new DirectoryNote { Description = null }; Notes.Insert(0, noteEmpty); SelectedNote = Notes.First(); SelectedCostItem = CostItems.First(); BC.DataContext.Configuration.AutoDetectChangesEnabled = true; InfoCost.OnChangeIsReturn += InfoCost_OnChangeIsReturn; }