Subversion Repositories DevTools

Rev

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

Rev 5512 Rev 5835
Line 1... Line 1...
1
<%
1
<%
2
'=============================================================
2
'=============================================================
3
'//
3
'//
4
'//						Validation Control
4
'//                  Validation Control
5
'//
5
'//
6
'// version: 		1.4
-
 
7
'//	last modified: 	20-Jul-2004 11:26 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
			If fieldValue <> "" Then ValidForIsRequired = TRUE
233
 
236
			
234
 
237
		Else
235
 
238
			ValidForIsRequired = TRUE
236
         End If
239
			
237
 
240
		End If
238
 
241
	End Function
239
      End If
242
	'-----------------------------------------------------------------------------------------------------------------
240
   End Sub
243
	Private Function ValidForRegExp ( fieldValue, rowId )
241
   '-----------------------------------------------------------------------------------------------------------------
244
		Dim objRegEx
242
   Private Function ValidForIsRequired ( fieldValue, rowId )
245
		
243
      ValidForIsRequired = FALSE
246
		ValidForRegExp = FALSE
244
      If maRules( InxIsRequired, rowId ) = enumDB_YES Then
247
		If IsNull( maRules( InxRegExp, rowId ) ) OR (maRules( InxRegExp, rowId ) = "") Then 
245
         '/* Check if empty */
248
			ValidForRegExp = TRUE
246
         If fieldValue <> "" Then
249
		Else
247
 
250
			Set objRegEx = New RegExp 
248
            '/* Check for spaces */
251
			
249
            If Len( Replace(fieldValue, " ", "") ) > 0 Then   ValidForIsRequired = TRUE
252
			objRegEx.Global = False		' Only find first match. This is enough to fail the validation
250
 
253
			objRegEx.IgnoreCase = False	' Follow match pattern exactly. 
251
         End If
254
    		objRegEx.Pattern = maRules( InxRegExp, rowId ) 		' Set the pattern to match
252
 
255
			
253
      Else
256
			' Now test the pattern match.
254
         ValidForIsRequired = TRUE
257
			If NOT objRegEx.Test( fieldValue ) Then
255
 
258
				ValidForRegExp = TRUE
256
      End If
259
			End If
257
   End Function
260
			
258
   '-----------------------------------------------------------------------------------------------------------------
261
			Set objRegEx = Nothing
259
   Private Function ValidForRegExp ( fieldValue, rowId )
262
		End If
260
      Dim objRegEx
263
	End Function
261
 
264
	'-----------------------------------------------------------------------------------------------------------------
262
      ValidForRegExp = FALSE
265
	Private Function ValidForIsNumeric ( fieldValue, rowId )
263
      If IsNull( maRules( InxRegExp, rowId ) ) OR (maRules( InxRegExp, rowId ) = "") Then
266
		ValidForIsNumeric = FALSE
264
         ValidForRegExp = TRUE
267
		If maRules( InxIsNumeric, rowId ) = enumDB_YES Then 
265
      Else
268
			If IsNumeric( fieldValue ) Then ValidForIsNumeric = TRUE
266
         Set objRegEx = New RegExp
269
			
267
 
270
		Else
268
         objRegEx.Global = False      ' Only find first match. This is enough to fail the validation
271
			ValidForIsNumeric = TRUE
269
         objRegEx.IgnoreCase = False   ' Follow match pattern exactly.
272
			
270
          objRegEx.Pattern = maRules( InxRegExp, rowId )       ' Set the pattern to match
273
		End If
271
 
274
	End Function
272
         ' Now test the pattern match.
275
	'-----------------------------------------------------------------------------------------------------------------
273
         If NOT objRegEx.Test( fieldValue ) Then
276
	Private Function ValidForMinNumericValue ( fieldValue, rowId )
274
            ValidForRegExp = TRUE
277
		ValidForMinNumericValue = FALSE
275
         End If
278
		If IsNull( maRules( InxMinNumericValue, rowId ) ) OR (maRules( InxMinNumericValue, rowId ) = "") Then 
