Hello,
Welcome to our Microsoft Q&A platform!
Do you want to filter out the cases that meet all the conditions(Age, Gender, and Symptoms), and then return DName
s to the Listview?
For example, I want to filter the Age is 50, Gender is Male, DSymptoms is pain chest. We can use following code to filter it, Do not need to use ( )
to wrap all of the filter situation. we will get the two records High blood pressure, Diabetes in the listview.
var resList= _container.DiseaseDetails.Where(i => i.DSymptoms.ToLower().Contains(symptoms.ToLower()) && i.DAgeLow <= age && i.DAgeHigh >= age && i.MGender.Contains(gender) ).ToList();
And I notice you alway to get the first record in the tabel, If you want to get the lastest record that insert to the sqlite DB, you need to change the OnAppearing
method's code from Dlistpage.cs
protected override void OnAppearing()
{
base.OnAppearing();
using(SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
conn.CreateTable<PersonInfo>();
var personinfo = conn.Table<PersonInfo>().ToList();
int age = personinfo[personinfo.Count-1].PAge;
string gender = personinfo[personinfo.Count - 1].PGender;
string symptoms = personinfo[personinfo.Count - 1].PSymptoms;
if (symptoms == null)
{
symptoms = " ";
}
var _container = BindingContext as DViewModel;
DisplayList.BeginRefresh();
var resList= _container.DiseaseDetails.Where(i => i.DSymptoms.ToLower().Contains(symptoms.ToLower()) && i.DAgeLow <= age && i.DAgeHigh >= age && i.MGender.Contains(gender) ).ToList();
DisplayList.ItemsSource = resList; //_container.DiseaseDetails.Where(i => (i.DSymptoms.ToLower().Contains(symptoms.ToLower())) && (i.DAgeLow <= age && i.DAgeHigh >= age) /*&& (i.MGender.Contains(gender))*/ );
DisplayList.EndRefresh();
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.