1. /// <summary>
  2. /// 处理PDM文件
  3. /// </summary>
  4. public class DoPDMDal:IDoDataBaseDal
  5. {
  6. public List<DataBaseInfo> GetDataBaseTable()
  7. {
  8. XmlDocument xmlDoc = new XmlDocument();
  9. xmlDoc.Load(AppSettings.PdmFilePath);
  10. XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);
  11. xmlnsManager.AddNamespace("a", "attribute");
  12. xmlnsManager.AddNamespace("c", "collection");
  13. xmlnsManager.AddNamespace("o", "object");
  14. XmlNode xnTables = xmlDoc.SelectSingleNode("//" + "c:Tables", xmlnsManager);
  15.  
  16. List<PDMTableInfo> Tables = new List<PDMTableInfo>();
  17. foreach (XmlNode xnTable in xnTables.ChildNodes)
  18. {
  19. Tables.Add(GetTable(xnTable));
  20. }
  21. List<DataBaseInfo> list = new List<DataBaseInfo>();
  22.  
  23. foreach (var m in Tables)
  24. {
  25. DataBaseInfo entity = new DataBaseInfo();
  26. entity.TableName=m.Code;
  27. list.Add(entity);
  28. }
  29. return list;
  30. }
  31.  
  32. public List<TableInfo> GetTableColumnName(string tableName)
  33. {
  34. XmlDocument xmlDoc = new XmlDocument();
  35. xmlDoc.Load(AppSettings.PdmFilePath);
  36. XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);
  37. xmlnsManager.AddNamespace("a", "attribute");
  38. xmlnsManager.AddNamespace("c", "collection");
  39. xmlnsManager.AddNamespace("o", "object");
  40. XmlNode xnTables = xmlDoc.SelectSingleNode("//" + "c:Tables", xmlnsManager);
  41.  
  42. List<PDMColumnInfo> list = new List<PDMColumnInfo>();
  43. foreach (XmlNode xnTable in xnTables.ChildNodes)
  44. {
  45.  
  46. PDMTableInfo entity = GetTable(xnTable);
  47. if(entity.Code==tableName)
  48. list= GetTable(xnTable).Columns.ToList();
  49. }
  50.  
  51. List<TableInfo> tableInfoList = new List<TableInfo>();
  52. foreach (var m in list)
  53. {
  54. tableInfoList.Add(
  55. new TableInfo()
  56. {
  57. ColumnName=m.Code,
  58. ColumnType=m.DataType
  59. }
  60. );
  61. }
  62. return tableInfoList;
  63. }
  64.  
  65. //初始化"o:Table"的节点
  66. private PDMTableInfo GetTable(XmlNode xnTable)
  67. {
  68. PDMTableInfo mTable = new PDMTableInfo();
  69. XmlElement xe = (XmlElement)xnTable;
  70. mTable.TableId = xe.GetAttribute("Id");
  71. XmlNodeList xnTProperty = xe.ChildNodes;
  72. foreach (XmlNode xnP in xnTProperty)
  73. {
  74. switch (xnP.Name)
  75. {
  76. case "a:ObjectID": mTable.ObjectID = xnP.InnerText;
  77. break;
  78. case "a:Name": mTable.Name = xnP.InnerText;
  79. break;
  80. case "a:Code": mTable.Code = xnP.InnerText;
  81. break;
  82. case "a:CreationDate": mTable.CreationDate = Convert.ToInt32(xnP.InnerText);
  83. break;
  84. case "a:Creator": mTable.Creator = xnP.InnerText;
  85. break;
  86. case "a:ModificationDate": mTable.ModificationDate = Convert.ToInt32(xnP.InnerText);
  87. break;
  88. case "a:Modifier": mTable.Modifier = xnP.InnerText;
  89. break;
  90. case "a:Comment": mTable.Comment = xnP.InnerText;
  91. break;
  92. case "a:PhysicalOptions": mTable.PhysicalOptions = xnP.InnerText;
  93. break;
  94. case "c:Columns": InitColumns(xnP, mTable);
  95. break;
  96. case "c:Keys": InitKeys(xnP, mTable);
  97. break;
  98. }
  99. }
  100. return mTable;
  101. }
  102. //初始化"c:Columns"的节点
  103. private void InitColumns(XmlNode xnColumns, PDMTableInfo pTable)
  104. {
  105. foreach (XmlNode xnColumn in xnColumns)
  106. {
  107. pTable.AddColumn(GetColumn(xnColumn));
  108. }
  109. }
  110.  
  111. //初始化c:Keys"的节点
  112. private void InitKeys(XmlNode xnKeys, PDMTableInfo pTable)
  113. {
  114. foreach (XmlNode xnKey in xnKeys)
  115. {
  116. pTable.AddKey(GetKey(xnKey));
  117. }
  118. }
  119.  
  120. private PDMColumnInfo GetColumn(XmlNode xnColumn)
  121. {
  122. PDMColumnInfo mColumn = new PDMColumnInfo();
  123. XmlElement xe = (XmlElement)xnColumn;
  124. mColumn.ColumnId = xe.GetAttribute("Id");
  125. XmlNodeList xnCProperty = xe.ChildNodes;
  126. foreach (XmlNode xnP in xnCProperty)
  127. {
  128. switch (xnP.Name)
  129. {
  130. case "a:ObjectID": mColumn.ObjectID = xnP.InnerText;
  131. break;
  132. case "a:Name": mColumn.Name = xnP.InnerText;
  133. break;
  134. case "a:Code": mColumn.Code = xnP.InnerText;
  135. break;
  136. case "a:CreationDate": mColumn.CreationDate = Convert.ToInt32(xnP.InnerText);
  137. break;
  138. case "a:Creator": mColumn.Creator = xnP.InnerText;
  139. break;
  140. case "a:ModificationDate": mColumn.ModificationDate = Convert.ToInt32(xnP.InnerText);
  141. break;
  142. case "a:Modifier": mColumn.Modifier = xnP.InnerText;
  143. break;
  144. case "a:Comment": mColumn.Comment = xnP.InnerText;
  145. break;
  146. case "a:DataType": mColumn.DataType = xnP.InnerText;
  147. break;
  148. case "a:Length": mColumn.Length = xnP.InnerText;
  149. break;
  150. case "a:Identity": mColumn.Identity = ConvertToBooleanPG(xnP.InnerText);
  151. break;
  152. case "a:Mandatory": mColumn.Mandatory = ConvertToBooleanPG(xnP.InnerText);
  153. break;
  154. case "a:PhysicalOptions": mColumn.PhysicalOptions = xnP.InnerText;
  155. break;
  156. case "a:ExtendedAttributesText": mColumn.ExtendedAttributesText = xnP.InnerText;
  157. break;
  158. }
  159. }
  160. return mColumn;
  161. }
  162.  
  163. private PDMKey GetKey(XmlNode xnKey)
  164. {
  165. PDMKey mKey = new PDMKey();
  166. XmlElement xe = (XmlElement)xnKey;
  167. mKey.KeyId = xe.GetAttribute("Id");
  168. XmlNodeList xnKProperty = xe.ChildNodes;
  169. foreach (XmlNode xnP in xnKProperty)
  170. {
  171. switch (xnP.Name)
  172. {
  173. case "a:ObjectID": mKey.ObjectID = xnP.InnerText;
  174. break;
  175. case "a:Name": mKey.Name = xnP.InnerText;
  176. break;
  177. case "a:Code": mKey.Code = xnP.InnerText;
  178. break;
  179. case "a:CreationDate": mKey.CreationDate = Convert.ToInt32(xnP.InnerText);
  180. break;
  181. case "a:Creator": mKey.Creator = xnP.InnerText;
  182. break;
  183. case "a:ModificationDate": mKey.ModificationDate = Convert.ToInt32(xnP.InnerText);
  184. break;
  185. case "a:Modifier": mKey.Modifier = xnP.InnerText;
  186. break;
  187. //还差 <c:Key.Columns>
  188. }
  189. }
  190. return mKey;
  191. }
  192.  
  193. private static Boolean ConvertToBooleanPG(Object obj)
  194. {
  195. if (obj != null)
  196. {
  197. string mStr = obj.ToString();
  198. mStr = mStr.ToLower();
  199. if ((mStr.Equals("y") || mStr.Equals("1")) || mStr.Equals("true"))
  200. {
  201. return true;
  202. }
  203. }
  204. return false;
  205. }
  206. }

