Subversion Repositories DevTools

Rev

Rev 5513 | Rev 5840 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5513 Rev 5836
Line 1... Line 1...
1
<%
1
<%
2
'=============================================================
2
'=============================================================
3
'//
3
'//
4
'//						Validation Control
4
'//                  Validation Control
5
'//
5
'//
6
'// version: 		1.6
-
 
7
'//	last modified: 	02-Sep-2004 12:11 by Sasha Vukovic
-
 
8
'=============================================================
6
'=============================================================
9
%>
7
%>
10
<%
8
<%
11
Class ValidationControl
9
Class ValidationControl
12
	
10
 
13
	Private maRules()
11
   Private maRules()
14
	Private mobjFieldMap
12
   Private mobjFieldMap
15
	Private mobjErrorMsg
13
   Private mobjErrorMsg
16
	Private mobjAltVal
14
   Private mobjAltVal
17
	
15
 
18
	Private InxFieldName
16
   Private InxFieldName
19
	Private InxIsRequired
17
   Private InxIsRequired
20
	Private InxIsNumeric
18
   Private InxIsNumeric
21
	Private InxMinNumericValue
19
   Private InxMinNumericValue
22
	Private InxMaxNumericValue
20
   Private InxMaxNumericValue
23
	Private InxIsDate
21
   Private InxIsDate
24
	Private InxStartDate
22
   Private InxStartDate
25
	Private InxEndDate
23
   Private InxEndDate
26
	Private InxMinStringLength
24
   Private InxMinStringLength
27
	Private InxMaxStringLength
25
   Private InxMaxStringLength
28
	Private InxRegExp
26
   Private InxRegExp
29
	Private InxRegExpDescription
27
   Private InxRegExpDescription
30
	
28
 
31
	Private mNumOfRules
29
   Private mNumOfRules
32
	Private mLastRuleInx
30
   Private mLastRuleInx
33
	
31
 
34
	Private bIsFormValid
32
   Private bIsFormValid
35
	Private bIsValidated
33
   Private bIsValidated
36
	Private bIsPostBack
34
   Private bIsPostBack
37
	Private bHiddenTagPlanted
35
   Private bHiddenTagPlanted
38
	
36
 
39
	Private sPostBackTagName
37
   Private sPostBackTagName
40
	Private sBULET
38
   Private sBULET
41
	
39
 
42
	
40
 
43
	Public Property Get IsPostBack ()
41
   Public Property Get IsPostBack ()
44
		IsPostBack = bIsPostBack
42
      IsPostBack = bIsPostBack
45
	End Property
43
   End Property
46
	
44
 
47
	Public Property Get IsValidOnPostBack
45
   Public Property Get IsValidOnPostBack
48
		If bIsValidated Then
46
      If bIsValidated Then
49
			IsValidOnPostBack = bIsFormValid
47
         IsValidOnPostBack = bIsFormValid
50
		Else
48
      Else
51
			IsValidOnPostBack = ValidateForm()
49
         IsValidOnPostBack = ValidateForm()
52
		End If
50
      End If
53
		
51
 
54
	End Property
52
   End Property
55
	
53
 
56
	'-----------------------------------------------------------------------------------------------------------------
54
   '-----------------------------------------------------------------------------------------------------------------
57
	Public Function GetValue ( sFieldName, altValue )
55
   Public Function GetValue ( sFieldName, altValue )
58
		If NOT bIsPostBack Then 
56
      If NOT bIsPostBack Then
59
			GetValue = altValue
57
         GetValue = altValue
60
		Else
58
      Else
61
			GetValue = Request(sFieldName)
59
         GetValue = Request(sFieldName)
62
		End If
60
      End If
63
		
61
 
64
		mobjAltVal.Item ( sFieldName ) = GetValue
62
      mobjAltVal.Item ( sFieldName ) = GetValue
65
	End Function
63
   End Function
66
	'-----------------------------------------------------------------------------------------------------------------
64
   '-----------------------------------------------------------------------------------------------------------------
67
	Public Sub SetValue ( sFieldName, altValue )
65
   Public Sub SetValue ( sFieldName, altValue )
68
		If NOT bIsPostBack Then 
66
      If NOT bIsPostBack Then
69
			mobjAltVal.Item ( sFieldName ) = altValue
67
         mobjAltVal.Item ( sFieldName ) = altValue
70
		Else
68
      Else
71
			mobjAltVal.Item ( sFieldName ) = Request(sFieldName)
69
         mobjAltVal.Item ( sFieldName ) = Request(sFieldName)
72
		End If
70
      End If
73
		
71
 
74
	End Sub
72
   End Sub
75
	'-----------------------------------------------------------------------------------------------------------------
73
   '-----------------------------------------------------------------------------------------------------------------
76
	Private Function RequestValue( sFieldName )
74
   Public Sub SetValueForced ( sFieldName, value )
77
		If NOT bIsPostBack Then 
75
      mobjAltVal.Item ( sFieldName ) = value
78
			RequestValue = mobjAltVal.Item ( sFieldName )
76
 
79
		Else
77
   End Sub
80
			If Request(sFieldName) <> "" Then
78
   '-----------------------------------------------------------------------------------------------------------------
81
				RequestValue = Request(sFieldName)
79
   Private Function RequestValue( sFieldName )
82
			Else
80
      If NOT bIsPostBack Then
83
				RequestValue = mobjAltVal.Item ( sFieldName )
81
         RequestValue = mobjAltVal.Item ( sFieldName )
84
			End If
82
      Else
85
		End If
83
         If Request(sFieldName) <> "" Then
86
		
84
            RequestValue = Request(sFieldName)
87
	End Function
85
         Else
88
	'-----------------------------------------------------------------------------------------------------------------
86
            RequestValue = mobjAltVal.Item ( sFieldName )
