简体   繁体   中英

Filter search results from database

Right now I'm working with a search function. I've a textbox and a button and search in a database full of employees. In another web part employees have the possibility to save their technical skills in a database and also on which level they are in (Beginner, Intermediate, Advanced or Expert). When I as an admin want to lookup for an employee that knows for example C#, then I just search for it and all the employees with the skill turns up in a gridview.

But my question here is:

Is it possible to filter those results? For example if I put in a checkboxlist after the search and I want to filter on employees that are "Experts" on C#, is it possible to just display them? Sorry for my english, but I did my best. Hopefully I get an answer.

在此处输入图片说明

Here's an code example of how I search:

    private void SearchEmployeeSkillEng()
    {
        using (var db = new KnowItCvdbEntities())
        {
            var searchTechSkill = (from p in db.EMPLOYEES
                                  join ets in db.EMPLOYEES_TECHNICAL_SKILLS on p.employee_id equals
                                      ets.employee_id
                                  join ts in db.TECHNICAL_SKILLS_VALUES on ets.technical_skill_value_id
                                      equals
                                      ts.technical_skill_value_id
                                  join tsl in db.TECHNICAL_SKILL_LEVEL on ets.technical_skill_level_id
                                      equals
                                      tsl.technical_skill_level_id
                                  where
                                      ts.skill_name.Contains(TextBoxSearchCvEng.Text) ||
                                      ets.skill_name_other.Contains(TextBoxSearchCvEng.Text)
                                  select new TechnicalSkillsSearch()
                                  {
                                      EmployeeId = p.employee_id,
                                      FirstName = p.firstname,
                                      LastName = p.lastname,

                                      TechnicalSkillValueId = ts.technical_skill_value_id,
                                      SkillName = ts.skill_name,
                                      SkillNameOther = ets.skill_name_other,
                                      SkillType = ts.skill_type,
                                      TechnicalSkillLevelId = tsl.technical_skill_level_id,
                                      SkillLevel = tsl.skill_level
                                  }).ToList();

            if(searchTechSkill.Count > 0)
            {
                LabelException.Visible = false;
                foreach (var vTechSkill in searchTechSkill)
                {
                    if (vTechSkill != null)
                    {
                        if (vTechSkill.SkillNameOther != null)
                        {
                            if (!_searchEmpListEng.Contains(vTechSkill.FirstName + " " + vTechSkill.LastName + "," +
                                                         vTechSkill.EmployeeId))
                            {
                                _searchEmpListEng.Add(vTechSkill.FirstName + " " + vTechSkill.LastName + "," +
                                                   vTechSkill.EmployeeId.ToString());
                            }
                        }
                        else
                        {
                            if (!_searchEmpListEng.Contains(vTechSkill.FirstName + " " + vTechSkill.LastName + "," +
                                                         vTechSkill.EmployeeId))
                            {
                                _searchEmpListEng.Add(vTechSkill.FirstName + " " + vTechSkill.LastName + "," +
                                                   vTechSkill.EmployeeId.ToString());
                            }
                        }
                    }
                }
            }
            else
            {
                LabelException.Visible = true;
                LabelException.Text = "Nothing found";
            }
            _dtEng.Clear();

        }
    }

TECHNICAL_SKILLS_VALUES is for example C#, MS ACCESS etc and TECHNICAL_SKILL_LEVEL is for example Expert, Beginner etc.

Yours, Kristian

Here is some pseudo code to filter the Employees at the point right after you've serialized the queries results into a collection of native C# objects. I'm assuming you have a List<Employee> (list of employee objects) and the Employee object has a level field.

   List<Employee> experts = oldList.Select(x => x).Where(y => y.level == "Expert").ToList();

Of course you should replace my hard coded "Expert" with something like ListBox.CurrentSelection or whatever you're using to get the users input on level but that's the basic idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM