Пример #1
0
        public static X12BaseDataType CreateX12DataTypeFromXmlSchema(XmlSchemaElement element, bool bDesignTime, string dataTypeName, string stringMinL, string stringMaxL)
        {
            if (string.IsNullOrEmpty(dataTypeName))
            {
                dataTypeName = "STRING";
            }

            else
            {
                dataTypeName = dataTypeName.ToUpper();
            }

            X12BaseDataType dataType = null;
            int             minL, maxL;

            minL = maxL = -1;
            Dictionary <string, string> allowedValues = null;

            if (string.Equals(dataTypeName, IDNew_DataTypeName, StringComparison.OrdinalIgnoreCase))
            {
                allowedValues = DataTypeHelper.RetrieveFacetMetadata(element, stringMinL, stringMaxL, out minL, out maxL);
            }

            switch (dataTypeName)
            {
            case RNew_DataTypeName:
                dataType = new X12_RDataType(RNew_DataTypeName, minL, maxL);
                break;

            case "STRING":
            case "SYSTEM.STRING":
            case EFACT_A_DataTypeName:
            case EFACT_AN_DataTypeName:
            case ANNew_DataTypeName:
                dataType = new X12_AnDataType(ANNew_DataTypeName, minL, maxL);
                break;

            case IDNew_DataTypeName:
                dataType = new X12_IdDataType(IDNew_DataTypeName, allowedValues);
                break;

            case DateNew_DataTypeName:
                dataType = new X12_DtDataType(DateNew_DataTypeName, minL, maxL);
                break;

            case TimeNew_DataTypeName:
                dataType = new X12_TmDataType(TimeNew_DataTypeName, minL, maxL);
                break;

            case EFACT_N_DataTypeName:
            case NNew_DataTypeName:
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            default:
                if (dataTypeName.Length == 2 && dataTypeName.StartsWith("N", StringComparison.Ordinal) &&
                    dataTypeName[1] >= '0' && dataTypeName[1] <= '9')
                {
                    dataType = X12_NDataType.GetDataTypeWithPrecision(dataTypeName[1] - '0',
                                                                      minL, maxL);
                }

                else
                {
                    throw new Exception(string.Format("{0} data type is not supported", dataTypeName));
                }

                break;
            }

            return(dataType);
        }
Пример #2
0
        public static X12BaseDataType CreateX12DataTypeFromXmlSchema2(XmlSchemaElement element, bool bDesignTime)
        {
            string          dataTypeName;
            X12BaseDataType dataType = null;
            XmlSchemaSimpleTypeRestriction restriction = null;
            int minL, maxL;

            minL = maxL = -1;
            Dictionary <string, string> sortedList = null;

            if (element.ElementType is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType sType = (XmlSchemaSimpleType)element.ElementType;
                XmlQualifiedName    name  = sType.QualifiedName;
                dataTypeName = sType.Name;

                restriction = sType.Content as XmlSchemaSimpleTypeRestriction;
                if (restriction != null)
                {
                    dataTypeName = name.Name != null && name.Name.StartsWith(ID_DataTypeName, StringComparison.Ordinal)
                        ? ID_DataTypeName : restriction.BaseTypeName.Name;
                    sortedList = DataTypeHelper.RetrieveFacets(restriction, out minL, out maxL);
                }
                //Console.WriteLine("Element name = " + element.Name + " SimpleType name = " + dataTypeName);
            }

            else
            {
                XmlSchemaDatatype dType = (XmlSchemaDatatype)element.ElementType;
                dataTypeName = dType.ValueType.ToString();
                //Console.WriteLine("Element name = " + element.Name + " DataType name = " + dType.ValueType);
            }

            switch (dataTypeName.ToUpper())
            {
            case R_DataTypeName:
                dataType = new X12_RDataType(R_DataTypeName, minL, maxL);
                break;

            case "STRING":
            case "SYSTEM.STRING":
            case EFACT_A_DataTypeName:
            case EFACT_AN_DataTypeName:
            case AN_DataTypeName:
                dataType = new X12_AnDataType(AN_DataTypeName, minL, maxL);
                break;

            case ID_DataTypeName:
                dataType = new X12_IdDataType(ID_DataTypeName, sortedList);
                break;

            case Date_DataTypeName:
                dataType = new X12_DtDataType(Date_DataTypeName, minL, maxL);
                break;

            case Time_DataTypeName:
                dataType = new X12_TmDataType(Time_DataTypeName, minL, maxL);
                break;

            case EFACT_N_DataTypeName:
            case N_DataTypeName:
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            default:
                if (dataTypeName.Length == 6 && dataTypeName.StartsWith("X12_N", StringComparison.Ordinal) &&
                    dataTypeName[5] >= '0' && dataTypeName[5] <= '9')
                {
                    dataType = X12_NDataType.GetDataTypeWithPrecision(dataTypeName[5] - '0',
                                                                      minL, maxL);
                }

                else
                {
                    //throw new Exception(string.Format("{0} data type is not supported", dataTypeName));
                    dataType = new X12_AnDataType(AN_DataTypeName, -1, -1);
                }

                break;
            }

            return(dataType);
        }