天天看點

PowerDesigner優化配置

一、設定PowerDesigner模型視圖中資料表顯示列

1、Tools-Display Preference…

2、視窗左邊Category中General Settings下選擇Table

3、視窗右邊Advanced…

4、視窗左邊選擇Columns

5、視窗右邊List columns中,選擇要顯示的列

PowerDesigner優化配置

二、設定PowerDesigner設計表時,自動将name列值中的一部分複制到code列

1、把name/code自動複制功能打開。預設是打開的。

Tool-Genneral-Options Dialog-Name to Code mirroring

2、Tools->Model Options....->Naming Convention

3、選中Name,并勾選Enable name/code conversions.

4、選擇Name To Code

粘貼腳本代碼

?

腳本1:
.set_value(_First, true, new)
.foreach_part(%Name%,"'#'")
.if (%_First%)
.delete(%CurrentPart%)
.enddelete
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next
這個例子是把Name内容的#号後邊的内容當作Code.
  
腳本2:
.set_value(_First, true, new)
.foreach_part(%Name%,"'#'")
.if (%_First%)
%CurrentPart%
.set_value(_First, false, update)
.endif
.next
 這個例子是把Name内容的#号前邊的内容當作Code.
           

三、從資料庫導入資料到PowerDesigner中後,将comment列值複制到name列

運作腳本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

?

'******************************************************************************
'* File:     comment2name.vbs
'* Purpose:  在PowerDesigner的PDM圖形視窗中顯示資料列的中文注釋
'* Title:    将字段的comment指派到字段的name中
'* Category: 打開實體模型,運作本腳本(Ctrl+Shift+X)
'* Copyright:[email protected],2006/07/25 .
'* Author:   foxzz
'* Created: 
'* Modified:
'* Version:  1.0
'* Comment:  周遊實體模型中的所有表,将字段的comment指派到字段的name中。
'            在将name置換為comment過程中,需要考慮的問題
'            1、name必須唯一,而comment有可能不唯一。
'               處理辦法是如果字段的comment重複,則字段的name=comment+1、2、3...
'            2、comment值有可能為空,這種情況下對字段的name不處理。
'               針對oracle資料庫,将comment on column 字段名稱 is '';添加到C:/pdcomment.txt檔案中。
'               在補充comment完畢後,便于在資料庫中執行       
'******************************************************************************
 
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
 
Dim system, file
Set system = CreateObject("Scripting.FileSystemObject")
Dim ForReading, ForWriting, ForAppending   '打開檔案選項
ForReading   = 1 ' 隻讀
ForWriting   = 2 ' 可寫
ForAppending = 8 ' 可寫并追加
'打開文本檔案
Set file = system.OpenTextFile("C:/pdcomment.txt", ForWriting, true)
 
 
'判斷目前model是否實體資料模型
Dim mdl
Set mdl = ActiveModel
If (mdl Is Nothing)Then
   MsgBox"處理對象無模型"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
   MsgBox"目前模型不是實體資料模型"
Else
   ProcessFolder mdl,file
End If
file.Close
 
 
'******************************************************************************
Private sub ProcessFolder(folder,file)
 
Dim i,j,k
i=0:j=0:k=0
 
'列數組,記錄字段裡不重複的comment
Dim ColumnComment()
Dim ColumnCommentNumber()
ReDim Preserve ColumnComment(i)
ReDim Preserve ColumnCommentNumber(i)
 
Dim tbl   '目前表
Dim col   '目前字段
dim curComment  '目前字段comment
 
'處理模型中的表
for each tbl in folder.tables
    if not tbl.isShortcut then
       if len(trim(tbl.comment))<>0 then
          '可以在這裡顯示table的comment
          'tbl.name = tbl.name+"("+trim(tbl.comment)+")"
       end if 
 
       '處理表中的列
       for each col in tbl.columns
           k = 0
           curComment = trim(col.comment)
           if len(curComment)<>0 then
              '周遊相異的comment數組
              for j = 0 to i
                  if ColumnComment(j) = curComment then
                     '如果找到相同的comment,則相關計數器加1
                     ColumnCommentNumber(j) = ColumnCommentNumber(j) + 1
                     k = j
                  end if
              Next
              '如果沒有相同的comment,則k=0,此時ColumnCommentNumber(0)也為0
              '否則ColumnCommentNumber(k)不為0
              if ColumnCommentNumber(k) <> 0 then
                 col.name = curComment & cstr(ColumnCommentNumber(k))
              else
                 col.name  = curComment
                 'ColumnComment(0)、ColumnCommentNumber(0)永遠為空
                 '将相異的comment記錄添加到數組中
                 i = i + 1
                 ReDimPreserveColumnComment(i)
                 ReDimPreserveColumnCommentNumber(i)
                 ColumnComment(i) = curComment
                 ColumnCommentNumber(i) = 0
              end if
           else
              '寫入檔案中
              file.WriteLine"comment on column "+ tbl.name+"."+col.code+" is '';"          
           end if
       next
    end if
    '由于不同表的name允許相同,是以此時重新初始化。
    '因為ColumnComment(0)、ColumnCommentNumber(0)為空,可以保留
    ReDimPreserveColumnComment(0)
    ReDimPreserveColumnCommentNumber(0)
    i=0:j=0:k=0
 
next
 
Dim view  '目前視圖
for each view in folder.Views
    if not view.isShortcut then
       '可以在這裡顯示view的comment
       'view.name =  view.comment
    end if
next
 
'對子目錄進行遞歸
Dim subpackage 'folder
For Each subpackage Infolder.Packages
    if not subpackage.IsShortcut then
       ProcessFolder subpackage , file
    end if
Next
 
end sub
           

四、将name列值複制到comment列

運作腳本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

?

'把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) 
 DimTab'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 
 Dimcol' 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 
   
 Dimview'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 
 Dimf' running folder 
 ForEachfInfolder.Packages 
  if not f.IsShortcut then 
 ProcessFolder f 
  end if 
 Next 
end sub
           

參考:

1、PowerDesigner中Table視圖同時顯示Code和Name http://blog.csdn.net/downmoon/article/details/8108968

2、PowerDesigner Name/Code自動調整(轉) http://hi.baidu.com/jonik/item/7d39588c3dda708e4514cf76

3、在PowerDesigner的PDM圖形視窗中顯示資料列的中文注釋 http://blog.csdn.net/zengzhe/article/details/974205

4、powerDesigner 把name項添加到注釋(comment),完美方案! http://www.cnblogs.com/dukey/archive/2010/01/20/dukey.html

5、 http://www.cnblogs.com/afarmer/archive/2012/11/05/2755327.html

繼續閱讀