276
 
279
			ValidForMinNumericValue = TRUE
277
         Set objRegEx = Nothing
280
		Else
278
      End If
281
			If CDbl(fieldValue) >= CDbl(maRules( InxMinNumericValue, rowId )) Then	ValidForMinNumericValue = TRUE
279
   End Function
282
			
280
   '-----------------------------------------------------------------------------------------------------------------
283
		End If
281
   Private Function ValidForIsNumeric ( fieldValue, rowId )
284
	End Function
282
      ValidForIsNumeric = FALSE
285
	'-----------------------------------------------------------------------------------------------------------------
283
      If maRules( InxIsNumeric, rowId ) = enumDB_YES Then
286
	Private Function ValidForMaxNumericValue ( fieldValue, rowId )
284
         If IsNumeric( fieldValue ) Then ValidForIsNumeric = TRUE
287
		ValidForMaxNumericValue = FALSE
285
 
288
		If IsNull( maRules( InxMaxNumericValue, rowId ) ) OR (maRules( InxMaxNumericValue, rowId ) = "") Then 	
286
      Else
289
			ValidForMaxNumericValue = TRUE
287
         ValidForIsNumeric = TRUE
290
		Else
288
 
291
			If CDbl(fieldValue) <= CDbl(maRules( InxMaxNumericValue, rowId )) Then	ValidForMaxNumericValue = TRUE
289
      End If
292
			
290
   End Function
293
		End If
291
   '-----------------------------------------------------------------------------------------------------------------
294
	End Function
292
   Private Function ValidForMinNumericValue ( fieldValue, rowId )
295
	'-----------------------------------------------------------------------------------------------------------------
293
      ValidForMinNumericValue = FALSE
296
	Private Function ValidForIsDate ( fieldValue, rowId )
294
      If IsNull( maRules( InxMinNumericValue, rowId ) ) OR (maRules( InxMinNumericValue, rowId ) = "") Then
297
		ValidForIsDate = FALSE
295
         ValidForMinNumericValue = TRUE
298
		If maRules( InxIsDate, rowId ) = enumDB_YES Then 
296
      Else
299
			If IsDate( fieldValue ) Then ValidForIsDate = TRUE
297
         If CDbl(fieldValue) >= CDbl(maRules( InxMinNumericValue, rowId )) Then   ValidForMinNumericValue = TRUE
300
			
298
 
301
		Else
299
      End If
302
			ValidForIsDate = TRUE
300
   End Function
303
			
301
   '-----------------------------------------------------------------------------------------------------------------
304
		End If
302
   Private Function ValidForMaxNumericValue ( fieldValue, rowId )
305
	End Function
303
      ValidForMaxNumericValue = FALSE
306
	'-----------------------------------------------------------------------------------------------------------------
304
      If IsNull( maRules( InxMaxNumericValue, rowId ) ) OR (maRules( InxMaxNumericValue, rowId ) = "") Then
307
	Private Function ValidForStartDate ( fieldValue, rowId )
305
         ValidForMaxNumericValue = TRUE
308
		ValidForStartDate = FALSE
306
      Else
309
		If IsNull( maRules( InxStartDate, rowId ) ) OR (maRules( InxStartDate, rowId ) = "") Then 
307
         If CDbl(fieldValue) <= CDbl(maRules( InxMaxNumericValue, rowId )) Then   ValidForMaxNumericValue = TRUE
310
			ValidForStartDate = TRUE
308
 
311
		Else
309
      End If
312
			If CDate(fieldValue) >= CDate(maRules( InxStartDate, rowId )) Then	ValidForStartDate = TRUE
310
   End Function
313
			
311
   '-----------------------------------------------------------------------------------------------------------------
314
		End If
312
   Private Function ValidForIsDate ( fieldValue, rowId )
315
	End Function
313
      ValidForIsDate = FALSE
316
	'-----------------------------------------------------------------------------------------------------------------
314
      If maRules( InxIsDate, rowId ) = enumDB_YES Then
317
	Private Function ValidForEndDate ( fieldValue, rowId )
