Beispiel #1
0
        // create read data types in bpp
        public void CreateDataTypes(ref DataTable mappedDataTypes)
        {
            DataTypeManager dataTypeManager = null;

            try
            {
                dataTypeManager = new DataTypeManager();

                foreach (DataRow mappedDataType in mappedDataTypes.Rows)
                {
                    string dtName        = mappedDataType["Name"].ToString();
                    string dtDescription = mappedDataType["Description"].ToString();
                    DataTypeDisplayPattern dtDisplayPettern = new DataTypeDisplayPattern();
                    TypeCode dtSystemType = new TypeCode();
                    foreach (TypeCode type in Enum.GetValues(typeof(TypeCode)))
                    {
                        if (type.ToString().Equals(mappedDataType["SystemType"].ToString()))
                        {
                            dtSystemType = type;
                        }
                    }

                    if (dtSystemType == TypeCode.DateTime)
                    {
                        if (mappedDataType["DisplayPattern"] != null && mappedDataType["DisplayPattern"].ToString() != "")
                        {
                            dtDisplayPettern = DataTypeDisplayPattern.Pattern.Where(p => p.Systemtype.Equals(DataTypeCode.DateTime) && p.Name.Equals(mappedDataType["DisplayPattern"].ToString())).FirstOrDefault();
                        }
                        else
                        {
                            dtDisplayPettern = DataTypeDisplayPattern.Pattern.Where(p => p.Name.Equals("DateTimeIso")).FirstOrDefault();
                        }
                    }

                    DataType dataType = new DataType();
                    // get existing dataTypes
                    DataType existDT = dataTypeManager.Repo.Get().Where(d =>
                                                                        d.Name.Equals(dtName) &&
                                                                        d.SystemType.ToString().Equals(mappedDataType["SystemType"].ToString())
                                                                        ).FirstOrDefault();
                    // return ID of existing dataType or create dataType
                    if (existDT == null && dtSystemType != null)
                    {
                        dataType = dataTypeManager.Create(dtName, dtDescription, dtSystemType);

                        XmlDocument xmlDoc = new XmlDocument();
                        XmlNode     xmlNode;
                        xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Extra", null);
                        xmlDoc.AppendChild(xmlNode);
                        xmlNode          = xmlDoc.CreateNode(XmlNodeType.Element, "DisplayPattern", null);
                        xmlNode.InnerXml = DataTypeDisplayPattern.Dematerialize(dtDisplayPettern).InnerXml;
                        xmlDoc.DocumentElement.AppendChild(xmlNode);
                        dataType.Extra = xmlDoc;

                        dataTypeManager.Update(dataType);
                    }
                    else
                    {
                        dataType = existDT;
                    }

                    mappedDataType["DataTypesId"] = dataType.Id;
                }
            }
            finally
            {
                dataTypeManager.Dispose();
            }
        }