protected void ReadBasicRowData(ExcelWorksheet schemaWorksheet, SchemaRow schemaRow, int row)
        {
            if (row > schemaWorksheet.Dimension.End.Row)
            {
                return;
            }

            schemaRow.MandatoryCode   = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, MandatoryCodeIndex);
            schemaRow.DataType        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, DataTypeIndex);
            schemaRow.MinMaxLength    = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, MinMaxIndex);
            schemaRow.EnumCode        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, EnumCodeIndex);
            schemaRow.EnumName        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, EnumNameIndex);
            schemaRow.EnumFlag        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, EnumFlagIndex, true);
            schemaRow.MandatoryFlag   = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, MandatoryFlagIndex, true);
            schemaRow.IgnoreFlag      = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, IgnoreFlagIndex, true);
            schemaRow.Contingencies   = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, ContingenciesIndex, true);
            schemaRow.ContingencyType = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, ContingencyTypeIndex, true);

            if (TriggerFieldIndex != -1)
            {
                string triggerFieldText = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, TriggerFieldIndex, true);
                if (string.IsNullOrWhiteSpace(triggerFieldText) == false && triggerFieldText.Trim().ToUpperInvariant().Equals(TriggerFieldValue))
                {
                    schemaRow.IsTriggerField = true;
                }
            }

            if (string.IsNullOrWhiteSpace(schemaRow.EnumFlag))
            {
                schemaRow.EnumFlag = "?";
            }

            if (string.IsNullOrWhiteSpace(schemaRow.MandatoryFlag))
            {
                schemaRow.MandatoryFlag = "";
            }

            if (string.IsNullOrWhiteSpace(schemaRow.IgnoreFlag))
            {
                schemaRow.IgnoreFlag = "P";
            }
        }
        // crossSegmentPointer = Path to data element followed by expected value in "[]" e.g. HLO->REF->REF01[PK]
        private void AddIdValue(SchemaRow segmentRow, int row, string crossSegmentPointer, List <string> optionalValues, Dictionary <string, string> allowedValues, Dictionary <string, Contingency> contingencies)
        {
            allowedValues.Add(segmentRow.EnumCode, segmentRow.EnumName);

            if (string.Compare(segmentRow.IgnoreFlag, "I", true) == 0 || string.Compare(segmentRow.EnumFlag, "?", true) == 0)
            {
                optionalValues.Add(segmentRow.EnumCode);
            }

            if (string.IsNullOrWhiteSpace(segmentRow.ContingencyType) == false)
            {
                segmentRow.ContingencyType = segmentRow.ContingencyType.Trim();
                if (string.Compare(segmentRow.ContingencyType, "E", true) != 0 && string.Compare(segmentRow.ContingencyType, "CS", true) != 0)
                {
                    AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(ContingencyTypeIndex), string.Format("Invalid contingency type {0}", segmentRow.ContingencyType));
                }
                else
                {
                    Contingency contingency = new Contingency();
                    if (string.Compare(segmentRow.ContingencyType, "E", true) == 0)
                    {
                        contingency.Type = ContingencyType.Enumeration;
                    }
                    else
                    if (string.Compare(segmentRow.ContingencyType, "CS", true) == 0)
                    {
                        contingency.Type = ContingencyType.CrossSegment;
                    }

                    AddPendingContingencies(row, segmentRow.Contingencies, contingency);
                    ResolveContingency(row, crossSegmentPointer, segmentRow.EnumCode);

                    contingencies.Add(segmentRow.EnumCode, contingency);
                }
            }
        }
        protected X12BaseDataType ReadDataType(SchemaRow segmentRow, ExcelWorksheet schemaWorksheet, string segmentPath, ref int row)
        {
            List <string> optionalValues = new List <string>();
            Dictionary <string, string>      allowedValues = new Dictionary <string, string>();
            Dictionary <string, Contingency> contingencies = new Dictionary <string, Contingency>();
            X12BaseDataType dataType;
            string          dataTypeName = segmentRow.DataType;
            string          currentTag   = segmentRow.GetDataElementTag();
            int             dataTypeRow  = row - 1;

            // In sample schema ISA016 has data type blank hence AN and default is set to AN
            if (string.IsNullOrEmpty(dataTypeName) == true)
            {
                dataTypeName = "AN";
                AddValidationResult(ResultType.Warning, dataTypeRow, GCExcelReaderHelper.GetColumnIndex(DataTypeIndex),
                                    string.Format("'{0}' segment is missing data type, treating it as AlphaNumeric", currentTag));
            }

            int minL, maxL;

            GetMinMax(segmentRow.MinMaxLength, row, out minL, out maxL);

            // add current row enum code if present
            if (string.IsNullOrWhiteSpace(segmentRow.EnumCode) == false && string.Compare(segmentRow.EnumFlag, "n", true) != 0)
            {
                AddIdValue(segmentRow, row, string.Format("{0}[{1}]", segmentPath, segmentRow.EnumCode), optionalValues, allowedValues, contingencies);
            }

            // Traverse all sub rows - these rows are mostly relevant for enums (containing enum values)
            // however sample schema shows multiple rows for other data types too
            while ((segmentRow = ReadRow(schemaWorksheet, row)) != null)
            {
                if ((string.IsNullOrEmpty(segmentRow.GetDataElementTag()) == false && string.Compare(segmentRow.GetDataElementTag(), currentTag, true) != 0) ||
                    IsDataTypeRowsOver(segmentRow, row))
                {
                    break;
                }

                switch (dataTypeName)
                {
                case "ID":
                    if (string.IsNullOrEmpty(segmentRow.EnumCode) == false && string.Compare(segmentRow.EnumFlag, "n", true) != 0)
                    {
                        AddIdValue(segmentRow, row, string.Format("{0}[{1}]", segmentPath, segmentRow.EnumCode), optionalValues, allowedValues, contingencies);
                    }
                    break;

                case "DT":
                case "AN":
                case "N0":
                case "N2":
                case "TM":
                case "R":
                    break;

                default:
                    //AddValidationResult(ResultType.Error, row, GetColumnIndex(EnumCodeIndex), string.Format("Unknown data type {0}", dataTypeName));
                    //throw new SchemaReaderException(string.Format("Unknown data type {0} on row {1}", dataTypeName, row));
                    break;
                }
                ++row;
            }

            switch (dataTypeName)
            {
            case "ID":
                if (allowedValues == null || allowedValues.Count == 0)
                {
                    dataType = new X12_AnDataType(dataTypeName, minL, maxL);
                    AddValidationResult(ResultType.Warning, dataTypeRow, GCExcelReaderHelper.GetColumnIndex(EnumCodeIndex),
                                        string.Format("'{0}' segment has ID type without any values, treating it as AlphaNumeric.", currentTag));
                }
                else
                {
                    dataType = new X12_IdDataType(dataTypeName, optionalValues, allowedValues, contingencies);
                }
                break;

            case "DT":
                dataType = new X12_DtDataType(dataTypeName, minL, maxL);
                break;

            case "Comp":
            case "AN":
                dataType = new X12_AnDataType(dataTypeName, minL, maxL);
                break;

            case "N":
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            case "N0":
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            case "N2":
                dataType = X12_NDataType.GetDataTypeWithPrecision(2, minL, maxL);
                break;

            case "TM":
                dataType = new X12_TmDataType(dataTypeName, minL, maxL);
                break;

            case "R":
                dataType = new X12_RDataType(dataTypeName, minL, maxL);
                break;

            default:
                AddValidationResult(ResultType.Error, dataTypeRow, GCExcelReaderHelper.GetColumnIndex(EnumCodeIndex), string.Format("Unknown data type {0}", dataTypeName));
                dataType = new X12_AnDataType(dataTypeName, minL, maxL);     // This is to avoid compiler error.
                //throw new SchemaReaderException(string.Format("Unknown data type {0} on row {1}", dataTypeName, row));
                break;
            }

            return(dataType);
        }
 protected abstract bool IsDataTypeRowsOver(SchemaRow schemaRow, int row);
예제 #5
0
        protected override bool IsDataTypeRowsOver(SchemaRow schemaRow, int row)
        {
            FlatFileSchemaRow flatFileSchemaRow = schemaRow as FlatFileSchemaRow;

            return(string.IsNullOrEmpty(flatFileSchemaRow.Segment) == false);
        }
 protected override bool IsDataTypeRowsOver(SchemaRow schemaRow, int row)
 {
     // TODO: read all segments and check data type is over
     return(false);
 }
 protected override bool IsDataTypeRowsOver(SchemaRow schemaRow, int row)
 {
     // no special check for X12
     return(false);
 }