pdm中批量添加字段

'******************************************************************************

'* File:     pdm_addcolumn_vbs.txt

'* Purpose:  批量新增列,常用于增加公共字段。

'* Title:    Add Column

'* Category: Add Column

'* Version:  1.0

'* Company:  ffcs. 

'******************************************************************************


Option Explicit


Dim mdl ' the current model   

Set mdl = ActiveModel

Dim Tab 'running table   

Dim col 'running table col


Dim col_status_cd, col_create_date,col_status_date,col_update_date,col_sharding_id,col_create_staff,col_update_staff,col_tenant_id

' 定义列变量


ProcessFolder mdl  '调用ProcessFolder函数

ProcessTables mdl  '调用ProcessTables函数

    

 '--------------------------------------------------------------------------------

 '功能函数 针对pdm下有多个package的表,增加列操作。

 '--------------------------------------------------------------------------------

 Private Sub ProcessFolder(folder)

    Dim ent '定义实体

    Dim pack '定义实体

    for each pack in folder.packages

    for each Tab in pack.tables

      if not Tab.isShortcut then

      

' 新增列前,删除已经存在的列,防止出现冲突

for each col in Tab.Columns

  '根据列code属性,删除列

if instr(col.code,"status_cd")>0  then col.Delete()  end if 

if instr(col.code,"create_date")>0  then col.Delete()  end if 

if instr(col.code,"status_date")>0  then col.Delete()  end if 

if instr(col.code,"update_date")>0  then col.Delete()  end if 

if instr(col.code,"sharding_id")>0  then col.Delete()  end if 

if instr(col.code,"create_staff")>0  then col.Delete()  end if 

if instr(col.code,"update_staff")>0  then col.Delete()  end if 

if instr(col.code,"tenant_id")>0  then col.Delete()  end if 

next

'新增列

Set col_status_cd = Tab.Columns.CreateNew

set col_create_date = Tab.Columns.CreateNew

set col_status_date = Tab.Columns.CreateNew

set col_update_date = Tab.Columns.CreateNew

set col_sharding_id = Tab.Columns.CreateNew

set col_create_staff = Tab.Columns.CreateNew

set col_update_staff = Tab.Columns.CreateNew

set col_tenant_id = Tab.Columns.CreateNew

 

'设置新增列的属性,如name,code,datatype等      

col_status_cd.name = "状态"

col_status_cd.code = "status_cd"

col_status_cd.DataType = "varchar(6)"

col_status_cd.comment ="状态"

 

col_create_date.name = "创建时间"

col_create_date.code = "create_date"

col_create_date.DataType = "datetime"

col_create_date.comment ="描述记录创建的时间"

 

col_status_date.name = "状态时间"

col_status_date.code = "status_date"

col_status_date.DataType = "datetime"

col_status_date.comment ="描述记录被应用程序更新的时间"

 

col_update_date.name = "更新时间"

col_update_date.code = "update_date"

col_update_date.DataType = "datetime"

col_update_date.comment ="描述记录物理更新的时间"

 

col_sharding_id.name = "分片键"

col_sharding_id.code = "sharding_id"

col_sharding_id.DataType = "bigint(12)"

col_sharding_id.comment ="描述记录的分片键"

 

col_create_staff.name = "创建员工"

col_create_staff.code = "create_staff"

col_create_staff.DataType = "bigint(12)"

col_create_staff.comment ="描述创建记录的员工标识"

 

col_update_staff.name = "更新员工"

col_update_staff.code = "update_staff"

col_update_staff.DataType = "bigint(12)"

col_update_staff.comment ="描述更新记录的员工标识"

 

 

col_tenant_id.name = "租户标识"

col_tenant_id.code = "tenant_id"

col_tenant_id.DataType = "bigint(12)"

col_tenant_id.comment ="描述租户标识"

        

      end if

    next

    next

    

    '对子包进行递归,如果不使用递归只能取到第一个模型图内的表

    dim subfolder

    for each subfolder in folder.Packages

       ProcessFolder subfolder

    next

 

End Sub



 '--------------------------------------------------------------------------------

 '功能函数 针对直接挂在pdm下的表,增加列操作。

 '--------------------------------------------------------------------------------

 Private Sub ProcessTables(folder)

for each Tab in folder.Tables


 ' 删除已经存在的列

 for each col in Tab.Columns

 if instr(col.code,"status_cd")>0  then col.Delete()  end if 

 if instr(col.code,"create_date")>0  then col.Delete()  end if 

 if instr(col.code,"status_date")>0  then col.Delete()  end if 

 if instr(col.code,"update_date")>0  then col.Delete()  end if 

 if instr(col.code,"sharding_id")>0  then col.Delete()  end if 

 if instr(col.code,"create_staff")>0  then col.Delete()  end if 

 if instr(col.code,"update_staff")>0  then col.Delete()  end if 

 if instr(col.code,"tenant_id")>0  then col.Delete()  end if 

 

next

 

 '新增列

 Set col_status_cd = Tab.Columns.CreateNew

 set col_create_date = Tab.Columns.CreateNew

 set col_status_date = Tab.Columns.CreateNew

 set col_update_date = Tab.Columns.CreateNew

 set col_sharding_id = Tab.Columns.CreateNew

 set col_create_staff = Tab.Columns.CreateNew

 set col_update_staff = Tab.Columns.CreateNew

 set col_tenant_id = Tab.Columns.CreateNew

      

 col_status_cd.name = "状态"

 col_status_cd.code = "status_cd"

 col_status_cd.DataType = "varchar(6)"

 col_status_cd.comment ="状态"

 

 col_create_date.name = "创建时间"

 col_create_date.code = "create_date"

 col_create_date.DataType = "datetime"

 col_create_date.comment ="描述记录创建的时间"

 

 col_status_date.name = "状态时间"

 col_status_date.code = "status_date"

 col_status_date.DataType = "datetime"

 col_status_date.comment ="描述记录被应用程序更新的时间"

 

 col_update_date.name = "更新时间"

 col_update_date.code = "update_date"

 col_update_date.DataType = "datetime"

 col_update_date.comment ="描述记录物理更新的时间"

 

 col_sharding_id.name = "分片键"

 col_sharding_id.code = "sharding_id"

 col_sharding_id.DataType = "bigint(12)"

 col_sharding_id.comment ="描述记录的分片键"

 

 col_create_staff.name = "创建员工"

 col_create_staff.code = "create_staff"

 col_create_staff.DataType = "bigint(12)"

 col_create_staff.comment ="描述创建记录的员工标识"

 

 col_update_staff.name = "更新员工"

 col_update_staff.code = "update_staff"

 col_update_staff.DataType = "bigint(12)"

 col_update_staff.comment ="描述更新记录的员工标识"

 

 

 col_tenant_id.name = "租户标识"

 col_tenant_id.code = "tenant_id"

 col_tenant_id.DataType = "bigint(12)"

 col_tenant_id.comment ="描述租户标识"

 


next

End Sub


你可能感兴趣的:(pdm中批量添加字段)