89
	Public Function IsTicked( sFieldName, nParId, altValue )
87
         End If
90
		Dim sParList
88
      End If
91
		
89
 
92
		nParId 	 = ","&  Replace(nParId, " ", "") &","
90
   End Function
93
		sParList = ","&  Replace( Request(sFieldName), " ", "") &","
91
   '-----------------------------------------------------------------------------------------------------------------
94
			
92
   Public Function IsTicked( sFieldName, nParId, altValue )
95
		If NOT bIsPostBack Then 
93
      Dim sParList
96
			IsTicked = (NOT IsNull(altValue))  OR  (altValue <> "")
94
 
97
			
95
      nParId     = ","&  Replace(nParId, " ", "") &","
98
		Else
96
      sParList = ","&  Replace( Request(sFieldName), " ", "") &","
99
			If InStr( sParList, nParId ) > 0 Then
97
 
100
				IsTicked = TRUE
98
      If NOT bIsPostBack Then
101
			Else
99
         IsTicked = (NOT IsNull(altValue))  OR  (altValue <> "")
102
				IsTicked = FALSE
100
 
103
			End If
101
      Else
104
			
102
         If InStr( sParList, nParId ) > 0 Then
105
		End If
103
            IsTicked = TRUE
106
		
104
         Else
107
	End Function
105
            IsTicked = FALSE
108
	'-----------------------------------------------------------------------------------------------------------------
106
         End If
109
	Public Function Validate ( sFieldName )
107
 
110
		
108
      End If
111
		'--- Plant Hidden Tag
109
 
112
		If NOT bHiddenTagPlanted Then
110
   End Function
113
			' This tag is used by this class to know if the form is posted back
111
 
114
			Response.write "<input type='hidden' name='"& sPostBackTagName &"' value='true'>"
112
   '-----------------------------------------------------------------------------------------------------------------
115
			bHiddenTagPlanted = TRUE
113
   Public Function AddPostBack ()
116
		End If
114
      '--- Plant Hidden Tag
117
		
115
      If NOT bHiddenTagPlanted Then
118
		Call ValidateField ( RequestValue(sFieldName), mobjFieldMap.Item ( Cstr( sFieldName  ) ) )
116
         ' This tag is used by this class to know if the form is posted back
119
		
117
         Response.write "<input type='hidden' name='"& sPostBackTagName &"' value='true'>"
120
		Validate = GetErrorMsg ( sFieldName )
118
         bHiddenTagPlanted = TRUE
121
		
119
      End If
122
	End Function
120
   End Function
123
	'-----------------------------------------------------------------------------------------------------------------
121
 
124
	Private Function ValidateForm()
122
   '-----------------------------------------------------------------------------------------------------------------
125
		Dim i, FieldValue, nLastRowInx
123
   Public Function Validate ( sFieldName )
126
		mobjErrorMsg.RemoveAll	' Clean Error Messages
124
 
127
		
125
      '--- Plant Hidden Tag
128
		nLastRowInx = LastRowInx ()
126
      AddPostBack()
129
		
127
 
130
		For i = 0 To nLastRowInx
128
      Call ValidateField ( RequestValue(sFieldName), mobjFieldMap.Item ( Cstr( sFieldName  ) ) )
131
			FieldValue = RequestValue( maRules( InxFieldName, i ) )
129
 
132
			
130
      Validate = GetErrorMsg ( sFieldName )
133
			Call ValidateField ( FieldValue, i )
131
 
134
			
132
   End Function
135
		Next
133
   '-----------------------------------------------------------------------------------------------------------------
136
		
134
   Private Function ValidateForm()
137
		' --- Finally, set the Form state of validity
135
      Dim i, FieldValue, nLastRowInx
138
		If mobjErrorMsg.Count > 0 Then 
136
      mobjErrorMsg.RemoveAll   ' Clean Error Messages
139
			bIsFormValid = FALSE
137
 
140
		Else
138
      nLastRowInx = LastRowInx ()
141
			bIsFormValid = TRUE
139
 
142
		End If
140
      For i = 0 To nLastRowInx
143
		
141
         FieldValue = RequestValue( maRules( InxFieldName, i ) )
144
		
142
 
145
		bIsValidated = TRUE
143
         Call ValidateField ( FieldValue, i )
146
		ValidateForm = bIsFormValid
144
 
147
		
145
      Next
148
	End Function
146
 
149
	'-----------------------------------------------------------------------------------------------------------------
147
      ' --- Finally, set the Form state of validity
150
	Private Sub ValidateField ( FieldValue, i )
148
      If mobjErrorMsg.Count > 0 Then
151
		
149
         bIsFormValid = FALSE
152
		If (i = "") OR (IsNull(i)) Then
150
      Else
153
			Err.Raise 8, "Cannot Find Field Name.", "Make sure you have correct filed names listed for validation."
151
         bIsFormValid = TRUE
154
			Exit Sub
152
      End If
155
		End If
153
 
156
		
154
 
157
		If mobjErrorMsg.Exists ( CStr( maRules( InxFieldName, i ) ) ) Then mobjErrorMsg.Remove ( CStr( maRules( InxFieldName, i ) ) )	' Clean this field Error Messages
155
      bIsValidated = TRUE
158
		
156
      ValidateForm = bIsFormValid
159
		' RULE is_Required
157
 
160
		If NOT ValidForIsRequired ( FieldValue, i ) Then 
158
   End Function
161
			Call AddErrorMessage ( i, "Required." )
159
   '-----------------------------------------------------------------------------------------------------------------
162
			
160
   Private Sub ValidateField ( FieldValue, i )
163
		Else
161
 
164
			
162
      If (i = "") OR (IsNull(i)) Then
165
			If FieldValue <> "" Then
