Exemple #1
0
        /// <summary>
        ///     搜索
        /// </summary>
        private void buttonSearch_Click()
        {
            if (string.IsNullOrEmpty(searchTextBox.Text))
            {
                dataContext = new DataClassesProjectClassifyDataContext();
                MainTreeView.DataContext = dataContext.ProjectClassify;
                WindowDataBind();
                return;
            }
            dataContext = new DataClassesProjectClassifyDataContext();
            var searchPredicate = PredicateExtensions.True <ProjectBase>();

            searchText = new List <string>();
            searchText = Regex.Split(searchTextBox.Text, @"[' ']+").ToList();
            //foreach (string str in searchText)
            //{
            //    searchPredicate = searchPredicate.Or(p => p.ProjectName.Contains(str));
            //}
            //var pb = dataContext.ProjectBase.Where(searchPredicate);
            var pb   = dataContext.ProjectBase.Where(p => p.ProjectName.Contains(searchText[0]));
            var list = pb.ToList();

            if (searchText.Count > 1)
            {
                foreach (var str in searchText)
                {
                    if (str == searchText[0])
                    {
                        continue;
                    }
                    pb   = pb.Where(c => c.ProjectName.Contains(str));
                    list = pb.ToList();
                    //合并结果示例
                    //pb = pb.Union<ProjectBase>(dataContext.ProjectBase.Where(p => p.ProjectName.Contains(str)));
                }
            }

            //创建符合条件的项目的所有关联项目的项目树ProjectID列表
            LinkProjectForSearch = new List <int>();
            LinkProjectClassify  = new List <int>();
            foreach (var p in pb)
            {
                var pp = p;
                if (!LinkProjectForSearch.Contains(pp.ProjectId))
                {
                    LinkProjectForSearch.Add(pp.ProjectId);
                    while (pp.ParentID != null)
                    {
                        pp = dataContext.ProjectBase.Single(ppb => ppb.ProjectId.Equals(pp.ParentID));
                        if (!LinkProjectForSearch.Contains(pp.ProjectId))
                        {
                            LinkProjectForSearch.Add(pp.ProjectId);
                        }
                    }
                }
                if (pp.ProjectClassifyID != null && !LinkProjectClassify.Contains((int)pp.ProjectClassifyID))
                {
                    LinkProjectClassify.Add((int)pp.ProjectClassifyID);
                }
            }
            //dataContext = new DataClassesProjectClassifyDataContext();
            MainTreeView.DataContext = dataContext.ProjectClassify;
            buildSearchTreeProjectClassify();
            if (LinkProjectForSearch.Count > 0)
            {
                ProjectID = LinkProjectForSearch[0];
                WindowDataBind();
            }
        }
Exemple #2
0
        private void FreshData()
        {
            string filter = "";
            //_listPrizes = new List<Prizes>();

            var searchPredicate = PredicateExtensions.True <Prizes>();

            if (ListBoxDepartment.SelectedItem != null)
            {
                filter = (string)ListBoxDepartment.SelectedItem;
                if (filter != "全部")
                {
                    var filter1 = filter;
                    searchPredicate = searchPredicate.And(p => p.Department.Equals(filter1));
                }
            }

            if (ListBoxDeclareDepartment.SelectedItem != null)
            {
                filter = (string)ListBoxDeclareDepartment.SelectedItem;
                if (filter != "全部")
                {
                    var filter1 = filter;
                    searchPredicate = searchPredicate.And(p => p.DeclareDepartment.Equals(filter1));
                }
            }

            if (ListBoxYear.SelectedItem != null)
            {
                filter = (string)ListBoxYear.SelectedItem;
                if (filter != "全部")
                {
                    var filter1 = filter;
                    searchPredicate = searchPredicate.And(p => p.PayYear.Equals(filter1));
                }
            }

            if (ListBoxProject.SelectedItem != null)
            {
                filter = (string)ListBoxProject.SelectedItem;
                if (filter != "全部")
                {
                    var filter1 = filter;
                    searchPredicate = searchPredicate.And(p => p.Project.Equals(filter1));
                }
            }

            var          prizess     = dataContext.Prizes.Where(searchPredicate);
            List <Prize> _listPrizes =
                prizess.Select(p => new Prize
            {
                PrizeClassify     = p.PrizeClassify,
                Project           = p.Project,
                AwardName         = p.AwardName,
                Name              = p.Name,
                AccountName       = p.AccountName,
                Department        = p.Department,
                DeclareDepartment = p.DeclareDepartment,
                PayYear           = p.PayYear,
                PrizeValue        = Convert.ToDecimal(p.Prize)
            }).AsEnumerable().Distinct(new PrizeComparer()).ToList();
            List <Prize> result = new List <Prize>();

            foreach (Prize prize in _listPrizes)
            {
                bool boolMatch = result.Any(p => prize.AccountName == p.AccountName && prize.AwardName == p.AwardName && prize.Department == p.Department && prize.PayYear == p.PayYear && prize.PrizeClassify == p.PrizeClassify && prize.Project == p.Project && prize.PrizeValue == p.PrizeValue && prize.Name == p.Name);

                if (!boolMatch)
                {
                    result.Add(prize);
                }
            }

            //_listPrizes = _listPrizes.Where(searchPredicate);

            //if (ListBoxDepartment.SelectedItem != null)
            //{
            //    filter = (string) ListBoxDepartment.SelectedItem;
            //    if (filter != "全部")
            //    {
            //        _listPrizes = _listPrizes.Where(p => p.Department.Equals(filter)).AsEnumerable().Distinct(new PrizeComparer()).ToList();
            //    }
            //}
            //if (ListBoxDeclareDepartment.SelectedItem != null)
            //{
            //    filter = (string) ListBoxDeclareDepartment.SelectedItem;
            //    if (filter != "全部")
            //    {
            //        _listPrizes = _listPrizes.Where(p => p.DeclareDepartment.Equals(filter)).AsEnumerable().Distinct(new PrizeDepartmentComparer()).ToList();
            //    }
            //}
            //if (ListBoxYear.SelectedItem != null)
            //{
            //    filter = (string) ListBoxYear.SelectedItem;
            //    if (filter != "全部")
            //    {
            //        _listPrizes = _listPrizes.Where(p => p.PayYear.Equals(filter)).AsEnumerable().Distinct(new PrizeComparer()).ToList();
            //    }
            //}
            //if (ListBoxProject.SelectedItem != null)
            //{
            //    filter = (string) ListBoxProject.SelectedItem;
            //    if (filter != "全部")
            //    {
            //        _listPrizes = _listPrizes.Where(p => p.Project.Equals(filter)).AsEnumerable().Distinct(new PrizeComparer()).ToList();
            //    }
            //}
            //_listPrizes = _listPrizes.Distinct(new PrizeComparer()).ToList();
            DataGridPrizes.ItemsSource = result;
        }