private void importCSVDialogOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.DefaultExt = ".csv"; // Default file extension openFileDialog.Filter = "Comma separated values (.csv)|*.csv"; // Filter files by extension if (openFileDialog.ShowDialog() == true) { try { int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(openFileDialog.FileName); webReportNames.Clear(); while ((line = file.ReadLine()) != null) { if (counter != 0) { WebRecord parsed = parseCSVLine(line); if (parsed != null) { webReportNames.Add(parsed); } } counter++; } file.Close(); } catch { string message = "Nelze načíst soubor"; string caption = "Chyba"; MessageBoxButton buttons = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Error; MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon); } } showData(); }
private void updateBtn_Click(object sender, RoutedEventArgs e) { WebRecord webSelectedItem = webOnlyDataGrid.SelectedCells .Select(cell => (WebRecord)cell.Item).First(); ComputerRecord localSelected = localRecordDataGrid.SelectedCells .Select(cell => (ComputerRecord)cell.Item).First(); localSelected.CName = webSelectedItem.Name; webOnlyDataGrid.UnselectAll(); localRecordDataGrid.UnselectAll(); //List<ComputerRecord> sourceTmp = (List<ComputerRecord>) localRecordDataGrid.ItemsSource; //localRecordDataGrid.ItemsSource = null; //localRecordDataGrid.ItemsSource = sourceTmp; showDiff(); }
private WebRecord parseCSVLine(string csv) { string[] values = csv.Split(','); WebRecord record = new WebRecord(); try { record.Name = values[0].Trim(); record.Product = values[1].Trim(); record.Status = values[2].Trim(); record.Expiration = values[3].Trim(); } catch { if (record.Name == "") { return(null); } } return(record); }