private void ViewAllQuotes_Load(object sender, EventArgs e) { try { if (File.Exists(@"quotes.json")) { using (StreamReader sr = new StreamReader(@"quotes.json")) { string jsonData = sr.ReadToEnd().Trim(); string[] lines = jsonData.Split( new[] { "\r\n", "\r", "\n", "\\n" }, StringSplitOptions.None ); List <Row> arrayList = new List <Row>(); for (int i = 0; i < lines.Length; i++) { // Read lines and parse Objects DeskQuoteRootObj DeskQuote = JsonConvert.DeserializeObject <DeskQuoteRootObj>(lines[i]); Row row = new Row(DeskQuote.Today, DeskQuote.Name, DeskQuote.Desk.Width, DeskQuote.Desk.Depth, DeskQuote.Desk.material, DeskQuote.RushDays, DeskQuote.Quote); arrayList.Add(row); } //Fill a new data table for sorting DataTable dt = new DataTable(); dt.Columns.Add("Date"); dt.Columns.Add("CustomerName"); dt.Columns.Add("Width"); dt.Columns.Add("Depth"); dt.Columns.Add("Material"); dt.Columns.Add("RushDays"); dt.Columns.Add("Price"); foreach (var item in arrayList) { dt.Rows.Add(item.Date, item.CustomerName, item.Width, item.Depth, item.Material, item.RushDays, item.Price); } dataGridViewAll.DataSource = dt; //dataGridViewAll.DataSource = arrayList; } } } catch (Exception) { throw; } }
private void searchBtn_Click(object sender, EventArgs e) { string MaterialSelected = searchCombo.SelectedItem.ToString(); try { if (File.Exists(@"quotes.json")) { using (StreamReader sr = new StreamReader(@"quotes.json")) { string jsonData = sr.ReadToEnd().Trim(); string[] lines = jsonData.Split( new[] { "\r\n", "\r", "\n", "\\n" }, StringSplitOptions.None ); List <Row> arrayList = new List <Row>(); for (int i = 0; i < lines.Length; i++) { // Read lines and parse Objects DeskQuoteRootObj DeskQuote = JsonConvert.DeserializeObject <DeskQuoteRootObj>(lines[i]); Row row = new Row(DeskQuote.Today, DeskQuote.Name, DeskQuote.Desk.Width, DeskQuote.Desk.Depth, DeskQuote.Desk.material, DeskQuote.RushDays, DeskQuote.Quote); arrayList.Add(row); } // Obtener el material Seleccionado DesktopMaterial selMaterial = (DesktopMaterial)Enum.Parse(typeof(DesktopMaterial), searchCombo.Text); // Attach data to grid var source = new BindingSource(); source.DataSource = arrayList.FindAll(line => line.Material == selMaterial); searchGrid.DataSource = source; } } } catch (Exception) { throw; } }