public void ReloadGrid() { var data = new ObservableCollection <Order>(Configuration.DatabaseHelper.GetAllOrders()); dgOrders.ItemsSource = data; ControlPanelGeneric <Order> genericContainer = new ControlPanelGeneric <Order>(controlPanel); genericContainer.DataToTransform = data; genericContainer.GetAllDataMethod += () => { return(new ObservableCollection <Order>(Configuration.DatabaseHelper.GetAllOrders())); }; genericContainer.SearchMethod += (dataGridDataSource, search) => { return(new ObservableCollection <Order>(dataGridDataSource.Where(c => c.Comment.ToLower().Contains(search.ToLower())))); }; genericContainer.SearchResultIsEmpty += () => { dgOrders.Visibility = Visibility.Hidden; }; genericContainer.SearchResultIsNotEmpty += () => { dgOrders.Visibility = Visibility.Visible; }; genericContainer.OrderByCriteria = new List <string> { "Komentář", "Id" }; genericContainer.OrderByAlphabetical += (dataToSort, criterion) => { if (criterion == "Komentář") { return(new ObservableCollection <Order>(dataToSort.OrderBy(o => o.Comment))); } else if (criterion == "Id") { return(new ObservableCollection <Order>(dataToSort.OrderBy(o => o.Id))); } else { return(dataToSort); } }; genericContainer.OrderByReverseAlphabetical += (dataToSort, criterion) => { if (criterion == "Komentář") { return(new ObservableCollection <Order>(dataToSort.OrderByDescending(o => o.Comment))); } else if (criterion == "Id") { return(new ObservableCollection <Order>(dataToSort.OrderByDescending(o => o.Id))); } else { return(dataToSort); } }; genericContainer.CallSearchMethod(); }
public void ReloadDatagrid() { // Inicializace vyhledávače //ControlPanel.DataToTransform = data; //ControlPanel.GetAllDataMethod += () => { return new ObservableCollection<Customer>(Configuration.DatabaseHelper.GetAllCustomers()); }; //ControlPanel.SearchMethod += (dataGridDataSource, search) => { return new ObservableCollection<Customer>(dataGridDataSource.Where(c => c.Name.ToLower().Contains(search.ToLower()) || c.Surname.ToLower().Contains(search.ToLower())).ToList()); }; //ControlPanel.SearchResultIsEmpty += () => { customersGrid.Visibility = Visibility.Hidden; tblockEmptySearchResult.Visibility = Visibility.Visible; }; //ControlPanel.SearchResultIsNotEmpty += () => { customersGrid.Visibility = Visibility.Visible; tblockEmptySearchResult.Visibility = Visibility.Hidden; }; //ControlPanel.Transform(); var data = new ObservableCollection <Customer>(Configuration.DatabaseHelper.GetAllCustomers()); customersGrid.ItemsSource = data; genericContainer = new ControlPanelGeneric <Customer>(ControlPanel); genericContainer.DataToTransform = data; genericContainer.GetAllDataMethod += () => { return(new ObservableCollection <Customer>(Configuration.DatabaseHelper.GetAllCustomers())); }; // genericContainer.SearchMethod += (dataGridDataSource, search) => { return new ObservableCollection<Customer>(dataGridDataSource.Where(c => (c.Name.ToLower() + " " + c.Surname.ToLower()).Contains(search.ToLower())).ToList()); }; genericContainer.SearchMethod += (dataGridDataSource, search) => { return(new ObservableCollection <Customer>(dataGridDataSource.Where(c => { string customerData = c.Name.ToLower() + " " + c.Surname.ToLower(); List <string> keywords = search.Split(' ').ToList(); foreach (string keyword in keywords) { if (customerData.Contains(keyword.ToLower().Trim())) { return true; } } return false; }))); }; genericContainer.SearchResultIsEmpty += () => { customersGrid.Visibility = Visibility.Hidden; tblockEmptySearchResult.Visibility = Visibility.Visible; }; genericContainer.SearchResultIsNotEmpty += () => { customersGrid.Visibility = Visibility.Visible; tblockEmptySearchResult.Visibility = Visibility.Hidden; }; genericContainer.OrderByCriteria = new List <string>() { "Id", "Jméno", "Příjmení" }; genericContainer.OrderByAlphabetical += (dataToSort, criterion) => { if (criterion == "Jméno") { return(new ObservableCollection <Customer>(dataToSort.OrderBy(c => c.Name))); } else if (criterion == "Příjmení") { return(new ObservableCollection <Customer>(dataToSort.OrderBy(c => c.Surname))); } else if (criterion == "Id") { return(new ObservableCollection <Customer>(dataToSort.OrderBy(c => c.Id))); } else { return(dataToSort); } }; genericContainer.OrderByReverseAlphabetical += (dataToSort, criterion) => { if (criterion == "Jméno") { return(new ObservableCollection <Customer>(dataToSort.OrderByDescending(c => c.Name))); } else if (criterion == "Příjmení") { return(new ObservableCollection <Customer>(dataToSort.OrderByDescending(c => c.Surname))); } else if (criterion == "Id") { return(new ObservableCollection <Customer>(dataToSort.OrderByDescending(c => c.Id))); } else { return(dataToSort); } }; genericContainer.CallSearchMethod(); }