public void selectStore(string path) { StreamReader readFile = new StreamReader(path); string line; storesList.Items.Clear(); try { if (Path.GetFileName(path) == "StoreCodes.csv") { CBItem AllStores = new CBItem(); AllStores.Content = "Select a Store"; storesList.Items.Add(AllStores); storesList.SelectedItem = AllStores; //reads the stores and populates combobox while ((line = readFile.ReadLine()) != null) { String[] split = line.Split(','); CBItem item = new CBItem(); item.Value = split[0]; item.Content = split[1]; storesList.Items.Add(item); } } else { Dispatcher.Invoke(new Action(() => { MessageBox.Show("Please select file named: StoreCodes.csv"); })); } } catch (Exception) { Dispatcher.Invoke(new Action(() => { MessageBox.Show("Error loading stores"); })); } }
private void GUI_Update() { //Task will wait until the files have been parsed generateData.getFilesTask.Wait(); //The parsed data object will be stored in a new list result = new List <Order>(generateData.getFilesTask.Result); //Hashset are used to remove duplicates HashSet <string> suppliers = new HashSet <string>(); HashSet <string> types = new HashSet <string>(); HashSet <int> yearsHash = new HashSet <int>(); for (int i = 0; i < result.Count(); i++) { if (result[i].Supplier != null) { suppliers.Add(result[i].Supplier); } if (result[i].Type != null) { types.Add(result[i].Type); } if (result[i].Year.ToString() != null) { yearsHash.Add(result[i].Year); } } Console.WriteLine("End Hashset"); //Prints data to user Dispatcher.Invoke(new Action(() => { itemsParsedCount.Content = result.Count(); reportGrid.ItemsSource = result; CBItem itemSupplier = new CBItem(); itemSupplier.Content = "Select a Supplier"; supplierList.Items.Add(itemSupplier); supplierList.SelectedItem = itemSupplier; CBItem itemType = new CBItem(); itemType.Content = "Select Supplier Type"; supplierTypeList.Items.Add(itemType); supplierTypeList.SelectedItem = itemType; CBItem yearItem = new CBItem(); yearItem.Content = "Select Year"; yearsList.Items.Add(yearItem); yearsList.SelectedItem = yearItem; //Populates comboboxes foreach (var supplierItem in suppliers) { CBItem itemAdd = new CBItem(); itemAdd.Content = supplierItem; supplierList.Items.Add(itemAdd); } foreach (var typeItem in types) { if (typeItem != null) { CBItem itemAdd = new CBItem(); itemAdd.Content = typeItem; supplierTypeList.Items.Add(itemAdd); } } foreach (var yearFound in yearsHash) { int y = yearFound; CBItem itemAdd = new CBItem(); itemAdd.Content = y.ToString(); yearsList.Items.Add(itemAdd); } //End timer and set status to complete sW.Stop(); if (cancelTask.IsCancellationRequested) { status.Content = "Action Canceled"; } else { status.Content = "Done"; } timeTaken.Content = sW.Elapsed; cancelBtn.Visibility = Visibility.Hidden; loading.Visibility = Visibility.Hidden; })); }