-
Notifications
You must be signed in to change notification settings - Fork 0
/
Web QCFunctions.bas
305 lines (218 loc) · 6.61 KB
/
Web QCFunctions.bas
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
Attribute VB_Name = "QCFunctions"
Public Function IsConnected() As Boolean
If tdc Is Nothing Then
IsConnected = False
Else
IsConnected = tdc.Connected
End If
End Function
Public Sub DisconnectFromQC()
If IsConnected Then
tdc.Disconnect
tdc.ReleaseConnection
' Destroy the object
Set tdc = Nothing
End If
End Sub
Public Function ConnectToQC(strDomain As String, strTDProject As String)
'Method to connect to Quaility Centre. This takes the domain, product,
'username and password as input strings
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
' Connect to the domain and project
tdc.Connect strDomain, strTDProject
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function
Public Function LoginToQCProject(strUser As String, strPassWord As String)
'Method to login to QC Project. Takes project and password as inputs.
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
' Exit out if we're already logged in
Set tdc = New TDAPIOLELib.TDConnection
If tdc.Connected = True Then
If tdc.LoggedIn Then
Exit Function
End If
End If
tdc.InitConnectionEx "http://cmutility:8080/qcbin"
tdc.Login strUser, strPassWord
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function
Public Sub CreateFactories()
Dim tdcBugFactory
Dim tdcBugFilter
Dim tdcTestSetFactory
Dim tdcTestFactory
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
'Set up the Bug Factory
Set tdcBugFactory = tdc.BugFactory
Set tdcBugFilter = tdcBugFactory.Filter
'Set up the Test Set Factory
Set tdcTestSetFactory = tdc.TestSetFactory
'Set up the Test Factory
Set tdcTestFactory = tdc.TestFactory
Exit Sub
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Sub
Public Function GetListValues(strListName As String) As list
'This function gets the values in a QC list
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
Dim custom As Customization
Dim customLists As CustomizationLists
Dim customList As CustomizationList
Dim Node As CustomizationListNode
Dim lstValues As list
Dim strValue As Variant
Dim i As Integer
'Get the cust list
Set custom = tdc.Customization
Set customLists = custom.lists
Set customList = customLists.list(strListName)
'Get the tree node that represents the list
Set Node = customList.RootNode
Set lstValues = New list
'Loop through list and assign each value to array.
i = 1
Do Until i = Node.ChildrenCount + 1
strValue = Node.Children(i).Name
lstValues.Add (strValue)
i = i + 1
Loop
Set GetListValues = lstValues
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function
Public Function GetFieldLabels(strTableName As String) As Variant
'This function builds an array contain all the label names of fields in an entity
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
Dim i As Integer
Dim arLabels()
' Get the list of fields
Set fieldList = tdc.Fields(strTableName)
'Loop through all of the fields in the entity and assign the label name to an array
i = -1
For Each myField In fieldList
i = i + 1
ReDim Preserve arLabels(i)
arLabels(i) = myField.Property.UserLabel
Next
'Return the array of labels
GetFieldLabels = arLabels
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function
Public Function GetFieldName(strField As String, strTable As String) As String
'This function searches an array of labels to return a field name
Dim fieldList
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
Dim i As Integer
' Set up the field list
Set fieldList = tdc.Fields(strTable)
'Loop through the array of field labels to find the one that matches the input field
For i = 1 To fieldList.Count
If fieldList.Item(i).Property.UserLabel = strField Then
GetFieldName = fieldList.Item(i).Name
Exit Function
End If
Next
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function
Public Function customLists(strFieldName As String, strTable As String) As String
'This function finds the list which is associated with a field
If blnDebug = False Then
On Error GoTo ErrorHandler
End If
Dim cust As Customization
Dim custFields As CustomizationFields
Dim aCustField As CustomizationField
Dim custLists As CustomizationLists
Dim aCustList As CustomizationList
Dim listName As String
Set cust = tdc.Customization
Set custFields = cust.Fields
Set aCustField = custFields.Field(strTable, strFieldName)
Set aCustList = aCustField.list
listName = aCustList.Name
customLists = listName
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function
Sub ErrorHandler(MyErr As ErrObject)
Dim Prompt As String
Dim Title As String
Dim MyResponse As VbMsgBoxResult
' Show the app again
Application.Visible = True
' Create the message
Prompt = "The following error has occured:" & vbCrLf & vbCrLf & MyErr.Description & " - Ending now"
Title = "Error"
' Display the message and clean up
MyResponse = MsgBox(Prompt, vbOKOnly, Title)
If objWrkBk Is Nothing Then
Else
objWrkBk.Save
objWrkBk.Close
Set objWrkSht = Nothing
Set objWrkBk = Nothing
End If
DisconnectFromQC
Application.Cursor = xlDefault
Application.ScreenUpdating = True
End
On Error GoTo 0
End Sub
Public Function GetComboValues(strListName As String) As Variant
'This function gets the values in a QC list
On Error GoTo ErrorHandler
Dim custom As Customization
Dim lists As CustomizationLists
Dim list As CustomizationList
Dim Node As CustomizationListNode
Dim i As Integer
'Get the cust list
Set custom = tdc.Customization
Set lists = custom.lists
Set list = lists.list(strListName)
'Get the tree node that represents the list
Set Node = list.RootNode
ReDim arListValues(Node.ChildrenCount) As String
'Loop through list and assign each value to array.
i = 1
Do Until i > Node.ChildrenCount
arListValues(i - 1) = Node.Children(i).Name
i = i + 1
Loop
'Return the array of list values
GetComboValues = arListValues
Exit Function
ErrorHandler:
Call ErrorHandler(Err)
Resume Next
End Function