Exemplo n.º 1
0
 public ValuePair(ValuePair vp)
 {
     From = vp.From;
     To = vp.To;
 }
Exemplo n.º 2
0
        private void AddValues(string line)
        {
            line = line.Trim();

            if( line.Length == 0 )
                return;

            ValuePair vp = new ValuePair();

            int semicolonPos = line.IndexOf(';');

            if( semicolonPos == 0 )
            {
                ParseLabel(_vsValue,line.Substring(1));
                return;
            }

            else if( line.IndexOf('\'') == 0 )
            {
                int nextPos = line.IndexOf('\'',1);

                if( nextPos >= 1 )
                {
                    vp.From = line.Substring(1,nextPos - 1);
                    _vsValue.AddValuePair(vp);
                    AddValues(line.Substring(nextPos + 1));
                    return;
                }

                else
                    throw new DataDictionaryReaderException(line);
            }

            else if( line.IndexOf('"') == 0 )
            {
                int nextPos = line.IndexOf('"',1);

                if( nextPos >= 1 )
                {
                    vp.From = line.Substring(1,nextPos - 1);
                    _vsValue.AddValuePair(vp);
                    AddValues(line.Substring(nextPos + 1));
                    return;
                }

                else
                    throw new DataDictionaryReaderException(line);
            }

            string thisValue;
            int spacePos = line.IndexOf(' ');

            if( spacePos > 0 && ( semicolonPos < 0 || spacePos < semicolonPos ) )
                thisValue = line.Substring(0,spacePos);

            else if( semicolonPos >= 0 )
                thisValue = line.Substring(0,semicolonPos);

            else
                thisValue = line;

            int colonPos = line.IndexOf(':');

            if( colonPos >= 0 && ( spacePos < 0 || colonPos < spacePos ) && ( semicolonPos < 0 || colonPos < semicolonPos ) )
            {
                vp.From = Double.Parse(thisValue.Substring(0,colonPos),CultureInfo.InvariantCulture).ToString();
                vp.To = Double.Parse(thisValue.Substring(colonPos + 1),CultureInfo.InvariantCulture).ToString();
            }

            else
                vp.From = Double.Parse(thisValue,CultureInfo.InvariantCulture).ToString();

            _vsValue.AddValuePair(vp);

            if( spacePos > 0 && ( semicolonPos < 0 || spacePos < semicolonPos ) )
                AddValues(line.Substring(spacePos + 1));

            else if( semicolonPos >= 0 )
                AddValues(line.Substring(semicolonPos));

            else
                ParseLabel(_vsValue,"");
        }
Exemplo n.º 3
0
 public void AddValuePair(ValuePair vp)
 {
     _pairs.Add(vp);
 }
Exemplo n.º 4
0
        private void AddValues(string line)
        {
            line = line.Trim();

            if (line.Length == 0)
            {
                return;
            }

            ValuePair vp = new ValuePair();

            int semicolonPos = line.IndexOf(';');

            if (semicolonPos == 0)
            {
                ParseLabel(_vsValue, line.Substring(1));
                return;
            }

            else if (line.IndexOf('\'') == 0)
            {
                int nextPos = line.IndexOf('\'', 1);

                if (nextPos >= 1)
                {
                    vp.From = line.Substring(1, nextPos - 1);
                    _vsValue.AddValuePair(vp);
                    AddValues(line.Substring(nextPos + 1));
                    return;
                }

                else
                {
                    throw new DataDictionaryReaderException(line);
                }
            }

            else if (line.IndexOf('"') == 0)
            {
                int nextPos = line.IndexOf('"', 1);

                if (nextPos >= 1)
                {
                    vp.From = line.Substring(1, nextPos - 1);
                    _vsValue.AddValuePair(vp);
                    AddValues(line.Substring(nextPos + 1));
                    return;
                }

                else
                {
                    throw new DataDictionaryReaderException(line);
                }
            }

            string thisValue;
            int    spacePos = line.IndexOf(' ');

            if (spacePos > 0 && (semicolonPos < 0 || spacePos < semicolonPos))
            {
                thisValue = line.Substring(0, spacePos);
            }

            else if (semicolonPos >= 0)
            {
                thisValue = line.Substring(0, semicolonPos);
            }

            else
            {
                thisValue = line;
            }

            int colonPos = line.IndexOf(':');

            if (colonPos >= 0 && (spacePos < 0 || colonPos < spacePos) && (semicolonPos < 0 || colonPos < semicolonPos))
            {
                vp.From = Double.Parse(thisValue.Substring(0, colonPos), CultureInfo.InvariantCulture).ToString();
                vp.To   = Double.Parse(thisValue.Substring(colonPos + 1), CultureInfo.InvariantCulture).ToString();
            }

            else
            {
                vp.From = Double.Parse(thisValue, CultureInfo.InvariantCulture).ToString();
            }

            _vsValue.AddValuePair(vp);

            if (spacePos > 0 && (semicolonPos < 0 || spacePos < semicolonPos))
            {
                AddValues(line.Substring(spacePos + 1));
            }

            else if (semicolonPos >= 0)
            {
                AddValues(line.Substring(semicolonPos));
            }

            else
            {
                ParseLabel(_vsValue, "");
            }
        }
Exemplo n.º 5
0
 public ValuePair(ValuePair vp)
 {
     From = vp.From;
     To   = vp.To;
 }
Exemplo n.º 6
0
 public void AddValuePair(ValuePair vp)
 {
     _pairs.Add(vp);
 }
Exemplo n.º 7
0
        private void SaveValue(Value value, Item item)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < value.Pairs.Count; i++)
            {
                ValuePair vp = value.Pairs[i];

                // space out multiple pairs
                if (i != 0)
                {
                    sb.Append(' ');
                }

                // blank values get written out with spaces
                if (String.IsNullOrWhiteSpace(vp.From))
                {
                    sb.AppendFormat("'{0}'", new String(' ', item.Length));
                }

                else if (item.Alpha)
                {
                    char separator = vp.From.IndexOf('\'') < 0 ? '\'' : '"';
                    sb.AppendFormat(separator + vp.From + separator);
                }

                else // numeric values
                {
                    sb.Append(GetNumericSaveFormat(vp.From, item.Decimal));

                    if (!String.IsNullOrWhiteSpace(vp.To))
                    {
                        sb.AppendFormat(":{0}", GetNumericSaveFormat(vp.To, item.Decimal));
                    }
                }
            }

            if (!String.IsNullOrWhiteSpace(value.Label))
            {
                sb.AppendFormat(";{0}", GetSaveLabelText(value));
            }

            SaveOption(DataDictionaryElements.VALUE_VALUE, sb.ToString());

            if (value.SpecialValue != Value.Special.None)
            {
                string specialValueText =
                    value.SpecialValue == Value.Special.Missing ? DataDictionaryElements.VALUE_MISSING :
                    value.SpecialValue == Value.Special.NotApplicable ? DataDictionaryElements.VALUE_NOTAPPL :
                    DataDictionaryElements.VALUE_DEFAULT;

                SaveOption(DataDictionaryElements.DICT_NAME, String.Format("{0},{1}", specialValueText, DataDictionaryElements.VALUE_SPECIAL));
            }

            SaveNote(value.Note);

            if (!String.IsNullOrWhiteSpace(value.ImageFilename))
            {
                SaveOption(DataDictionaryElements.VALUE_IMAGE, Paths.MakeRelativePath(Path.GetDirectoryName(_filename), value.ImageFilename));
            }
        }