315
         If IsDate( fieldValue ) Then ValidForIsDate = TRUE
318
		ValidForEndDate = FALSE
316
 
319
		If IsNull( maRules( InxEndDate, rowId ) ) OR (maRules( InxEndDate, rowId ) = "") Then 
317
      Else
320
			ValidForEndDate = TRUE
318
         ValidForIsDate = TRUE
321
		Else
319
 
322
			If CDate(fieldValue) <= CDate(maRules( InxStartDate, rowId )) Then	ValidForEndDate = TRUE
320
      End If
323
			
321
   End Function
324
		End If
322
   '-----------------------------------------------------------------------------------------------------------------
325
	End Function
323
   Private Function ValidForStartDate ( fieldValue, rowId )
326
	'-----------------------------------------------------------------------------------------------------------------
324
      ValidForStartDate = FALSE
327
	Private Function ValidForMinStringLength ( fieldValue, rowId )
325
      If IsNull( maRules( InxStartDate, rowId ) ) OR (maRules( InxStartDate, rowId ) = "") Then
328
		ValidForMinStringLength = FALSE
326
         ValidForStartDate = TRUE
329
		If IsNull( maRules( InxMinStringLength, rowId ) ) OR (maRules( InxMinStringLength, rowId ) = "") Then 
327
      Else
330
			ValidForMinStringLength = TRUE
328
         If CDate(fieldValue) >= CDate(maRules( InxStartDate, rowId )) Then   ValidForStartDate = TRUE
331
		Else
329
 
332
			If CInt(Len(fieldValue)) >= CInt(maRules( InxMinStringLength, rowId )) Then	ValidForMinStringLength = TRUE
330
      End If
333
			
331
   End Function
334
		End If
332
   '-----------------------------------------------------------------------------------------------------------------
335
	End Function
333
   Private Function ValidForEndDate ( fieldValue, rowId )
336
	'-----------------------------------------------------------------------------------------------------------------
334
      ValidForEndDate = FALSE
337
	Private Function ValidForMaxStringLength ( fieldValue, rowId )
335
      If IsNull( maRules( InxEndDate, rowId ) ) OR (maRules( InxEndDate, rowId ) = "") Then
338
		ValidForMaxStringLength = FALSE
336
         ValidForEndDate = TRUE
339
		
337
      Else
340
		If IsNull( maRules( InxMaxStringLength, rowId ) ) OR (maRules( InxMaxStringLength, rowId ) = "") Then 
338
         If CDate(fieldValue) <= CDate(maRules( InxStartDate, rowId )) Then   ValidForEndDate = TRUE
341
			ValidForMaxStringLength = TRUE
339
 
342
		Else
340
      End If
343
			If CInt(Len(fieldValue)) <= CInt(maRules( InxMaxStringLength, rowId )) Then	ValidForMaxStringLength = TRUE
341
   End Function
344
			
342
   '-----------------------------------------------------------------------------------------------------------------
345
		End If
343
   Private Function ValidForMinStringLength ( fieldValue, rowId )
346
	End Function
344
      ValidForMinStringLength = FALSE
347
	'-----------------------------------------------------------------------------------------------------------------
345
      If IsNull( maRules( InxMinStringLength, rowId ) ) OR (maRules( InxMinStringLength, rowId ) = "") Then
348
	Private Sub AddErrorMessage ( rowId, sErrMsg )
346
         ValidForMinStringLength = TRUE
349
		mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) = _
347
      Else
350
			mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) &_
348
         If CInt(Len(fieldValue)) >= CInt(maRules( InxMinStringLength, rowId )) Then   ValidForMinStringLength = TRUE
351
			"<tr>"&_
349
 
352
			sBULET  &"<td class='val_err'>"&  sErrMsg  &"</td>"&_
350
      End If
353
			"</tr>"& VBNewLine
351
   End Function
354
	End Sub
352
   '-----------------------------------------------------------------------------------------------------------------
355
	'-----------------------------------------------------------------------------------------------------------------
