Beispiel #1
0
        /// <summary>
        /// 从pdm中读取表信息
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static List <TableInfo> ReaderPdm(string path)
        {
            //加载xml
            XmlDocument xml = ReadPdmToXml(path);

            _xmlnsManager = new XmlNamespaceManager(xml.NameTable);
            _xmlnsManager.AddNamespace("a", "attribute");
            _xmlnsManager.AddNamespace("c", "collection");
            _xmlnsManager.AddNamespace("o", "object");

            //获取数据库类型
            DataBaseType dbType = ReadDBType(xml);

            List <TableInfo> list = new List <TableInfo>();
            //获取表
            XmlNodeList nodes = xml.SelectNodes(_tbPath, _xmlnsManager);

            foreach (XmlNode item in nodes)
            {
                //读取表信息
                TableInfo table = new TableInfo();
                table.Name   = GetNodeText(item, "a:Code");
                table.Desc   = TBFieldHelper.FormatDesc(GetNodeText(item, "a:Name"));
                table.Fields = new List <TBField>();

                //获取主键字段Id
                List <string> primaryKey_oids = ReadPrimaryKey(item);
                //获取字段
                XmlNodeList fields = item.SelectNodes("c:Columns//o:Column", _xmlnsManager);
                foreach (XmlNode xnitem in fields)
                {
                    TBField field = new TBField();
                    if (primaryKey_oids.Find(x => x == GetNodeAttrVal(xnitem, "Id")) != null)
                    {
                        field.IsPrimaryKey = true;
                    }
                    field.Name       = GetNodeText(xnitem, "a:Code");
                    field.Length     = GetNodeText <int>(xnitem, "a:Length");
                    field.Precision  = GetNodeText <int>(xnitem, "a:Precision");
                    field.IsRequired = GetNodeText <int>(xnitem, "a:Column.Mandatory") == 1 ? true : false;
                    field.DataType   = GetNodeText(xnitem, "a:DataType");
                    field.Default    = GetNodeText(xnitem, "a:DefaultValue");
                    field.FieldType  = TBFieldHelper.GetFieldType(
                        field.Name,
                        GetNodeText(xnitem, "a:DataType"),
                        dbType,
                        () => { return(field.Length); },
                        () => { return(field.Precision); });
                    field.Desc = TBFieldHelper.FormatDesc(GetNodeText(xnitem, "a:Name"));
                    TBFieldHelper.DealEnum(field, GetNodeText(xnitem, "a:Comment"));
                    table.Fields.Add(field);
                }
                list.Add(table);
            }
            return(list);
        }
Beispiel #2
0
        /// <summary>
        /// 处理枚举
        /// 枚举条件:有换行符,以及有等号,并且数据类型包含int
        /// </summary>
        /// <param name="field">对应字段信息</param>
        /// <param name="comment">pdm中的comment</param>
        public static void DealEnum(TBField field, string comment)
        {
            if (comment.IndexOf("\n") >= 0)
            {
                if (comment.IndexOf("=") >= 0 && field.FieldType.ToLower().IndexOf("int") >= 0)//枚举处理
                {
                    if (EnumList == null)
                    {
                        EnumList = new List <EnumModel>();
                    }

                    field.FieldType = field.Name;//枚举名称,默认为字段名称

                    //去重
                    if (EnumList.Find(x => x.EnumName == field.Name) == null)
                    {
                        EnumList.Add(new EnumModel(field.Name, comment, field.Desc));
                    }
                }
            }
        }