Ejemplo n.º 1
0
        /// <summary>
        /// Check if current data value should be processed (mainly for conditional fields). For values
        /// which do not match a condition, the StringReader is set back to the previous position. If
        /// an optional fields does not define a condition or predefined value and the datavalue matches
        /// next EOR, that EOR is written.
        /// </summary>
        /// <param name="recordIndex"></param>
        /// <param name="theRecId"></param>
        /// <param name="fmtRec"></param>
        /// <param name="fieldRow"></param>
        /// <param name="eor"></param>
        /// <param name="dataValue"></param>
        /// <returns></returns>
        private bool CheckValueForProcessing(int recordIndex, RecordIdentifier theRecId, FormattedDataDataset.RecordRow fmtRec, LayoutDataset.FieldRow fieldRow, LayoutDataset.FieldRow eor, string dataValue)
        {
            if ((!fieldRow.IsIsOptionalNull()) && (fieldRow.IsOptional))
            {
                // optional values are identified either by predefined values
                // or by conditions


                if ((!fieldRow.IsConditionNull()) && (fieldRow.Condition.Length > 0))
                {
                    string condExpression = "((RecordName = '" + theRecId.RecordName + "') and (RecordIndex = '" + recordIndex + "'))";
                    condExpression = condExpression + " and (" + fieldRow.Condition + ")";

                    Condition cond = new Condition(condExpression, ds.Field);

                    if (!cond.IsConditionTrue())
                    {
                        // go back
                        return(false);
                    }
                    return(true);
                }

                if ((!fieldRow.IsPredefinedValueNull()) &&
                    (fieldRow.PredefinedValue.Length > 0))
                {
                    // field has predefined value, check and roll back if no match
                    if (!layout.Escape(fieldRow.PredefinedValue).Equals(dataValue))
                    {
                        return(false);
                    }

                    return(true);
                }

                if (eor != null)
                {
                    // optional field has no condition and no predefined value,
                    // compare current data against next EOR, maybe record is
                    // already finished
                    string seor = layout.Escape(eor.PredefinedValue);
                    if (dataValue.Substring(0, seor.Length).Equals(seor))
                    {
                        FormattedDataDataset.FieldRow fmtField = ds.Field.NewFieldRow();
                        fmtField.Name        = eor.Name;
                        fmtField.RecordName  = fmtRec.Name;
                        fmtField.RecordIndex = recordIndex;
                        fmtField.Description = eor.IsDescriptionNull() ? "" : fieldRow.Description;
                        fmtField.Value       = seor;
                        fmtField.Index       = eor.Index;
                        fmtField.Length      = eor.Length;

                        ds.Field.AddFieldRow(fmtField);

                        this.idx += seor.Length;
                        // datavalue already written, do not process again
                        return(false);
                    }
                    return(true);
                }

                throw new Exception("Parse error: optional field " + fieldRow.Name + " must have condition or predefined value.");
            }

            return(true);
        }
Ejemplo n.º 2
0
        private void FormatRecord(int recordIndex, RecordIdentifier theRecId)
        {
            LayoutDataset.FieldRow[]       fields;
            FormattedDataDataset.RecordRow fmtRec = ds.Record.NewRecordRow();
            fmtRec.Name   = theRecId.RecordName;
            fmtRec.Index  = recordIndex;
            fmtRec.Hidden = theRecId.HideInFormattedView;
            ds.Record.AddRecordRow(fmtRec);

            // b. process this record and move position accordingly
            fields = (LayoutDataset.FieldRow[])layout.DataSet.Field.Select("RecordName = '" + theRecId.RecordName + "'", "Index");

            logger.Log(Logger.MessageType.DEBUG, "Parsing " + fields.Length + " fields ...");

            int fieldIndex = 0;

            for (; fieldIndex < fields.Length; fieldIndex++)
            {
                bool indexMoved = false;
                LayoutDataset.FieldRow fieldRow = fields[fieldIndex];
                LayoutDataset.FieldRow eor      = GetNextEorField(theRecId, fieldRow, recordIndex);

                string dataValue = null;

                if (fieldRow.Length < 0)
                {
                    dataValue  = GetVariableLengthValue(fields, fieldIndex, fieldRow);
                    indexMoved = true;
                }
                else
                {
                    dataValue = GetString(0, fieldRow.Length);
                }

                if (dataValue != null)
                {
                    bool processField = CheckValueForProcessing(recordIndex, theRecId, fmtRec, fieldRow, eor, dataValue);

                    if (processField)
                    {
                        FormattedDataDataset.FieldRow fmtField = ds.Field.NewFieldRow();
                        fmtField.Name        = fieldRow.Name;
                        fmtField.RecordName  = fmtRec.Name;
                        fmtField.RecordIndex = recordIndex;
                        fmtField.Description = fieldRow.IsDescriptionNull() ? "" : fieldRow.Description;
                        fmtField.Value       = dataValue;
                        fmtField.Index       = fieldRow.Index;
                        fmtField.Length      = fieldRow.Length;

                        ds.Field.AddFieldRow(fmtField);

                        if (!indexMoved)
                        {
                            this.idx += dataValue.Length;
                        }
                    }
                }
                else if (!indexMoved && !fieldRow.IsLengthNull())
                {
                    // if data field was not set, still move index
                    this.idx += fieldRow.Length;
                }
            }
        }