353
   Private Function ValidForMaxStringLength ( fieldValue, rowId )
356
	Public Sub LoadFieldRules ( aRows )
354
      ValidForMaxStringLength = FALSE
357
		' Pass the full array row matching the columns of maRules()
355
 
358
		Dim nProperty, newArrayDim, numOfRows, rowNum
356
      If IsNull( maRules( InxMaxStringLength, rowId ) ) OR (maRules( InxMaxStringLength, rowId ) = "") Then
359
		
357
         ValidForMaxStringLength = TRUE
360
		numOfRows = UBound( aRows, 2 )
358
      Else
361
		
359
         If CInt(Len(fieldValue)) <= CInt(maRules( InxMaxStringLength, rowId )) Then   ValidForMaxStringLength = TRUE
362
		
360
 
363
		For rowNum = 0 To numOfRows
361
      End If
364
			' Increase array by 1
362
   End Function
365
			newArrayDim = LastRowInx() + 1
363
   '-----------------------------------------------------------------------------------------------------------------
366
			ReDim Preserve maRules( mNumOfRules, newArrayDim )
364
   Private Sub AddErrorMessage ( rowId, sErrMsg )
367
			
365
      mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) = _
368
			mobjFieldMap.Add ( Cstr( aRows ( InxFieldName, rowNum ) ) ), CStr( newArrayDim )
366
         mobjErrorMsg.Item (Cstr( maRules( InxFieldName, rowId ) )) &_
369
			
367
         "<tr>"&_
370
			For nProperty = 0 To mLastRuleInx
368
         sBULET  &"<td class='val_err'>"&  sErrMsg  &"</td>"&_
371
				maRules ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum )
369
         "</tr>"& VBNewLine
372
			Next
370
   End Sub
373
			
371
   '-----------------------------------------------------------------------------------------------------------------
374
		Next
372
   Private Function LastRowInx ()
375
		
373
       LastRowInx = UBound ( maRules, 2 )
376
		' --- Validate Form ---
374
   End Function
377
		'ValidateForm()
375
   '-----------------------------------------------------------------------------------------------------------------
378
		
376
   Private Function GetErrorMsg ( sFieldName )
379
	End Sub
377
      Dim msg
380
	'-----------------------------------------------------------------------------------------------------------------
378
      msg = mobjErrorMsg.Item (CStr(sFieldName))
381
	Private Function LastRowInx ()
379
      If msg <> "" Then
382
		 LastRowInx = UBound ( maRules, 2 )
380
         GetErrorMsg = _
383
	End Function
381
         "<table width='100%'  border='0' cellspacing='2' cellpadding='0'>"& VBNewLine &_
384
	'-----------------------------------------------------------------------------------------------------------------
382
         msg & VBNewLine &_
385
	Private Function GetErrorMsg ( sFieldName )
383
         "<tr><td width='1'>"& SPACER &"</td><td width='1'>"& SPACER &"</td><td width='100%'>"& SPACER &"</td></tr>"& VBNewLine &_
386
		Dim msg
384
         "</table>"
387
		msg = mobjErrorMsg.Item (CStr(sFieldName))
385
      Else
388
		If msg <> "" Then
386
         GetErrorMsg = NULL
389
			GetErrorMsg = _
387
      End If
390
			"<table width='100%'  border='0' cellspacing='2' cellpadding='0'>"& VBNewLine &_
388
   End Function
391
			msg & VBNewLine &_
389
   '-----------------------------------------------------------------------------------------------------------------
392
			"<tr><td width='1'>"& SPACER &"</td><td width='1'>"& SPACER &"</td><td width='100%'>"& SPACER &"</td></tr>"& VBNewLine &_
390
   Private Function ParseParams ( sParams )
393
			"</table>"
391
      Dim paramArr, i
394
		Else
392
 
395
			GetErrorMsg = NULL
393
      paramArr = Split ( sParams, "'" )      ' Expected Params value:  id='field_name' IsRequired='N' param2='val' ...
396
		End If
394
 
397
	End Function
395
      ' Store Validation changes/rules in array