种个实体:

  1. public class PDMColumnInfo
  2. {
  3. public PDMColumnInfo()
  4. { }
  5.  
  6. string columnId;
  7.  
  8. public string ColumnId
  9. {
  10. get { return columnId; }
  11. set { columnId = value; }
  12. }
  13. string objectID;
  14.  
  15. public string ObjectID
  16. {
  17. get { return objectID; }
  18. set { objectID = value; }
  19. }
  20. string name;
  21.  
  22. public string Name
  23. {
  24. get { return name; }
  25. set { name = value; }
  26. }
  27. string code;
  28.  
  29. public string Code
  30. {
  31. get { return code; }
  32. set { code = value; }
  33. }
  34. int creationDate;
  35.  
  36. public int CreationDate
  37. {
  38. get { return creationDate; }
  39. set { creationDate = value; }
  40. }
  41. string creator;
  42.  
  43. public string Creator
  44. {
  45. get { return creator; }
  46. set { creator = value; }
  47. }
  48. int modificationDate;
  49.  
  50. public int ModificationDate
  51. {
  52. get { return modificationDate; }
  53. set { modificationDate = value; }
  54. }
  55. string modifier;
  56.  
  57. public string Modifier
  58. {
  59. get { return modifier; }
  60. set { modifier = value; }
  61. }
  62. string comment;
  63.  
  64. public string Comment
  65. {
  66. get { return comment; }
  67. set { comment = value; }
  68. }
  69. string dataType;
  70.  
  71. public string DataType
  72. {
  73. get { return dataType; }
  74. set
  75. {
  76. if (value.Contains("nvarchar") || value.Contains("varchar"))
  77. {
  78. value = "string";
  79. }
  80. if (value.Contains("money"))
  81. {
  82. value = "decimal";
  83. }
  84. dataType = value;
  85. }
  86. }
  87. string length;
  88.  
  89. public string Length
  90. {
  91. get { return length; }
  92. set { length = value; }
  93. }
  94. //是否自增量
  95. bool identity;
  96.  
  97. public bool Identity
  98. {
  99. get { return identity; }
  100. set { identity = value; }
  101. }
  102. bool mandatory;
  103. //禁止为空
  104. public bool Mandatory
  105. {
  106. get { return mandatory; }
  107. set { mandatory = value; }
  108. }
  109. string extendedAttributesText;
  110. //扩展属性
  111. public string ExtendedAttributesText
  112. {
  113. get { return extendedAttributesText; }
  114. set { extendedAttributesText = value; }
  115. }
  116. string physicalOptions;
  117.  
  118. public string PhysicalOptions
  119. {
  120. get { return physicalOptions; }
  121. set { physicalOptions = value; }
  122. }
  123. }

  

  1. public class PDMKey
  2. {
  3. public PDMKey()
  4. {
  5. }
  6.  
  7. string keyId;
  8.  
  9. public string KeyId
  10. {
  11. get { return keyId; }
  12. set { keyId = value; }
  13. }
  14. string objectID;
  15.  
  16. public string ObjectID
  17. {
  18. get { return objectID; }
  19. set { objectID = value; }
  20. }
  21. string name;
  22.  
  23. public string Name
  24. {
  25. get { return name; }
  26. set { name = value; }
  27. }
  28. string code;
  29.  
  30. public string Code
  31. {
  32. get { return code; }
  33. set { code = value; }
  34. }
  35. int creationDate;
  36.  
  37. public int CreationDate
  38. {
  39. get { return creationDate; }
  40. set { creationDate = value; }
  41. }
  42. string creator;
  43.  
  44. public string Creator
  45. {
  46. get { return creator; }
  47. set { creator = value; }
  48. }
  49. int modificationDate;
  50.  
  51. public int ModificationDate
  52. {
  53. get { return modificationDate; }
  54. set { modificationDate = value; }
  55. }
  56. string modifier;
  57.  
  58. public string Modifier
  59. {
  60. get { return modifier; }
  61. set { modifier = value; }
  62. }
  63.  
  64. IList<PDMColumnInfo> columns;
  65.  
  66. public IList<PDMColumnInfo> Columns
  67. {
  68. get { return columns; }
  69. }
  70.  
  71. public void AddColumn(PDMColumnInfo mColumn)
  72. {
  73. if (columns == null)
  74. columns = new List<PDMColumnInfo>();
  75. columns.Add(mColumn);
  76. }
  77. }

  

  1. public class PDMTableInfo
  2. {
  3. public PDMTableInfo()
  4. {
  5. }
  6. string tableId;
  7.  
  8. public string TableId
  9. {
  10. get { return tableId; }
  11. set { tableId = value; }
  12. }
  13. string objectID;
  14.  
  15. public string ObjectID
  16. {
  17. get { return objectID; }
  18. set { objectID = value; }
  19. }
  20. string name;
  21.  
  22. public string Name
  23. {
  24. get { return name; }
  25. set { name = value; }
  26. }
  27. string code;
  28.  
  29. public string Code
  30. {
  31. get { return code; }
  32. set { code = value; }
  33. }
  34. int creationDate;
  35.  
  36. public int CreationDate
  37. {
  38. get { return creationDate; }
  39. set { creationDate = value; }
  40. }
  41. string creator;
  42.  
  43. public string Creator
  44. {
  45. get { return creator; }
  46. set { creator = value; }
  47. }
  48. int modificationDate;
  49.  
  50. public int ModificationDate
  51. {
  52. get { return modificationDate; }
  53. set { modificationDate = value; }
  54. }
  55. string modifier;
  56.  
  57. public string Modifier
  58. {
  59. get { return modifier; }
  60. set { modifier = value; }
  61. }
  62. string comment;
  63.  
  64. public string Comment
  65. {
  66. get { return comment; }
  67. set { comment = value; }
  68. }
  69.  
  70. string physicalOptions;
  71.  
  72. public string PhysicalOptions
  73. {
  74. get { return physicalOptions; }
  75. set { physicalOptions = value; }
  76. }
  77.  
  78. IList<PDMColumnInfo> columns;
  79.  
  80. public IList<PDMColumnInfo> Columns
  81. {
  82. get { return columns; }
  83. }
  84.  
  85. IList<PDMKey> keys;
  86.  
  87. public IList<PDMKey> Keys
  88. {
  89. get { return keys; }
  90. }
  91.  
  92. public void AddColumn(PDMColumnInfo mColumn)
  93. {
  94. if (columns == null)
  95. columns = new List<PDMColumnInfo>();
  96. columns.Add(mColumn);
  97. }
  98.  
  99. public void AddKey(PDMKey mKey)
  100. {
  101. if (keys == null)
  102. keys = new List<PDMKey>();
  103. keys.Add(mKey);
  104. }
  105. }

  