163
         Err.Raise 8, "Cannot Find Field Name.", "Make sure you have correct filed names listed for validation."
166
				
164
         Exit Sub
167
				' --- RULE is_Number ---
165
      End If
168
				If NOT ValidForIsNumeric ( FieldValue, i ) Then 
166
 
169
					Call AddErrorMessage ( i, "Must be a number." )
167
      If mobjErrorMsg.Exists ( CStr( maRules( InxFieldName, i ) ) ) Then mobjErrorMsg.Remove ( CStr( maRules( InxFieldName, i ) ) )   ' Clean this field Error Messages
170
				Else
168
 
171
					
169
      ' RULE is_Required
172
					If maRules( InxIsNumeric, i ) = enumDB_YES Then  ' Continue if field is a Number
170
      If NOT ValidForIsRequired ( FieldValue, i ) Then
173
						' --- RULE min_Numeric_value ---
171
         Call AddErrorMessage ( i, "Required." )
174
						If NOT ValidForMinNumericValue ( FieldValue, i ) Then 
172
 
175
							Call AddErrorMessage ( i, "Must be minimum "& maRules( InxMinNumericValue, i ) &"." )
173
      Else
176
						End If
174
 
177
						
175
         If FieldValue <> "" Then
178
						' --- RULE max_Numeric_value ---
176
 
179
						If NOT ValidForMaxNumericValue ( FieldValue, i ) Then 
177
            ' --- RULE is_Number ---
180
							Call AddErrorMessage ( i, "Must be maximum "& maRules( InxMaxNumericValue, i ) &"." )
178
            If NOT ValidForIsNumeric ( FieldValue, i ) Then
181
						End If
179
               Call AddErrorMessage ( i, "Must be a number." )
182
					End If
180
            Else
183
					
181
 
184
				End If
182
               If maRules( InxIsNumeric, i ) = enumDB_YES Then  ' Continue if field is a Number
185
				
183
                  ' --- RULE min_Numeric_value ---
186
				
184
                  If NOT ValidForMinNumericValue ( FieldValue, i ) Then
187
				' --- RULE is_Date ---
185
                     Call AddErrorMessage ( i, "Must be minimum "& maRules( InxMinNumericValue, i ) &"." )
188
				If NOT ValidForIsDate ( FieldValue, i ) Then 
186
                  End If
189
					Call AddErrorMessage ( i, "Must be a date." )
187
 
190
				Else
188
                  ' --- RULE max_Numeric_value ---
191
					
189
                  If NOT ValidForMaxNumericValue ( FieldValue, i ) Then
192
					If maRules( InxIsDate, i ) = enumDB_YES Then  ' Continue if field is a Date
190
                     Call AddErrorMessage ( i, "Must be maximum "& maRules( InxMaxNumericValue, i ) &"." )
193
						' --- RULE start_Date ---
191
                  End If
194
						If NOT ValidForStartDate ( FieldValue, i ) Then 
192
               End If
195
							Call AddErrorMessage ( i, "Cannot be before "& maRules( InxStartDate, i ) &"." )
193
 
196
						End If
194
            End If
197
						
195
 
198
						' --- RULE end_Date ---
196
 
199
						If NOT ValidForEndDate ( FieldValue, i ) Then 
197
            ' --- RULE is_Date ---
200
							Call AddErrorMessage ( i, "Cannot be after "& maRules( InxStartDate, i ) &"." )
198
            If NOT ValidForIsDate ( FieldValue, i ) Then
201
						End If
199
               Call AddErrorMessage ( i, "Must be a date." )
202
						
200
            Else
203
					End If
201
 
204
					
202
               If maRules( InxIsDate, i ) = enumDB_YES Then  ' Continue if field is a Date
205
				End If
203
                  ' --- RULE start_Date ---
206
				
204
                  If NOT ValidForStartDate ( FieldValue, i ) Then
207
				
205
                     Call AddErrorMessage ( i, "Cannot be before "& maRules( InxStartDate, i ) &"." )
208
				' --- RULE min_String_Length ---
206
                  End If
209
				If NOT ValidForMinStringLength ( FieldValue, i ) Then 
207
 
210
					Call AddErrorMessage ( i, "Must be at least "& maRules( InxMinStringLength, i ) &" character(s) long." )
208
                  ' --- RULE end_Date ---
211
				End If
209
                  If NOT ValidForEndDate ( FieldValue, i ) Then
212
				
210
                     Call AddErrorMessage ( i, "Cannot be after "& maRules( InxStartDate, i ) &"." )
213
				' --- RULE min_String_Length ---
211
                  End If
214
				If NOT ValidForMaxStringLength ( FieldValue, i ) Then 
212
 
215
					Call AddErrorMessage ( i, "Can be maximum "& maRules( InxMaxStringLength, i ) &" character(s) long." )
213
               End If
216
				End If
214
 
217
				
215
            End If
218
				
216
 
219
				' --- RULE Regular Expression ---
217
 
220
				If NOT ValidForRegExp ( FieldValue, i ) Then 
218
            ' --- RULE min_String_Length ---
221
					Call AddErrorMessage ( i, maRules( InxRegExpDescription, i ) )
219
            If NOT ValidForMinStringLength ( FieldValue, i ) Then
222
				End If
220
               Call AddErrorMessage ( i, "Must be at least "& maRules( InxMinStringLength, i ) &" character(s) long." )
223
				
221
            End If
224
				
222
 
225
				
223
            ' --- RULE min_String_Length ---
226
			End If
224
            If NOT ValidForMaxStringLength ( FieldValue, i ) Then
227
			
225
               Call AddErrorMessage ( i, "Can be maximum "& maRules( InxMaxStringLength, i ) &" character(s) long." )
228
			
226
            End If
229
		End If
227
 
230
	End Sub
