public override ExtractStatus Extract(ExcelFileReader recordSource) { V v = new V(); if (null != this.PropertySetter) { this.PropertySetter(this, this.Target, v); } return(ExtractValues(v, recordSource)); }
public override ExtractStatus Extract(ExcelFileReader recordSource) { dynamic v = null; try { v = recordSource.Extract(this.ColumnNo); this.Value = (V)v; } catch (Exception exc) { throw new Exception(this.FieldInfo + " value=" + (v == null ? "[null]" : "\"" + v.ToString() + "\""), exc); } return(null == this.PropertySetter ? ExtractStatus.Success : this.PropertySetter(this, this.Target, this.Value)); }
public virtual ExtractStatus Import(ExcelFileReader recordSource) { recordSource.Next(); try { ExtractStatus r = this.Extract(recordSource); if (r == ExtractStatus.ValueMismatched) { recordSource.Previous(); } return(r); } catch (Exception exc) { throw new Exception(string.Format("Line {0} : ", recordSource.LineNo), exc); } }
//public virtual ExtractStatus Extract(ExcelFileReader recordSource) //{ // if (this.SignatureFieldMapper == null) // { // if (this.Value == null) // this.Value = new V(); // } // else // { // this.SignatureFieldMapper.Target = this.Value; // ExtractStatus r = this.SignatureFieldMapper.Extract(recordSource); // if (r != ExtractStatus.Success) // return r; // if (this.Value == null) // this.Value = this.SignatureFieldMapper.Target; // } // return ExtractValues(this.Value, recordSource); //} public virtual ExtractStatus ExtractValues(V v, ExcelFileReader recordSource) { ExtractStatus r = ExtractStatus.Success; if (null != this.FieldMappers) { foreach (var f in this.FieldMappers) { f.Target = v; r = f.Extract(recordSource); if (r != ExtractStatus.Success) { break; } } } return(r); }
/// <summary> /// Import records to create an instance of T that would be put in the property Value. /// </summary> /// <param name="reader"></param> /// <returns></returns> public override ExtractStatus Import(ExcelFileReader reader) { this.HeaderMapper.Value = null; ExtractStatus r = this.HeaderMapper.Import(reader); if (r != ExtractStatus.Success) { return(r); } this.Target = this.DetailMapper.Target = this.FooterMapper.Value = this.HeaderMapper.Value; r = this.DetailMapper.Import(reader); if (r == ExtractStatus.Success) { reader.Next(); r = this.FooterMapper.Extract(reader); } return(r); }
public override ExtractStatus Import(String filePath, out T t) { ExcelFileReader reader = null; t = null; ExtractStatus r = ExtractStatus.Success; try { reader = new ExcelFileReader(filePath); if (null != this.OnImportStartHandler) { this.OnImportStartHandler(filePath, t); } r = this.RecordMapping.Import(reader); if (r == ExtractStatus.Success) { t = this.RecordMapping.Target; reader.Close(); if (null != this.OnImportFinishHandler) { this.OnImportFinishHandler(filePath, t); } } } catch (Exception exc) { reader.Close(); if (!(exc is EndOfStreamException)) { throw exc; } } return(r); }
public override IList <T> Import(String filePath) { IList <T> records = new List <T>(); if (null == this.RecordMapping) { throw new iSabayaException(Messages.DetailRecordFormatNotDefined); } ExcelFileReader excelFileReader = new ExcelFileReader(filePath); //read and process the first line excelFileReader.CurrentRowNo = this.LineNoOfFirstDetailRecord; this.RecordBuffer = (Worksheet)excelFileReader.Next(); Range endRow = this.RecordBuffer.get_Range("A1", Missing.Value).get_End(XlDirection.xlDown); int endRowNo = endRow.Row; //for (excelFileReader.CurrentRowNo = this.LineNoOfFirstDetailRecord; excelFileReader.CurrentRowNo <= endRowNo; ++excelFileReader.CurrentRowNo) // records.Add(this.RecordMapping.Import(excelFileReader)); excelFileReader.Close(); return(records); }
public override ExtractStatus Extract(ExcelFileReader recordSource) { dynamic v = null; try { v = recordSource.Extract(this.ColumnNo); this.Value = (V)v; } catch (Exception exc) { throw new Exception(this.FieldInfo + " value=" + (v == null ? "[null]" : "\"" + v.ToString() + "\""), exc); } ExtractStatus r = ExtractStatus.Success; if (null == this.InstanceCreator) { if (this.Value.Equals(SignatureValue)) { if (this.Target == null) { this.Target = new T(); } } else { return(ExtractStatus.ValueMismatched); } } else { this.Target = this.InstanceCreator(this, this.Value); } return(r); }
public abstract ExtractStatus Extract(ExcelFileReader recordSource);
public override ExtractStatus Import(ExcelFileReader reader) { return(this.Import <T, V>(reader)); }