PDM後續處理-駝峰規則、清除約束、外鍵改名
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ‘當前model
‘獲取當前活動model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then ‘如果是處理pdm,這裏換成PdPDM.cls_Model
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If
Private sub ProcessFolder(folder)
dim tab
‘11111111111111111111111111111111111111111111111111111111111111111
for each tab in folder.tables
if not tab.isShortcut then
‘處理每個實體或類的Name和Code
‘先處理表名
Dim code
code = tab.code
code=ManageNameFormat code
tab.code=code
tab.name=code
‘再處理每個字段的名稱
dim col
for each col in tab.columns
Dim acode
acode = col.code
acode=ManageNameFormat acode
col.code=acode
col.name=acode
col.ServerCheckExpression="" ‘清除每個字段正則表達式約束
col.ListOfValues ="" ‘清除枚舉項約束
col.lowvalue="" ‘清除最大值約束
col.highvalue="" ‘最小值約束
next
end if
next
‘222222222222222222222222222222222222222222222222222222222222222222222222222
‘更改特定外鍵名稱
for each ref in folder.references
if not ref.isShortcut then
‘根據子表和主表名稱更改外鍵字段名稱,將該外鍵字段名稱直接改為該關系名,以子表-主表方式判斷
‘根據單表也可以設置
if lcase(ref.parenttable.name)=lcase("ExVersion") or lcase(ref.parenttable.name)=lcase("Ex_Version") or _
(lcase(ref.childtable.name)=lcase("GM_Arc") and lcase(ref.parenttable.name)=lcase("Point" )) or _
(lcase(ref.childtable.name)=lcase("GM_Geodesic") and lcase(ref.parenttable.name)=lcase("Point") ) then
dim col
for each col in ref.childtable.columns ‘不用遍歷尋找對應table對象,直接用ref.childtable就能操作,比以前更智能
if lcase(col.name)= lcase(ref.ForeignKeyColumnList) then
output ref.childtable.name+"."+ref.ForeignKeyColumnList+ "<--------------->"+ ref.childtable.name+"."+ref.name
col.name=ref.name
col.code=col.name
end if
next
end if
end if
next
‘////////////////////////////////////////////////////////////////////////////////////
‘遞歸遍歷子文件夾
Dim f ‘子文件夾
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
‘函數將輸入的低駝峰字符串整理成_符分割的字符串
Function ManageNameFormat (code as string) as string
Dim i
i=2
Do While i < len(code)
If mid(code,i,1)=ucase(mid(code,i,1)) and mid(code,i-1,1)=lcase(mid(code,i-1,1)) and mid(code,i-1,1)<>"_" and mid(code,i,1)<>"_" and mid(code,i-1,1)<>"2" and mid(code,i,1)<>"2" Then ‘連續大寫字母不用加_
code = left(code,i-1) + "_" + mid(code,i)
i =i+ 1
End If
i =i+ 1
Loop
ManageNameFormat=code
End Function
PDM後續處理-駝峰規則、清除約束、外鍵改名