// parse the CSV file internal Collection<RepairOrder> Parse(Stream stream) { var items = new Collection<RepairOrder>(); int max = _MaxPreview; int ret = max; if (_ShowAll | 0 == max) { max = 0; } else { max = _MaxPreview + 1; } CSV file = new CSV(stream, hasHeaders: true, charDelimiter:',', charQuote:'"', charEscapeQuote:'\\', fileEncoding:Encoding.UTF8, maxRecords:max, name:Title); DataTable table = file.ToDataTable(); if (null == table) { _Proxy.NoticeLog(string.Format("EBS Bulk Import cannot parse file {0} id {1}. Cannot create data table.", Title, FileId), null); _JobStatus = JobStatus.ParseError; stream.Dispose(); items.Clear(); return items; } stream.Dispose(); DataRowCollection rows = table.Rows; int rowCount = rows.Count; ret = rowCount; if (0 == rowCount || (rowCount <= _MaxPreview) || (0 == max)) { _LoadedAll = true; IsShowAllEnabled = false; } else if (rowCount == (_MaxPreview + 1)) { _LoadedAll = false; IsShowAllEnabled = true; ret = rowCount - 1; } else { _LoadedAll = false; IsShowAllEnabled = true; } int i = 0; foreach (DataRow row in rows) { if (++i > ret) { break; } var item = new RepairOrder( this, this._Model.EbsSrId, Convert.ToString(row.Field<object>("PROBLEM_DESCRIPTION")), 0, Convert.ToString(row.Field<object>("APPROVAL_REQUIRED_FLAG")), Convert.ToDecimal(row.Field<object>("REPAIR_TYPE_ID")), Convert.ToDecimal(row.Field<object>("QUANTITY")), Convert.ToString(row.Field<object>("UNIT_OF_MEASURE")), Convert.ToString(row.Field<object>("CURRENCY_CODE")), 0 ); item.SerialNumber = Convert.ToString(row.Field<object>("SERIAL_NUMBER")); items.Add(item); } return items; }
// parse the CSV file internal Collection <RepairOrder> Parse(Stream stream) { var items = new Collection <RepairOrder>(); int max = _MaxPreview; int ret = max; if (_ShowAll | 0 == max) { max = 0; } else { max = _MaxPreview + 1; } CSV file = new CSV(stream, hasHeaders: true, charDelimiter: ',', charQuote: '"', charEscapeQuote: '\\', fileEncoding: Encoding.UTF8, maxRecords: max, name: Title); DataTable table = file.ToDataTable(); if (null == table) { _Proxy.NoticeLog(string.Format("EBS Bulk Import cannot parse file {0} id {1}. Cannot create data table.", Title, FileId), null); _JobStatus = JobStatus.ParseError; stream.Dispose(); items.Clear(); return(items); } stream.Dispose(); DataRowCollection rows = table.Rows; int rowCount = rows.Count; ret = rowCount; if (0 == rowCount || (rowCount <= _MaxPreview) || (0 == max)) { _LoadedAll = true; IsShowAllEnabled = false; } else if (rowCount == (_MaxPreview + 1)) { _LoadedAll = false; IsShowAllEnabled = true; ret = rowCount - 1; } else { _LoadedAll = false; IsShowAllEnabled = true; } int i = 0; foreach (DataRow row in rows) { if (++i > ret) { break; } var item = new RepairOrder( this, this._Model.EbsSrId, Convert.ToString(row.Field <object>("PROBLEM_DESCRIPTION")), 0, Convert.ToString(row.Field <object>("APPROVAL_REQUIRED_FLAG")), Convert.ToDecimal(row.Field <object>("REPAIR_TYPE_ID")), Convert.ToDecimal(row.Field <object>("QUANTITY")), Convert.ToString(row.Field <object>("UNIT_OF_MEASURE")), Convert.ToString(row.Field <object>("CURRENCY_CODE")), 0 ); item.SerialNumber = Convert.ToString(row.Field <object>("SERIAL_NUMBER")); items.Add(item); } return(items); }