PowerDesigner增强

把注释显示出来

选定编辑的表,右键- >Properties- >Columns- >Customize Columns and Filter(或直接用快捷键Ctrl+U)- >Comment(前面打勾)- >OK

image

image

 

把Name的值变成comment(注释) 参照<powerdesigner逆向工程生成PDM时的列注释解决方案的补充>

改进脚本:Powerdesigner界面-Database-Edit Current DBMS

将表的Name换为Comment

28235194_4

将列的Name换为Comment

28235194_5

Name/Code自动填写

大家都清楚在用PowerDesigner的时候,当你输入Name的时候Code是会自动帮你按照Name的内容填上的.
这个功能虽然好用,但是我需要在Name这一项加上一个中文的注释,这个时候怎么办呢?
下面两个例子,相信对你相当有用.
Examples

· Script 1:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
.delete(%CurrentPart%)
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next

这个例子是把Name内容的#号后边的内容当作Code.
如:在Name列输入   用户名#user_name  则在Code列自动会变成   user_name
//////////////////////据说上面是错的

.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
.delete(%CurrentPart%)
.enddelete
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next

////////////////
· Script 2:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
%CurrentPart%
.set_value(_First, false, update)
.endif
.next

这个例子是把Name内容的#号前边的内容当作Code.
如:在Name列输入    user_name#用户名  则在Code列自动会变成   user_name

具体操作方法是:
1、打开powerDesigner菜单的Tools->Model Options....->Naming Convention
2、选中Name,并勾选Enable name/code conversions.
3、选择Name To Code,把上面任意一个例子的代码(红色部分)贴到conversion script内容框中即可。

注:用这个script的时候,必须先设置,才会转换的。
如果你已经设计好了,再设置是不会对之前的东西改变的。

另外在使用这个功能时候最好把name/code自动复制功能打开。Tool——Genneral——Options Dialog——Name to Code mirroring.默认就是打开的。

当生成的PDM,用pdmreader来读取,增加查询链接后,很强悍

VHZ4IG(LKQ6KG9P}KTY$A_7

 