代码生成器的关键代码(读取PDM文件)的更多相关文章

  1. 读取Pdm文件内容(含源码)

    Pdm文件,就是PowerDesigner软件生成的文件,用来设计数据库表结构非常适合.其实,它的文件存储格式就是Xml,网上有很多代码,可以读取pdm文件内容.代码可以使用,但一般只能读取简单的pd ...

  2. 分享非常有用的Java程序 (关键代码) (二)---列出文件和目录

    原文:分享非常有用的Java程序 (关键代码) (二)---列出文件和目录 File dir = new File("directoryName"); String[] child ...

  3. Java 代码读取properties文件

    jdk1.6 package read;import java.io.File;import java.io.FileInputStream;import java.io.IOException;im ...

  4. WEB应用中普通java代码如何读取资源文件

    首先: 资源文件分两种:后缀.xml文件和.properties文件 .xml文件:当数据之间有联系时用.xml .properties文件:当数据之间没有联系时用.properties 正题:   ...

  5. C#读取Excel文件,准换为list

    经常会用到,废话不多说直接贴代码 //读取Excel文件 public static DataTable ReadExcelToTable(string path)//excel存放的路径{try{ ...

  6. 基于GDAL库,读取.nc文件(以海洋表温数据为例)C++版

    对于做海洋数据处理的同学,会经常遇到nc格式的文件,nc文件的格式全称是NetCDF,具体的详细解释请查询官网[https://www.unidata.ucar.edu/software/netcdf ...

  7. 分享非常有用的Java程序 (关键代码)(六)---解析/读取XML 文件(重要)

    原文:分享非常有用的Java程序 (关键代码)(六)---解析/读取XML 文件(重要) XML文件 <?xml version="1.0"?> <student ...

  8. paip.powerdesign cdm pdm文件 代码生成器 java web 页面 实现

    paip.powerdesign cdm pdm文件 代码生成器 java web 页面 实现 准备从pd cdm生成java web 页面...但是,ms无直接地生成软件.... 只好自己解析cdm ...

  9. 分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要)

    原文:分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要) Java InputStream读取数据问题 ======== ...