398
	'-----------------------------------------------------------------------------------------------------------------
396
      For i = 0 To UBound( paramArr )-1 Step 2
399
	Private Function ParseParams ( sParams )
397
         Call UpdateRow ( paramArr(1), GetColumnInx ( paramArr(i) ), paramArr(i+1) )
400
		Dim paramArr, i
398
      Next
401
		
399
 
402
		paramArr = Split ( sParams, "'" )		' Expected Params value:  id='field_name' param1='val' param2='val' ...
400
      ParseParams = paramArr(1)   ' id must be first param
403
		
401
 
404
		' Store Validation changes/rules in array
402
   End Function
405
		For i = 0 To UBound( paramArr )-1 Step 2
403
   '-----------------------------------------------------------------------------------------------------------------
406
			Call UpdateRow ( paramArr(1), GetColumnInx ( paramArr(i) ), paramArr(i+1) )
404
   Public Sub UpdateRules ( sParams )
407
		Next
405
      ParseParams ( sParams )
408
		
406
 
409
		ParseParams = paramArr(1)	' id must be first param
407
   End Sub
410
		
408
   '-----------------------------------------------------------------------------------------------------------------
411
	End Function
409
   Private Sub UpdateRow ( sFieldName, sColumnInx, sColumnVal )
412
	'-----------------------------------------------------------------------------------------------------------------
410
      Dim rowNum
413
	Public Sub UpdateRules ( sParams )
411
 
414
		ParseParams ( sParams )
412
      If mobjFieldMap.Exists (CStr(sFieldName)) Then
415
		
413
         rowNum = mobjFieldMap.Item ( Cstr( sFieldName  ) )
416
	End Sub
414
 
417
	'-----------------------------------------------------------------------------------------------------------------
415
      Else
418
	Private Sub UpdateRow ( sFieldName, sColumnInx, sColumnVal )
416
         rowNum = LastRowInx() + 1
419
		Dim rowNum
417
         ReDim Preserve maRules( mNumOfRules, rowNum )
420
		
418
 
421
		If mobjFieldMap.Exists (CStr(sFieldName)) Then
419
         mobjFieldMap.Add ( Cstr( sFieldName ) ), CStr( rowNum )
422
			rowNum = mobjFieldMap.Item ( Cstr( sFieldName  ) )
420
 
423
			
421
      End If
424
		Else
422
 
425
			rowNum = LastRowInx() + 1
423
      maRules ( sColumnInx, rowNum ) = sColumnVal
426
			ReDim Preserve maRules( mNumOfRules, rowNum )
424
 
427
			
425
   End Sub
428
			mobjFieldMap.Add ( Cstr( sFieldName ) ), CStr( rowNum )
426
   '-----------------------------------------------------------------------------------------------------------------
429
			
427
   Private Function GetColumnInx ( ByVal sParam )
430
		End If
428
      sParam = Trim( sParam )      ' Trim spaces
431
		
429
      sParam = Left( sParam, Len(sParam)-1 )   ' Remove trailing "="
432
		maRules ( sColumnInx, rowNum ) = sColumnVal
430
 
433
		
431
      Select Case Trim( sParam )
434
	End Sub
432
         Case "id"
435
	'-----------------------------------------------------------------------------------------------------------------
433
            GetColumnInx = InxFieldName
436
	Private Function GetColumnInx ( ByVal sParam )
434
         Case Else
437
		sParam = Trim( sParam )		' Trim spaces
435
            GetColumnInx = Eval( "Inx"& Trim( sParam ) )
438
		sParam = Left( sParam, Len(sParam)-1 )	' Remove trailing "="
436
 
439
		
437
      End Select
440
		Select Case Trim( sParam )
438
   End Function
441
			Case "id"
439
   '-----------------------------------------------------------------------------------------------------------------
442
				GetColumnInx = InxFieldName
-
 
443
			Case Else
-
 
444
				GetColumnInx = Eval( "Inx"& Trim( sParam ) )
-
 
445
			
-
 
446
		End Select
-
 
