public List <DeskQuote> searchQuotes(Stream file, string searchBy, SearchAllQuotes searchAllQuotes) { //StorageFolder storageFolder = ApplicationData.Current.LocalFolder; //StorageFile quoteFile = await storageFolder.GetFileAsync("Quotes.json"); StreamReader sr = new StreamReader(file); List <DeskQuote> deskQuotes = new List <DeskQuote>(); string JSONString; try { while (!sr.EndOfStream) { JSONString = sr.ReadLine(); DeskQuote deskQuote = new DeskQuote(); deskQuote = JsonConvert.DeserializeObject <DeskQuote>(JSONString); if (searchAllQuotes.getSearchBy().Equals("Client")) { if (searchAllQuotes.getCriteria().Equals(deskQuote.clientName)) { deskQuotes.Add(deskQuote); } } else if (searchAllQuotes.getSearchBy().Equals("Material")) { if (searchAllQuotes.getCriteria() == deskQuote.desk.material) { deskQuotes.Add(deskQuote); } } } sr.Dispose(); } catch (IOException e) { //System.Windows.Forms.MessageBox.Show("There was a problem trying to read the file" + e); } return(deskQuotes); }
private void Search_Click(object sender, RoutedEventArgs e) { DeskQuote deskQuote = new DeskQuote(); List <DeskQuote> deskQuotes = new List <DeskQuote>(); StorageFolder storageFolder = ApplicationData.Current.LocalFolder; string file = storageFolder.Path + "\\Quotes.json"; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); deskQuotes = deskQuote.searchQuotes(fs, this.searchBy, this); this.Results.Text += "Date" + "\t\t"; this.Results.Text += "Client" + "\t"; this.Results.Text += "Depth" + "\t"; this.Results.Text += "Width" + "\t"; this.Results.Text += "Sice" + "\t"; this.Results.Text += "Material" + "\t\t"; this.Results.Text += "Price" + "\n"; for (int i = 0; i < deskQuotes.Count; i++) { this.Results.Text += deskQuotes.ElementAt(i).date + "\t"; this.Results.Text += deskQuotes.ElementAt(i).clientName + "\t"; this.Results.Text += deskQuotes.ElementAt(i).desk.width + "\t"; this.Results.Text += deskQuotes.ElementAt(i).desk.depth + "\t"; this.Results.Text += deskQuotes.ElementAt(i).desk.size + "\t"; if (deskQuotes.ElementAt(i).desk.material.Equals("Rossewood")) { this.Results.Text += deskQuotes.ElementAt(i).desk.material + "\t"; } else { this.Results.Text += deskQuotes.ElementAt(i).desk.material + "\t\t"; } this.Results.Text = "$" + string.Format("{0:n0}", deskQuotes.ElementAt(i).price) + "\n"; } this.Search.IsEnabled = false; }