<% 'File Description @0-0F32E374 '====================================================== ' ' This file contains the following classes: ' Class clsSQLParameters ' Class clsSQLParameter ' Class clsFields ' Class clsControls ' Class clsControl ' Class clsField ' Class clsButton ' Class clsFileUpload ' Class clsDatePicker ' Class clsListControl ' Class clsErrors ' Class clsEmptyDataSource ' Class clsDataSource ' Class clsCommand ' Class clsStringBuffer ' '====================================================== 'End File Description 'Constant List @0-52D70043 ' ------- Controls --------------- Const ccsLabel = 00001 Const ccsLink = 00002 Const ccsTextBox = 00003 Const ccsTextArea = 00004 Const ccsListBox = 00005 Const ccsRadioButton = 00006 Const ccsButton = 00007 Const ccsCheckBox = 00008 Const ccsImage = 00009 Const ccsImageLink = 00010 Const ccsHidden = 00011 Const ccsCheckBoxList = 00012 Const ccsDatePicker = 00013 Dim ccsControlTypes(13) ccsControlTypes(ccsLabel) = "Label" ccsControlTypes(ccsLink) = "Link" ccsControlTypes(ccsTextBox) = "TextBox" ccsControlTypes(ccsTextArea) = "TextArea" ccsControlTypes(ccsListBox) = "ListBox" ccsControlTypes(ccsRadioButton) = "RadioButton" ccsControlTypes(ccsButton) = "Button" ccsControlTypes(ccsCheckBox) = "CheckBox" ccsControlTypes(ccsImage) = "Image" ccsControlTypes(ccsImageLink) = "ImageLink" ccsControlTypes(ccsHidden) = "Hidden" ccsControlTypes(ccsCheckBoxList) = "CheckBoxList" ccsControlTypes(ccsDatePicker) = "DatePicker" ' ------- Operators -------------- Const opEqual = 00001 Const opNotEqual = 00002 Const opLessThan = 00003 Const opLessThanOrEqual = 00004 Const opGreaterThan = 00005 Const opGreaterThanOrEqual = 00006 Const opBeginsWith = 00007 Const opNotBeginsWith = 00008 Const opEndsWith = 00009 Const opNotEndsWith = 00010 Const opContains = 00011 Const opNotContains = 00012 Const opIsNull = 00013 Const opNotNull = 00014 ' ------- Datasource types ------- Const dsTable = 00001 Const dsSQL = 00002 Const dsProcedure = 00003 Const dsListOfValues = 00004 Const dsEmpty = 00005 ' ------- Command types ------- Const cmdOpen = 00001 Const cmdExec = 00002 ' ------- Parse types ------------ Const ccsParseAccumulate = True Const ccsParseOverwrite = False ' ------- Listbox populating types ------------ Const ccsJoins = 0 Const ccsStringConcats = 1 ' ------- CheckBox states -------- Const ccsChecked = True Const ccsUnchecked = False 'End Constant List 'clsSQLParameters Class @0-14A751AF Class clsSQLParameters Public Connection Public Criterion() Public AssembledWhere Public ParameterSources Public Errors Public DataSource Public ParametersList Private Sub Class_Initialize() ReDim Criterion(100) Set ParametersList = Server.CreateObject("Scripting.Dictionary") Set DataSource = Nothing End Sub Private Sub Class_Terminate() Set ParametersList = Nothing End Sub Public Default Property Get Parameters(Name) Set Parameters = ParametersList(Name) End Property Public Property Set Parameters(Name, NewParameter) Set ParametersList(Name) = NewParameter End Property Property Get Count() Count = ParametersList.Count End Property Function AddParameter(ID, ParameterSource, DataType, Format, DBFormat, DefaultValue, UseIsNull) Dim SQLParameter Set SQLParameter = New clsSQLParameter With SQLParameter Set .Connection = Connection .DataType = DataType .Format = Format .DBFormat = DBFormat .Caption = ParameterSource .DefaultValue = DefaultValue .UseIsNull = UseIsNull Set .DataSource = DataSource If IsObject(ParameterSources) Then If IsEmpty(DefaultValue) Or ((DataType <> ccsText And DataType <> ccsMemo) And CStr(DefaultValue) = "") Then .Text = ParameterSources(ParameterSource) Else If IsEmpty(ParameterSources(ParameterSource)) Or ((DataType <> ccsText And DataType <> ccsMemo) And ParameterSources(ParameterSource) = "") Then .Value = DefaultValue Else .Text = ParameterSources(ParameterSource) End If End If End If End With Set ParametersList(ID) = SQLParameter Set SQLParameter = Nothing End Function Function getParamByID(ID) Set getParamByID = ParametersList(ID) End Function Property Get AllParamsSet() Dim ParametersItems, I, Result Result = True I = 0 ParametersItems = ParametersList.Items While Result AND (I <= UBound(ParametersItems)) Result = NOT IsEmpty(ParametersItems(I).Value) I = I + 1 Wend AllParamsSet = Result End Property Function GetError() Dim ParametersItems, I, Result ParametersItems = ParametersList.Items For I = 0 To UBound(ParametersItems) Result = Result & ParametersItems(I).Errors.ToString Next GetError = Result End Function Function opAND(Brackets, LeftPart, RightPart) Dim Result If NOT IsEmpty(LeftPart) Then If NOT IsEmpty(RightPart) Then Result = LeftPart & " and " & RightPart If Brackets Then Result = " (" & Result & ") " Else Result = LeftPart End If Else If NOT IsEmpty(RightPart) Then Result = RightPart End If End If opAND = Result End Function Function opOR(Brackets, LeftPart, RightPart) Dim Result If NOT IsEmpty(LeftPart) Then If NOT IsEmpty(RightPart) Then Result = LeftPart & " or " & RightPart If Brackets Then Result = " (" & Result & ") " Else Result = LeftPart End If Else If NOT IsEmpty(RightPart) Then Result = RightPart End If End If opOR = Result End Function Function Operation(Operator, Brackets, FieldName, Parameter) If CStr(Parameter.Text) <> "" Then Dim Result Dim Value, SQLValue Value = Parameter.SQLText SQLValue = Connection.ToSQL(Value, Parameter.DataType) Value = Replace(Value, "'", "''") Select Case Operator Case opEqual Result = FieldName & " = " & SQLValue Case opNotEqual Result = FieldName & " <> " & SQLValue Case opLessThan Result = FieldName & " < " & SQLValue Case opLessThanOrEqual Result = FieldName & " <= " & SQLValue Case opGreaterThan Result = FieldName & " > " & SQLValue Case opGreaterThanOrEqual Result = FieldName & " >= " & SQLValue Case opBeginsWith Result = FieldName & " like '" & Value & "%'" Case opNotBeginsWith Result = FieldName & " not like '" & Value & "%'" Case opEndsWith Result = FieldName & " like '%" & Value & "'" Case opNotEndsWith Result = FieldName & " not like '%" & Value & "'" Case opContains Result = FieldName & " like '%" & Value & "%'" Case opNotContains Result = FieldName & " not like '%" & Value & "%'" Case opIsNull Result = FieldName & " is null" Case opNotNull Result = FieldName & " is not null" End Select Operation = Result Else If Parameter.UseIsNull Then Select Case Operator Case opNotEqual, opNotBeginsWith, opNotEndsWith, opNotContains, opNotNull Result = FieldName & " is not null" Case Else Result = FieldName & " is null" End Select Operation = Result Else Operation = Empty End If End If End Function End Class 'End clsSQLParameters Class 'clsSQLParameter Class @0-7B4E1941 Class clsSQLParameter Public Errors Public DataType Public Format Public DBFormat Public Caption Public Connection Public DataSource Public DefaultValue Public UseIsNull Private VarValue Private SQLTextValue Private TextValue Private Sub Class_Initialize() VarValue = Empty SQLTextValue = Empty TextValue = Empty UseIsNull = False DataType = ccsText Set Errors = New clsErrors End Sub Private Sub Class_Terminate() Set Errors = Nothing End Sub Function GetParsedValue(ParsingValue, MaskFormat) Dim Result If Not IsEmpty(ParsingValue) Then Select Case DataType Case ccsDate If VarType(ParsingValue) = vbDate Then Result = ParsingValue ElseIf CCValidateDate(ParsingValue, MaskFormat) Then Result = CCParseDate(ParsingValue, MaskFormat) Else If IsArray(Format) Then PrintDBError "", "", "The value in field " & Caption & " is not valid. Use the following format: " & Join(Format, "") & "." Else PrintDBError "", "", "The value in field " & Caption & " is not valid." End If End If Case ccsBoolean Result = CCParseBoolean(ParsingValue, MaskFormat) Case ccsInteger If CCValidateNumber(ParsingValue, MaskFormat) Then Result = CCParseInteger(ParsingValue, MaskFormat) Else PrintDBError "", "", "The value in field " & Caption & " is not valid." End If Case ccsFloat If CCValidateNumber(ParsingValue, MaskFormat) Then Result = CCParseFloat(ParsingValue, MaskFormat) Else PrintDBError "", "", "The value in field " & Caption & " is not valid." End If Case ccsText, ccsMemo Result = CStr(ParsingValue) End Select End If GetParsedValue = Result End Function Function GetFormattedValue(MaskFormat) Dim Result, Value If IsEmpty(VarValue) Then Value = DefaultValue Else Value = VarValue End If Select Case DataType Case ccsDate Result = CCFormatDate(Value, MaskFormat) Case ccsBoolean Result = CCFormatBoolean(Value, MaskFormat) Case ccsInteger, ccsFloat Result = CCFormatNumber(Value, MaskFormat) Case ccsText, ccsMemo Result = CStr(Value) End Select GetFormattedValue = Result End Function Property Let Value(NewValue) VarValue = Empty SQLTextValue = Empty TextValue = Empty If NOT IsEmpty(NewValue) And Not (NewValue="") Then Select Case DataType Case ccsDate VarValue = CDate(NewValue) Case ccsBoolean VarValue = CBool(NewValue) Case ccsInteger VarValue = CLng(NewValue) Case ccsFloat VarValue = CDbl(NewValue) Case ccsText, ccsMemo VarValue = CStr(NewValue) End Select End If End Property Property Get Value() If IsEmpty(VarValue) Then Value = DefaultValue Else Value = VarValue End If End Property Property Let Text(NewText) If Not IsEmpty(NewText) Then SQLTextValue = Empty TextValue = NewText VarValue = GetParsedValue(TextValue, Format) End If End Property Property Get Text() If IsEmpty(TextValue) Then TextValue = GetFormattedValue(Format) Text = TextValue End Property Property Let SQLText(varNewSQLText) SQLTextValue = varNewSQLText End Property Property Get SQLText() If IsEmpty(SQLTextValue) Then SQLTextValue = GetFormattedValue(DBFormat) End If SQLText = SQLTextValue End Property End Class 'End clsSQLParameter Class 'clsFields Class @0-791D3D1C Class clsFields Private objFields Private Items Private Counter Private Sub Class_Initialize() Set objFields = CreateObject("Scripting.Dictionary") End Sub Sub AddFields(Fields) ' Add new objects to Object array Dim I If IsArray(Fields) Then For I = LBound(Fields) To UBound(Fields) Set objFields(Fields(I).Name) = Fields(I) Next End If End Sub Public Default Property Get Item(Name) Set Item = objFields(Name) End Property Sub InitEnum() Items = objFields.Items Counter = 0 End Sub Function NextItem() Set NextItem = Items(Counter) Counter = Counter + 1 End Function Function EndOfEnum() EndOfEnum = (Counter > UBound(Items)) End Function Function Exists(Name) Exists = objFields.Exists(Name) End Function End Class 'End clsFields Class 'CCCreateCollection Function @0-61899D71 Function CCCreateCollection(Block, TargetBlock, Accumulate, Controls) Dim Collection Set Collection = New clsControls With Collection Set .Block = Block If NOT IsNull(TargetBlock) Then Set .TargetBlock = TargetBlock End If .Accumulate = Accumulate .AddControls Controls End With Set CCCreateCollection = Collection End Function 'End CCCreateCollection Function 'clsControls Class @0-77F5EEBC Class clsControls Private Objects ' Dictionary object Private CCSEventResult Public Block Public Accumulate Private objTargetBlock Private isSetTargetBlock Private mVisible Private Sub Class_Initialize() Set Objects = Server.CreateObject("Scripting.Dictionary") mVisible = True End Sub Private Sub Class_Terminate() Set Objects = Nothing End Sub Sub AddControls(Controls) ' Add new objects to Object array Dim ArraySize, NumberControls, I If IsArray(Controls) Then NumberControls = UBound(Controls) ArraySize = Objects.Count For i = ArraySize To ArraySize + NumberControls Objects.Add i,Controls(I) Next End If End Sub Sub AddControl(Control) ' Add a new object to Object array If TypeName(Control) = "clsControls" Then Objects.Add Objects.Count, Control Else Objects.Add Control.Name, Control End If End Sub Property Get Items(ItemName) If Objects.Exists(ItemName) Then Set Items = Objects(ItemName) Else Set Items = Nothing End If End Property Property Let Items(ItemName, NewItem) If Objects.Exists(ItemName) Then Objects(ItemName) = NewItem Else Objects.Add ItemName, NewItem End If End Property Sub Show() Dim Element, Obj If NOT mVisible Then Exit Sub For Each Element In Objects Set Obj = Objects.Item(element) If TypeName(Obj) = "clsControls" Then Obj.Show Else Obj.Show Block End If Next If Not IsEmpty(Accumulate) Then If isSetTargetBlock Then Block.ParseTo Accumulate, objTargetBlock Else Block.Parse Accumulate End If End If End Sub Function Validate() Dim Validation, Element Validation = True For Each Element In Objects Objects.Item(Element).Validate Validation = Validation And (Objects.Item(Element).Errors.Count = 0) Next Validate = Validation End Function Function GetErrors() Dim Errors, Element For Each Element In Objects Errors = Errors & Objects.Item(Element).Errors.ToString Next GetErrors = Errors End Function Property Set TargetBlock(NewBlock) isSetTargetBlock = True Set objTargetBlock = NewBlock End Property Sub InitEnum() Items = objFields.Items Counter = 0 End Sub Function NextItem() Set NextItem = Items(Counter) Counter = Counter + 1 End Function Function EndOfEnum() EndOfEnum = (Counter > UBound(Items)) End Function Property Let Visible(newValue) mVisible = CBool(newValue) End Property Property Get Visible() Visible = mVisible End Property End Class 'End clsControls Class 'CCCreateControl Function @0-C7701CBD Function CCCreateControl(ControlType, Name, Caption, DataType, Format, InitValue) Dim Control Set Control = New clsControl With Control .ControlType = ControlType .Name = Name .BlockName = ccsControlTypes(ControlType) & " " & Name .ControlTypeName = ccsControlTypes(ControlType) .Caption = Caption .DataType = DataType .Format = Format If ControlType = ccsCheckBox Then If NOT IsEmpty(InitValue) Then .State = True End If Else .Text = InitValue End If End With Set CCCreateControl = Control End Function 'End CCCreateControl Function 'clsControl Class @0-93407BFD Class clsControl Public Errors Public DataType Public Format Public DBFormat Public Caption Public ControlType Public ControlTypeName Public Name Public BlockName Public ExternalName Public HTML Public Required Public CheckedValue Public UncheckedValue Public State Public Visible Public TemplateBlock Public Parameters Private mPage Private VarValue Private SQLTextValue Private TextValue Public CCSEvents Private CCSEventResult Private Sub Class_Initialize() VarValue = Empty SQLTextValue = Empty TextValue = Empty Visible = True ExternalName = Empty DataType = ccsText HTML = False Required = False Set Errors = New clsErrors Set CCSEvents = CreateObject("Scripting.Dictionary") Parameters = "" End Sub Private Sub Class_Terminate() Set Errors = Nothing End Sub Sub SetDBValue(DBValue) VarValue = Empty SQLTextValue = Empty TextValue = Empty VarValue = GetParsedValue(DBValue, DBFormat) If ControlType = ccsCheckBox Then If DataType = ccsBoolean Then State = VarValue Else State = (VarValue = CheckedValue) End If End If End Sub Function Validate() If Required And CStr(VarValue) = "" And Errors.Count = 0 Then Dim FieldName If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Errors.addError("The value in field " & FieldName & " is required.") End If Validate = CCRaiseEvent(CCSEvents, "OnValidate", Me) End Function Function GetParsedValue(ParsingValue, MaskFormat) Dim Result If Not IsEmpty(ParsingValue) Then Select Case DataType Case ccsDate If VarType(ParsingValue) = vbDate Then Result = ParsingValue ElseIf CCValidateDate(ParsingValue, MaskFormat) Then Result = CCParseDate(ParsingValue, MaskFormat) Else If IsArray(Format) Then Errors.addError("The value in field " & Caption & " is not valid. Use the following format: " & Join(Format, "") & ".") Else Errors.addError("The value in field " & Caption & " is not valid.") End If End If Case ccsBoolean If CCValidateBoolean(ParsingValue, MaskFormat) Then Result = CCParseBoolean(ParsingValue, MaskFormat) Else Errors.addError("The value in field " & Caption & " is not valid.") End If Case ccsInteger If CCValidateNumber(ParsingValue, MaskFormat) Then Result = CCParseInteger(ParsingValue, MaskFormat) Else Errors.addError("The value in field " & Caption & " is not valid.") End If Case ccsFloat If CCValidateNumber(ParsingValue, MaskFormat) Then Result = CCParseFloat(ParsingValue, MaskFormat) Else Errors.addError("The value in field " & Caption & " is not valid.") End If Case ccsText, ccsMemo Result = CStr(ParsingValue) End Select End If GetParsedValue = Result End Function Property Get Link() If Parameters = "" Then Link = mPage Else Link = mPage & "?" & Parameters End If End Property Property Let Link(newLink) Dim parsedLink If CStr(newLink) = "" Then mPage = "" Parameters = "" Else parsedLink = Split(newLink, "?") mPage = parsedLink(0) If UBound(parsedLink) = 1 Then Parameters = parsedLink(1) Else Parameters = "" End If End If End Property Property Get Page() Page = mPage End Property Property Let Page(newPage) mPage = newPage End Property Function GetFormattedValue(MaskFormat) Dim Result Select Case DataType Case ccsDate Result = CCFormatDate(VarValue, MaskFormat) Case ccsBoolean Result = CCFormatBoolean(VarValue, MaskFormat) Case ccsInteger, ccsFloat Result = CCFormatNumber(VarValue, MaskFormat) Case ccsText, ccsMemo Result = CStr(VarValue) End Select GetFormattedValue = Result End Function Sub Show(Template) Dim NeedShow, sTmpValue Set TemplateBlock = Template.Block(ControlTypeName & " " & Name) If TemplateBlock Is Nothing Then Set TemplateBlock = Template NeedShow = False Else NeedShow = True TemplateBlock.HTML = "" End If CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me) If NOT Visible Then Exit Sub If IsEmpty(ExternalName) Then TemplateBlock.Variable(Name & "_Name") = Name Else TemplateBlock.Variable(Name & "_Name") = ExternalName End If If IsEmpty(TextValue) Then TextValue = GetFormattedValue(Format) End If Select Case ControlType Case ccsLabel, ccsTextBox, ccsTextArea, ccsHidden If HTML Then TemplateBlock.Variable(Name) = TextValue Else sTmpValue = Server.HTMLEncode(TextValue) If ControlType = ccsLabel Then sTmpValue = Replace(sTmpValue, vbCrLf, "
") End If TemplateBlock.Variable(Name) = sTmpValue End If Case ccsImage sTmpValue = Server.HTMLEncode(TextValue) If ControlType = ccsLabel Then sTmpValue = Replace(sTmpValue, vbCrLf, "
") End If TemplateBlock.Variable(Name) = sTmpValue Case ccsLink If HTML Then TemplateBlock.Variable(Name) = TextValue Else TemplateBlock.Variable(Name) = Replace(Server.HTMLEncode(TextValue), vbCrLf, "
") End If TemplateBlock.Variable(Name & "_Src") = Me.Link Case ccsImageLink TemplateBlock.Variable(Name & "_Src") = Server.HTMLEncode(TextValue) TemplateBlock.Variable(Name) = Me.Link Case ccsCheckBox If State Then TemplateBlock.Variable(Name) = "CHECKED" Else TemplateBlock.Variable(Name) = "" End If End Select If NeedShow Then TemplateBlock.Show Set TemplateBlock = Nothing End Sub Property Let Value(NewValue) VarValue = Empty SQLTextValue = Empty TextValue = Empty If NOT IsEmpty(NewValue) And Not (NewValue="") Then Select Case DataType Case ccsDate VarValue = CDate(NewValue) Case ccsBoolean VarValue = CBool(NewValue) Case ccsInteger VarValue = CLng(NewValue) Case ccsFloat VarValue = CDbl(NewValue) Case ccsText, ccsMemo VarValue = CStr(NewValue) End Select End If If ControlType = ccsCheckBox Then If DataType = ccsBoolean Then If IsEmpty(NewValue) Or (NewValue="") Then State = False Else State = VarValue End If Else if DataType = ccsDate Then State = (VarValue = CDate(CheckedValue)) Else State = (VarValue = CheckedValue) End if End If End If End Property Property Get Value() If ControlType = ccsCheckBox Then If IsEmpty(State) Then Value = UncheckedValue Else Value = IIf(State, CheckedValue, UncheckedValue) End If Else Value = VarValue End If End Property Property Let Text(NewText) VarValue = Empty SQLTextValue = Empty TextValue = NewText VarValue = GetParsedValue(TextValue, Format) If ControlType = ccsCheckBox Then State = (VarValue = CheckedValue) End If End Property Property Get Text() If IsEmpty(TextValue) Then TextValue = GetFormattedValue(Format) End If Text = TextValue End Property Property Let SQLText(varNewSQLText) SQLTextValue = varNewSQLText End Property Property Get SQLText() If IsEmpty(SQLTextValue) Then SQLTextValue = GetFormattedValue(DBFormat) Select Case DataType Case ccsBoolean Select Case VarType(SQLTextValue) Case vbString SQLTextValue = "'" & SQLTextValue & "'" Case vbEmpty SQLTextValue = "null" End Select Case Else SQLTextValue = CCToSQL(SQLTextValue, DataType) End Select End If SQLText = SQLTextValue End Property End Class 'End clsControl Class 'CCCreateField Function @0-A187BD87 Function CCCreateField(Name, DBFieldName, DataType, DBFormat, DataSource) Dim Field Set Field = New clsField With Field .Name = Name .DBFieldName = DBFieldName .DataType = DataType .DBFormat = DBFormat Set .DataSource = DataSource End With Set CCCreateField = Field End Function 'End CCCreateField Function 'clsField Class @0-BC2FE3CD Class clsField Public DataType Public DBFormat Public Name Public DBFieldName Public DataSource Public Errors Private VarValue Private SQLTextValue Private TextValue Private Sub Class_Initialize() VarValue = Empty SQLTextValue = Empty TextValue = Empty DataType = ccsText Set Errors = New clsErrors End Sub Private Sub Class_Terminate() Set Errors = Nothing End Sub Sub SetDBValue(DBValue) VarValue = Empty SQLTextValue = Empty TextValue = Empty VarValue = GetParsedValue(DBValue, DBFormat) End Sub Function GetParsedValue(ParsingValue, MaskFormat) Dim Result If Not IsEmpty(ParsingValue) Then Select Case DataType Case ccsDate If VarType(ParsingValue) = vbDate Then Result = ParsingValue ElseIf CCValidateDate(ParsingValue, MaskFormat) Then Result = CCParseDate(ParsingValue, MaskFormat) Else If IsArray(MaskFormat) Then Errors.addError("The value in field " & Name & " is not valid. Use the following format: " & Join(MaskFormat, "") & ".") Else Errors.addError("The value in field " & Name & " is not valid.") End If End If Case ccsBoolean Result = CCParseBoolean(ParsingValue, MaskFormat) Case ccsInteger If CCValidateNumber(ParsingValue, MaskFormat) Then Result = CCParseInteger(ParsingValue, MaskFormat) Else Errors.addError("The value in field " & Name & " is not valid.") End If Case ccsFloat If CCValidateNumber(ParsingValue, MaskFormat) Then Result = CCParseFloat(ParsingValue, MaskFormat) Else Errors.addError("The value in field " & Name & " is not valid.") End If Case ccsText, ccsMemo Result = CStr(ParsingValue) End Select End If GetParsedValue = Result End Function Function GetFormattedValue(MaskFormat) Dim Result Select Case DataType Case ccsDate Result = CCFormatDate(VarValue, MaskFormat) Case ccsBoolean Result = CCFormatBoolean(VarValue, MaskFormat) Case ccsInteger, ccsFloat Result = CCFormatNumber(VarValue, MaskFormat) Case ccsText, ccsMemo Result = CStr(VarValue) End Select GetFormattedValue = Result End Function Property Let Value(NewValue) VarValue = Empty SQLTextValue = Empty TextValue = Empty If Not IsEmpty(NewValue) And Not (NewValue="") Then Select Case DataType Case ccsDate VarValue = CDate(NewValue) Case ccsBoolean VarValue = CBool(NewValue) Case ccsInteger VarValue = CLng(NewValue) Case ccsFloat VarValue = CDbl(NewValue) Case ccsText, ccsMemo VarValue = CStr(NewValue) End Select End If End Property Public Default Property Get Value() If IsObject(DataSource.Recordset) Then If DataSource.Recordset.State = adStateOpen Then VarValue = CCGetValue(DataSource.Recordset, DBFieldName) VarValue = GetParsedValue(VarValue, DBFormat) End If End If Value = VarValue End Property Property Let Text(NewText) VarValue = Empty SQLTextValue = Empty TextValue = NewText VarValue = GetParsedValue(TextValue, DBFormat) End Property Property Get Text() Text = TextValue End Property Property Let SQLText(varNewSQLText) SQLTextValue = varNewSQLText End Property Property Get SQLText() If IsEmpty(SQLTextValue) Then SQLTextValue = GetFormattedValue(DBFormat) End If SQLText = SQLTextValue End Property End Class 'End clsField Class 'CCCreateFileUpload Function @0-A734B792 Function CCCreateFileUpload(Name,Caption,TemporaryFolder,FileFolder,AllowedFileMasks,DisallowedFileMasks,FileSizeLimit,Required) Dim FileUpload Set FileUpload = New clsFileUpload With FileUpload .Name = Name .DeleteControlName = Name & "_Delete" .Caption = Caption .TemporaryFolder = TemporaryFolder & "\" .FileFolder = FileFolder & "\" .AllowedFileMasks = AllowedFileMasks .DisallowedFileMasks = DisallowedFileMasks .FileSizeLimit = FileSizeLimit .Required = Required End With Set CCCreateFileUpload = FileUpload End Function 'End CCCreateFileUpload Function 'clsFileUpload Class @0-721CE678 Class clsFileUpload Public Name Public CCSEvents Public Visible Public ExternalName Public Errors Public Caption Public Required Public TemplateBlock Public AllowedFileMasks Public DisallowedFileMasks Public FileSizeLimit Public IsUploaded Public FileSize Public fso Public DeleteControlName Public ExternalDeleteControlName Private VarTemporaryFolder Private VarFileFolder Private VarValue Private VarText Private StateArray(1) Private CCSEventResult Private Sub Class_Initialize() Set CCSEvents = CreateObject("Scripting.Dictionary") Set fso = CreateObject("Scripting.FileSystemObject") Set Errors = New clsErrors ExternalName = Empty Visible = True IsUploaded = False FileSize = 0 StateArray(0) = Empty StateArray(1) = Empty End Sub Private Sub Class_Terminate() Set CCSEvents = Nothing Set Errors = Nothing Set fso = Nothing End Sub Public Function Upload(CurrentRow) On Error Resume Next Dim f, FieldName, NewFileName If Not IsEmpty(CurrentRow) Then ExternalName = Name & "_" & CStr(CurrentRow) ExternalDeleteControlName = Name & "_Delete_" & CStr(CurrentRow) End If If CCGetRequestParam("ccsForm",ccsGet) <> "" Then SetState CCGetRequestParam(IIf(Not IsEmpty(ExternalName), ExternalName, Name), ccsPost) Value = StateArray(0) End If If UploadedFilesCount > 0 Then Set f = objUpload.Files(IIf(Not IsEmpty(ExternalName), ExternalName, Name) & "_File") If Not (f is Nothing) Then FileSize = f.Size NewFileName = GetValidFileName(f.FileName) & f.FileName f.SaveAs VarTemporaryFolder & NewFileName StateArray(1) = NewFileName If Not IsEmpty(StateArray(0)) And StateArray(1) <> StateArray(0) Then DeleteFile Value = NewFileName Else If IsEmpty(StateArray(0)) Then VarValue = "" FileSize = 0 End If StateArray(1) = Empty End If End If If CCGetRequestParam(IIf(Not IsEmpty(ExternalDeleteControlName), ExternalDeleteControlName, DeleteControlName), ccsPost) <> "" Then DeleteFile If Not Err.Number = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "An error occured when uploading file specified in " & FieldName & ". Error description: " & CStr(Err.Source) & ", " & CStr(Err.Description) & "." Response.End End If End Function Public Function GetFile(CurrentRow) On Error Resume Next Dim f, FieldName If Not IsEmpty(CurrentRow) Then ExternalName = Name & "_" & CStr(CurrentRow) ExternalDeleteControlName = Name & "_Delete_" & CStr(CurrentRow) End If If CCGetRequestParam("ccsForm",ccsGet) <> "" Then SetState CCGetRequestParam(IIf(Not IsEmpty(ExternalName), ExternalName, Name), ccsPost) Text = StateArray(0) Value = Text End If If UploadedFilesCount > 0 Then Set f = objUpload.Files(IIf(Not IsEmpty(ExternalName), ExternalName, Name) & "_File") If Not (f is Nothing) Then FileSize = f.Size Text = f.FileName Else If IsEmpty(StateArray(0)) Then Text = "" FileSize = 0 End If End If End If If Not Err.Number = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "An error occured when uploading file specified in " & FieldName & ". Error description: " & CStr(Err.Source) & ", " & CStr(Err.Description) & "." Response.End End If End Function Public Function MoveFromTempFolder On Error Resume Next Dim FieldName CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeProcessFile", Me) If (fso.FileExists(VarTemporaryFolder & VarValue)) Then fso.MoveFile VarTemporaryFolder & VarValue, VarFileFolder & VarValue StateArray(0) = VarValue StateArray(1) = VarValue End If CCSEventResult = CCRaiseEvent(CCSEvents, "AfterProcessFile", Me) If Not Err.Number = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "An error occured when uploading file specified in " & FieldName & ". Error description: " & CStr(Err.Source) & ", " & CStr(Err.Description) & "." Response.End End If End Function Public Function DeleteFile() On Error Resume Next Dim FieldName, FileName CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeDeleteFile", Me) FileName = VarValue If IsEmpty(FileName) Then FileName = VarText If (fso.FileExists(VarTemporaryFolder & FileName)) Then fso.DeleteFile VarTemporaryFolder & FileName, True VarValue = "" End If If (fso.FileExists(VarFileFolder & FileName)) Then fso.DeleteFile VarFileFolder & FileName, True VarValue = "" End If CCSEventResult = CCRaiseEvent(CCSEvents, "AfterDeleteFile", Me) If Not Err.Number = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "An error occured when uploading file specified in " & FieldName & ". Error description: " & CStr(Err.Source) & ", " & CStr(Err.Description) & "." Response.End End If End Function Property Let TemporaryFolder(NewText) Dim FieldName VarTemporaryFolder = NewText If UCase(Left(NewText, 5)) = "%TEMP" Then VarTemporaryFolder = fso.GetSpecialFolder(2) & Mid(NewText, 6) End If If Not fso.FolderExists(VarTemporaryFolder) Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "" & CStr(VarValue) & "" Response.End End If End Property Property Get TemporaryFolder() TemporaryFolder = VarTemporaryFolder End Property Property Let FileFolder(NewText) Dim FieldName VarFileFolder = NewText If UCase(Left(NewText, 5)) = "%TEMP" Then VarFileFolder = fso.GetSpecialFolder(2) & Mid(NewText, 6) End If If Not fso.FolderExists(VarFileFolder) Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "" & CStr(VarValue) & "" Response.End End If End Property Property Get FileFolder() FileFolder = CStr(VarFileFolder) End Property Property Let Value(NewValue) On Error Resume Next Dim f, FieldName If Not IsEmpty(NewValue) Then If Len(NewValue) > 0 Then If (fso.FileExists(VarTemporaryFolder & NewValue)) Then VarValue = NewValue VarText = VarValue StateArray(0) = NewValue StateArray(1) = Empty IsUploaded = True Set f = fso.GetFile(VarTemporaryFolder & NewValue) FileSize = f.Size VarText = f.Path ElseIf (fso.FileExists(VarFileFolder & NewValue)) Then VarValue = NewValue VarText = VarValue StateArray(0) = NewValue StateArray(1) = Empty IsUploaded = True Set f = fso.GetFile(VarFileFolder & NewValue) FileSize = f.Size End If End If End If If Not IsEmpty(ExternalName) And NewValue = "" Then VarValue = "" VarText = "" StateArray(0) = Empty StateArray(1) = Empty IsUploaded = False FileSize = 0 End If If Not Err.Number = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "An error occured when uploading file specified in " & FieldName & ". Error description: " & CStr(Err.Source) & ", " & CStr(Err.Description) & "." Response.End End If End Property Property Get Value() Value = VarValue End Property Property Let Text(NewText) Dim f VarText = NewText End Property Property Get Text() Text = CStr(VarText) End Property Public Function GetValidFileName(FileName) On Error Resume Next Dim dta, tm, index, prefix, FieldName dta = Date() tm = time() index = 0 Do prefix = Year(dta) & Month(dta) & Day(dta) & Hour(tm) & Minute(tm) & Second(tm) & CStr(index) & "." index = index + 1 Loop While fso.FileExists(VarTemporaryFolder & prefix & FileName) Or fso.FileExists(VarFileFolder & prefix & FileName) GetValidFileName = prefix If Not Err.Number = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Response.Write "An error occured when uploading file specified in " & FieldName & ". Error description: " & CStr(Err.Source) & ", " & CStr(Err.Description) & "." Response.End End If End Function Public Function GetOriginFileName(FileName) Dim nPos nPos = InStr(FileName,".") If nPos > 0 Then GetOriginFileName = Mid(FileName,nPos+1) Else GetOriginFileName = FileName End If End Function Function Validate() Dim FieldName If Required And CStr(VarText) = "" Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Errors.addError("The file attachment in field " & FieldName & " is required.") End If If Not CStr(Text) = "" And DisallowedFileMasks <> "" And CCRegExpTest(VarText, Replace(Replace(Replace(DisallowedFileMasks, "?", "[^\.]"), "*", "[^\.]*"), ";", "|"), True, True) And Errors.Count = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Errors.addError("The file type specified in field " & FieldName & " is not allowed.") End If If Not CStr(Text) = "" And AllowedFileMasks <> "" And AllowedFileMasks <> "*" And Not CCRegExpTest(VarText, Replace(Replace(Replace(AllowedFileMasks, "?", "[^\.]"), "*", "[^\.]*"), ";", "|"), True, True) And Errors.Count = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Errors.addError("The file type specified in field " & FieldName & " is not allowed.") End If If Not IsUploaded And FileSize > FileSizeLimit And Errors.Count = 0 Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Errors.addError("The file size in field " & FieldName & " is too large.") End If If Errors.Count > 0 And fso.FileExists(VarTemporaryFolder & VarText) Then DeleteFile Validate = CCRaiseEvent(CCSEvents, "OnValidate", Me) End Function Sub Show(Template) Dim TemplateBlock, UploadBlock, InfoBlock, DeleteControlBlock CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me) If Visible Then Set TemplateBlock = Template.Block("FileUpload " & Name) Set UploadBlock = TemplateBlock.Block("Upload") Set InfoBlock = TemplateBlock.Block("Info") Set DeleteControlBlock = TemplateBlock.Block("DeleteControl") If Not (TemplateBlock Is Nothing) Then If IsEmpty(ExternalName) Then TemplateBlock.Variable("ControlName") = Name Else TemplateBlock.Variable("ControlName") = ExternalName End If TemplateBlock.Variable("State") = GetState() If (Not IsUploaded Or Required) And Not (UploadBlock Is Nothing) Then If IsEmpty(ExternalName) Then UploadBlock.Variable("FileControl") = Name & "_File" Else UploadBlock.Variable("FileControl") = ExternalName & "_File" End If UploadBlock.Parse ccsParseOverwrite InfoBlock.Visible = False DeleteControlBlock.Visible = False End If If IsUploaded And Not (InfoBlock Is Nothing) Then InfoBlock.Variable("FileName") = GetOriginFileName(VarValue) InfoBlock.Variable("FileSize") = FileSize InfoBlock.Parse ccsParseOverwrite UploadBlock.Visible = Required End If If IsUploaded And Not Required And Not (DeleteControlBlock Is Nothing) Then If IsEmpty(ExternalDeleteControlName) Then DeleteControlBlock.Variable("DeleteControl") = DeleteControlName Else DeleteControlBlock.Variable("DeleteControl") = ExternalDeleteControlName End If DeleteControlBlock.Parse ccsParseOverwrite UploadBlock.Visible = Required End If TemplateBlock.Parse ccsParseOverwrite End if End If End Sub Function OnClick() OnClick = CCRaiseEvent(CCSEvents, "OnClick", Me) End Function Private Function GenerateStateKey() Dim dta, tm, random_number dta = Date() tm = time() Randomize random_number = Abs(Int((2147483647 + 2147483648 + 1) * Rnd - 2147483648)) GenerateStateKey = CStr(random_number) & Day(dta) & Hour(tm) & Minute(tm) & Second(tm) End Function Private Function GetState() Dim ControlStateKey If StateArray(0) = Empty Then StateArray(0) = Value ControlStateKey = GenerateStateKey() Session(ControlStateKey) = StateArray GetState = ControlStateKey End Function Private Function SetState(value) If IsArray(Session(value)) Then StateArray(0) = Session(value)(0) StateArray(1) = Session(value)(1) Else StateArray(0) = Empty StateArray(1) = Empty End If End Function End Class 'End clsFileUpload Class 'CCCreateButton Function @0-E8E95E8F Function CCCreateButton(Name) Dim Button Set Button = New clsButton Button.Name = Name Set CCCreateButton = Button End Function 'End CCCreateButton Function 'clsButton Class @0-FE2F9E8E Class clsButton Public Name Public CCSEvents Public Visible Public ExternalName Private CCSEventResult Private Sub Class_Initialize() Set CCSEvents = CreateObject("Scripting.Dictionary") ExternalName = Empty Visible = True End Sub Private Sub Class_Terminate() Set CCSEvents = Nothing End Sub Sub Show(Template) CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me) If Visible Then If Template.BlockExists("Button " & Name, "block") Then Template.Block("Button " & Name).Variable("Button_Name") = Name Template.Block("Button " & Name).Parse ccsParseOverwrite End If End If End Sub Function OnClick() OnClick = CCRaiseEvent(CCSEvents, "OnClick", Me) End Function End Class 'End clsButton Class 'CCCreateDatePicker Function @0-BFE7B3B4 Function CCCreateDatePicker(Name, FormName, ControlName) Dim DatePicker Set DatePicker = New clsDatePicker DatePicker.Name = Name DatePicker.FormName = FormName DatePicker.ControlName = ControlName Set CCCreateDatePicker = DatePicker End Function 'End CCCreateDatePicker Function 'clsDatePicker Class @0-92779F3E Class clsDatePicker Public Name Public ExternalName Public FormName Public ControlName Public ExternalControlName Public Visible Private Sub Class_Initialize() ExternalName = Empty ExternalControlName = Empty Visible = True End Sub Private Sub Class_Terminate() End Sub Sub Show(Template) Dim TemplateBlock If Visible Then Set TemplateBlock = Template.Block("DatePicker " & Name) If Template.BlockExists("DatePicker " & Name, "block") Then TemplateBlock.Variable("Name") = CStr(FormName) & "_" & CStr(Name) TemplateBlock.Variable("FormName") = CStr(FormName) If IsEmpty(ExternalControlName) Then TemplateBlock.Variable("DateControl") = CStr(ControlName) Else TemplateBlock.Variable("DateControl") = CStr(ExternalControlName) End If TemplateBlock.Parse ccsParseOverwrite End If End If End Sub End Class 'End clsDatePicker Class 'CCCreateList Function @0-54E52904 Function CCCreateList(ControlType, Name, Caption, DataType, InitValue, DataSource) Dim Control Set Control = New clsListControl With Control .Name = Name .ControlType = ControlType .Caption = Caption .DataType = DataType .ControlTypeName = ccsControlTypes(ControlType) If IsArray(InitValue) Then .MultipleValues = InitValue Else .Text = InitValue End If If IsObject(DataSource) Then Set .DataSource = DataSource End If End With Set CCCreateList = Control End Function 'End CCCreateList Function 'clsListControl Class @0-7E1D77A9 Class clsListControl Private Control Private DataTypeValue Public CCSEvents Public DataSource Public Recordset Public Errors Public Name Public ControlType Public Caption Public Required Public TemplateBlock Public Visible Public HTML Public MultipleValues Public IsMultiple Public ExternalName Public ControlTypeName Public TextColumn Public BoundColumn Private CCSEventResult Private mPopulatingType Public IsPopulated Public ItemsList() Public KeysList() Public ItemsCount Private Sub Class_Initialize() Required = False BoundColumn = 0 TextColumn = 1 Visible = True PopulatingType = ccsStringConcats HTML = False ExternalName = Empty IsPopulated = False ItemsCount = 0 Set Control = New clsControl Set CCSEvents = CreateObject("Scripting.Dictionary") Set Errors = New clsErrors End Sub Private Sub Class_Terminate() Set Control = Nothing Set Errors = Nothing Set DataSource = Nothing Set Recordset = Nothing Set CCSEvents = Nothing End Sub Public Function AddValue(NewValue) Dim NumberOfValues NumberOfValues = Ubound(MultipleValues) ReDim Preserve MultipleValues(NumberOfValues + 1) MultipleValues(NumberOfValues + 1) = NewValue End Function Public Function HasMultipleValues If IsArray(MultipleValues) Then HasMultipleValues = (Ubound(MultipleValues) > 0) Else HasMultipleValues = False End If End Function Property Let Value(NewValue) If IsMultiple Then If HasMultipleValues Then MultipleValues(1) = NewValue Else AddValue NewValue End If End If Control.Value = NewValue End Property Property Get Value() If IsMultiple And HasMultipleValues Then Value = MultipleValues(1) Else Value = Control.Value End If End Property Public Property Let PopulatingType(vType) mPopulatingType = vType End Property Public Property Get PopulatingType() PopulatingType = mPopulatingType End Property Property Let DataType(NewDataType) DataTypeValue = NewDataType Control.DataType = DataTypeValue End Property Property Get DataType() DataType = DataTypeValue End Property Property Get SQLValue() SQLValue = Control.SQLValue End Property Function Validate() Dim FieldName,Passed If Required Then If IsMultiple Then Passed = (Ubound(MultipleValues) = 0) Else Passed = (CStr(Control.Value) = "") End If If Passed Then If Not CStr(Caption) = "" Then FieldName = Caption Else FieldName = Name Errors.addError("The value in field " & FieldName & " is required.") End If End If Validate = CCRaiseEvent(CCSEvents, "OnValidate", Me) End Function Public Sub RePopulate Dim cmdErrors, MaxBound, i If NOT IsObject(DataSource) Then Exit Sub Set cmdErrors = new clsErrors Set Recordset = DataSource.Exec(cmdErrors) If cmdErrors.Count > 0 Then Dim ErrorString If ControlType = ccsRadioButton Then ErrorString = "RadioButton " & Name ElseIf ControlType = ccsListBox Then ErrorString = "ListBox " & Name Else ErrorString = "CheckBoxList" & Name End If PrintDBError ErrorString, "", cmdErrors.ToString() Else MaxBound = 25: i = 1 ReDim ItemsList(MaxBound) ReDim KeysList (MaxBound) While NOT Recordset.EOF If i >= MaxBound Then MaxBound = MaxBound + 25 ReDim Preserve ItemsList(MaxBound) ReDim Preserve KeysList (MaxBound) End If ItemsList(i) = Recordset.Fields(TextColumn) KeysList(i) = Recordset.Fields(BoundColumn) i = i + 1 Recordset.MoveNext Wend End If Recordset.Close IsPopulated = True ItemsCount = i - 1 Set cmdErrors = Nothing End Sub Sub Show(Template) Dim Result, Selected, Recordset, ResultBuffer, i, j Dim cmdErrors Dim NeedShow If NOT IsObject(DataSource) Then Exit Sub If Not IsPopulated Then RePopulate() Set TemplateBlock = Template.Block(ControlTypeName & " " & Name) NeedShow = NOT (TemplateBlock Is Nothing) If ControlType = ccsListBox Then If NOT NeedShow Then _ Set TemplateBlock = Template End If If IsEmpty(ExternalName) Then TemplateBlock.Variable(Name & "_Name") = Name Else TemplateBlock.Variable(Name & "_Name") = ExternalName End If CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me) If NOT Visible Then Exit Sub If ControlType = ccsRadioButton or ControlType = ccsCheckBoxList Then TemplateBlock.Clear For j = 1 To ItemsCount Selected = "" If IsMultiple Then For i = 1 To Ubound(MultipleValues) If UCase(CStr(KeysList(j))) = UCase(CStr(MultipleValues(i))) Then Selected = " CHECKED" End If Next Else If UCase(CStr(KeysList(j))) = UCase(CStr(Value)) Then Selected = " CHECKED" End If End If TemplateBlock.Variable("Value") = CStr(KeysList(j)) TemplateBlock.Variable("Check") = Selected If HTML Then TemplateBlock.Variable("Description") = CStr(ItemsList(j)) Else TemplateBlock.Variable("Description") = Server.HTMLEncode(CStr(ItemsList(j))) End If TemplateBlock.Parse True Next ElseIf ControlType = ccsListBox Then Set ResultBuffer = new clsStringBuffer Result = "" If mPopulatingType = ccsStringConcats Then For j = 1 To ItemsCount Selected = "" If IsMultiple Then For i = 1 To Ubound(MultipleValues) If UCase(CStr(KeysList(j))) = UCase(CStr(MultipleValues(i))) Then Selected = " SELECTED" Exit For End If Next Else If UCase(CStr(KeysList(j))) = UCase(CStr(Value)) Then Selected = " SELECTED" End If End If Result = Result & "" & vbNewLine Next Else For j = 1 To ItemsCount Selected = "" If IsMultiple Then For i=1 To Ubound(MultipleValues) If UCase(CStr(KeysList(j))) = UCase(CStr(MultipleValues(i))) Then Selected = " SELECTED" Exit For End If Next Else If UCase(CStr(KeysList(j))) = UCase(CStr(Value)) Then Selected = " SELECTED" End If End If ResultBuffer.Append "" & vbNewLine Next Result = ResultBuffer.ToString End If TemplateBlock.Variable(Name & "_Options") = Result If NeedShow Then TemplateBlock.Show End If Set TemplateBlock = Nothing End Sub Function SetDBValue(DBValue) Control.SetDBValue DBValue End Function Property Get Text() Text = Control.Text End Property Property Let Text(NewText) Control.Text = NewText End Property Property Get SQLText() SQLText = Control.SQLText End Property Property Let SQLText(NewSQLText) Control.SQLText = NewSQLText End Property End Class 'End clsListControl Class 'clsErrors Class @0-DC79566E Class clsErrors Private ErrorsCount Private Errors Public ErrorDelimiter Private Sub Class_Initialize() Clear ErrorDelimiter = "
" End Sub Sub AddError(Description) If NOT(CStr(Description) = "") Then ReDim Preserve Errors(ErrorsCount) Errors(ErrorsCount) = Description ErrorsCount = ErrorsCount + 1 End If End Sub Sub AddErrors(objErrors) Dim I For I = 0 To objErrors.Count - 1 AddError(objErrors.ErrorByNumber(I)) Next End Sub Sub Clear() ErrorsCount = 0 ReDim Errors(1) End Sub Property Get Count() Count = ErrorsCount End Property Property Get ErrorByNumber(ErrorNumber) If ErrorNumber > ErrorsCount OR ErrorNumber < 0 Then Err.Raise 4001, "Error class, ErrorByNumber function. Parameter out of range." End If ErrorByNumber = Errors(ErrorNumber) End Property Property Get ToString() If ErrorsCount > 0 Then ToString = Join(Errors, ErrorDelimiter) & ErrorDelimiter Else ToString = "" End If End Property End Class 'End clsErrors Class 'CCCreateDataSource Function @0-07E5CF26 Function CCCreateDataSource(DataSourceType, Connection, CommandSource) Dim Cmd Set Cmd = New clsCommand If DataSourceType <> dsListOfValues Then Set Cmd.Connection = Connection Set Cmd.WhereParameters.Connection = Connection End If Cmd.CommandType = DataSourceType Cmd.CommandOperation = cmdOpen Cmd.ActivePage = -1 Select Case DataSourceType Case dsTable Cmd.SQL = CommandSource(0) Cmd.Where = CommandSource(1) Cmd.OrderBy = CommandSource(2) Case dsSQL Cmd.SQL = CommandSource Case dsProcedure Set Cmd.SQL = CommandSource Case dsListOfValues Cmd.LOV = CommandSource End Select Set CCCreateDataSource = Cmd End Function 'End CCCreateDataSource Function 'clsEmptyDataSource Class @0-BF6C2454 Class clsEmptyDataSource Public Errors Private Sub Class_Initialize() Set CCSEvents = CreateObject("Scripting.Dictionary") Set Errors = New clsErrors End Sub Private Sub Class_Terminate() Set CCSEvents = Nothing Set Errors = Nothing End Sub Function Open() Set Open = Me End Function Property Get EOF() EOF = True End Property Property Get State() State = adStateClosed End Property End Class 'End clsEmptyDataSource Class 'clsDataSource Class @0-5C773C21 Class clsDataSource Public DataSourceType Public DataSource Public Errors, Connection, Parameters, CCSEvents Public Recordset Public PageSize Public Command Private mRecordCount Public Order Private objFields Private AbsolutePage Private prvRecordsCount Private builtSQL Private Opened Private MemoFields Private Sub Class_Initialize() Set CCSEvents = CreateObject("Scripting.Dictionary") Set MemoFields = CreateObject("Scripting.Dictionary") Set Errors = New clsErrors Set Parameters = New clsSQLParameters Set Parameters.DataSource = Me AbsolutePage = 0 RecordCount = -1 Opened = False End Sub Sub Close() If Recordset.State = adStateOpen Then Recordset.Close End If Opened = False Set Recordset = Nothing End Sub Function GetData(Pages) If Pages = 0 Then Set GetData = Recordset End If End Function Property Get Fields(Name) If IsNumeric(Name) Then Fields = CCGetValue(Recordset, CInt(Name)) ElseIf IsObject(objFields) Then If Not objFields is Nothing Then If objFields.Exists(Name) Then If MemoFields.Exists(objFields(Name).DBFieldName) Then Fields = MemoFields(objFields(Name).DBFieldName) Else Fields = objFields(Name).Value If objFields(Name).DataType = ccsMemo Then MemoFields.Add objFields(Name).DBFieldName, Fields End If End If Else Fields = CCGetValue(Recordset, Name) End If Else Fields = CCGetValue(Recordset, Name) End If Else Fields = CCGetValue(Recordset, Name) End If End Property Property Set FieldsCollection(NewFieldsCollection) Set objFields = NewFieldsCollection If Not objFields Is Nothing Then objFields.InitEnum While Not objFields.EndOfEnum Set objFields.NextItem.DataSource = Me Wend End If End Property Property Get EOF() EOF = Recordset.EOF End Property Property Get State() If IsObject(Recordset) Then State = Recordset.State Else State = False End If End Property Sub MoveNext() Recordset.MoveNext MemoFields.RemoveAll End Sub Sub MoveFirst() Recordset.MoveFirst MemoFields.RemoveAll End Sub Function GetOrder(DefaultSorting, Sorter, Direction, MapArray) Dim OrderValue, I, ActiveSorter If NOT IsEmpty(Sorter) Then ' Select sorted column I = 0 Do While I <= UBound(MapArray) If MapArray(I)(0) = Sorter Then ActiveSorter = I Exit Do End If I = I + 1 Loop If NOT IsEmpty(ActiveSorter) Then If NOT IsEmpty(Direction) AND (Direction = "ASC" OR Direction = "DESC") Then If Direction = "ASC" Then OrderValue = MapArray(ActiveSorter)(1) ElseIf Direction = "DESC" Then OrderValue = MapArray(ActiveSorter)(2) End If If OrderValue = "" Then OrderValue = MapArray(ActiveSorter)(1) & " DESC" End If Else OrderValue = MapArray(ActiveSorter)(1) End If End If End If If Len(OrderValue) > 0 Then Order = OrderValue Else Order = DefaultSorting End If GetOrder = Order End Function Public Property Let RecordCount(vData) mRecordCount = vData End Property Public Property Get RecordCount() If mRecordCount < 0 Then mRecordCount = Command.ExecuteCount End If RecordCount = mRecordCount End Property Function MoveToPage(Page) Dim PageCounter Dim RecordCounter If Recordset.State = adStateOpen Then PageCounter = 1 RecordCounter = 1 While NOT Recordset.EOF AND PageCounter < Page If RecordCounter MOD Command.PageSize = 0 Then PageCounter = PageCounter + 1 End If RecordCounter = RecordCounter + 1 Recordset.MoveNext Wend End If Command.ActivePage = PageCounter End Function Function PageCount() Dim Result If Command.PageSize > 0 Then Result = RecordCount \ Command.PageSize If (RecordCount MOD Command.PageSize) > 0 Then Result = Result + 1 End If Else Result = 1 End If PageCount = Result End Function Private Sub Class_Terminate() Set Command = Nothing Set Errors = Nothing Set Parameters = Nothing Set CCSEvents = Nothing End Sub End Class 'End clsDataSource Class 'clsCommand Class @0-920B04E6 Class clsCommand Private mCommandType Private mCommandOperation Private mPrepared Private mSQL Private mCountSQL Private mWhere Private mOrderBy Private mLOV Private mSP Private mPageSize Private mActivePage Private RecordsCount Public Errors, Connection, CCSEvents Public WhereParameters, Parameters Public CommandParameters Private Sub Class_Initialize() Set CCSEvents = CreateObject("Scripting.Dictionary") Set WhereParameters = New clsSQLParameters Set WhereParameters.ParameterSources = CreateObject("Scripting.Dictionary") Set Parameters = New clsSQLParameters Set Parameters.ParameterSources = CreateObject("Scripting.Dictionary") ActivePage = 0 Prepared = False End Sub Public Function Exec(Err) Set Errors = Err Select Case CommandOperation Case cmdOpen Set Exec = DoOpen Case cmdExec DoExec End Select End Function Private Function OpenRecordset(sSQL) Dim Command Dim Recordset Set Command = CreateObject("ADODB.Command") Command.CommandType = adCmdText Command.CommandText = sSQL Set Command.ActiveConnection = Connection.Connection Set Recordset = Connection.Execute(Command) If Connection.Errors.Count > 0 Then Errors.AddError Connection.Errors.ToString & sSQL & Errors.ErrorDelimiter End If Set OpenRecordset = Recordset Set Command = Nothing End Function Private Function ParseParams(sSQL, Params) Dim I Dim NewSQL Dim ParamKeys Dim ParamItems NewSQL = sSQL If CommandType = dsSQL Then If Not Params is Nothing Then ParamItems = Params.ParametersList.Items ParamKeys = Params.ParametersList.Keys For I = 0 To UBound(ParamItems) NewSQL = Replace(NewSQL, "{" & ParamKeys(I) & "}", ParamItems(I).SQLText) Next End If End If ParseParams = NewSQL End Function Private Function DoOpen() Dim Command Dim builtSQL Dim DataSource Dim CountRecordset Dim ResultRecordset Dim CCSEventResult Dim ParameterValue Dim Parameter Set DataSource = new clsDataSource Set DataSource.Command = Me Select Case CommandType Case dsTable, dsSQL CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeBuildSelect", Me) builtSQL = ParseParams(SQL & IIf(Len(Where) > 0, " WHERE " & Where, "") & IIf(Len(OrderBy) > 0, " ORDER BY " & OrderBy, ""), WhereParameters) CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeExecuteSelect", Me) Set DataSource.Recordset = OpenRecordset(builtSQL) If ActivePage > 0 Then DataSource.MoveToPage ActivePage End If CCSEventResult = CCRaiseEvent(CCSEvents, "AfterExecuteSelect", Me) Set DoOpen = DataSource Case dsProcedure CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeBuildSelect", Me) Set Command = CreateSP() CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeExecuteSelect", Me) Set DataSource.Recordset = Connection.Execute(Command) If ActivePage > 0 Then DataSource.MoveToPage ActivePage End If Do Until DataSource.Recordset Is Nothing If DataSource.Recordset.Fields.Count >0 Then Exit Do Set DataSource.Recordset = DataSource.Recordset.NextRecordset Loop If Connection.Errors.Count > 0 Then Errors.AddError Connection.Errors.ToString & mSP & Errors.ErrorDelimiter End If Set Command = Nothing Set DoOpen = DataSource Case dsListOfValues Dim I CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeBuildSelect", Me) Set DataSource.Recordset = CreateObject("ADODB.Recordset") DataSource.Recordset.Fields.Append "bound", adBSTR, 256, adFldCacheDeferred + adFldUpdatable DataSource.Recordset.Fields.Append "text", adBSTR, 256, adFldCacheDeferred + adFldUpdatable CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeExecuteSelect", Me) DataSource.Recordset.Open For I = 0 To UBound(mLOV(0)) DataSource.Recordset.AddNew DataSource.Recordset.Fields("bound").Value = mLOV(0)(I) DataSource.Recordset.Fields("text").Value = mLOV(1)(I) Next DataSource.Recordset.Update DataSource.Recordset.MoveFirst CCSEventResult = CCRaiseEvent(CCSEvents, "AfterExecuteSelect", Me) Set DoOpen = DataSource End Select End Function Public Function ExecuteCount() Dim Result: Result = 0 Dim builtSQL: builtSQL = "" Dim CountRecordset If Len(CountSQL) > 0 Then builtSQL = ParseParams(CountSQL & IIf(Len(Where) > 0, " WHERE " & Where, ""), WhereParameters) Set CountRecordset = OpenRecordset(builtSQL) If CountRecordset.State = adStateOpen Then Result = CLng(CountRecordset.Fields(0).Value) End If Set CountRecordset = Nothing End If ExecuteCount = Result End Function Private Function CreateSP() Dim Command, I, ParameterValue, Parameter, Sources Set Command = Server.CreateObject("ADODB.Command") Set Command.ActiveConnection = Connection.Connection Command.CommandType = adCmdStoredProc Command.CommandText = mSP If IsArray(CommandParameters) Then Set Sources = Parameters.ParameterSources For I = 0 To UBound(CommandParameters) ParameterValue = Sources(CommandParameters(I)(1)) If IsEmpty(ParameterValue) Then ParameterValue = CommandParameters(I)(7) End If If IsEmpty(ParameterValue) Then ParameterValue = Null End If Set Parameter = Command.CreateParameter(CommandParameters(I)(0), CommandParameters(I)(2), CommandParameters(I)(3), CommandParameters(I)(4), ParameterValue) If Parameter.Type = adNumeric Then Parameter.NumericScale = CommandParameters(I)(5) Parameter.Precision = CommandParameters(I)(6) End If Command.Parameters.Append Parameter Next Set Sources = Nothing End If Set CreateSP = Command End Function Private Sub DoExec Dim Command, I Dim builtSQL Dim ParameterValue If CommandType = dsProcedure Then Set Command = CreateSP() Else Set Command = CreateObject("ADODB.Command") Command.CommandType = adCmdText builtSQL = SQL If CommandType = dsSQL Then builtSQL = ParseParams(builtSQL, WhereParameters) builtSQL = ParseParams(builtSQL, Parameters) Else If IsArray(CommandParameters) Then For I = 0 To UBound(CommandParameters) If IsEmpty(CommandParameters(I)(4)) Then ParameterValue = Null Else ParameterValue = CommandParameters(I)(4) End If Command.Parameters.Append Command.CreateParameter(CommandParameters(I)(0), CommandParameters(I)(1), CommandParameters(I)(2), CommandParameters(I)(3), ParameterValue) Next End If End If Command.CommandText = builtSQL Command.Prepared = Prepared Set Command.ActiveConnection = Connection.Connection End If Connection.Execute(Command) If Connection.Errors.Count > 0 Then Errors.AddError Connection.Errors.ToString & SQL & Errors.ErrorDelimiter End If Set Command = Nothing End Sub Public Property Let ActivePage(vData) mActivePage = vData End Property Public Property Get ActivePage() ActivePage = mActivePage End Property Public Property Let PageSize(vData) mPageSize = vData End Property Public Property Get PageSize() PageSize = mPageSize End Property Public Property Let CommandOperation(vData) mCommandOperation = vData End Property Public Property Get CommandOperation() CommandOperation = mCommandOperation End Property Public Property Let LOV(vData) mLOV = vData End Property Public Property Get LOV() LOV = mLOV End Property Public Property Let SP(vData) mSP = vData End Property Public Property Get SP() SP = mSP End Property Public Property Let CountSQL(vData) mCountSQL = vData End Property Public Property Get CountSQL() CountSQL = mCountSQL End Property Public Property Let SQL(vData) mSQL = vData End Property Public Property Get SQL() SQL = mSQL End Property Public Property Let Prepared(vData) mPrepared = vData End Property Public Property Get Prepared() Prepared = mPrepared End Property Public Property Let CommandType(vData) mCommandType = vData End Property Public Property Get CommandType() CommandType = mCommandType End Property Public Property Let OrderBy(vData) mOrderBy = vData End Property Public Property Get OrderBy() OrderBy = mOrderBy End Property Public Property Let Order(vData) mOrderBy = vData End Property Public Property Get Order() Order = mOrderBy End Property Public Property Let Where(vData) mWhere = vData End Property Public Property Get Where() Where = mWhere End Property End Class 'End clsCommand Class 'clsStringBuffer @0-0A3F192B Class clsStringBuffer Private incremetRate Private itemCount Private items Private Sub Class_Initialize() incremetRate = 50 itemCount = 0 ReDim items(incremetRate) End Sub Public Sub Append(ByVal strValue) If itemCount > UBound(items) Then ReDim Preserve items(UBound(items) + incremetRate) End If items(itemCount) = strValue itemCount = itemCount + 1 End Sub Public Function ToString() ToString = Join(items, "") End Function End Class 'End clsStringBuffer %>