228
 
231
	'-----------------------------------------------------------------------------------------------------------------
229
            ' --- RULE Regular Expression ---
232
	Private Function ValidForIsRequired ( fieldValue, rowId )
230
            If NOT ValidForRegExp ( FieldValue, i ) Then
233
		ValidForIsRequired = FALSE
231
               Call AddErrorMessage ( i, maRules( InxRegExpDescription, i ) )
234
		If maRules( InxIsRequired, rowId ) = enumDB_YES Then 
232
            End If
235
			'/* Check if empty */
233
 
236
			If fieldValue <> "" Then 
234
 
237
				
235
 
238
				'/* Check for spaces */
236
         End If
239
				If Len( Replace(fieldValue, " ", "") ) > 0 Then	ValidForIsRequired = TRUE
237
 
240
				
238
 
241
			End If
239
      End If
242
			
240
   End Sub
243
		Else
241
   '-----------------------------------------------------------------------------------------------------------------
244
			ValidForIsRequired = TRUE
242
   Private Function ValidForIsRequired ( fieldValue, rowId )
245
			
243
      ValidForIsRequired = FALSE
246
		End If
244
      If maRules( InxIsRequired, rowId ) = enumDB_YES Then
247
	End Function
245
         '/* Check if empty */
248
	'-----------------------------------------------------------------------------------------------------------------
246
         If fieldValue <> "" Then
249
	Private Function ValidForRegExp ( fieldValue, rowId )
247
 
250
		Dim objRegEx
248
            '/* Check for spaces */
251
		
249
            If Len( Replace(fieldValue, " ", "") ) > 0 Then   ValidForIsRequired = TRUE
252
		ValidForRegExp = FALSE
250
 
253
		If IsNull( maRules( InxRegExp, rowId ) ) OR (maRules( InxRegExp, rowId ) = "") Then 
251
         End If
254
			ValidForRegExp = TRUE
252
 
255
		Else
253
      Else
256
			Set objRegEx = New RegExp 
254
         ValidForIsRequired = TRUE
257
			
255
 
258
			objRegEx.Global = False		' Only find first match. This is enough to fail the validation
256
      End If
259
			objRegEx.IgnoreCase = False	' Follow match pattern exactly. 
257
   End Function
260
    		objRegEx.Pattern = maRules( InxRegExp, rowId ) 		' Set the pattern to match
258
   '-----------------------------------------------------------------------------------------------------------------
261
			
259
   Private Function ValidForRegExp ( fieldValue, rowId )
262
			' Now test the pattern match.
260
      Dim objRegEx
263
			If NOT objRegEx.Test( fieldValue ) Then
261
 
264
				ValidForRegExp = TRUE
262
      ValidForRegExp = FALSE
265
			End If
263
      If IsNull( maRules( InxRegExp, rowId ) ) OR (maRules( InxRegExp, rowId ) = "") Then
266
			
264
         ValidForRegExp = TRUE
267
			Set objRegEx = Nothing
265
      Else
268
		End If
266
         Set objRegEx = New RegExp
269
	End Function
267
 
270
	'-----------------------------------------------------------------------------------------------------------------
268
         objRegEx.Global = False      ' Only find first match. This is enough to fail the validation
271
	Private Function ValidForIsNumeric ( fieldValue, rowId )
269
         objRegEx.IgnoreCase = False   ' Follow match pattern exactly.
272
		ValidForIsNumeric = FALSE
270
          objRegEx.Pattern = maRules( InxRegExp, rowId )       ' Set the pattern to match
273
		If maRules( InxIsNumeric, rowId ) = enumDB_YES Then 
271
 
274
			If IsNumeric( fieldValue ) Then ValidForIsNumeric = TRUE
272
         ' Now test the pattern match.
275
			
273
         If NOT objRegEx.Test( fieldValue ) Then
276
		Else
274
            ValidForRegExp = TRUE
277
			ValidForIsNumeric = TRUE
275
         End If
278
			
276
 
279
		End If
277
         Set objRegEx = Nothing
280
	End Function
278
      End If
281
	'-----------------------------------------------------------------------------------------------------------------
279
   End Function
282
	Private Function ValidForMinNumericValue ( fieldValue, rowId )
280
   '-----------------------------------------------------------------------------------------------------------------
283
		ValidForMinNumericValue = FALSE
281
   Private Function ValidForIsNumeric ( fieldValue, rowId )
284
		If IsNull( maRules( InxMinNumericValue, rowId ) ) OR (maRules( InxMinNumericValue, rowId ) = "") Then 
282
      ValidForIsNumeric = FALSE
285
			ValidForMinNumericValue = TRUE
283
      If maRules( InxIsNumeric, rowId ) = enumDB_YES Then
286
		Else
284
         If IsNumeric( fieldValue ) Then ValidForIsNumeric = TRUE
287
			If CDbl(fieldValue) >= CDbl(maRules( InxMinNumericValue, rowId )) Then	ValidForMinNumericValue = TRUE
285
 
288
			
286
      Else
289
		End If
287
         ValidForIsNumeric = TRUE
290
	End Function
288
 
291
	'-----------------------------------------------------------------------------------------------------------------
289
      End If
292
	Private Function ValidForMaxNumericValue ( fieldValue, rowId )
290
   End Function
293
		ValidForMaxNumericValue = FALSE
291
   '-----------------------------------------------------------------------------------------------------------------
294
		If IsNull( maRules( InxMaxNumericValue, rowId ) ) OR (maRules( InxMaxNumericValue, rowId ) = "") Then 	
292
   Private Function ValidForMinNumericValue ( fieldValue, rowId )
295
			ValidForMaxNumericValue = TRUE
293
      ValidForMinNumericValue = FALSE
296
		Else
