Subversion Repositories DevTools

Rev

Rev 119 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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