在大型系统建模时,基本上90%的表中都有 创建人,创建日期,更新人,更新日期这些字段,这时我们可以不让一个一个表添加相同字段
Tools->Execute Commands->Edit/Run Script 弹出窗 将如下代码贴入 点击 Run 即可
如果有表不想添加可以在这段代码里排除
instr(",PmPrTOPd,PmPdTOPo,PmPdDocTypeRefer,排除的表名,",","+CurrentObject.Code+",")>0
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
'ceaate by runnerrunning
' get the current active model
Dim mdl ' the current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
Else
ListObjects(mdl)
End If
'-----------------------------------------------------------------------------
Private Sub ListObjects(fldr) '列出所有的对象
output "Scanning " & fldr.code
Dim obj ' running object
For Each obj In fldr.children
' Calling sub procedure to print out information on the object
TableSetComment obj
Next
' go into the sub-packages
Dim f ' running folder
For Each f In fldr.Packages '递归调用列出所有的对象
'calling sub procedure to scan children package
ListObjects f
Next
End Sub
Private Sub TableSetComment(CurrentObject)
if not CurrentObject.Iskindof(cls_Table) then exit sub
output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)
'output "Found "+CurrentObject.ClassName+" ; "+CurrentObject.Name
if instr(",PmPrTOPd,PmPdTOPo,PmPdDocTypeRefer,",","+CurrentObject.Code+",")>0 then exit sub
if not CurrentObject.isShortcut then
'CurrentObject.Comment = CurrentObject.name &vbCrLf& CurrentObject.Comment
Dim col ' running column
Dim num
dim Creator
dim CreateDate
dim CreatorCode
dim Updater
dim UpdaterCode
dim UpdateDate
dim IsDelete
dim OperDept
dim Timestamp
dim RoCode
Creator=1
CreateDate=1
Updater=1
UpdateDate=1
IsDelete=1
CreatorCode=1
UpdaterCode=1
OperDept=1
Timestamp=1
RoCode=1
for each col in CurrentObject.columns
'if num < 5 then
'output "Found column "+col.Name+" ,"+col.Code+" ,"+col.DataType
num= num + 1
'MsgBox col.name
'end if
if col.Code="Creator" then
Creator=100
end if
if col.Code="CreatorCode" then
CreatorCode=100
'col.Name="创建人编码"
'col.Comment="创建人编码"
end if
if col.Code="CreateDate" then
CreateDate=100
end if
if col.Code="Updater" then
Updater=100
end if
if col.Code="UpdaterCode" then
UpdaterCode=100
'col.Name="更新人编码"
'col.Comment="更新人编码"
end if
if col.Code="UpdateDate" then
UpdateDate=100
end if
if col.Code="IsDelete" then
IsDelete=100
'col.DataType="tinyint"
'col.DefaultValue="IsDel"
end if
if col.Code="OperDept" then
OperDept=100
end if
if col.Code="Timestamp" then
Timestamp=100
end if
if col.Code="RoCode" then
RoCode=100
end if
next
if Creator=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="创建人"
col.Code="Creator"
col.Comment="创建人"
col.DataType="nvarchar(50)"
end if
next
num=num+1
end if
if CreatorCode=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="创建人编码"
col.Code="CreatorCode"
col.Comment="创建人编码"
col.DataType="varchar(50)"
end if
next
num=num+1
end if
if CreateDate=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="创建日期"
col.Code="CreateDate"
col.Comment="创建日期"
col.DataType="datetime"
end if
next
num=num+1
end if
if Updater=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="更新人"
col.Code="Updater"
col.Comment="更新人"
col.DataType="nvarchar(50)"
end if
next
num=num+1
end if
if UpdaterCode=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="更新人编码"
col.Code="UpdaterCode"
col.Comment="更新人编码"
col.DataType="varchar(50)"
end if
next
num=num+1
end if
if UpdateDate=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="更新日期"
col.Code="UpdateDate"
col.Comment="更新日期"
col.DataType="datetime"
end if
next
num=num+1
end if
if IsDelete=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="删除标记"
col.Code="IsDelete"
col.Comment="删除标记"
col.DataType="tinyint"
col.Mandatory=1
col.DefaultValueDisplayed=0
end if
next
num=num+1
end if
if OperDept=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="操作部门"
col.Code="OperDept"
col.Comment="操作部门"
col.DataType="nvarchar(20)"
end if
next
num=num+1
end if
if RoCode=1 then
CurrentObject.columns.CreateNewAt(num)
for each col in CurrentObject.columns
'修改新加的那个字段的属性
if col.DataType="" then
col.Name="角色编码"
col.Code="RoCode"
col.Comment="角色编码"
col.DataType="varchar(50)"
end if
next
num=num+1
end if
'if Timestamp=1 then
' CurrentObject.columns.CreateNewAt(num)
' for each col in CurrentObject.columns
' '修改新加的那个字段的属性
' if col.DataType="" then
' col.Name="时间戳"
' col.Code="Timestamp"
' col.Comment="时间戳"
' col.DataType="timestamp"
' end if
' next
' num=num+1
'end if
end if
End Sub