CEG template of ASP

Source: Internet
Author: User

'*************************************** ***********************

'Class Name: c @ objectname

'Memo:

'

'Write: www.yuanyue.cn/Tom @ date @ time

'*************************************** ************************

Class C @ objectname

{Public @ fieldname '@ fieldmemo}

End Class

'Get list Array

'Conn database connection

'Site site

'Return c @ objectname array of the object

'Note: If no data exists, the result of the typeof operation on the returned value is not an array.

Public Function read @ objectnamelist (Conn, site)

Dim result

Dim RS: Set rs = server. Createobject ("ADODB. recordset ")

Rs. Open "select * From @ objectname where site = '" & replace (site, "'", "'' ") &" '", Conn, 1, 3

If not Rs. EOF then

Redim result (Rs. recordcount-1)

Dim I

Do while not Rs. EOF

Dim item: Set item = new c @ objectname

{Item. @ fieldname = RS ("@ fieldname ")}

Set result (I) = item

I = I + 1

Rs. movenext

Loop

End if

Rs. Close

Set rs = nothing

Read @ objectnamelist = Result

End Function

'Read object

Public Function read @ objectname (Conn, ID)

Dim result

Dim RS: Set rs = server. Createobject ("ADODB. recordset ")

Rs. Open "select * From @ objectname where id =" & ID, Conn, 1, 3

If not Rs. EOF then

Set result = new c @ objectname

{Result. @ fieldname = RS ("@ fieldname ")}

End if

Rs. Close

Set rs = nothing

Set read @ objectname = Result

End Function

'Show drop-down list

'Conn database connection

'Site site

'Selected selected content

'Note: Output Format: <option value = ID> text </option>

Public sub show @ objectnameoptions (Conn, site, selected)

Dim list: List = read @ objectnamelist (Conn, site)

If isarray (list) then

Dim I

Dim item

If Len (selected)> 0 then

Dim find: Find = false

For I = 0 to ubound (list)

Set item = List (I)

If (not find) and trim (item. ID) = selected then

Find = true

Response. Write "<option value = '" & item. ID & "'selected>" & item. Name & "</option>"

Else

Response. Write "<option value = '" & item. ID & "'>" & item. Name & "</option>"

End if

Next

Else

For I = 0 to ubound (list)

Set item = List (I)

Response. Write "<option value =" & item. ID & ">" & item. Name & "</option>"

Next

End if

End if

End sub

'Add object

Public sub create @ objectname (Conn, object)

Dim RS: Set rs = server. Createobject ("ADODB. recordset ")

Rs. Open "select * From @ objectname where 1 = 0", Conn, 1, 3

Rs. addnew

Call init @ objectnamerecord (object, RS)

Rs. Update

'Object. ID = RS ("ID") 'to get the automatic ID

Rs. Close

Set rs = nothing

End sub

'Modify the object

Public sub update @ objectname (Conn, object)

Dim RS: Set rs = server. Createobject ("ADODB. recordset ")

Rs. Open "select * From @ objectname where id =" & object. ID, Conn, 1, 3

Call init @ objectnamerecord (object, RS)

Rs. Update

Rs. Close

Set rs = nothing

End sub

'Delete object

'Conn database connection

'Idarray number Array

Public sub Delete @ objectname (Conn, idarray)

Dim idstr: idstr = ""

If not isarray (idarray) Then exit sub

 

Idstr = join (idarray ,",")

Dim SQL: SQL = "delete from @ objectname where ID in (" & idstr &")"

Conn.exe cute SQL

End sub

'Fill in the object content in the record set

Public sub init @ objectnamerecord (object, RS)

{RS ("@ fieldname") = object. @ fieldname}

End sub

'Fill in the record set content into the object

Public sub init @ objectnameobject (object, RS)

{Object. @ fieldname = RS ("@ fieldname ")}

End sub

'Initialize the object from request. form.

Public sub init @ objectnamefromrequest (object)

{Object. @ fieldname = request. Form ("@ fieldname ")}

End sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.