Hi everyone
I have an issue in the following Linq to collection query it give me the wrong result and i spend a lot of hours to discover the issue, so kindly tell me if you see anything error:
The wrong is on the condition
The case is:
I want to filter the listed items be provide a search criteria for the user
so the user will select the Item_Class and enter the available amounts then choose the mathematical sign (<, <=, >=, >, ==) so the listed items will match the search criteria
The results totally ignore the final condition i don't know why ?
from item in ItemsList where
!String.IsNullOrEmpty(txtBoxItemCode.Text)? (item.Code.ToString() == (txtBoxItemCode.Text)) : true &&
!String.IsNullOrEmpty(txtBoxItemName.Text)? (item.ItemName.Contains(txtBoxItemName.Text)) : true &&
(DDLClass.SelectedIndex != 0)? item.Class.Equals(DDLClass.SelectedItem as ItemsClass) : true &&
!String.IsNullOrEmpty(txtBoxQuantity.Text)? Compute(item.Quantity, float.Parse(txtBoxQuantity.Text), DDLQuantitySign.SelectedValue.ToString()) : true
select item;
public static bool Compute(float param1, float param2, string op)
{
switch (op)
{
case "<":
return param1 < param2;
case "<=":
return param1 <= param2;
case ">":
return param1 > param2;
case ">=":
return param1 >= param2;
case "=":
return param1 == param2;
default:
return false;
}
}
Thanks in advance :)