C# Filtering employee ID's from a list to modify a query
Learning C# here. I have a monthly process form whereby one can select to process salaries for all employees or select the employees to process for using radio buttons (SAP B1 开发者_StackOverflowform using screenpainter).
One is able to open a form to select employees and the employee ID's are sent to this monthly process form and are stored in a list.
//Method to retrieve string values from child form
public void GetFilteredIds(List<string> idValues)
{
List<string> employeeIDs = new List<string>();
employeeIDs = idValues;
}
I wanted to filter this query on the monthly process form that selects ALL emp IDs
//Query database
var salaryFitments = salaryFitmentService.GetAllSalaryFitments();
var employeeIdList = (from sf in salaryFitments select sf.U_Employee_ID).Distinct();
such that I have something similar to this:
var k = from id in employeeIdList
where employeeIDs.Contains(id)
select id;
How do I write my code such that just before processing (hitting a process button), I have an if statement to check if its a monthly process for all or just a few selected
if (_selectedEmployees.Selected == true)
{
...code to write
}
else
{
...code to write
}
_selectedEmployees refers to private SAPbouiCOM.OptionBtn _selectedEmployees;
Just before processing
if (employeeIdList.Any())
{ ............
I hope my question is clear enough
Not 100% sure what you're after, but would this help:
// Code to see if the 'all employees' radiobutton is selected.
var k = from id in employeeIdList
where AllSelected || employeeIDs.Contains(id)
select id;
You wouldn't have to duplicate your query then.
精彩评论