随机推荐

  1. java的反射机制(第二篇)

    本文转载自:http://c.biancheng.net/cpp/html/1781.html 要理解RTTI在Java中的工作原理,首先必须知道类型信息在运行时是如何表示的,这项工作是由“Class ...

  2. noip 1995 灯的排列问题 排列组合 DFS

    题目描述 设在一排上有N个格子(N≤20),若在格子中放置有不同颜色的灯,每种灯的个数记为N1,N2,……Nk(k表示不同颜色灯的个数). 放灯时要遵守下列规则: ①同一种颜色的灯不能分开: ②不同颜 ...

  3. ZOJ 3632 K - Watermelon Full of Water 优先队列优化DP

    K - Watermelon Full of Water Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld &am ...

  4. CGI 、PHP-CGI、FASTCGI、PHP-FPM

    CGI是干嘛的? CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者.web server(比如说nginx)只是内容的分发者.比如,如果请求的是/index/ht ...

  5. redux基础(1)

    redux ps:每个案例都是接着上一个案例写的 主要以案例讲解如何使用,具体概念请参考如下: 基本概念参考1 基本概念参考2 案例源码戳这里 一.Store.Action.Reducer简介 Sto ...

  6. 华为S5300系列升级固件S5300SI-V100R003C00SPC301.cc

    这个固件是升级V100R005的中间件,所以是必经的,注意,这个固件带有http的服务,但现在无论官网还是外面,几乎找不到这个固件的web功能,如果非要实现,可以拿V100R005的web文件改名为w ...

  7. MySQL的mysql.sock文件作用(转)

    mysql.sock是可用于本地服务器的套接字文件.它只是另一种连接机制. 不包含任何数据,但仅用于从客户端到本地服务器来进行交换数据.

  8. SQLite 一款轻型的数据库

    SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp建立的公有领域项目.它的设计目标是嵌入式的,而且目前已经在很多嵌入式产 ...

  9. MVC扩展ActionInvoker,自定义ActionInvoker,根据请求数据返回不同视图

    ActionInvoker的作用是:根据请求数据(HttpPost,HttpGet等)和action名称,来激发响应的action,再由action渲染视图.本文通过自定义ActionInvoker, ...

  10. .NET:CLR via C# Manifest

    An assembly is a collection of one or more files containing type definitions and resource files. One ...