private void backgroundWorkerConversion_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <int> SelectionIndexList = new List <int>(); if (!consoleMode) { listView1.Invoke((MethodInvoker) delegate { listView1.BeginUpdate(); listView1.Columns.Clear(); listView1.VirtualListSize = 0; }); } WriteLog("Start Processing", true); String filename = CSVFileName; Stream stream = File.OpenRead(filename); if (filename.EndsWith("gz")) { stream = new GZipStream(stream, System.IO.Compression.CompressionMode.Decompress); } using (var reader = new StreamReader(stream)) { var data = CsvParser.ParseHeadAndTail(reader, ',', '"'); var header = data.Item1; var lines = data.Item2; ListViewHeader.Clear(); ListViewData.Clear(); // filter the available columns by the ones selected in the GUI and store the index // and the column names for the actual list, also create the header line for (int i = 0; i < header.Count; i++) { if (SelectionList.Contains(header[i])) { SelectionIndexList.Add(i); ListViewHeader.Add(header[i]); } } WriteLog("Colums to scan: " + header.Count.ToString(), true); // Now go through the lines and build both the CSV output and the content of // the listview int linecount = 0; foreach (var line in lines) { if (backgroundWorkerConversion.CancellationPending) { break; } List <String> SelectionRow = new List <string>(); foreach (var Index in SelectionIndexList) { if (line.Count > Index && !string.IsNullOrEmpty(line[Index])) { SelectionRow.Add(line[Index]); } else { SelectionRow.Add("0"); } } ListViewData.Add(SelectionRow); if ((linecount++ % 100) == 0) { int progress = (linecount / 100) % 100; if (worker != null) { worker.ReportProgress(progress); } } } } if (backgroundWorkerConversion.CancellationPending) { e.Cancel = true; } if (!consoleMode) { listView1.Invoke((MethodInvoker) delegate { foreach (var Header in ListViewHeader.GetRange(0, ListViewHeader.Count > 100 ? 100 : ListViewHeader.Count)) { listView1.Columns.Add(Header, 100); } listView1.VirtualListSize = ListViewData.Count; listView1.EndUpdate(); }); } WriteLog("Processing finished", true); TableFinshed = true; SetButtonStatus(); }
private void StartConversionBtn_Click(object sender, EventArgs e) { if (File.Exists(openFileDialog1.FileName)) { if (SelectionList.Count > 0) { WriteLog("Start Processing"); listView1.BeginUpdate(); listView1.ListViewItemSorter = null; listView1.Clear(); rows.Clear(); using (var stream = File.OpenRead(openFileDialog1.FileName)) using (var reader = new StreamReader(stream)) { var data = CsvParser.ParseHeadAndTail(reader, ',', '"'); var header = data.Item1; var lines = data.Item2; SelectionIndexList.Clear(); for (int i = 0; i < header.Count; i++) { if (SelectionList.Contains(header[i])) { SelectionIndexList.Add(i); } } WriteLog("Colums to scan: " + header.Count.ToString()); listView1.View = View.Details; listView1.GridLines = true; listView1.FullRowSelect = true; string[] arr = new string[SelectionList.Count + 1]; ListViewItem itm; headerLine = ""; for (var i = 0; i < SelectionIndexList.Count; i++) { if (showValuesCB.Checked) { listView1.Columns.Add(header[SelectionIndexList[i]], 100); } headerLine += "\"" + header[SelectionIndexList[i]] + "\","; } string tempLine; foreach (var line in lines) { tempLine = ""; for (int i = 0; i < SelectionIndexList.Count; i++) { if (line.Count > SelectionIndexList[i]) { if (!string.IsNullOrEmpty(line[SelectionIndexList[i]])) { arr[i] = line[SelectionIndexList[i]]; tempLine += "\"" + line[SelectionIndexList[i]] + "\","; } else { arr[i] = ""; tempLine += "\"" + "0" + "\","; } } else { arr[i] = ""; } } itm = new ListViewItem(arr); if (showValuesCB.Checked) { listView1.Items.Add(itm); } rows.Add(tempLine); } } listView1.EndUpdate();; WriteLog("Processing finished"); Log.ScrollToCaret(); } else { MessageBox.Show("No Columns selected"); } } else { MessageBox.Show("No valid CSV File choosen"); } }
private void BuildTreeView() { treeView1.Nodes.Clear(); TreeNode node; int CharCount = charCountTrb.Value; Stream stream = File.OpenRead(CSVFilename); if (CSVFilename.EndsWith("gz")) { stream = new GZipStream(stream, System.IO.Compression.CompressionMode.Decompress); } using (var reader = new StreamReader(stream)) { var data = CsvParser.ParseHeadAndTail(reader, ',', '"'); var header = data.Item1; var lines = data.Item2; node = treeView1.Nodes.Add(header[0]); string Start; string Item = header[0]; string ItemStart; string NextItem; string NextItemStart; Start = Item.Substring(0, Item.Length > CharCount ? CharCount : Item.Length); for (var i = 1; i < header.Count; i++) { Item = header[i]; ItemStart = Item.Substring(0, Item.Length > CharCount ? CharCount : Item.Length); if (i < header.Count - 1) { NextItem = header[i + 1]; NextItemStart = NextItem.Substring(0, NextItem.Length > CharCount ? CharCount : NextItem.Length); } else { NextItem = ""; NextItemStart = ""; } if (Item.Substring(0, Item.Length > CharCount ? CharCount : Item.Length) == Start) { node.Nodes.Add(Item); } else { if (NextItemStart == ItemStart) { node = treeView1.Nodes.Add(Item.Substring(0, Item.Length > CharCount ? CharCount : Item.Length)); node.Nodes.Add(Item); } else { node = treeView1.Nodes.Add(Item); } Start = Item.Substring(0, Item.Length > CharCount ? CharCount : Item.Length); } } // if (selectionList.Count > 0) SetCheckStatus(); SearchTreeView(false, SearchTb.Text); } }