예제 #1
0
        public EmpViewModel()
        {
            EmpList = EmpService.GetEmpList();

            Paging = new PaginationViewModel
            {
                PeopleList = _empList,
            };
            Paging.ViewList.Filter += ViewList_Filter;


            ImportCommand = new RelayCommand(() =>
            {
                IsImportDataVisible = true;
                IsSearchVisible     = false;
            }, () => true);

            SearchCommand = new RelayCommand(() =>
            {
                IsImportDataVisible = false;
                IsSearchVisible     = true;
                EmpFormViewModel    = new EmpFormViewModel();
            }, () => true);


            NavigateToForm = new RelayCommand <dynamic>(vm =>
            {
                this.IsImportDataVisible = false;
                this.IsSearchVisible     = true;

                if (vm != null)
                {
                    EmpFormViewModel = vm;
                }
            });

            SortCommand1 = new RelayCommand <dynamic>(item =>
            {
                if (string.Equals(item, "Name", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (SortColumn.NameSortOrder == SortDir.Descending)
                    {
                        Paging.ViewList.SortDescriptions.Clear();
                        Paging.ViewList.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                        SortColumn.NameSortOrder = SortDir.Ascending;
                    }
                    else
                    {
                        Paging.ViewList.SortDescriptions.Clear();
                        Paging.ViewList.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Descending));
                        SortColumn.NameSortOrder = SortDir.Descending;
                    }
                }

                if (string.Equals(item, "Id", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Paging.ViewList.View.Filter(propfull=) implement filter based on textBox

                    if (SortColumn.NameSortOrder == SortDir.Descending)
                    {
                        Paging.ViewList.SortDescriptions.Clear();
                        Paging.ViewList.SortDescriptions.Add(new SortDescription("Id", ListSortDirection.Ascending));
                        SortColumn.NameSortOrder = SortDir.Ascending;
                    }
                    else
                    {
                        Paging.ViewList.SortDescriptions.Clear();
                        Paging.ViewList.SortDescriptions.Add(new SortDescription("Id", ListSortDirection.Descending));
                        SortColumn.NameSortOrder = SortDir.Descending;
                    }
                }
            }, item => true);

            Paging.SearchByColumnCommand = new RelayCommand(() =>
            {
                Paging.PeopleList = new ObservableCollection <EmpFormViewModel>(EmpList.Where(p => new SearchCondition(Paging, p).Evaluate()));
            }, () => true);

            IsImportDataVisible = true;
        }