294
      If IsNull( maRules( InxMinNumericValue, rowId ) ) OR (maRules( InxMinNumericValue, rowId ) = "") Then
297
			If CDbl(fieldValue) <= CDbl(maRules( InxMaxNumericValue, rowId )) Then	ValidForMaxNumericValue = TRUE
295
         ValidForMinNumericValue = TRUE
298
			
296
      Else
299
		End If
297
         If CDbl(fieldValue) >= CDbl(maRules( InxMinNumericValue, rowId )) Then   ValidForMinNumericValue = TRUE
300
	End Function
298
 
301
	'-----------------------------------------------------------------------------------------------------------------
299
      End If
302
	Private Function ValidForIsDate ( fieldValue, rowId )
300
   End Function
303
		ValidForIsDate = FALSE
301
   '-----------------------------------------------------------------------------------------------------------------
304
		If maRules( InxIsDate, rowId ) = enumDB_YES Then 
302
   Private Function ValidForMaxNumericValue ( fieldValue, rowId )
305
			If IsDate( fieldValue ) Then ValidForIsDate = TRUE
303
      ValidForMaxNumericValue = FALSE
306
			
304
      If IsNull( maRules( InxMaxNumericValue, rowId ) ) OR (maRules( InxMaxNumericValue, rowId ) = "") Then
307
		Else
305
         ValidForMaxNumericValue = TRUE
308
			ValidForIsDate = TRUE
306
      Else
309
			
307
         If CDbl(fieldValue) <= CDbl(maRules( InxMaxNumericValue, rowId )) Then   ValidForMaxNumericValue = TRUE
310
		End If
308
 
311
	End Function
309
      End If
312
	'-----------------------------------------------------------------------------------------------------------------
310
   End Function
313
	Private Function ValidForStartDate ( fieldValue, rowId )
311
   '-----------------------------------------------------------------------------------------------------------------
314
		ValidForStartDate = FALSE
312
   Private Function ValidForIsDate ( fieldValue, rowId )
315
		If IsNull( maRules( InxStartDate, rowId ) ) OR (maRules( InxStartDate, rowId ) = "") Then 
313
      ValidForIsDate = FALSE
316
			ValidForStartDate = TRUE
314
      If maRules( InxIsDate, rowId ) = enumDB_YES Then
317
		Else
315
         If IsDate( fieldValue ) Then ValidForIsDate = TRUE
318
			If CDate(fieldValue) >= CDate(maRules( InxStartDate, rowId )) Then	ValidForStartDate = TRUE
316
 
319
			
317
      Else
320
		End If
318
         ValidForIsDate = TRUE
321
	End Function
319
 
322
	'-----------------------------------------------------------------------------------------------------------------
320
      End If
323
	Private Function ValidForEndDate ( fieldValue, rowId )
321
   End Function
324
		ValidForEndDate = FALSE
322
   '-----------------------------------------------------------------------------------------------------------------
325
		If IsNull( maRules( InxEndDate, rowId ) ) OR (maRules( InxEndDate, rowId ) = "") Then 
323
   Private Function ValidForStartDate ( fieldValue, rowId )
326
			ValidForEndDate = TRUE
324
      ValidForStartDate = FALSE
327
		Else
325
      If IsNull( maRules( InxStartDate, rowId ) ) OR (maRules( InxStartDate, rowId ) = "") Then
328
			If CDate(fieldValue) <= CDate(maRules( InxStartDate, rowId )) Then	ValidForEndDate = TRUE
326
         ValidForStartDate = TRUE
329
			
327
      Else
330
		End If
328
         If CDate(fieldValue) >= CDate(maRules( InxStartDate, rowId )) Then   ValidForStartDate = TRUE
331
	End Function
329
 
332
	'-----------------------------------------------------------------------------------------------------------------
330
      End If
333
	Private Function ValidForMinStringLength ( fieldValue, rowId )
331
   End Function
334
		ValidForMinStringLength = FALSE
332
   '-----------------------------------------------------------------------------------------------------------------
335
		If IsNull( maRules( InxMinStringLength, rowId ) ) OR (maRules( InxMinStringLength, rowId ) = "") Then 
333
   Private Function ValidForEndDate ( fieldValue, rowId )
336
			ValidForMinStringLength = TRUE
334
      ValidForEndDate = FALSE
337
		Else
335
      If IsNull( maRules( InxEndDate, rowId ) ) OR (maRules( InxEndDate, rowId ) = "") Then
338
			If CInt(Len(fieldValue)) >= CInt(maRules( InxMinStringLength, rowId )) Then	ValidForMinStringLength = TRUE
336
         ValidForEndDate = TRUE
339
			
337
      Else
340
		End If
338
         If CDate(fieldValue) <= CDate(maRules( InxStartDate, rowId )) Then   ValidForEndDate = TRUE
341
	End Function
339
 
342
	'-----------------------------------------------------------------------------------------------------------------
340
      End If
343
	Private Function ValidForMaxStringLength ( fieldValue, rowId )
341
   End Function
344
		ValidForMaxStringLength = FALSE
342
   '-----------------------------------------------------------------------------------------------------------------
345
		
343
   Private Function ValidForMinStringLength ( fieldValue, rowId )
346
		If IsNull( maRules( InxMaxStringLength, rowId ) ) OR (maRules( InxMaxStringLength, rowId ) = "") Then 
344
      ValidForMinStringLength = FALSE
347
			ValidForMaxStringLength = TRUE
345
      If IsNull( maRules( InxMinStringLength, rowId ) ) OR (maRules( InxMinStringLength, rowId ) = "") Then
348
		Else
346
         ValidForMinStringLength = TRUE
349
			If CInt(Len(fieldValue)) <= CInt(maRules( InxMaxStringLength, rowId )) Then	ValidForMaxStringLength = TRUE