447
	End Function
-
 
448
	'-----------------------------------------------------------------------------------------------------------------
-
 
449
	Sub LoadValidationRules ( aFieldList, ByRef objOraDatabase )
440
	Sub LoadValidationRules ( aFieldList, ByRef objOraDatabase )
450
		Dim rsQry, query
-
 
451
		
-
 
452
		query = _
-
 
453
		"   SELECT FIELD_NAME, "&_
441
        UpdateRules ("id='app_acr' IsRequired='Y' MaxStringLength='3' RegExp='' RegExpDescription=''")
454
		"		   IS_REQUIRED, "&_
-
 
455
		"		   IS_NUMERIC, "&_
-
 
456
		"		   MIN_NUMERIC_VALUE, "&_
442
        UpdateRules ("id='app_name' IsRequired='Y' MaxStringLength='255' RegExp='' RegExpDescription=''")
457
		"		   MAX_NUMERIC_VALUE, "&_
443
        UpdateRules ("id='display_column_name' IsRequired='Y' MaxStringLength='1000'")
458
		"		   IS_DATE, "&_
-
 
459
		"		   START_DATE, "&_
-
 
460
		"		   END_DATE, "&_
-
 
461
		"		   MIN_STRING_LENGTH, "&_
444
        UpdateRules ("id='domain' IsRequired='N' MaxStringLength='20'")
462
		" 		   MAX_STRING_LENGTH, "&_
445
        UpdateRules ("id='full_name' IsRequired='Y' MaxStringLength='255'")
463
		"		   REGEXP, "&_
-
 
464
		"		   REGEXP_DESCRIPTION "&_
446
        UpdateRules ("id='obj_description' IsRequired='Y' MaxStringLength='1000' MinStringLength='15'")
-
 
447
        UpdateRules ("id='obj_name' IsRequired='Y' MaxStringLength='255' RegExp='[^a-zA-Z0-9]' RegExpDescription='Must be alpha-numeric<br>[a-z,A-Z,0-9].'")
465
		"	  FROM VALIDATION_RULES"&_
448
        UpdateRules ("id='ref_column_name' IsRequired='Y' MaxStringLength='1000'")
466
		"	 WHERE field_name IN ( '"& Join( aFieldList, "','") &"' )"
449
        UpdateRules ("id='role_comments' IsRequired='Y' MaxStringLength='255' MinStringLength='15'")
467
		
-
 
468
		
-
 
469
		Set rsQry = objOraDatabase.DbCreateDynaset( query , 0 )
450
        UpdateRules ("id='role_name' IsRequired='Y' MaxStringLength='50'")
470
		If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
451
        UpdateRules ("id='table_name' IsRequired='Y' MaxStringLength='1000'")
471
			Call LoadFieldRules ( rsQry.GetRows() )
452
        UpdateRules ("id='user_email' IsRequired='Y' MaxStringLength='1000'")
472
			
-
 
473
		End If
-
 
474
		
-
 
475
		rsQry.Close
-
 
476
		Set rsQry = Nothing
453
        UpdateRules ("id='user_name' IsRequired='Y' MaxStringLength='1000'")
477
	End Sub
454
    End Sub
478
	'-----------------------------------------------------------------------------------------------------------------
455
   '-----------------------------------------------------------------------------------------------------------------
479
	Private Sub Class_Initialize()
456
   Private Sub Class_Initialize()
480
		'// Perform action on creation of object. e.g. Set myObj = New ThisClassName
457
      '// Perform action on creation of object. e.g. Set myObj = New ThisClassName
481
		Set mobjFieldMap = CreateObject("Scripting.Dictionary")
458
      Set mobjFieldMap = CreateObject("Scripting.Dictionary")
482
		Set mobjErrorMsg = CreateObject("Scripting.Dictionary")
459
      Set mobjErrorMsg = CreateObject("Scripting.Dictionary")
483
		Set mobjAltVal 	 = CreateObject("Scripting.Dictionary")
460
      Set mobjAltVal     = CreateObject("Scripting.Dictionary")
