Beispiel #1
1
        // UNCHECKBOXIZE -- item-name
        private void ProcessUncheckboxize(string[] commands)
        {
            const string UncheckboxizeNameFormat = "{0}_{1}";
            const string UncheckboxizeValueSetSuffix = "_VS1";

            Item item = (Item)GetSymbolFromName(commands[1],SymbolTypes.Item);

            if( !item.Alpha )
                throw new Exception(String.Format(Messages.UncheckboxizeNotAlpha,item.Name));

            if( item.ValueSets.Count == 0 )
                throw new Exception(String.Format(Messages.UncheckboxizedNoValueSet,item.Name));

            List<Value> checkboxValues = item.ValueSets[0].Values;
            int maxValueWidth = 0;

            foreach( Value value in checkboxValues )
                maxValueWidth = Math.Max(maxValueWidth,value.Pairs[0].From.Trim().Length);

            if( maxValueWidth == 0 || item.Length % maxValueWidth != 0 )
                throw new Exception(String.Format(Messages.UncheckboxizedNotValidCheckbox,item.Name,item.ValueSets[0].Name,maxValueWidth,item.Length));

            int numCheckboxes = item.Length / maxValueWidth;

            // make sure that all of the names (to be created) are valid and available
            for( int occ = 0; occ < numCheckboxes; occ++ )
            {
                string newName = null;

                try
                {
                    newName = String.Format(UncheckboxizeNameFormat,item.Name,occ + 1);
                    CheckIfValidNewName(item.ParentDictionary,newName);

                    newName = newName + UncheckboxizeValueSetSuffix;
                    CheckIfValidNewName(item.ParentDictionary,newName);
                }

                catch( Exception )
                {
                    throw new Exception(String.Format(Messages.UnsubitemizeNameInvalid,item.Name,newName));
                }
            }

            // remove the old item
            int itemIndex = item.ParentRecord.Items.IndexOf(item);
            item.ParentRecord.Items.RemoveAt(itemIndex);

            // create the new items
            ValueSet baseVS = null;

            for( int occ = 0; occ < numCheckboxes; occ++ )
            {
                Item newItem = new Item(item.ParentRecord);
                newItem.ParentRecord.Items.Insert(itemIndex + occ,newItem);

                newItem.Name = String.Format(UncheckboxizeNameFormat,item.Name,occ + 1);
                newItem.Label = occ < checkboxValues.Count ? String.Format("{0} ({1})",item.Label,checkboxValues[occ].Label) : item.Label;

                newItem.Start = item.Start + maxValueWidth * occ;
                newItem.Occurrences = 1;

                newItem.Note = item.Note;
                newItem.Length = maxValueWidth;
                newItem.Numeric = true;
                newItem.Subitem = item.Subitem;
                newItem.ZeroFill = item.ParentDictionary.ZeroFillDefault;

                ValueSet vs = null;

                // add the value set
                if( baseVS == null )
                {
                    Value uncheckedValue = new Value();
                    uncheckedValue.Label = "Unchecked";
                    uncheckedValue.Pairs.Add(new ValuePair("0"));

                    Value checkedValue = new Value();
                    checkedValue.Label = "Checked";
                    checkedValue.Pairs.Add(new ValuePair("1"));

                    baseVS = new ValueSet(newItem);
                    baseVS.AddValue(uncheckedValue);
                    baseVS.AddValue(checkedValue);

                    vs = baseVS;
                }

                else
                {
                    if( baseVS.LinkID == Int32.MinValue )
                        baseVS.LinkID = DataDictionaryWorker.GetNewValueSetLinkID(item.ParentDictionary);

                    vs = new ValueSet(newItem);
                    vs.EstablishValueSetLink(baseVS);
                }

                vs.Name = String.Format(UncheckboxizeNameFormat,item.Name,occ + 1) + UncheckboxizeValueSetSuffix;
                vs.Label = newItem.Label;

                newItem.AddValueSet(vs);
            }

            SetOutputSuccess(String.Format(Messages.UncheckboxizedSuccess,item.Name,numCheckboxes));
        }
