-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapConnection.cls
176 lines (144 loc) · 5.48 KB
/
MapConnection.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "MapConnection"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@Folder("Operation.ConnAnalysis")
Private mModel As New StrModel
Private mDsSys As New DataSheetSystem
Private mCompleteMessageAddition As String
Private mTerminateMessageMain As String, mTerminateMessageAddition As String
Private MapByJointName As New MapByJointName
Private MapByContainsSecAndRestr As New MapByContainsSecAndRestr
Private MapByMatchAllSecAndRestr As New MapByMatchAllSecAndRestr
Private MapByContainsOnly As New MapByContainsOnly
Public Property Get CompleteMessageAddition() As String
CompleteMessageAddition = mCompleteMessageAddition
End Property
Public Property Get TerminateMessageMain() As String
TerminateMessageMain = mTerminateMessageMain
End Property
Public Property Get TerminateMessageAddition() As String
TerminateMessageAddition = mTerminateMessageAddition
End Property
Public Function Main() As Integer
Dim ret As Integer
ret = CheckDataBeforeStart
If Not ret = 0 Then
mTerminateMessageMain = "no data is found in the workbook! The macro will be terminated."
GoTo ExitFunction
End If
g_log.WriteLog "Connection Matching Started."
ret = FormStrObj
If Not ret = 0 Then
GoTo ExitFunction
End If
ret = MatchConn
If Not ret = 0 Then
mTerminateMessageMain = "no Connection Type is defined in the workbook! The macro will be terminated." _
& " Plesae go to the worksheet 'Define_ConnectionType' to define the connection type."
GoTo ExitFunction
End If
WriteData
g_log.WriteLog "Connection Matching Completed."
mDsSys.prop("isCreated", "isMappedConn") = True
ExitFunction:
Main = ret
Application.StatusBar = False
End Function
Private Function CheckDataBeforeStart() As Integer
If Not mDsSys.prop("WhatOperationCanProcess", "MapConnection") Then
CheckDataBeforeStart = -1
End If
End Function
Private Function FormStrObj() As Integer
Dim ret As Integer
With mModel.Constructor
ret = .FormJointObj
If Not ret = 0 Then GoTo ExitFunction
ret = .FormJointObjForConnMap
If Not ret = 0 Then GoTo ExitFunction
ret = .FormFrmObj
If Not ret = 0 Then GoTo ExitFunction
ret = .FormMemberObj
If Not ret = 0 Then GoTo ExitFunction
ret = .FormConnTypeObjForMatching
If Not ret = 0 Then GoTo ExitFunction
End With
ExitFunction:
FormStrObj = ret
End Function
Private Function MatchConn() As Integer
Dim i As Long
Dim connType As StrConnectionType, connTypes As Collection
Dim oMapMethod As IMapConnMethod
Dim ret As Integer, numOfConnTypes As Long
Set connTypes = mModel.conns
numOfConnTypes = connTypes.count
If numOfConnTypes = 0 Then
ret = -1
GoTo ExitFunction
End If
'InitializeMappingMethod
For i = 1 To numOfConnTypes
Application.StatusBar = "Start Mapping Connection...Progress = " & i & "/" & numOfConnTypes
Set connType = connTypes(i)
Set oMapMethod = SelectMappingMethod(connType.mapMethod, mModel, connType)
If Not oMapMethod Is Nothing Then
oMapMethod.MapConnection connType
g_log.WriteLog " Connection Type '" & connType.Name & "' matching completed."
End If
Next
ExitFunction:
MatchConn = ret
End Function
Private Sub WriteData()
Dim dsManager As DataSheetManager
Dim dsJtConnectivity As oDataSheet, dsConnType As oDataSheet
Dim df As clsDataFrame
Set dsManager = New DataSheetManager
Set dsJtConnectivity = dsManager.DSJointConnectivity
Set dsConnType = dsManager.DSConnectionType
Set df = mModel.GetDataframe(obj_jt, "matchedConnectionStr")
With dsJtConnectivity.tagSelector
dsJtConnectivity.ClearColumnData .matchedType
dsJtConnectivity.WriteDataframe df, True, False, .matchedType
End With
Set df = mModel.GetDataframe(obj_connection, "jointsName")
With dsConnType.tagSelector
dsConnType.ClearColumnData .matchedJoint
dsConnType.WriteDataframe df, True, False, .matchedJoint
End With
End Sub
'Private Sub InitializeMappingMethod()
'' MapByJointName.Initialize mModel
'' MapByContainsSecAndRestr.Initialize mModel
'' MapByMatchAllSecAndRestr.Initialize mModel
'' MapByContainsOnly.Initialize mModel
'End Sub
Private Function SelectMappingMethod(sMapMethod As String, model As StrModel, connType As StrConnectionType) As IMapConnMethod
Dim oMapMethod As IMapConnMethod
sMapMethod = UCase(sMapMethod)
If Not connType.mapJtsName = vbNullString Then
Set oMapMethod = MapByJointName
ElseIf sMapMethod = "CONTAINS" Then
Set oMapMethod = MapByContainsSecAndRestr
ElseIf sMapMethod = "MATCH ALL" Then
Set oMapMethod = MapByMatchAllSecAndRestr
ElseIf sMapMethod = "CONTAINS ONLY" Then
Set oMapMethod = MapByContainsOnly
Else
g_log.RaiseWarning "Cannot regconize connection mapping method for Connection Type '" & _
connType.Name & "'. Record Skip", failToRegconizeConnMatchMethod
Exit Function
End If
oMapMethod.Initialize model
Set SelectMappingMethod = oMapMethod
End Function
Public Property Get completeMsg() As String
completeMsg = mCompleteMsg
End Property