代码生成器的关键代码(读取PDM文件)
/// <summary>
/// 处理PDM文件
/// </summary>
public class DoPDMDal:IDoDataBaseDal
{
public List<DataBaseInfo> GetDataBaseTable()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppSettings.PdmFilePath);
XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);
xmlnsManager.AddNamespace("a", "attribute");
xmlnsManager.AddNamespace("c", "collection");
xmlnsManager.AddNamespace("o", "object");
XmlNode xnTables = xmlDoc.SelectSingleNode("//" + "c:Tables", xmlnsManager); List<PDMTableInfo> Tables = new List<PDMTableInfo>();
foreach (XmlNode xnTable in xnTables.ChildNodes)
{
Tables.Add(GetTable(xnTable));
}
List<DataBaseInfo> list = new List<DataBaseInfo>(); foreach (var m in Tables)
{
DataBaseInfo entity = new DataBaseInfo();
entity.TableName=m.Code;
list.Add(entity);
}
return list;
} public List<TableInfo> GetTableColumnName(string tableName)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppSettings.PdmFilePath);
XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);
xmlnsManager.AddNamespace("a", "attribute");
xmlnsManager.AddNamespace("c", "collection");
xmlnsManager.AddNamespace("o", "object");
XmlNode xnTables = xmlDoc.SelectSingleNode("//" + "c:Tables", xmlnsManager); List<PDMColumnInfo> list = new List<PDMColumnInfo>();
foreach (XmlNode xnTable in xnTables.ChildNodes)
{ PDMTableInfo entity = GetTable(xnTable);
if(entity.Code==tableName)
list= GetTable(xnTable).Columns.ToList();
} List<TableInfo> tableInfoList = new List<TableInfo>();
foreach (var m in list)
{
tableInfoList.Add(
new TableInfo()
{
ColumnName=m.Code,
ColumnType=m.DataType
}
);
}
return tableInfoList;
} //初始化"o:Table"的节点
private PDMTableInfo GetTable(XmlNode xnTable)
{
PDMTableInfo mTable = new PDMTableInfo();
XmlElement xe = (XmlElement)xnTable;
mTable.TableId = xe.GetAttribute("Id");
XmlNodeList xnTProperty = xe.ChildNodes;
foreach (XmlNode xnP in xnTProperty)
{
switch (xnP.Name)
{
case "a:ObjectID": mTable.ObjectID = xnP.InnerText;
break;
case "a:Name": mTable.Name = xnP.InnerText;
break;
case "a:Code": mTable.Code = xnP.InnerText;
break;
case "a:CreationDate": mTable.CreationDate = Convert.ToInt32(xnP.InnerText);
break;
case "a:Creator": mTable.Creator = xnP.InnerText;
break;
case "a:ModificationDate": mTable.ModificationDate = Convert.ToInt32(xnP.InnerText);
break;
case "a:Modifier": mTable.Modifier = xnP.InnerText;
break;
case "a:Comment": mTable.Comment = xnP.InnerText;
break;
case "a:PhysicalOptions": mTable.PhysicalOptions = xnP.InnerText;
break;
case "c:Columns": InitColumns(xnP, mTable);
break;
case "c:Keys": InitKeys(xnP, mTable);
break;
}
}
return mTable;
}
//初始化"c:Columns"的节点
private void InitColumns(XmlNode xnColumns, PDMTableInfo pTable)
{
foreach (XmlNode xnColumn in xnColumns)
{
pTable.AddColumn(GetColumn(xnColumn));
}
} //初始化c:Keys"的节点
private void InitKeys(XmlNode xnKeys, PDMTableInfo pTable)
{
foreach (XmlNode xnKey in xnKeys)
{
pTable.AddKey(GetKey(xnKey));
}
} private PDMColumnInfo GetColumn(XmlNode xnColumn)
{
PDMColumnInfo mColumn = new PDMColumnInfo();
XmlElement xe = (XmlElement)xnColumn;
mColumn.ColumnId = xe.GetAttribute("Id");
XmlNodeList xnCProperty = xe.ChildNodes;
foreach (XmlNode xnP in xnCProperty)
{
switch (xnP.Name)
{
case "a:ObjectID": mColumn.ObjectID = xnP.InnerText;
break;
case "a:Name": mColumn.Name = xnP.InnerText;
break;
case "a:Code": mColumn.Code = xnP.InnerText;
break;
case "a:CreationDate": mColumn.CreationDate = Convert.ToInt32(xnP.InnerText);
break;
case "a:Creator": mColumn.Creator = xnP.InnerText;
break;
case "a:ModificationDate": mColumn.ModificationDate = Convert.ToInt32(xnP.InnerText);
break;
case "a:Modifier": mColumn.Modifier = xnP.InnerText;
break;
case "a:Comment": mColumn.Comment = xnP.InnerText;
break;
case "a:DataType": mColumn.DataType = xnP.InnerText;
break;
case "a:Length": mColumn.Length = xnP.InnerText;
break;
case "a:Identity": mColumn.Identity = ConvertToBooleanPG(xnP.InnerText);
break;
case "a:Mandatory": mColumn.Mandatory = ConvertToBooleanPG(xnP.InnerText);
break;
case "a:PhysicalOptions": mColumn.PhysicalOptions = xnP.InnerText;
break;
case "a:ExtendedAttributesText": mColumn.ExtendedAttributesText = xnP.InnerText;
break;
}
}
return mColumn;
} private PDMKey GetKey(XmlNode xnKey)
{
PDMKey mKey = new PDMKey();
XmlElement xe = (XmlElement)xnKey;
mKey.KeyId = xe.GetAttribute("Id");
XmlNodeList xnKProperty = xe.ChildNodes;
foreach (XmlNode xnP in xnKProperty)
{
switch (xnP.Name)
{
case "a:ObjectID": mKey.ObjectID = xnP.InnerText;
break;
case "a:Name": mKey.Name = xnP.InnerText;
break;
case "a:Code": mKey.Code = xnP.InnerText;
break;
case "a:CreationDate": mKey.CreationDate = Convert.ToInt32(xnP.InnerText);
break;
case "a:Creator": mKey.Creator = xnP.InnerText;
break;
case "a:ModificationDate": mKey.ModificationDate = Convert.ToInt32(xnP.InnerText);
break;
case "a:Modifier": mKey.Modifier = xnP.InnerText;
break;
//还差 <c:Key.Columns>
}
}
return mKey;
} private static Boolean ConvertToBooleanPG(Object obj)
{
if (obj != null)
{
string mStr = obj.ToString();
mStr = mStr.ToLower();
if ((mStr.Equals("y") || mStr.Equals("1")) || mStr.Equals("true"))
{
return true;
}
}
return false;
}
}
种个实体:
public class PDMColumnInfo
{
public PDMColumnInfo()
{ } string columnId; public string ColumnId
{
get { return columnId; }
set { columnId = value; }
}
string objectID; public string ObjectID
{
get { return objectID; }
set { objectID = value; }
}
string name; public string Name
{
get { return name; }
set { name = value; }
}
string code; public string Code
{
get { return code; }
set { code = value; }
}
int creationDate; public int CreationDate
{
get { return creationDate; }
set { creationDate = value; }
}
string creator; public string Creator
{
get { return creator; }
set { creator = value; }
}
int modificationDate; public int ModificationDate
{
get { return modificationDate; }
set { modificationDate = value; }
}
string modifier; public string Modifier
{
get { return modifier; }
set { modifier = value; }
}
string comment; public string Comment
{
get { return comment; }
set { comment = value; }
}
string dataType; public string DataType
{
get { return dataType; }
set
{
if (value.Contains("nvarchar") || value.Contains("varchar"))
{
value = "string";
}
if (value.Contains("money"))
{
value = "decimal";
}
dataType = value;
}
}
string length; public string Length
{
get { return length; }
set { length = value; }
}
//是否自增量
bool identity; public bool Identity
{
get { return identity; }
set { identity = value; }
}
bool mandatory;
//禁止为空
public bool Mandatory
{
get { return mandatory; }
set { mandatory = value; }
}
string extendedAttributesText;
//扩展属性
public string ExtendedAttributesText
{
get { return extendedAttributesText; }
set { extendedAttributesText = value; }
}
string physicalOptions; public string PhysicalOptions
{
get { return physicalOptions; }
set { physicalOptions = value; }
}
}
public class PDMKey
{
public PDMKey()
{
} string keyId; public string KeyId
{
get { return keyId; }
set { keyId = value; }
}
string objectID; public string ObjectID
{
get { return objectID; }
set { objectID = value; }
}
string name; public string Name
{
get { return name; }
set { name = value; }
}
string code; public string Code
{
get { return code; }
set { code = value; }
}
int creationDate; public int CreationDate
{
get { return creationDate; }
set { creationDate = value; }
}
string creator; public string Creator
{
get { return creator; }
set { creator = value; }
}
int modificationDate; public int ModificationDate
{
get { return modificationDate; }
set { modificationDate = value; }
}
string modifier; public string Modifier
{
get { return modifier; }
set { modifier = value; }
} IList<PDMColumnInfo> columns; public IList<PDMColumnInfo> Columns
{
get { return columns; }
} public void AddColumn(PDMColumnInfo mColumn)
{
if (columns == null)
columns = new List<PDMColumnInfo>();
columns.Add(mColumn);
}
}
public class PDMTableInfo
{
public PDMTableInfo()
{
}
string tableId; public string TableId
{
get { return tableId; }
set { tableId = value; }
}
string objectID; public string ObjectID
{
get { return objectID; }
set { objectID = value; }
}
string name; public string Name
{
get { return name; }
set { name = value; }
}
string code; public string Code
{
get { return code; }
set { code = value; }
}
int creationDate; public int CreationDate
{
get { return creationDate; }
set { creationDate = value; }
}
string creator; public string Creator
{
get { return creator; }
set { creator = value; }
}
int modificationDate; public int ModificationDate
{
get { return modificationDate; }
set { modificationDate = value; }
}
string modifier; public string Modifier
{
get { return modifier; }
set { modifier = value; }
}
string comment; public string Comment
{
get { return comment; }
set { comment = value; }
} string physicalOptions; public string PhysicalOptions
{
get { return physicalOptions; }
set { physicalOptions = value; }
} IList<PDMColumnInfo> columns; public IList<PDMColumnInfo> Columns
{
get { return columns; }
} IList<PDMKey> keys; public IList<PDMKey> Keys
{
get { return keys; }
} public void AddColumn(PDMColumnInfo mColumn)
{
if (columns == null)
columns = new List<PDMColumnInfo>();
columns.Add(mColumn);
} public void AddKey(PDMKey mKey)
{
if (keys == null)
keys = new List<PDMKey>();
keys.Add(mKey);
}
}
代码生成器的关键代码(读取PDM文件)的更多相关文章
- 读取Pdm文件内容(含源码)
Pdm文件,就是PowerDesigner软件生成的文件,用来设计数据库表结构非常适合.其实,它的文件存储格式就是Xml,网上有很多代码,可以读取pdm文件内容.代码可以使用,但一般只能读取简单的pd ...
- 分享非常有用的Java程序 (关键代码) (二)---列出文件和目录
原文:分享非常有用的Java程序 (关键代码) (二)---列出文件和目录 File dir = new File("directoryName"); String[] child ...
- Java 代码读取properties文件
jdk1.6 package read;import java.io.File;import java.io.FileInputStream;import java.io.IOException;im ...
- WEB应用中普通java代码如何读取资源文件
首先: 资源文件分两种:后缀.xml文件和.properties文件 .xml文件:当数据之间有联系时用.xml .properties文件:当数据之间没有联系时用.properties 正题: ...
- C#读取Excel文件,准换为list
经常会用到,废话不多说直接贴代码 //读取Excel文件 public static DataTable ReadExcelToTable(string path)//excel存放的路径{try{ ...
- 基于GDAL库,读取.nc文件(以海洋表温数据为例)C++版
对于做海洋数据处理的同学,会经常遇到nc格式的文件,nc文件的格式全称是NetCDF,具体的详细解释请查询官网[https://www.unidata.ucar.edu/software/netcdf ...
- 分享非常有用的Java程序 (关键代码)(六)---解析/读取XML 文件(重要)
原文:分享非常有用的Java程序 (关键代码)(六)---解析/读取XML 文件(重要) XML文件 <?xml version="1.0"?> <student ...
- paip.powerdesign cdm pdm文件 代码生成器 java web 页面 实现
paip.powerdesign cdm pdm文件 代码生成器 java web 页面 实现 准备从pd cdm生成java web 页面...但是,ms无直接地生成软件.... 只好自己解析cdm ...
- 分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要)
原文:分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要) Java InputStream读取数据问题 ======== ...
随机推荐
- 【洛谷】1852:[国家集训队]跳跳棋【LCA】【倍增?】
P1852 [国家集训队]跳跳棋 题目背景 原<奇怪的字符串>请前往 P2543 题目描述 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子. 我们用跳跳棋来做一个 ...
- Python知识(5)--绘图
Python学习变得很方便,不用任何安装一个浏览器也能够使用学习,比如Jupyter就是很好的一个网络工具,提供了编辑编译展示等强大的功能,网址如下: https://try.jupyter.org/ ...
- BlueMind 3.0.17 发布,消息和协作平台
BlueMind 3.0.17 发布,此版本对即时消息 Web 应用连接处理做了较大改进(更可靠),还修复了通讯录浏览器. BlueMind 3.0.17 现已提供下载. 详细改进记录如下: Addr ...
- SPOJ 10628. Count on a tree (树上第k大,LCA+主席树)
10628. Count on a tree Problem code: COT You are given a tree with N nodes.The tree nodes are number ...
- SyncThingWin -- Run syncthing as a windows service
SyncThingWin Auto restart and minor bug fixes bloones released this on 23 Dec 2014 There is now an a ...
- 2017微软 MVP 数据实践技术活动日(北京站)
Power BI | 交互式数据可视化 BI 工具 EXCEL BI :无所不能的业务数据分析利器 EXCEL +POWERBI=EXCEL BI https://edu.hellobi.com/co ...
- jQuery碎语(3) 动画特效
5.动画特效 ● 自制折叠内容块 内容块如下 <div class="module"> <div class="caption"> &l ...
- 解决Arcgis10.2.2中dbf文件用EXCEL打开乱码问题
1.开始 -- 运行,输入”Regedit“,打开 注册表 . 2.如是用的是 10.x 版本 ArcGIS Desktop,定位到 ‘计算机\HKEY_CURRENT_USER\Software\E ...
- 【spring cloud】spring cloud集成zipkin报错:Prometheus requires that all meters with the same name have the same set of tag keys.
spring boot 2.0.X 的版本,整合zipkin2.10.1 zipkin服务启动后,访问zipkin的UI http://localhost:8002/zipkin/ 页面显示空白,cs ...
- Android开发之ListView条目批量选择删除
ListView实现的列表,假设是可编辑,可删除的,一般都要提供批量删除功能,否则的话,一项一项的删除体验非常不好,也给用户带来了非常大的麻烦. 实现效果图 详细实现代码 select.xml 主布局 ...