Beispiel #2
0
        private string LoadValueSet()
        {
            _valueset = new ValueSet(_item);
            _vsValue = null;

            string line;
            bool firstName = true;

            while( ( line = ReadTrimmedLine() ) != null && !IsHeader(line) )
            {
                string argument,value;

                ParseLine(line,out argument,out value);

                // special parsing for the name
                if( argument.Equals(DataDictionaryElements.DICT_NAME,StringComparison.InvariantCultureIgnoreCase) )
                {
                    if( firstName )
                    {
                        _valueset.Name = value.ToUpper();
                        firstName = false;
                    }

                    else
                    {
                        int commaPos = value.IndexOf(',');

                        if( commaPos < 0 )
                            throw new DataDictionaryReaderException(line);

                        string specialVal,description;

                        specialVal = value.Substring(0,commaPos);
                        description = value.Substring(commaPos + 1);

                        if( !description.Equals(DataDictionaryElements.VALUE_SPECIAL,StringComparison.InvariantCultureIgnoreCase) )
                            throw new DataDictionaryReaderException(line);

                        else if( specialVal.Equals(DataDictionaryElements.VALUE_MISSING,StringComparison.InvariantCultureIgnoreCase) )
                            _vsValue.SpecialValue = Value.Special.Missing;

                        else if( specialVal.Equals(DataDictionaryElements.VALUE_NOTAPPL,StringComparison.InvariantCultureIgnoreCase) )
                            _vsValue.SpecialValue = Value.Special.NotApplicable;

                        else if( specialVal.Equals(DataDictionaryElements.VALUE_DEFAULT,StringComparison.InvariantCultureIgnoreCase) )
                            _vsValue.SpecialValue = Value.Special.Default;

                        else
                            throw new DataDictionaryReaderException(line);
                    }
                }

                // a value (not value set) note
                else if( _vsValue != null && argument.Equals(DataDictionaryElements.DICT_NOTE,StringComparison.InvariantCultureIgnoreCase) )
                    _vsValue.Note = AppendNote(_vsValue.Note,value);

                else if( AssignSharedComponents(_valueset,argument,value) ) // the value set label and note will be handled here
                {
                }

                else if( argument.Equals(DataDictionaryElements.VALUE_LINK,StringComparison.InvariantCultureIgnoreCase) )
                {
                    int linkID = Int32.Parse(value,CultureInfo.InvariantCulture);

                    if( _vsLinks.ContainsKey(linkID) )
                        _valueset.EstablishValueSetLink(_vsLinks[linkID]);

                    else
                    {
                        _valueset.LinkID = linkID;
                        _vsLinks.Add(linkID,_valueset);
                    }
                }

                else if( argument.Equals(DataDictionaryElements.VALUE_VALUE,StringComparison.InvariantCultureIgnoreCase) )
                {
                    _vsValue = new Value();
                    AddValues(value);
                    _valueset.AddValue(_vsValue);
                }

                else if( argument.Equals(DataDictionaryElements.VALUE_IMAGE,StringComparison.InvariantCultureIgnoreCase) )
                    _vsValue.ImageFilename = Paths.MakeAbsolutePath(Path.GetDirectoryName(_filename),value);

                else
                    throw new DataDictionaryReaderException(line);
            }

            _item.AddValueSet(_valueset);

            return line;
        }
Beispiel #3
0
        public Value(Value value)
        {
            _pairs = new List<ValuePair>();
            Label = value.Label;
            SpecialValue = value.SpecialValue;

            for( int i = 0; i < value.Pairs.Count; i++ )
                AddValuePair(new ValuePair(value.Pairs[i]));
        }
Beispiel #4
0
 public void AddValue(Value value)
 {
     _values.Add(value);
 }
Beispiel #5
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));
        }