/// <summary> /// /// </summary> /// <param name="allLines"></param> /// <param name="ares"></param> /// <returns></returns> private List <RawDataRow> ParseDataLines(List <string> allLines, IOResults ares, char delimeter) { List <RawDataRow> dt = new List <RawDataRow>(); char[] splitArray = new char[3]; // set up the delimiting characters splitArray[0] = delimeter; int fileLineNumber = 1; foreach (string ln in allLines) { try { string[] items = splitQuoted(ln, delimeter); // string[] items = ln.Split(splitArray, StringSplitOptions.None); RawDataRow rdr = new RawDataRow(); rdr.dataItems = new List <string>(items); dt.Add(rdr); } catch (Exception ex) { // error parsing the line, or casting the objects ares.errorMessage += ex.ToString(); } fileLineNumber++; } return(dt); }
//public CsvRow() //{ // Date = ""; // Transaction = ""; // Category = ""; // Amount = ""; // Balance = ""; // SubCategory = ""; //} public CsvRow(RawDataRow dataRow) { Date = dataRow.GetDate(); Transaction = dataRow.GetTransaction(); Category = dataRow.GetCategory(); Amount = dataRow.GetAmount(); Balance = dataRow.GetBalance(); SubCategory = "Unset"; }
public void Parse(CT2UnPacker lpUnPack) { for (int i = 0, dsLen = lpUnPack.GetDatasetCount(); i < dsLen; i++) { RawDataSet dataSet = new RawDataSet(); dataSet.Rows = new List <RawDataRow>(); //设置当前结果集 lpUnPack.SetCurrentDatasetByIndex(i); Dictionary <int, string> columnDic = new Dictionary <int, string>(); //数据包中字段 for (int j = 0, hLen = lpUnPack.GetColCount(); j < hLen; j++) { columnDic.Add(j, lpUnPack.GetColName(j)); } //所有记录 for (int k = 0, rLen = (int)lpUnPack.GetRowCount(); k < rLen; k++) { RawDataRow row = new RawDataRow(); row.Columns = new Dictionary <string, DataValue>(); //每条记录 for (int t = 0, cLen = lpUnPack.GetColCount(); t < cLen; t++) { string colName = columnDic[t]; DataValue dataValue = new DataValue(); switch (lpUnPack.GetColType(t)) { case (sbyte)'I': //I 整数 { dataValue.Type = DataValueType.Int; dataValue.Value = lpUnPack.GetIntByIndex(t); } break; case (sbyte)'C': //C { dataValue.Type = DataValueType.Char; dataValue.Value = lpUnPack.GetCharByIndex(t); } break; case (sbyte)'S': //S { dataValue.Type = DataValueType.String; dataValue.Value = lpUnPack.GetStrByIndex(t); } break; case (sbyte)'F': //F { dataValue.Type = DataValueType.Float; dataValue.Value = lpUnPack.GetDoubleByIndex(t); } break; case (sbyte)'R': //R { break; } default: // 未知数据类型 break; } if (!row.Columns.ContainsKey(colName)) { row.Columns.Add(colName, dataValue); } }//end to read all column for each row dataSet.Rows.Add(row); Console.WriteLine(); lpUnPack.Next(); }//end to read rows _dataSets.Add(dataSet); } }
internal void ResetTable(List <DataRecords.RawDataRow> dt, bool _firstLineIsHeader) { dtTMP = dt; // get the number of columns to display //int maxCols = 0; firstLineIsHeader = _firstLineIsHeader; /*foreach (RawDataRow r in dt) * { * int ct = r.dataItems.Count; * * maxCols = Math.Max(ct, maxCols); * }*/ var counter = dt.Max(x => x.dataItems.Count()); columnNames = new Dictionary <string, int>(); RawDataRow rdr = dt[0]; List <string> newBMFieldList = new List <string>(); foreach (ColumnMetaInfo ss in bmRequiredFields) { newBMFieldList.Add(ss.columnName); } foreach (ColumnMetaInfo ss in bmOptionalFields) { newBMFieldList.Add(ss.columnName); } for (int i = 0; i < counter; i++) { bool errorinColumn = false; var col1 = new DataGridTextColumn(); ComboBox dropDown = new ComboBox(); dropDown.Width = 80; dropDown.HorizontalAlignment = HorizontalAlignment.Stretch; List <string> cli = new List <string>(); cli.Add(rdr.dataItems[i]); cli.Add(""); List <string> fields = new List <string>(); fields = newBMFieldList; // add in the optional fields foreach (string req in fields) { cli.Add("->" + req + " (" + rdr.dataItems[i] + ")"); } try { columnNames.Add(rdr.dataItems[i], i); } catch (Exception ex) { if (ex is ArgumentException) //i.e. column names are probably not unique, drop out with a more useful error message { if (!errorinColumn) { MessageBox.Show(String.Format("Column {0}, \"{1}\" in file: {2} is a duplicate, please ensure all column headings are unique, removing column for import. There may be other errors (showing only this one).", i, rdr.dataItems[i], ((NKD.Import.Client.MainWindow)(((System.Delegate)(this.ColumnsMapped)).Target)).SelectedFile)); } errorinColumn = true; } } if (!errorinColumn) { dropDown.SelectionChanged += new SelectionChangedEventHandler(dropDown_SelectionChanged); dropDown.ItemsSource = cli; dropDown.SelectedValue = ""; col1.Header = dropDown; col1.Binding = new Binding("dataItems[" + i + "]"); PreviewGrid.Columns.Add(col1); } } PreviewGrid.ItemsSource = dt; isFileLoaded = true; }