484
		
461
 
485
		sPostBackTagName = "VC_POST_BACK"
462
      sPostBackTagName = "VC_POST_BACK"
486
		
463
 
487
		
464
 
488
		bHiddenTagPlanted = FALSE
465
      bHiddenTagPlanted = FALSE
489
		bIsPostBack = FALSE		' When true, form has been submitted and need postback validation
466
      bIsPostBack = FALSE      ' When true, form has been submitted and need postback validation
490
		bIsValidated = FALSE
467
      bIsValidated = FALSE
491
		
468
 
492
		
469
 
493
		InxFieldName			= 0
470
      InxFieldName          = 0
494
		InxIsRequired			= 1
471
      InxIsRequired         = 1
495
		InxIsNumeric			= 2
472
      InxIsNumeric          = 2
496
		InxMinNumericValue		= 3
473
      InxMinNumericValue    = 3
497
		InxMaxNumericValue		= 4
474
      InxMaxNumericValue    = 4
498
		InxIsDate				= 5
475
      InxIsDate             = 5
499
		InxStartDate			= 6
476
      InxStartDate          = 6
500
		InxEndDate				= 7
477
      InxEndDate            = 7
501
		InxMinStringLength		= 8
478
      InxMinStringLength    = 8
502
		InxMaxStringLength		= 9
479
      InxMaxStringLength    = 9
503
		InxRegExp				= 10
480
      InxRegExp             = 10
504
		InxRegExpDescription	= 11
481
      InxRegExpDescription  = 11
505
		mNumOfRules = 12  	' Number of Rules that can be assigned to one field
482
      mNumOfRules           = 12     ' Number of Rules that can be assigned to one field
506
		mLastRuleInx = mNumOfRules - 1
483
      mLastRuleInx = mNumOfRules - 1
507
		
484
 
508
		ReDim maRules ( mNumOfRules, -1 )
485
      ReDim maRules ( mNumOfRules, -1 )
509
		
486
 
510
		'sSESSION_SEPARATOR = "|SEPARATOR|"		' Make sure it will never show in regexp field
487
      'sSESSION_SEPARATOR = "|SEPARATOR|"      ' Make sure it will never show in regexp field
511
		sBULET = "<td background='images/red_dot.gif'>"& SPACER &"</td>"&_
488
		sBULET = "<td background='images/red_dot.gif'>"& SPACER &"</td>"&_
512
				 "<td valign='top'><img src='icons/i_bulet_red.gif' width='4' height='4' hspace='3' vspace='4' border='0' align='absmiddle'></td>"
489
             "<td valign='top'><img src='icons/i_bulet_red.gif' width='4' height='4' hspace='3' vspace='4' border='0' align='absmiddle'></td>"
513
		
490
 
514
		
491
 
515
		'--- Check if Form is posted back
492
      '--- Check if Form is posted back
516
		If Request(sPostBackTagName) <> "" Then
493
      If Request(sPostBackTagName) <> "" Then
517
			bIsPostBack = TRUE
494
         bIsPostBack = TRUE
518
		End If
495
      End If
519
	End Sub
496
   End Sub
520
	'-----------------------------------------------------------------------------------------------------------------
497
   '-----------------------------------------------------------------------------------------------------------------
521
	Private Sub Class_Terminate()
498
   Private Sub Class_Terminate()
522
		'// Perform action on object disposal. e.g. Set myObj = Nothing
499
      '// Perform action on object disposal. e.g. Set myObj = Nothing
523
		Set mobjFieldMap = Nothing
500
      Set mobjFieldMap = Nothing
524
		Set mobjErrorMsg = Nothing
501
      Set mobjErrorMsg = Nothing
525
		Set mobjAltVal = Nothing
502
      Set mobjAltVal = Nothing
526
		
503
 
527
	End Sub
504
   End Sub
528
	'-----------------------------------------------------------------------------------------------------------------
505
   '-----------------------------------------------------------------------------------------------------------------
529
End Class
506
End Class
530
%>
-
 
531
507
%>
-
 
508