/// <summary> /// Search drugs when text input /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void acbDrugSearch_TextChanged(object sender, RoutedEventArgs e) { var folder = ApplicationData.Current.LocalFolder.GetFolderAsync("DataFolder"); SQLiteAsyncConnection conn = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "DataFile.sqlite"), true); string pillname = acbDrugSearch.Text; if (!string.IsNullOrEmpty(pillname) && !string.IsNullOrWhiteSpace(pillname) && pillname.Length > 3) { var query = conn.Table<drugs>().Where(x => x.drugname.Contains(pillname)); var result = await query.ToListAsync(); if (result == null) { MessageBox.Show("Pill not found."); } else { List<DrugDetails> druglist = new List<DrugDetails>(); foreach (var item in result) { DrugDetails dataRead = new DrugDetails(); dataRead._id = item._id; dataRead.amp = item.amp; dataRead.ampp =item.ampp; dataRead.drug_code =item.drug_code; dataRead.drugform = item.drugform; dataRead.strenght =item.strenght; dataRead.drugname = string.Format("{0} {1}", item.drugname, item.strenght); dataRead.size =item.size; dataRead.vmp =item.vmp; dataRead.vmpp =item.vmpp; druglist.Add(dataRead); } lstDrugSearch.ItemsSource = druglist; } } }
/// <summary> /// Drug search /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstDrugSearch_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedData = (sender as ListBox).SelectedItem as DrugDetails; _isSearchDone = true; if (selectedData != null) { prescription = new Prescription(); if (!string.IsNullOrEmpty(selectedData.amp)) prescription.amp = selectedData.amp; else prescription.amp = string.Empty; if (!string.IsNullOrEmpty(selectedData.ampp)) prescription.ampp = selectedData.ampp; else prescription.ampp = string.Empty; tbxDrugSearch.Text = selectedData.drugname; if (!string.IsNullOrEmpty(selectedData.vmp)) prescription.vmp = selectedData.vmp; else prescription.vmp = string.Empty; if (!string.IsNullOrEmpty(selectedData.vmpp)) prescription.vmpp = selectedData.vmpp; else prescription.vmpp = string.Empty; PopupSearch.IsOpen = false; } else { PopupSearch.IsOpen = true; } }