347
      Else
350
			
348
         If CInt(Len(fieldValue)) >= CInt(maRules( InxMinStringLength, rowId )) Then   ValidForMinStringLength = TRUE
351
		End If
349
 
352
	End Function
350
      End If
353
	'-----------------------------------------------------------------------------------------------------------------
351
   End Function
354
	Private Sub AddErrorMessage ( rowId, sErrMsg )
352
   '-----------------------------------------------------------------------------------------------------------------
355
		mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) = _
353
   Private Function ValidForMaxStringLength ( fieldValue, rowId )
356
			mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) &_
354
      ValidForMaxStringLength = FALSE
357
			"<tr>"&_
355
 
358
			sBULET  &"<td class='val_err'>"&  sErrMsg  &"</td>"&_
356
      If IsNull( maRules( InxMaxStringLength, rowId ) ) OR (maRules( InxMaxStringLength, rowId ) = "") Then
359
			"</tr>"& VBNewLine
357
         ValidForMaxStringLength = TRUE
360
	End Sub
358
      Else
361
	'-----------------------------------------------------------------------------------------------------------------
359
         If CInt(Len(fieldValue)) <= CInt(maRules( InxMaxStringLength, rowId )) Then   ValidForMaxStringLength = TRUE
362
	Public Sub LoadFieldRules ( aRows )
360
 
363
		' Pass the full array row matching the columns of maRules()
361
      End If
364
		Dim nProperty, newArrayDim, numOfRows, rowNum
362
   End Function
365
		
363
   '-----------------------------------------------------------------------------------------------------------------
366
		numOfRows = UBound( aRows, 2 )
364
   Private Sub AddErrorMessage ( rowId, sErrMsg )
367
		
365
      mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) = _
368
		
366
         mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) &_
369
		For rowNum = 0 To numOfRows
367
         "<tr>"&_
370
			' Increase array by 1
368
         sBULET  &"<td class='val_err'>"&  sErrMsg  &"</td>"&_
371
			newArrayDim = LastRowInx() + 1
369
         "</tr>"& VBNewLine
372
			ReDim Preserve maRules( mNumOfRules, newArrayDim )
370
   End Sub
373
			
371
   '-----------------------------------------------------------------------------------------------------------------
374
			mobjFieldMap.Add ( Cstr( aRows ( InxFieldName, rowNum ) ) ), CStr( newArrayDim )
372
   Private Function LastRowInx ()
375
			
373
       LastRowInx = UBound ( maRules, 2 )
376
			For nProperty = 0 To mLastRuleInx
374
   End Function
377
				maRules ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum )
375
   '-----------------------------------------------------------------------------------------------------------------
378
			Next
376
   Private Function GetErrorMsg ( sFieldName )
379
			
377
      Dim msg
380
		Next
378
      msg = mobjErrorMsg.Item (CStr(sFieldName))
381
		
379
      If msg <> "" Then
382
		' --- Validate Form ---
380
         GetErrorMsg = _
383
		'ValidateForm()
381
         "<table width='100%'  border='0' cellspacing='2' cellpadding='0'>"& VBNewLine &_
384
		
382
         msg & VBNewLine &_
385
	End Sub
383
         "<tr><td width='1'>"& SPACER &"</td><td width='1'>"& SPACER &"</td><td width='100%'>"& SPACER &"</td></tr>"& VBNewLine &_
386
	'-----------------------------------------------------------------------------------------------------------------
384
         "</table>"
387
	Private Function LastRowInx ()
385
      Else
388
		 LastRowInx = UBound ( maRules, 2 )
386
         GetErrorMsg = NULL
389
	End Function
387
      End If
390
	'-----------------------------------------------------------------------------------------------------------------
388
   End Function
391
	Private Function GetErrorMsg ( sFieldName )
389
   '-----------------------------------------------------------------------------------------------------------------
392
		Dim msg
390
   Private Function ParseParams ( sParams )
393
		msg = mobjErrorMsg.Item (CStr(sFieldName))
391
      Dim paramArr, i
394
		If msg <> "" Then
392
 
395
			GetErrorMsg = _
393
      paramArr = Split ( sParams, "'" )      ' Expected Params value:  id='field_name' IsRequired='N' param2='val' ...
396
			"<table width='100%'  border='0' cellspacing='2' cellpadding='0'>"& VBNewLine &_
394
 
397
			msg & VBNewLine &_
395
      ' Store Validation changes/rules in array
398
			"<tr><td width='1'>"& SPACER &"</td><td width='1'>"& SPACER &"</td><td width='100%'>"& SPACER &"</td></tr>"& VBNewLine &_
396
      For i = 0 To UBound( paramArr )-1 Step 2
399
			"</table>"
397
         Call UpdateRow ( paramArr(1), GetColumnInx ( paramArr(i) ), paramArr(i+1) )
400
		Else
398
      Next
401
			GetErrorMsg = NULL
399
 
402
		End If
400
      ParseParams = paramArr(1)   ' id must be first param
403
	End Function
401
 
404
	'-----------------------------------------------------------------------------------------------------------------
402
   End Function
405
	Private Function ParseParams ( sParams )
403
   '-----------------------------------------------------------------------------------------------------------------
406
		Dim paramArr, i
404
   Public Sub UpdateRules ( sParams )
407
		
405
      ParseParams ( sParams )
408
		paramArr = Split ( sParams, "'" )		' Expected Params value:  id='field_name' IsRequired='N' param2='val' ...
406
 
409
		
407
   End Sub
410
		' Store Validation changes/rules in array
408
   '-----------------------------------------------------------------------------------------------------------------
411
		For i = 0 To UBound( paramArr )-1 Step 2
409
   Private Sub UpdateRow ( sFieldName, sColumnInx, sColumnVal )
