Ejemplo n.º 1
0
        private sctParseValueLocation CreateLocation(String Location)
        {
            sctParseValueLocation rtnLocation = new sctParseValueLocation();

            Char[]   RepeatDelimiter = new Char[] { repeatDelimiter };
            String[] RepeatSearch    = Location.Split(RepeatDelimiter);
            if (RepeatSearch.Length > 1)
            {
                rtnLocation.RepeatLocation = Convert.ToInt32(RepeatSearch[1]);
            }
            Location = RepeatSearch[0];

            rtnLocation.Segment = Location.Substring(0, 3);
            if (Location.Length > 3)
            {
                Char[]   LocationDelimiter = new Char[] { locationDelimiter };
                String[] Search            = Location.Substring(3).Split(LocationDelimiter);
                rtnLocation.Field = Convert.ToInt16(Search[0]);
                if (Search.Length > 1)
                {
                    rtnLocation.Component = Convert.ToInt16(Search[1]);
                    if (Search.Length > 2)
                    {
                        rtnLocation.Subcomponent = Convert.ToInt16(Search[2]);
                    }
                    else
                    {
                        rtnLocation.Subcomponent = 0;
                    }
                }
                else
                {
                    rtnLocation.Component    = 0;
                    rtnLocation.Subcomponent = 0;
                }
            }
            else
            {
                rtnLocation.Field        = 0;
                rtnLocation.Component    = 0;
                rtnLocation.Subcomponent = 0;
            }


            return(rtnLocation);
        }
Ejemplo n.º 2
0
        private List <String> FindValues(String ValueLocation, String NewValue = null)
        {
            if (!messageLoaded)
            {
                return(new List <string>(0));
            }
            Int32 l = 0;
            sctParseValueLocation Locate       = CreateLocation(ValueLocation);
            List <String>         returnValues = new List <string>();

            foreach (clsSegment s in message.Segments)
            {
                if (s.Name == Locate.Segment)
                {
                    if (Locate.Field == 0)
                    {
                        l++;
                        if (l == Locate.RepeatLocation || Locate.RepeatLocation == 0)
                        {
                            returnValues.Add("");
                            returnValues[returnValues.Count - 1] = s.Value;
                        }
                    }
                    else
                    {
                        foreach (clsField f in s.Fields)
                        {
                            if (f.Location == Locate.Field)
                            {
                                if (Locate.Component == 0)
                                {
                                    l++;
                                    if (l == Locate.RepeatLocation || Locate.RepeatLocation == 0)
                                    {
                                        returnValues.Add("");
                                        returnValues[returnValues.Count - 1] = f.Value;
                                        if (NewValue != null)
                                        {
                                            f.Value = NewValue;
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (clsComponent c in f.Components)
                                    {
                                        if (c.Location == Locate.Component)
                                        {
                                            if (Locate.Subcomponent == 0)
                                            {
                                                l++;
                                                if (l == Locate.RepeatLocation || Locate.RepeatLocation == 0)
                                                {
                                                    returnValues.Add("");
                                                    returnValues[returnValues.Count - 1] = c.Value;
                                                    if (NewValue != null)
                                                    {
                                                        c.Value = NewValue;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                foreach (clsSubcomponent sc in c.Subcomponents)
                                                {
                                                    l++;
                                                    if (l == Locate.RepeatLocation || Locate.RepeatLocation == 0)
                                                    {
                                                        returnValues.Add("");
                                                        returnValues[returnValues.Count - 1] = sc.Value;
                                                        if (NewValue != null)
                                                        {
                                                            sc.Value = NewValue;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


            return(returnValues);
        }
        public Boolean FindValue(String ValueLocation)
        {
            try
            {
                parsedValue.Clear();
                sctParseValueLocation newLocation = CreateLocation(ValueLocation);

                Char[] SegmentDelimiter      = new Char[] { delimiters[0], delimiters[1] };
                Char[] FieldDelimiter        = new Char[] { delimiters[2] };
                Char[] ComponentDelimiter    = new Char[] { delimiters[3] };
                Char[] SubcomponentDelimiter = new Char[] { delimiters[6] };
                Char[] RepeatDelimiter       = new Char[] { delimiters[4] };


                String[] Segments = message.Split(SegmentDelimiter);
                int      v        = 0;
                for (int s = 0; s < Segments.Length; s++) //Move through Segments
                {
                    try
                    {
                        if (Segments[s].Length > 4 && Segments[s].Substring(0, 3) == newLocation.Segment) //Check to see if Sebement matches Search
                        {
                            parsedValue.Add("");
                            parsedValue[v] = Segments[s];
                            string tmpSeg;
                            if (Segments[s].Substring(0, 3) != "MSH")
                            {
                                tmpSeg = Segments[s].Substring(4);
                            }
                            else
                            {
                                tmpSeg = Segments[s];
                            }
                            if (newLocation.Field > 0)
                            {
                                String[] Fields = tmpSeg.Split(FieldDelimiter);
                                if (Fields.Length >= newLocation.Field)
                                {
                                    parsedValue[v] = Fields[newLocation.Field - 1];
                                    if (newLocation.Component > 0)
                                    {
                                        String[] ComponenetGroups = parsedValue[v].Split(RepeatDelimiter);
                                        for (Int32 g = 0; g < ComponenetGroups.Length; g++)
                                        {
                                            if (g > 0)
                                            {
                                                v++;
                                                parsedValue.Add("");
                                            }
                                            String[] Componenets = ComponenetGroups[g].Split(ComponentDelimiter);
                                            if (Componenets.Length >= newLocation.Component)
                                            {
                                                parsedValue[v] = Componenets[newLocation.Component - 1];
                                                if (newLocation.Subcomponent > 0)
                                                {
                                                    String[] Subcomponenets = parsedValue[v].Split(SubcomponentDelimiter);
                                                    if (Subcomponenets.Length >= newLocation.Subcomponent)
                                                    {
                                                        parsedValue[v] = Subcomponenets[newLocation.Subcomponent - 1];
                                                    }
                                                    else
                                                    {
                                                        return(false);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            v++;
                        }
                    }
                    catch (Exception ex)
                    {
                        parsedValue.Add("1: " + ex.Message);
                        return(true);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                parsedValue.Add("2: " + ex.Message);
                return(true);
            }
        }