Ejemplo n.º 1
0
        public void Import(string fileName)
        {
            int lineHeader = 0;

            Sample2 sample2Layout = new Sample2();

            ImportFile = new ImportFile(sample2Layout);
            if (ImportFile.PrepareFile(fileName))
            {
                Lines.Clear();

                while (ImportFile.ReadLine() && !ImportFile.ReadFailure)
                {
                    Lines.Append(ImportFile.Line + Environment.NewLine);

                    //The Sample2 line Identifier is encountered in column 1
                    //Delimited layout should always mark the column identifier
                    ImportFile.SetIdentificadorCorrente(ImportFile.CurrentLine["Col_1"].ToString());

                    switch ((Sample2.RecordType) int.Parse(ImportFile.CurrentIdentifier))
                    {
                    case Sample2.RecordType.Header:

                        lineHeader = ImportFile.CurrentLineNumber;
                        sample2Layout.HeaderRows.Add(new Sample2.HeaderRow(ImportFile.CurrentLine));
                        sample2Layout.HeaderRows.Last().LineNumber = ImportFile.CurrentLineNumber;
                        break;

                    case Sample2.RecordType.Detail:

                        sample2Layout.DetailRows.Add(new Sample2.DetailRow(ImportFile.CurrentLine));
                        sample2Layout.DetailRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        sample2Layout.DetailRows.Last().ParentLineNumber = lineHeader;
                        break;

                    case Sample2.RecordType.Trailer:
                        sample2Layout.TrailerRows.Add(new Sample2.TrailerRow(ImportFile.CurrentLine));
                        sample2Layout.TrailerRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        sample2Layout.TrailerRows.Last().ParentLineNumber = lineHeader;
                        break;
                    }

                    if (this.ImportOnlyFirstLine)
                    {
                        break;
                    }
                }

                if (ImportFile.Error)
                {
                    AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
                }
            }
            else
            {
                AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
            }
        }
Ejemplo n.º 2
0
        public void Import(string fileName)
        {
            int lineHeader    = 0;
            int linePagamento = 0;
            int lineSOC       = 0;

            Amex amexLayout = new Amex();

            ImportFile = new ImportFile(amexLayout);
            if (ImportFile.PrepareFile(fileName))
            {
                Lines.Clear();

                while (ImportFile.ReadLine() && !ImportFile.ReadFailure)
                {
                    Lines.Append(ImportFile.Line + Environment.NewLine);

                    //The Amex line Identifier is encountered in column 6
                    //Delimited layout should always mark the column identifier
                    ImportFile.SetIdentificadorCorrente(ImportFile.CurrentLine["Col_6"].ToString());

                    switch ((Amex.RecordType) int.Parse(ImportFile.CurrentIdentifier))
                    {
                    case Amex.RecordType.Header:

                        lineHeader = ImportFile.CurrentLineNumber;
                        amexLayout.HeaderRows.Add(new Amex.HeaderRow(ImportFile.CurrentLine));
                        amexLayout.HeaderRows.Last().LineNumber = ImportFile.CurrentLineNumber;
                        break;

                    case Amex.RecordType.Pagamento:

                        linePagamento = ImportFile.CurrentLineNumber;
                        amexLayout.PagamentoRows.Add(new Amex.PagamentoRow(ImportFile.CurrentLine));
                        amexLayout.PagamentoRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.PagamentoRows.Last().ParentLineNumber = lineHeader;
                        break;

                    case Amex.RecordType.SOC:

                        lineSOC = ImportFile.CurrentLineNumber;
                        amexLayout.SOCRows.Add(new Amex.SOCRow(ImportFile.CurrentLine));
                        amexLayout.SOCRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.SOCRows.Last().ParentLineNumber = linePagamento;
                        break;

                    case Amex.RecordType.ROC:
                        amexLayout.ROCRows.Add(new Amex.ROCRow(ImportFile.CurrentLine));
                        amexLayout.ROCRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.ROCRows.Last().ParentLineNumber = lineSOC;
                        break;

                    case Amex.RecordType.Ajustes:
                        amexLayout.AjustesRows.Add(new Amex.AjustesRow(ImportFile.CurrentLine));
                        amexLayout.AjustesRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.AjustesRows.Last().ParentLineNumber = linePagamento;
                        break;

                    case Amex.RecordType.Trailer:
                        amexLayout.TrailerRows.Add(new Amex.TrailerRow(ImportFile.CurrentLine));
                        amexLayout.TrailerRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.TrailerRows.Last().ParentLineNumber = lineHeader;
                        break;
                    }

                    if (this.ImportOnlyFirstLine)
                    {
                        break;
                    }
                }

                if (ImportFile.Error)
                {
                    AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
                }
            }
            else
            {
                AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
            }
        }