412
			Call UpdateRow ( paramArr(1), GetColumnInx ( paramArr(i) ), paramArr(i+1) )
410
      Dim rowNum
413
		Next
411
 
414
		
412
      If mobjFieldMap.Exists (CStr(sFieldName)) Then
415
		ParseParams = paramArr(1)	' id must be first param
413
         rowNum = mobjFieldMap.Item ( Cstr( sFieldName  ) )
416
		
414
 
417
	End Function
415
      Else
418
	'-----------------------------------------------------------------------------------------------------------------
416
         rowNum = LastRowInx() + 1
419
	Public Sub UpdateRules ( sParams )
417
         ReDim Preserve maRules( mNumOfRules, rowNum )
420
		ParseParams ( sParams )
418
 
421
		
419
         mobjFieldMap.Add ( Cstr( sFieldName ) ), CStr( rowNum )
422
	End Sub
420
 
423
	'-----------------------------------------------------------------------------------------------------------------
421
      End If
424
	Private Sub UpdateRow ( sFieldName, sColumnInx, sColumnVal )
422
 
425
		Dim rowNum
423
      maRules ( sColumnInx, rowNum ) = sColumnVal
426
		
424
 
427
		If mobjFieldMap.Exists (CStr(sFieldName)) Then
425
   End Sub
428
			rowNum = mobjFieldMap.Item ( Cstr( sFieldName  ) )
426
   '-----------------------------------------------------------------------------------------------------------------
429
			
427
   Private Function GetColumnInx ( ByVal sParam )
430
		Else
428
      sParam = Trim( sParam )      ' Trim spaces
431
			rowNum = LastRowInx() + 1
429
      sParam = Left( sParam, Len(sParam)-1 )   ' Remove trailing "="
432
			ReDim Preserve maRules( mNumOfRules, rowNum )
430
 
433
			
431
      Select Case Trim( sParam )
434
			mobjFieldMap.Add ( Cstr( sFieldName ) ), CStr( rowNum )
432
         Case "id"
435
			
433
            GetColumnInx = InxFieldName
436
		End If
434
         Case Else
437
		
435
            GetColumnInx = Eval( "Inx"& Trim( sParam ) )
438
		maRules ( sColumnInx, rowNum ) = sColumnVal
436
 
439
		
437
      End Select
440
	End Sub
438
   End Function
441
	'-----------------------------------------------------------------------------------------------------------------
439
   '-----------------------------------------------------------------------------------------------------------------
442
	Private Function GetColumnInx ( ByVal sParam )
-
 
443
		sParam = Trim( sParam )		' Trim spaces
-
 
444
		sParam = Left( sParam, Len(sParam)-1 )	' Remove trailing "="
-
 
445
		
-
 
446
		Select Case Trim( sParam )
-
 
447
			Case "id"
-
 
448
				GetColumnInx = InxFieldName
-
 
449
			Case Else
-
 
450
				GetColumnInx = Eval( "Inx"& Trim( sParam ) )
-
 
451
			
-
 
452
		End Select
-
 
453
	End Function
-
 
454
	'-----------------------------------------------------------------------------------------------------------------
-
 
455
	Sub LoadValidationRules ( aFieldList, ByRef objOraDatabase )
440
	Sub LoadValidationRules ( aFieldList, ByRef objOraDatabase )
456
		Dim rsQry, query
-
 
457
		
-
 
458
		query = _
-
 
459
		"   SELECT FIELD_NAME, "&_