1T2VR0MA@6XW]P[92S[GA{A

Power Designer导出实体类和NHibernate xml文件

今天研究了一下通过PowerDesigner生成实体类和NHibernate所需要的xml文件,方法是通过Power Designer的向对象模型 (OOM) 导出并配置相关模板,具体操作步骤如下:

第一步:创建OOM

在PowerDesigner中创建面向对象模型 (OOM)。

我首先创建物理数据模型 (PDM),然后在 Tools → Generate Object-Oriented Model 做了转换。

第二步:配置导出实体模板文件

菜单位置:Language → Edit Current Object Language

General:C# 2::Profile\Attribute\Templates\definition

我对模板进行了简单修改,添加了一行空格和 { get; set; }。又对文件头和字段描述的格式做了修改。

.if (%isGenerated%) and (%isValidAttribute%)

[%comment%\n]\
[%oidDocTag%\n]\
[%customAttributes%\n]\
   .if (%Multiple% == false) and (%isIndexer% == false)
[%visibility% ][%flags% ]%dataType%
.convert_name(%fieldCode%,,"_",FirstUpperChar) //首字母变大写
[ = %InitialValue%] { get; set; }
   .else
[%visibility% ][%flags% ]%dataType%[%arraySize%]
.convert_name(%fieldCode%,,"_",FirstUpperChar) //首字母变大写
[ = %InitialValue%] { get; set; }
   .endif
.endif

DefaultHeader

位置在:C# 2::Profile\Classifier\Templates\DefaultHeader

写自己的代码:

按 Ctrl+C 复制代码

// -------------------------------------------------------------------------------------------------------------------- // <copyright file="%sourceFilename%" company=""> // XXXX系统 // </copyright> // <summary> // %Comment% // </summary> // --------------------------------------------------------------------------------------------------------------------

按 Ctrl+C 复制代码

[%comment%\n]\

位置在:C# 2::Profile\Shared\Templates\comment

写自己的代码:

/// <summary>
/// %CurrentLine%
/// </summary>

提示:在做类时只有把Comment字段填上,导出是才会有字段描述。

对命名空间进行配置,我直接写到了 source 里面感觉不是太合适。

C# 2::Profile\Classifier\Templates\source

现在就可以将实体导出了。

菜单位置:Language → Generate C# 2 Code

第二步:配置导出NHibernatedxml模板文件

这个是通过在网上查资料学来的,

感谢:Powerdesigner生成NHebernate的MAP文件

只是他没有附图,让人找不到位置,我也研究了一个下午才找到的,以下参数命名仍采用他的。

1.还是打开 Object Language Properties

菜单位置:Language → Edit Current Object Language

在 C# 2::Profile\Classifier\Generated Files ,创建一个 hbm.xml 文件。

Name: hbm.xml

FileName:%topContainerCode%.hbm.xml

Comment:

.if (%isGenerated%)

.set_object(_usingContext,,new)

[\ %NHebernateHead%\n]\

%NHebernateBody% \n

%NHebernateFoot%

.endif  

%NHebernateBody%

2.设置%NHebernateBody%模板的内容

在 C# 2::Profile\Classifier\Templates ,新建一个模板 NHebernateBody

复制代码

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="%Parent.path%" namespace="%Parent.path%">
  <class name="%sourceFilename%" table="%sourceFilename%" lazy="true" >
    <id name="ID" column="ID" type="Guid" >
      <generator class="assigned" />
    </id> \n    
    .foreach_item(Attributes)
      .if(%dataType% == "string")      
    <property name="%Code%" type="String">
      <column name="%Code%" /> 
    </property> \n       
    .endif
    .if(%dataType% == "int")
    <property name="%Code%" type="Int32">
      <column name="%Code%" /> 
    </property> \n       
    .endif
    .next   
  </class>
</hibernate-mapping>

复制代码

具体里面的配置我还没写好,需要再查帮助。

3.配置输出NHibernate的xml文件

在 C# 2::Profile\BasePackage\Templates\Visual Studio ,将模板修改为:

复制代码

.// Declare classifiers of the package
.foreach_item(Classifiers,,,%IsShortcut%==false)
   .if (%IsSelected%) and (%isInner% == false)
<File
    RelPath = "%sourceFilePath%"
    SubType = "Code"
    BuildAction = "Compile"
/>
<File
    RelPath = "%sourceFilePath%\\%topContainerCode%.hbm.xml"
    BuildAction = "EmbeddedResource"
/>
   .endif(\n)
.next
.// Declare classifiers of the subpackages
.foreach_item(Packages,,,%IsShortcut%==false)
   .if (%isAssembly% == false)
%ProjectSourceFiles%
   .endif
.next

复制代码

NHibernate的xml配置完成。最后,一起导出实体和NHibernate的.xml文件

菜单位置:Language → Generate C# 2 Code

生成的两个文件:Customers.cs 和 Customers.hbm.xml

?

// --------------------------------------------------------------------------------------------------------------------

// <copyright file="Customers.cs" company="">

//   XXXX系统

// </copyright>

// <summary>

//   账户信息

// </summary>

// --------------------------------------------------------------------------------------------------------------------

namespace XXXX.Domain.Model

{

using System;

/// <summary>

/// 账户信息

/// </summary>

public class Customers

{

/// <summary>

/// 账户ID

/// </summary>

public string customerId { get; set; } dd

/// <summary>

/// 账户名称

/// </summary>

public string customerName { get; set; }

/// <summary>

/// 性别

/// </summary>

public bool gender { get; set; }

/// <summary>

/// 地址

/// </summary>

public string address { get; set; }

/// <summary>

/// 电话号码

/// </summary>

public string phoneNumber { get; set; }

}

}

复制代码

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="" namespace="">
  <class name="Customers.cs" table="Customers.cs" lazy="true" >
    <id name="ID" column="ID" type="Guid" >
      <generator class="assigned" />
    </id> 
    <property name="CustomerId" type="String">
      <column name="CustomerId" /> 
    </property> 
    <property name="CustomerName" type="String">
      <column name="CustomerName" /> 
    </property> 
    <property name="Address" type="String">
      <column name="Address" /> 
    </property> 
    <property name="PhoneNumber" type="String">
      <column name="PhoneNumber" /> 
    </property> 
  </class>
</hibernate-mapping>

复制代码

今天的学习只是找到了实现方法,想要把模板做好,还要再看看帮助。

不怎么会写博客,望前辈批评指正。

PowerDesigner PDM生成OOM问题?

从PDM转到OOM的时候

Name 是中文

Code 是英文

可是只要一转就出现在 Name=Code都成中文了。

现在从网上找了一个解决办法,挺好用的。

菜单栏Tools --> 选择 Generate Object-Oriented Model 的时候弹出下图窗体

在OOM Generation Options 界面中的

选择detail标签中,将Convert name into code,前面打钩去掉 保存就可能了。

如图所示:

 

PowerDesigner中NAME和COMMENT的互相转换,需要执行语句

使用说明: 在【Tools】-【Execute Commands】-【Edit/Run Script】 下。输入下面你要选择的语句即可,也可以保存起来,以便下次使用,后缀为.vbs。

需要注意的问题是:运行语句时必须在Module模式下,如果是导出报表时执行会出现错误提示。

1.Name转到Comment注释字段。一般情况下只填写NAME,COMMENT可以运行语句自动生成。

将该语句保存为name2comment.vbs

'把pd中那么name想自动添加到comment里面

'如果comment为空,则填入name;如果不为空,则保留不变,这样可以避免已有的注释丢失.

Option   Explicit

ValidationMode   =   True

InteractiveMode   =   im_Batch

Dim   mdl   '   the   current   model

'   get   the   current   active   model

Set   mdl   =   ActiveModel

If   (mdl   Is   Nothing)   Then

      MsgBox   "There   is   no   current   Model "

ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then

      MsgBox   "The   current   model   is   not   an   Physical   Data   model. "

Else

      ProcessFolder   mdl

End   If

'   This   routine   copy   name   into   comment   for   each   table,   each   column   and   each   view

'   of   the   current   folder

Private   sub   ProcessFolder(folder)   

      Dim   Tab   'running     table   

      for   each   Tab   in   folder.tables   

            if   not   tab.isShortcut then

                     if  trim(tab.comment)="" then'如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.

                        tab.comment   =   tab.name

                     end if 

                  Dim   col   '   running   column   

                  for   each   col   in   tab.columns  

                        if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.

                           col.comment=   col.name  

                        end if

                  next   

            end   if   

      next   

      Dim   view   'running   view   

      for   each   view   in   folder.Views   

            if   not   view.isShortcut and trim(view.comment)=""  then   

                  view.comment   =   view.name   

            end   if   

      next   

      '   go   into   the   sub-packages   

      Dim   f   '   running   folder   

      For   Each   f   In   folder.Packages   

            if   not   f.IsShortcut   then   

                  ProcessFolder   f   

            end   if   

      Next   

end   sub

2.将Comment内容保存到NAME中,comment2name.vbs 实习互换。语句为:

Option   Explicit   
ValidationMode   =   True   
InteractiveMode   =   im_Batch   
Dim   mdl   '   the   current   model   
'   get   the   current   active   model   
Set   mdl   =   ActiveModel   
If   (mdl   Is   Nothing)   Then   
      MsgBox   "There   is   no   current   Model "   
ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then   
      MsgBox   "The   current   model   is   not   an   Physical   Data   model. "   
Else   
      ProcessFolder   mdl   
End   If   
Private   sub   ProcessFolder(folder)   
On Error Resume Next  
      Dim   Tab   'running     table   
      for   each   Tab   in   folder.tables   
            if   not   tab.isShortcut   then   
                  tab.name   =   tab.comment  
                  Dim   col   '   running   column   
                  for   each   col   in   tab.columns   
                  if col.comment="" then  
                  else 
                        col.name=   col.comment   
                  end if 
                  next   
            end   if   
      next   
      Dim   view   'running   view   
      for   each   view   in   folder.Views   
            if   not   view.isShortcut   then   
                  view.name   =   view.comment   
            end   if   
      next   
      '   go   into   the   sub-packages   
      Dim   f   '   running   folder   
      For   Each   f   In   folder.Packages   
            if   not   f.IsShortcut   then   
                  ProcessFolder   f   
            end   if   
      Next   
end   sub

posted @ 2014-02-12 13:10  寒殇  阅读(592)  评论(2编辑  收藏  举报