运用环境:Power Designer
脚本:VBS
语言:C#+SQL
msgbox catch_string("1234567890 ref (sada) (jjjj)","ref","(",")")
function catch_string(wholestring,keystring,startstring,endstring)'取字符
'wholestring 整字符
'keystring '关键字
'startstring '起始点
'endstring '结束点
dim i
dim keylength
dim startnum
dim endnum
dim value
dim char
dim j
dim k
keylength=len(keystring)
for i=1 to len(wholestring)
if mid(wholestring,i,keylength)=keystring then
exit for
end if
next
for j=i to len(wholestring)
if mid(wholestring,j,len(startstring))=startstring then
startnum=j
exit for
end if
next
for k=startnum to len(wholestring)
if mid(wholestring,k,len(endstring))=endstring then
endnum=k
exit for
end if
next
value=mid(wholestring,startnum+1,endnum-startnum-1)
catch_string=value
end function
脚本:VBS
语言:C#+SQL
'******************************************************************************
'* File: Create OOM.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM for 工厂DAL方法
'* Version: 1.0基本
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "FACTORY" '层次名
'oom文件名CODE
model.Code = "FACTORY" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
dim cla
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="FACTORY_DAL"
cls.code="FACTORY_DAL"
cls.Imports=cls.Imports+vbcrlf+"using DAL;"+vbcrlf
cls.Imports=cls.Imports+vbcrlf+"namespace FACTORY"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
for each cla in actmodel.Classes
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
Dim sym
Set sym = diagram.AttachObject(cls)
CreateClasses = True
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
Function CreateAttributes(cls)
Dim attr
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "ID"
attr.Code = "ID"
attr.DataType = "int"
attr.Persistent = True
attr.PersistentCode = "ID"
attr.PersistentDataType = "I"
attr.PrimaryIdentifier = True
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Name"
attr.Code = "Name"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "NAME"
attr.PersistentDataType = "A30"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Phone"
attr.Code = "Phone"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "PHONE"
attr.PersistentDataType = "A20"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Email"
attr.Code = "Email"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "EMAIL"
attr.PersistentDataType = "A30"
CreateAttributes = True
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
dim i
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Get_DAL"+cla.name
oper.Code = "Get_DAL"+cla.code
oper.ReturnType = "DAL."+"DAL"+cla.code
oper.static=true
body = "{" + vbCrLf
body = body + " return new "+"DAL.DAL"+cla.code+"();"+ vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'* File: Create OOM.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM for 工厂DAL方法
'* Version: 1.0基本
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "FACTORY" '层次名
'oom文件名CODE
model.Code = "FACTORY" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
dim cla
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="FACTORY_DAL"
cls.code="FACTORY_DAL"
cls.Imports=cls.Imports+vbcrlf+"using DAL;"+vbcrlf
cls.Imports=cls.Imports+vbcrlf+"namespace FACTORY"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
for each cla in actmodel.Classes
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
Dim sym
Set sym = diagram.AttachObject(cls)
CreateClasses = True
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
Function CreateAttributes(cls)
Dim attr
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "ID"
attr.Code = "ID"
attr.DataType = "int"
attr.Persistent = True
attr.PersistentCode = "ID"
attr.PersistentDataType = "I"
attr.PrimaryIdentifier = True
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Name"
attr.Code = "Name"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "NAME"
attr.PersistentDataType = "A30"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Phone"
attr.Code = "Phone"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "PHONE"
attr.PersistentDataType = "A20"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Email"
attr.Code = "Email"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "EMAIL"
attr.PersistentDataType = "A30"
CreateAttributes = True
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
dim i
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Get_DAL"+cla.name
oper.Code = "Get_DAL"+cla.code
oper.ReturnType = "DAL."+"DAL"+cla.code
oper.static=true
body = "{" + vbCrLf
body = body + " return new "+"DAL.DAL"+cla.code+"();"+ vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'******************************************************************************
'* File: name2code.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Code for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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 code 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
tab.code = tab.name
Dim col ' running column
for each col in tab.columns
col.code= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.code = 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
'* File: name2code.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Code for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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 code 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
tab.code = tab.name
Dim col ' running column
for each col in tab.columns
col.code= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.code = 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
'******************************************************************************
'* File: name2code.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Code for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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 code 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
tab.name=tab.code
Dim col ' running column
for each col in tab.columns
col.name =col.code
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.name=view.code
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
'* File: name2code.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Code for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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 code 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
tab.name=tab.code
Dim col ' running column
for each col in tab.columns
col.name =col.code
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.name=view.code
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
'******************************************************************************
'* File: name2code.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Code for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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 code for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim refe 'running table
for each refe in folder.Associations
if not refe.isShortcut then
refe.code = refe.name
end if
next
end sub
'* File: name2code.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Code for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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 code for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim refe 'running table
for each refe in folder.Associations
if not refe.isShortcut then
refe.code = refe.name
end if
next
end sub
'******************************************************************************
'* File: BLL.vbs
'* Purpose: pdm to dal
'* Title: Create a new OOM
'* Category: Create
'* Version: 1.0Model
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "BLL" '层次名
'oom文件名CODE
model.Code = "BLL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Tables
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="BLL"+cla.name
cls.code="BLL"+cla.code
'cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace BLL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim refe
dim nums
nums=0
dim pkey
for each att in cla.Columns
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'------------------增加-------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = "int"
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i<>0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
datatype_change att,para
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i<>0 then
if att.foreignkey=false then
body=body+"model."+att.code+"="+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+"if("+att.code+"!=0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"model."+refe.code+"."+catch_string(refe.preview,"references","(",")")+"="+att.code+";"+vbcrlf
body=body+"}"
exit for
end if
next
end if
body=body+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Add(model);"+vbcrlf
body=body+"if(errnum==0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return model."+pkey.code+";"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return 0;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------修改---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
datatype_change att,para
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if att.foreignkey=false then
body=body+"model."+att.code+"="+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+"if("+att.code+"!=0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"model."+refe.code+"."+catch_string(refe.preview,"references","(",")")+"="+att.code+";"+vbcrlf
body=body+"}"
exit for
end if
next
end if
body=body+vbcrlf
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Update(model);"+vbcrlf
body=body+"if(errnum==0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------删除---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
datatype_change att,para
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Delete(model);"+vbcrlf
body=body+"if(errnum==0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
oper.static=true
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
'执行
body=body+"System.Data.DataSet ds=dal.All();"+vbcrlf
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------寻找单个---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code 'DS or DR
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
body=body+"model."
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
body=body+att.code+"="+att.code+";"+vbcrlf
end if
i=i+1
end if
next
body=body+"model=dal.Find(model);"+vbcrlf
body=body+"return model;"+vbcrlf
'
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
function catch_string(wholestring,keystring,startstring,endstring)'取字符
'wholestring 整字符
'keystring '关键字
'startstring '起始点
'endstring '结束点
dim i
dim keylength
dim startnum
dim endnum
dim value
dim char
dim j
dim k
keylength=len(keystring)
for i=1 to len(wholestring)
if mid(wholestring,i,keylength)=keystring then
exit for
end if
next
for j=i+keylength to len(wholestring)
if mid(wholestring,j,len(startstring))=startstring then
startnum=j
exit for
end if
next
for k=startnum to len(wholestring)
if mid(wholestring,k,len(endstring))=endstring then
endnum=k
exit for
end if
next
value=mid(wholestring,startnum+1,endnum-startnum-1)
catch_string=value
end function
function datatype_change(sql,net)'取数据类型
dim paratype
dim parasize
if sql.datatype="int" then net.datatype="int"
if sql.datatype="bit" then net.datatype="bool"
if sql.datatype="float" then net.datatype="float"
if sql.datatype="datetime" then net.datatype="DateTime"
if sql.datatype="tinyint" then net.datatype="Byte"
if left(cstr(sql.datatype),7)="varchar" then net.datatype="string"
if left(cstr(sql.datatype),6)="binary" then net.datatype="Binary"
end Function
'* File: BLL.vbs
'* Purpose: pdm to dal
'* Title: Create a new OOM
'* Category: Create
'* Version: 1.0Model
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "BLL" '层次名
'oom文件名CODE
model.Code = "BLL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Tables
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="BLL"+cla.name
cls.code="BLL"+cla.code
'cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace BLL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim refe
dim nums
nums=0
dim pkey
for each att in cla.Columns
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'------------------增加-------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = "int"
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i<>0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
datatype_change att,para
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i<>0 then
if att.foreignkey=false then
body=body+"model."+att.code+"="+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+"if("+att.code+"!=0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"model."+refe.code+"."+catch_string(refe.preview,"references","(",")")+"="+att.code+";"+vbcrlf
body=body+"}"
exit for
end if
next
end if
body=body+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Add(model);"+vbcrlf
body=body+"if(errnum==0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return model."+pkey.code+";"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return 0;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------修改---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
datatype_change att,para
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if att.foreignkey=false then
body=body+"model."+att.code+"="+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+"if("+att.code+"!=0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"model."+refe.code+"."+catch_string(refe.preview,"references","(",")")+"="+att.code+";"+vbcrlf
body=body+"}"
exit for
end if
next
end if
body=body+vbcrlf
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Update(model);"+vbcrlf
body=body+"if(errnum==0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------删除---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
datatype_change att,para
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Delete(model);"+vbcrlf
body=body+"if(errnum==0)"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
oper.static=true
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
'执行
body=body+"System.Data.DataSet ds=dal.All();"+vbcrlf
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------寻找单个---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code 'DS or DR
oper.static=true
'散装参数
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.FACTORY_DAL.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.FACTORY_MODEL.Get_MODEL"+cla.code+"();"+vbcrlf
body=body+"model."
i=0
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
body=body+att.code+"="+att.code+";"+vbcrlf
end if
i=i+1
end if
next
body=body+"model=dal.Find(model);"+vbcrlf
body=body+"return model;"+vbcrlf
'
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
function catch_string(wholestring,keystring,startstring,endstring)'取字符
'wholestring 整字符
'keystring '关键字
'startstring '起始点
'endstring '结束点
dim i
dim keylength
dim startnum
dim endnum
dim value
dim char
dim j
dim k
keylength=len(keystring)
for i=1 to len(wholestring)
if mid(wholestring,i,keylength)=keystring then
exit for
end if
next
for j=i+keylength to len(wholestring)
if mid(wholestring,j,len(startstring))=startstring then
startnum=j
exit for
end if
next
for k=startnum to len(wholestring)
if mid(wholestring,k,len(endstring))=endstring then
endnum=k
exit for
end if
next
value=mid(wholestring,startnum+1,endnum-startnum-1)
catch_string=value
end function
function datatype_change(sql,net)'取数据类型
dim paratype
dim parasize
if sql.datatype="int" then net.datatype="int"
if sql.datatype="bit" then net.datatype="bool"
if sql.datatype="float" then net.datatype="float"
if sql.datatype="datetime" then net.datatype="DateTime"
if sql.datatype="tinyint" then net.datatype="Byte"
if left(cstr(sql.datatype),7)="varchar" then net.datatype="string"
if left(cstr(sql.datatype),6)="binary" then net.datatype="Binary"
end Function
'******************************************************************************
'* File: DAL.vbs
'* Purpose: pdm to dal
'* Title: Create a new OOM
'* Category: Create
'* Version: 1.0Model
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "DAL" '层次名
'oom文件名CODE
model.Code = "DAL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Tables
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="DAL"+cla.name+"___"+"I"+cla.name
cls.code="DAL"+cla.code+"___"+"I"+cla.code
cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace DAL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim refe
dim nums
nums=0
dim pkey
for each att in cla.Columns
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'-----------------增加---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
if i=0 then
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
else
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf+"para["+cstr(i)+"].Value=obj."
if att.foreignkey=false then
body=body+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+refe.code+"."+catch_string(refe.preview,"references","(",")")+";"
exit for
end if
next
end if
body=body+vbcrlf
end if
body=body+vbcrlf
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " int ret=(db.Execproc("+chr(34)+"Proc_Add_"+cla.code+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
'再次循环,将OUTPUT参数赋给值对象
i=0
for each att in cla.Columns
if i=0 then body=body+"obj."+att.code+"="+"(int)para["+cstr(i)+"].Value;"+vbcrlf
i=i+1
next
'return
body=body+"return ret;"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "add ok"
'-----------------修改---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then 'oom 的隐藏属性
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."
if att.foreignkey=false then
body=body+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+refe.code+"."+catch_string(refe.preview,"references","(",")")+";"
exit for
end if
next
end if
body=body+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " int ret=db.Execproc("+chr(34)+"Proc_Upd_"+cla.code+chr(34)+","+"para"+"); " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"return ret;"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "update ok"
' ------------------删除---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+"1"+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+pkey.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+pkey.code+";"+vbcrlf
body=body+vbcrlf
end if
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " int ret=db.Execproc("+chr(34)+"Proc_Del_"+cla.code+chr(34)+","+"para"+"); " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"return ret;"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "delete ok"
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
body = "{" + vbCrLf
body=body+"string sql;"+vbcrlf
body=body+"sql="+chr(34)+"select * from vw_"+cla.name+chr(34)+";"+vbcrlf
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body=body+"System.Data.DataSet ds=db.getData(sql);"+vbcrlf'DB类名,方法名
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'msgbox "all ok"
'-----------------查找---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
if i=0 then
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf+"para["+cstr(i)+"].Value=obj."+att.code+";"+vbcrlf
else
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
end if
body=body+vbcrlf
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " if (db.Execproc("+chr(34)+"Proc_Find_"+cla.code+chr(34)+","+"para"+")==0) " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"{"+vbcrlf
'再次循环,将OUTPUT参数赋给值对象
i=0
for each att in cla.Columns
if i<>0 then
body=body+"obj."
if att.foreignkey=false then
body=body+att.code
body=body+"="+"para["+cstr(i)+"].Value.ToString();"+vbcrlf
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+refe.code+"."+catch_string(refe.preview,"references","(",")")
body=body+"="+"(int)para["+cstr(i)+"].Value;"+vbcrlf
exit for
end if
next
end if
end if
i=i+1
next
body=body+"//外键关系可能要先实例化"+vbcrlf
body=body+"return obj;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return null;"+vbcrlf
body=body+"}"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "find ok"
CreateOperations = True
End Function
Function datatype_transport(att,body,i)'取数据类型
dim paratype
dim parasize
body=body+"para["+cstr(i)+"].SqlDbType= System.Data.SqlDbType."
if att.datatype="int" then paratype="Int":parasize=4
if att.datatype="bit" then paratype="Bit":parasize=1
if att.datatype="float" then paratype="Float":parasize=8
if att.datatype="datetime" then paratype="DateTime":parasize=8
if att.datatype="tinyint" then paratype="TinyInt":parasize=2
if left(cstr(att.datatype),7)="varchar" then paratype="VarChar": datesize att,parasize
if left(cstr(att.datatype),6)="binary" then paratype="Binary": datesize att,parasize
body=body+paratype+";"
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Size="+cstr(parasize)+";"+vbcrlf
end Function
Function datesize(att,size)'取长度
dim lef,rig
dim i
for i=1 to len(att.datatype)
if mid(att.datatype,i,1)="(" then lef=i
if mid(att.datatype,i,1)=")" then rig=i
next
size=mid(att.datatype,lef+1,rig-lef-1)
end Function
function catch_string(wholestring,keystring,startstring,endstring)'取字符
'wholestring 整字符
'keystring '关键字
'startstring '起始点
'endstring '结束点
dim i
dim keylength
dim startnum
dim endnum
dim value
dim char
dim j
dim k
keylength=len(keystring)
for i=1 to len(wholestring)
if mid(wholestring,i,keylength)=keystring then
exit for
end if
next
for j=i+keylength to len(wholestring)
if mid(wholestring,j,len(startstring))=startstring then
startnum=j
exit for
end if
next
for k=startnum to len(wholestring)
if mid(wholestring,k,len(endstring))=endstring then
endnum=k
exit for
end if
next
value=mid(wholestring,startnum+1,endnum-startnum-1)
catch_string=value
end function
'* File: DAL.vbs
'* Purpose: pdm to dal
'* Title: Create a new OOM
'* Category: Create
'* Version: 1.0Model
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "DAL" '层次名
'oom文件名CODE
model.Code = "DAL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Tables
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="DAL"+cla.name+"___"+"I"+cla.name
cls.code="DAL"+cla.code+"___"+"I"+cla.code
cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace DAL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim refe
dim nums
nums=0
dim pkey
for each att in cla.Columns
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'-----------------增加---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
if i=0 then
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
else
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf+"para["+cstr(i)+"].Value=obj."
if att.foreignkey=false then
body=body+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+refe.code+"."+catch_string(refe.preview,"references","(",")")+";"
exit for
end if
next
end if
body=body+vbcrlf
end if
body=body+vbcrlf
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " int ret=(db.Execproc("+chr(34)+"Proc_Add_"+cla.code+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
'再次循环,将OUTPUT参数赋给值对象
i=0
for each att in cla.Columns
if i=0 then body=body+"obj."+att.code+"="+"(int)para["+cstr(i)+"].Value;"+vbcrlf
i=i+1
next
'return
body=body+"return ret;"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "add ok"
'-----------------修改---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then 'oom 的隐藏属性
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."
if att.foreignkey=false then
body=body+att.code+";"
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+refe.code+"."+catch_string(refe.preview,"references","(",")")+";"
exit for
end if
next
end if
body=body+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " int ret=db.Execproc("+chr(34)+"Proc_Upd_"+cla.code+chr(34)+","+"para"+"); " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"return ret;"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "update ok"
' ------------------删除---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+"1"+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then
if i=0 then
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+pkey.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+pkey.code+";"+vbcrlf
body=body+vbcrlf
end if
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " int ret=db.Execproc("+chr(34)+"Proc_Del_"+cla.code+chr(34)+","+"para"+"); " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"return ret;"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "delete ok"
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
body = "{" + vbCrLf
body=body+"string sql;"+vbcrlf
body=body+"sql="+chr(34)+"select * from vw_"+cla.name+chr(34)+";"+vbcrlf
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body=body+"System.Data.DataSet ds=db.getData(sql);"+vbcrlf'DB类名,方法名
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'msgbox "all ok"
'-----------------查找---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Columns
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"]=new System.Data.SqlClient.SqlParameter();"+vbcrlf
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
datatype_transport att,body,i
if i=0 then
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf+"para["+cstr(i)+"].Value=obj."+att.code+";"+vbcrlf
else
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
end if
body=body+vbcrlf
i=i+1
end if
next
body=body+"DB.DBCom db=new DB.DBCom();"+vbcrlf
body = body + " if (db.Execproc("+chr(34)+"Proc_Find_"+cla.code+chr(34)+","+"para"+")==0) " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"{"+vbcrlf
'再次循环,将OUTPUT参数赋给值对象
i=0
for each att in cla.Columns
if i<>0 then
body=body+"obj."
if att.foreignkey=false then
body=body+att.code
body=body+"="+"para["+cstr(i)+"].Value.ToString();"+vbcrlf
else
for each refe in cla.model.References
'preview分析
if att.code=catch_string(refe.preview,"foreign key","(",")") and catch_string(refe.preview,"alter table"," ",vbcrlf)=cla.code then
body=body+refe.code+"."+catch_string(refe.preview,"references","(",")")
body=body+"="+"(int)para["+cstr(i)+"].Value;"+vbcrlf
exit for
end if
next
end if
end if
i=i+1
next
body=body+"//外键关系可能要先实例化"+vbcrlf
body=body+"return obj;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return null;"+vbcrlf
body=body+"}"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
'msgbox "find ok"
CreateOperations = True
End Function
Function datatype_transport(att,body,i)'取数据类型
dim paratype
dim parasize
body=body+"para["+cstr(i)+"].SqlDbType= System.Data.SqlDbType."
if att.datatype="int" then paratype="Int":parasize=4
if att.datatype="bit" then paratype="Bit":parasize=1
if att.datatype="float" then paratype="Float":parasize=8
if att.datatype="datetime" then paratype="DateTime":parasize=8
if att.datatype="tinyint" then paratype="TinyInt":parasize=2
if left(cstr(att.datatype),7)="varchar" then paratype="VarChar": datesize att,parasize
if left(cstr(att.datatype),6)="binary" then paratype="Binary": datesize att,parasize
body=body+paratype+";"
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Size="+cstr(parasize)+";"+vbcrlf
end Function
Function datesize(att,size)'取长度
dim lef,rig
dim i
for i=1 to len(att.datatype)
if mid(att.datatype,i,1)="(" then lef=i
if mid(att.datatype,i,1)=")" then rig=i
next
size=mid(att.datatype,lef+1,rig-lef-1)
end Function
function catch_string(wholestring,keystring,startstring,endstring)'取字符
'wholestring 整字符
'keystring '关键字
'startstring '起始点
'endstring '结束点
dim i
dim keylength
dim startnum
dim endnum
dim value
dim char
dim j
dim k
keylength=len(keystring)
for i=1 to len(wholestring)
if mid(wholestring,i,keylength)=keystring then
exit for
end if
next
for j=i+keylength to len(wholestring)
if mid(wholestring,j,len(startstring))=startstring then
startnum=j
exit for
end if
next
for k=startnum to len(wholestring)
if mid(wholestring,k,len(endstring))=endstring then
endnum=k
exit for
end if
next
value=mid(wholestring,startnum+1,endnum-startnum-1)
catch_string=value
end function
'******************************************************************************
'* File: factory_model.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM for 工厂类
'* Version: 1.0 基本
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "FACTORY" '层次名
'oom文件名CODE
model.Code = "FACTORY" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="FACTORY_MODEL"
cls.code="FACTORY_MODEL"
cls.Imports=cls.Imports+vbcrlf+"using MODEL;"+vbcrlf
cls.Imports=cls.Imports+vbcrlf+"namespace FACTORY"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
for each cla in actmodel.Classes
CreateOperations cls,cla'写方法,参数为类
next
Set sym = diagram.AttachObject(cls)
CreateClasses = True
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
Function CreateAttributes(cls)
Dim attr
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "ID"
attr.Code = "ID"
attr.DataType = "int"
attr.Persistent = True
attr.PersistentCode = "ID"
attr.PersistentDataType = "I"
attr.PrimaryIdentifier = True
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Name"
attr.Code = "Name"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "NAME"
attr.PersistentDataType = "A30"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Phone"
attr.Code = "Phone"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "PHONE"
attr.PersistentDataType = "A20"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Email"
attr.Code = "Email"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "EMAIL"
attr.PersistentDataType = "A30"
CreateAttributes = True
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
dim i
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Get_MODEL"+cla.name
oper.Code = "Get_MODEL"+cla.code
oper.ReturnType = "MODEL."+cla.code
oper.static=true
body = "{" + vbCrLf
body = body + " return new "+"MODEL."+cla.code+"();"+ vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'* File: factory_model.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM for 工厂类
'* Version: 1.0 基本
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "FACTORY" '层次名
'oom文件名CODE
model.Code = "FACTORY" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="FACTORY_MODEL"
cls.code="FACTORY_MODEL"
cls.Imports=cls.Imports+vbcrlf+"using MODEL;"+vbcrlf
cls.Imports=cls.Imports+vbcrlf+"namespace FACTORY"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
for each cla in actmodel.Classes
CreateOperations cls,cla'写方法,参数为类
next
Set sym = diagram.AttachObject(cls)
CreateClasses = True
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
Function CreateAttributes(cls)
Dim attr
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "ID"
attr.Code = "ID"
attr.DataType = "int"
attr.Persistent = True
attr.PersistentCode = "ID"
attr.PersistentDataType = "I"
attr.PrimaryIdentifier = True
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Name"
attr.Code = "Name"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "NAME"
attr.PersistentDataType = "A30"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Phone"
attr.Code = "Phone"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "PHONE"
attr.PersistentDataType = "A20"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Email"
attr.Code = "Email"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "EMAIL"
attr.PersistentDataType = "A30"
CreateAttributes = True
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
dim i
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Get_MODEL"+cla.name
oper.Code = "Get_MODEL"+cla.code
oper.ReturnType = "MODEL."+cla.code
oper.static=true
body = "{" + vbCrLf
body = body + " return new "+"MODEL."+cla.code+"();"+ vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'******************************************************************************
'* File: IDAL.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM for interface
'* Version: 1.0基本
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "IDAL" '层次名
'oom文件名CODE
model.Code = "IDAL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim interface
Dim sym
dim cla
for each cla in actmodel.Classes
Set interface = model.CreateObject(PdOOM.cls_Interface)
interface.name="I"+cla.name
interface.code="I"+cla.code
interface.Imports=interface.Imports+vbcrlf+"namespace IDAL"+vbcrlf+"{"+vbcrlf
interface.Footer=interface.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations interface ,cla'写方法,参数为类
Set sym = diagram.AttachObject(interface)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
'Createinterface=true
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
'interface 无属性
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(interface ,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
for each att in cla.Attributes
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'-----------------增加---------------
i=0
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
'-----------------修改---------------
i=0
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
' ------------------删除---------------
i=0
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
' ------------------查找全部---------------
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "GetAll"
oper.Code = "GetAll"
oper.ReturnType = "System.Data.DataSet"
body = ";" + vbCrLf
oper.Body = body
' ------------------查找单个---------------
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
CreateOperations = True
End Function
'* File: IDAL.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM for interface
'* Version: 1.0基本
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "IDAL" '层次名
'oom文件名CODE
model.Code = "IDAL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim interface
Dim sym
dim cla
for each cla in actmodel.Classes
Set interface = model.CreateObject(PdOOM.cls_Interface)
interface.name="I"+cla.name
interface.code="I"+cla.code
interface.Imports=interface.Imports+vbcrlf+"namespace IDAL"+vbcrlf+"{"+vbcrlf
interface.Footer=interface.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations interface ,cla'写方法,参数为类
Set sym = diagram.AttachObject(interface)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
'Createinterface=true
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
'interface 无属性
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(interface ,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
for each att in cla.Attributes
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'-----------------增加---------------
i=0
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
'-----------------修改---------------
i=0
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
' ------------------删除---------------
i=0
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
' ------------------查找全部---------------
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "GetAll"
oper.Code = "GetAll"
oper.ReturnType = "System.Data.DataSet"
body = ";" + vbCrLf
oper.Body = body
' ------------------查找单个---------------
Set oper = interface.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = ";" + vbCrLf
oper.Body = body
CreateOperations = True
End Function
'******************************************************************************
'* File: Create OOM.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM
'* Category: Create Model
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "BLL" '层次名
'oom文件名CODE
model.Code = "BLL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Classes
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="BLL"+cla.name
cls.code="BLL"+cla.code
'cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace BLL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
Function CreateAttributes(cls)
Dim attr
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "ID"
attr.Code = "ID"
attr.DataType = "int"
attr.Persistent = True
attr.PersistentCode = "ID"
attr.PersistentDataType = "I"
attr.PrimaryIdentifier = True
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Name"
attr.Code = "Name"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "NAME"
attr.PersistentDataType = "A30"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Phone"
attr.Code = "Phone"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "PHONE"
attr.PersistentDataType = "A20"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Email"
attr.Code = "Email"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "EMAIL"
attr.PersistentDataType = "A30"
CreateAttributes = True
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
for each att in cla.Attributes
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'------------------增加-------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = "int"
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i<>0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i<>0 then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Add(model);"+vbcrlf
body=body+"if errnum=0 then"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return model."+pkey.code+";"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return 0;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------修改---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Update(model);"+vbcrlf
body=body+"if errnum=0 then"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------删除---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i=0 then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Delete(model);"+vbcrlf
body=body+"if errnum=0 then"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
oper.static=true
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
'执行
body=body+"System.Data.DataSet ds=dal.All();"+vbcrlf
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------寻找单个(未完)---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code 'DS or DR
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
'
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'* File: Create OOM.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM
'* Category: Create Model
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "BLL" '层次名
'oom文件名CODE
model.Code = "BLL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Classes
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="BLL"+cla.name
cls.code="BLL"+cla.code
'cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace BLL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create attributes function
'-----------------------------------------------------------------------------
Function CreateAttributes(cls)
Dim attr
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "ID"
attr.Code = "ID"
attr.DataType = "int"
attr.Persistent = True
attr.PersistentCode = "ID"
attr.PersistentDataType = "I"
attr.PrimaryIdentifier = True
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Name"
attr.Code = "Name"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "NAME"
attr.PersistentDataType = "A30"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Phone"
attr.Code = "Phone"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "PHONE"
attr.PersistentDataType = "A20"
Set attr = cls.CreateObject(PdOOM.cls_Attribute)
attr.Name = "Email"
attr.Code = "Email"
attr.DataType = "String"
attr.Persistent = True
attr.PersistentCode = "EMAIL"
attr.PersistentDataType = "A30"
CreateAttributes = True
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
for each att in cla.Attributes
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'------------------增加-------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = "int"
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i<>0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i<>0 then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Add(model);"+vbcrlf
body=body+"if errnum=0 then"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return model."+pkey.code+";"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return 0;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------修改---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Update(model);"+vbcrlf
body=body+"if errnum=0 then"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------删除---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = "bool"
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
body=body+"MODEL."+cla.code+vbtab+"model=FACTORY.Get_MODEL"+cla.code+"();"+vbcrlf
'封装
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i=0 then
body=body+"model."+att.code+"="+att.code+";"+vbcrlf
end if
end if
i=i+1
next
'执行
body=body+"int errnum=dal.Delete(model);"+vbcrlf
body=body+"if errnum=0 then"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return true;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return false;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
oper.static=true
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
'执行
body=body+"System.Data.DataSet ds=dal.All();"+vbcrlf
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------寻找单个(未完)---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code 'DS or DR
oper.static=true
'散装参数
i=0
for each att in cla.Attributes
if left(att.code,1)<>"_" then
if i=0 then
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name=att.name
para.code=att.code
para.datatype=att.datatype
end if
i=i+1
end if
next
'生成类
body = "{" + vbCrLf
body=body+"DAL.DAL"+cla.code+vbtab+"dal=FACTORY.Get_DAL"+cla.code+"();"+vbcrlf
'
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'******************************************************************************
'* File: Create OOM.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM
'* Category: Create Model
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "DAL" '层次名
'oom文件名CODE
model.Code = "DAL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Classes
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="DAL"+cla.name+"___"+"IDAL"+cla.name
cls.code="DAL"+cla.code+"___"+"IDAL"+cla.code
cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace DAL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
for each att in cla.Attributes
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'-----------------增加---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
select case i
case 0:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
case else:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
end select
body=body+"para["+cstr(i)+"].Direction= System.Data.ParameterDirection."
select case att.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+att.code+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body = body + " return(DB.DBCOM.Execproc("+chr(34)+"Proc_add"+cla.name+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
'-----------------修改---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+cstr(i)+"].Direction= System.Data.ParameterDirection."
select case att.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+att.code+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body = body + " return(DB.DBCOM.Execproc("+chr(34)+"Proc_Update"+cla.name+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
' ------------------删除---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+"1"+"];"+vbcrlf
'chr(34)=" " "
body=body+"para["+"0"+"].ParameterName="+chr(34)+"@"+pkey.code+chr(34)+";"+vbcrlf
body=body+"para["+"0"+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+"0"+"].Direction= System.Data.ParameterDirection."
select case pkey.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+"0"+"].Value=obj."+pkey.code+vbcrlf
body=body+vbcrlf
body = body + " return(DB.DBCOM.Execproc("+chr(34)+"Proc_Del"+cla.name+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
body = "{" + vbCrLf
body=body+"string sql;"+vbcrlf
body=body+"sql="+chr(34)+"select * from vw_"+cla.name+chr(34)+";"+vbcrlf
body=body+"System.Data.DataSet ds=DB.DBCOM.getData(sql);"+vbcrlf'DB类名,方法名
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------增加---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
select case i
case 0:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Intput;"+vbcrlf
case else:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
end select
body=body+"para["+cstr(i)+"].Direction= System.Data.ParameterDirection."
select case att.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+att.code+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body = body + " if (DB.DBCOM.Execproc("+chr(34)+"Proc_Find"+cla.name+chr(34)+","+"para"+")=0) " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"{"+vbcrlf
body=body+"return obj;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return null;"+vbcrlf
body=body+"}"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
'* File: Create OOM.vbs
'* Purpose: This VB Script shows how to create a new OOM model
'* Title: Create a new OOM
'* Category: Create Model
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
'由MODEL创建DAL
'-----------------------------------------------------------------------------
' Initialization
'-----------------------------------------------------------------------------
' Set interactive mode to Batch
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Create an OOM model with a class diagram
'原oom文件
dim actmodel
set actmodel=ActiveModel
Dim Model
'创建OOM实例
'oom名
Set model = CreateModel(PdOOM.cls_Model, "a") '无用
'oom文件名NAME
model.Name = "DAL" '层次名
'oom文件名CODE
model.Code = "DAL" '层次名
' Get the class diagram
Dim diagram
Set diagram = model.ClassDiagrams.Item(0)
CreateClasses model, diagram
' Create classes
'生成类
'-----------------------------------------------------------------------------
' Create classes function
'创建类
'-----------------------------------------------------------------------------
Function CreateClasses(model, diagram)
' Create a class
Dim cls
Dim sym
dim cla
for each cla in actmodel.Classes
Set cls = model.CreateObject(PdOOM.cls_Class)
cls.name="DAL"+cla.name+"___"+"IDAL"+cla.name
cls.code="DAL"+cla.code+"___"+"IDAL"+cla.code
cls.Imports=cls.Imports+vbcrlf+"using IDAL;"
cls.Imports=cls.Imports+vbcrlf+"namespace DAL"+vbcrlf+"{"+vbcrlf
cls.Footer=cls.Footer+"}"
'cls.Stereotype = "Class"
CreateOperations cls,cla'写方法,参数为类
Set sym = diagram.AttachObject(cls)
CreateClasses = True
next
' Create attributes属性
'CreateAttributes cls
' Create methods方法
'CreateOperations cls(cla)
' Create a symbol for the class
End Function
'-----------------------------------------------------------------------------
' Create operations function
'-----------------------------------------------------------------------------
'方法
Function CreateOperations(cls,cla)
Dim oper
dim att
Dim body
dim para
dim nums
nums=0
dim pkey
for each att in cla.Attributes
if nums=0 then set pkey=att
if left(att.code,1)<>"_" then nums=nums+1
next '先循环一遍,计算参数总数,并记录主健类型
dim i
'-----------------增加---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Add"
oper.Code = "Add"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
select case i
case 0:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
case else:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
end select
body=body+"para["+cstr(i)+"].Direction= System.Data.ParameterDirection."
select case att.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+att.code+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body = body + " return(DB.DBCOM.Execproc("+chr(34)+"Proc_add"+cla.name+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
'-----------------修改---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Update"
oper.Code = "Update"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+cstr(i)+"].Direction= System.Data.ParameterDirection."
select case att.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+att.code+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body = body + " return(DB.DBCOM.Execproc("+chr(34)+"Proc_Update"+cla.name+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
' ------------------删除---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Delete"
oper.Code = "Delete"
oper.ReturnType = pkey.datatype
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+"1"+"];"+vbcrlf
'chr(34)=" " "
body=body+"para["+"0"+"].ParameterName="+chr(34)+"@"+pkey.code+chr(34)+";"+vbcrlf
body=body+"para["+"0"+"].Direction=System.Data.ParameterDirection.Input;"+vbcrlf
body=body+"para["+"0"+"].Direction= System.Data.ParameterDirection."
select case pkey.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+"0"+"].Value=obj."+pkey.code+vbcrlf
body=body+vbcrlf
body = body + " return(DB.DBCOM.Execproc("+chr(34)+"Proc_Del"+cla.name+chr(34)+","+"para"+")); " + vbCrLf 'DB类名,方法名,存储过程名
body = body + "}"
body=body+vbcrlf
oper.Body = body
' ------------------查找全部---------------
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "All"
oper.Code = "All"
oper.ReturnType = "System.Data.DataSet"
body = "{" + vbCrLf
body=body+"string sql;"+vbcrlf
body=body+"sql="+chr(34)+"select * from vw_"+cla.name+chr(34)+";"+vbcrlf
body=body+"System.Data.DataSet ds=DB.DBCOM.getData(sql);"+vbcrlf'DB类名,方法名
body=body+"return ds;"+vbcrlf
body=body+"}"+vbcrlf
oper.Body = body
'-----------------增加---------------
i=0
Set oper = cls.CreateObject(PdOOM.cls_Operation)
oper.Name = "Find"
oper.Code = "Find"
oper.ReturnType = "MODEL."+cla.code
set para=oper.CreateObject(PdooM.cls_Parameter)
para.name="obj"
para.code="obj"
para.datatype="MODEL."+cla.code
body = "{" + vbCrLf
body=body+"System.Data.SqlClient.SqlParameter[] para=new System.Data.SqlClient.SqlParameter["+cstr(nums)+"];"+vbcrlf
'chr(34)=" " "
for each att in cla.Attributes
if left(att.code,1)<>"_" then
body=body+"para["+cstr(i)+"].ParameterName="+chr(34)+"@"+att.code+chr(34)+";"+vbcrlf
select case i
case 0:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Intput;"+vbcrlf
case else:body=body+"para["+cstr(i)+"].Direction=System.Data.ParameterDirection.Output;"+vbcrlf
end select
body=body+"para["+cstr(i)+"].Direction= System.Data.ParameterDirection."
select case att.datatype
case "int":body=body+"Int32;"
case "string":body=body+"String;"
case "Single":body=body+"Decimal;"
case "single":body=body+"Decimal;"
case "date":body=body+"DateTime;"
case "time":body=body+"DateTime;"
case else:body=body+"Int32;"
end select
body=body+vbcrlf
body=body+"para["+cstr(i)+"].Value=obj."+att.code+vbcrlf
body=body+vbcrlf
i=i+1
end if
next
body = body + " if (DB.DBCOM.Execproc("+chr(34)+"Proc_Find"+cla.name+chr(34)+","+"para"+")=0) " + vbCrLf 'DB类名,方法名,存储过程名
body=body+"{"+vbcrlf
body=body+"return obj;"+vbcrlf
body=body+"}"+vbcrlf
body=body+"else"+vbcrlf
body=body+"{"+vbcrlf
body=body+"return null;"+vbcrlf
body=body+"}"+vbcrlf
body = body + "}"
body=body+vbcrlf
oper.Body = body
CreateOperations = True
End Function
msgbox catch_string("1234567890 ref (sada) (jjjj)","ref","(",")")
function catch_string(wholestring,keystring,startstring,endstring)'取字符
'wholestring 整字符
'keystring '关键字
'startstring '起始点
'endstring '结束点
dim i
dim keylength
dim startnum
dim endnum
dim value
dim char
dim j
dim k
keylength=len(keystring)
for i=1 to len(wholestring)
if mid(wholestring,i,keylength)=keystring then
exit for
end if
next
for j=i to len(wholestring)
if mid(wholestring,j,len(startstring))=startstring then
startnum=j
exit for
end if
next
for k=startnum to len(wholestring)
if mid(wholestring,k,len(endstring))=endstring then
endnum=k
exit for
end if
next
value=mid(wholestring,startnum+1,endnum-startnum-1)
catch_string=value
end function