441
            UpdateRules ("id='node_comments' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
460
		"		   IS_REQUIRED, "&_
442
            UpdateRules ("id='os_name' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='' RegExpDescription=''")
461
		"		   IS_NUMERIC, "&_
-
 
462
		"		   MIN_NUMERIC_VALUE, "&_
443
            UpdateRules ("id='os_comments' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
463
		"		   MAX_NUMERIC_VALUE, "&_
444
            UpdateRules ("id='branch_name' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='' RegExpDescription=''")
464
		"		   IS_DATE, "&_
-
 
465
		"		   START_DATE, "&_
-
 
466
		"		   END_DATE, "&_
-
 
467
		"		   MIN_STRING_LENGTH, "&_
445
            UpdateRules ("id='proj_name' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='' RegExpDescription=''")
468
		" 		   MAX_STRING_LENGTH, "&_
446
            UpdateRules ("id='state_name' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='' RegExpDescription=''")
469
		"		   REGEXP, "&_
-
 
470
		"		   REGEXP_DESCRIPTION "&_
447
            UpdateRules ("id='bom_name' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='' RegExpDescription=''")
471
		"	  FROM VALIDATION_RULES"&_
448
            UpdateRules ("id='bom_comments' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
472
		"	 WHERE field_name IN ( '"& Join( aFieldList, "','") &"' )"
449
            UpdateRules ("id='reject_note' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
473
		
-
 
474
		
-
 
475
		Set rsQry = objOraDatabase.DbCreateDynaset( query , 0 )
450
            UpdateRules ("id='release_to_comments' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
476
		If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
451
            UpdateRules ("id='product_comments' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
477
			Call LoadFieldRules ( rsQry.GetRows() )
452
            UpdateRules ("id='base_env_name' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='' RegExpDescription=''")
478
			
-
 
479
		End If
-
 
480
		
-
 
481
		rsQry.Close
-
 
-
 
453
            UpdateRules ("id='prod_name' IsRequired='Y' MinStringLength='' MaxStringLength='255' RegExp='[^a-zA-Z0-9\.\!\$\-\_]' RegExpDescription='Allowed characters are <br>A-Z a-z 0-9 . ! $ - _'")
-
 
454
            UpdateRules ("id='prod_version' IsRequired='Y' MinStringLength='' MaxStringLength='50' RegExp='[^a-zA-Z0-9\.\!\$\-\_]' RegExpDescription='Allowed characters are <br>A-Z a-z 0-9 . ! $ - _'")
482
		Set rsQry = Nothing
455
            UpdateRules ("id='branch_comments' IsRequired='N' MinStringLength='' MaxStringLength='4000' RegExp='' RegExpDescription=''")
-
 
456
            UpdateRules ("id='bom_lifecycle' IsRequired='Y' MinStringLength='1' MaxStringLength='10' RegExp='[^0-9]' RegExpDescription='Only numbers accepted.'")
-
 
457
            UpdateRules ("id='bom_version' IsRequired='Y' MinStringLength='1' MaxStringLength='10' RegExp='[^a-zA-Z0-9\.\!\$\-\_]' RegExpDescription='Allowed characters are <br>A-Z a-z 0-9 . ! $ - _'")
483
	End Sub
458
    End Sub
484
	'-----------------------------------------------------------------------------------------------------------------
459
   '-----------------------------------------------------------------------------------------------------------------
485
	Private Sub Class_Initialize()
460
   Private Sub Class_Initialize()
486
		'// Perform action on creation of object. e.g. Set myObj = New ThisClassName
461
      '// Perform action on creation of object. e.g. Set myObj = New ThisClassName
487
		Set mobjFieldMap = CreateObject("Scripting.Dictionary")
462
      Set mobjFieldMap = CreateObject("Scripting.Dictionary")
488
		Set mobjErrorMsg = CreateObject("Scripting.Dictionary")
463
      Set mobjErrorMsg = CreateObject("Scripting.Dictionary")
489
		Set mobjAltVal 	 = CreateObject("Scripting.Dictionary")
464
      Set mobjAltVal     = CreateObject("Scripting.Dictionary")
490
		
465
 
491
		sPostBackTagName = "VC_POST_BACK"
466
      sPostBackTagName = "VC_POST_BACK"
492
		
467
 
493
		
468
 
494
		bHiddenTagPlanted = FALSE
469
      bHiddenTagPlanted = FALSE
495
		bIsPostBack = FALSE		' When true, form has been submitted and need postback validation
470
      bIsPostBack = FALSE      ' When true, form has been submitted and need postback validation
496
		bIsValidated = FALSE
471
      bIsValidated = FALSE
497
		
472
 
498
		
473
 
499
		InxFieldName			= 0
474
      InxFieldName          = 0
500
		InxIsRequired			= 1
475
      InxIsRequired         = 1
501
		InxIsNumeric			= 2
476
      InxIsNumeric          = 2
502
		InxMinNumericValue		= 3
477
      InxMinNumericValue    = 3
503
		InxMaxNumericValue		= 4
478
      InxMaxNumericValue    = 4
504
		InxIsDate				= 5
479
      InxIsDate             = 5
505
		InxStartDate			= 6
480
      InxStartDate          = 6
506
		InxEndDate				= 7
481
      InxEndDate            = 7
507
		InxMinStringLength		= 8
482
      InxMinStringLength    = 8
508
		InxMaxStringLength		= 9
483
      InxMaxStringLength    = 9
509
		InxRegExp				= 10
484
      InxRegExp             = 10
510
		InxRegExpDescription	= 11
485
      InxRegExpDescription  = 11
511
		mNumOfRules = 12  	' Number of Rules that can be assigned to one field
486
      mNumOfRules           = 12     ' Number of Rules that can be assigned to one field
512
		mLastRuleInx = mNumOfRules - 1
487
      mLastRuleInx = mNumOfRules - 1
513
		
488
 
514
		ReDim maRules ( mNumOfRules, -1 )
489
      ReDim maRules ( mNumOfRules, -1 )
515
		
490
 
516
		'sSESSION_SEPARATOR = "|SEPARATOR|"		' Make sure it will never show in regexp field
491
      'sSESSION_SEPARATOR = "|SEPARATOR|"      ' Make sure it will never show in regexp field
517
		sBULET = "<td background='images/red_dot.gif'>"& SPACER &"</td>"&_
492
		sBULET = "<td background='images/red_dot.gif'>"& SPACER &"</td>"&_
518
				 "<td valign='top'><img src='icons/i_bulet_red.gif' width='4' height='4' hspace='3' vspace='4' border='0' align='absmiddle'></td>"
493
             "<td valign='top'><img src='icons/i_bulet_red.gif' width='4' height='4' hspace='3' vspace='4' border='0' align='absmiddle'></td>"
519
		
494
 
520
		
495
 
521
		'--- Check if Form is posted back
496
      '--- Check if Form is posted back
522
		If Request(sPostBackTagName) <> "" Then
497
      If Request(sPostBackTagName) <> "" Then
523
			bIsPostBack = TRUE
498
         bIsPostBack = TRUE
524
		End If
499
      End If
525
	End Sub
500
   End Sub
526
	'-----------------------------------------------------------------------------------------------------------------
501
   '-----------------------------------------------------------------------------------------------------------------
527
	Private Sub Class_Terminate()
502
   Private Sub Class_Terminate()
528
		'// Perform action on object disposal. e.g. Set myObj = Nothing
503
      '// Perform action on object disposal. e.g. Set myObj = Nothing
529
		Set mobjFieldMap = Nothing
504
      Set mobjFieldMap = Nothing
530
		Set mobjErrorMsg = Nothing
505
      Set mobjErrorMsg = Nothing
531
		Set mobjAltVal = Nothing
506
      Set mobjAltVal = Nothing
532
		
507
 
533
	End Sub
508
   End Sub
534
	'-----------------------------------------------------------------------------------------------------------------
509
   '-----------------------------------------------------------------------------------------------------------------
535
End Class
510
End Class
536
%>
-
 
537
511
%>
-
 
512