Beispiel #1
0
        public TransactionSet(EdiTools.FunctionalGroup parent, EdiTools.Index[] indexes)
        {
            _parent  = parent;
            _indexes = indexes;

            EdiTools.Index st = indexes[0];
            EdiTools.Index se = indexes[indexes.Length - 1];

            string[] elements = st.Split();
            _st       = new EdiTools.ST();
            _st.ST01  = elements[1];
            _st.ST02  = elements[2];
            _st.Index = st;

            elements  = se.Split();
            _se       = new EdiTools.SE();
            _se.SE01  = elements[1];
            _se.SE02  = elements[2];
            _se.Index = se;
        }
Beispiel #2
0
        public EdiFile(string filePath)
        {
            try
            {
                this._rawtext = System.IO.File.ReadAllText(filePath);
                if (this._rawtext.Substring(0, 3) != "ISA")
                {
                    throw new System.IO.InvalidDataException("No ISA segment found. Not an EDI file.");
                }
                _delimiter.Element   = _rawtext[103];
                _delimiter.Component = _rawtext[104];
                _delimiter.Segment   = _rawtext[105];

                /* Determine if wrapped (no line breaks) or unwrapped (line breaks) */
                if (_rawtext[106] == (char)13 || _rawtext[106] == (char)10) /* carriage-return or new-line */
                {
                    _isunwrapped = true;

                    if (_rawtext[107] == (char)10) /* if the next char is new-line, assume cr/lf */
                    {
                        _delimiter.Line = _rawtext.Substring(106, 2);
                    }
                    else
                    {
                        _delimiter.Line = _rawtext[106].ToString();
                    }
                }

                _filename      = System.IO.Path.GetFileName(filePath);
                _directoryname = System.IO.Path.GetDirectoryName(filePath);

                // start position and length for every segment/line in the file. The foundation for parsing the file
                _fileindexes = this.GetIndexes();

                // to parse interchange
                EdiTools.Index isa = new EdiTools.Index(this);
                EdiTools.Index iea = new EdiTools.Index(this);

                // to parse functional groups
                System.Collections.Generic.List <EdiTools.FunctionalGroup> functionalGroups = new System.Collections.Generic.List <FunctionalGroup>();

                EdiTools.Index gs = new EdiTools.Index(this);
                EdiTools.Index ge = new EdiTools.Index(this);

                foreach (EdiTools.Index idx in _fileindexes)
                {
                    // interchange
                    if (idx.Name == "ISA")
                    {
                        isa = idx;
                    }
                    if (idx.Name == "IEA")
                    {
                        iea          = idx;
                        _interchange = new EdiTools.Interchange(this, isa, iea);
                    }

                    // functional group
                    if (idx.Name == "GS")
                    {
                        gs = idx;
                    }

                    // GE is the end of a functional group, so add to the functional group collection
                    if (idx.Name == "GE")
                    {
                        ge = idx;
                        EdiTools.FunctionalGroup group = new EdiTools.FunctionalGroup(this, gs, ge);
                        functionalGroups.Add(group);
                    }
                }

                _functionalgroups = functionalGroups.ToArray();
            }
            catch (System.Exception)
            {
                throw;
            }
        }