Object-oriented in the development of ASP

Source: Internet
Author: User

The development of the Web site is actually the operation of the data in the database, so we can think of the data as a total object, each data table is an object, add a data table topic, we can do this:

(The following part is just a train of thought, inside many things are in several other classes, such as Cms,data and so on, we look at the line of thought, do not understand can ask me)

Topic the field of the table is assumed to be id,title,content,hits,addtime

[Copy to Clipboard] CODE:
<%
' ==================== data class: Topic_class comment Start ==========================
' = = Important: Perform related operations on datasheet Topic
' = = written by:hankx Chen
' = = version:1.3
' = = Created date:2007-2-6 17:04:40
' ==================== data class: Topic_class annotation End ==========================
Class Topic_class
' This is the System data field
Public Id,title,content,hits,addtime
' The following are custom public properties
Public Template

' Initialize class
Private Sub Class_Initialize

Addtime=now ()
End Sub

' Logoff class
Private Sub Class_Terminate

End Sub

' Read method to read the specific data content
Public Sub Read ()
On Error Resume Next
Cms.errorcode=0
Cms.data.sql= "SELECT top 1 * from [Topic] where id=" &id
Set Cms.data.rs=cms.data.execute (Cms.data.sql)
If not cms.data.rs.eof Then
Id=cms.data.rs ("ID")
Title=cms.data.rs ("Title")
Content=cms.data.rs ("Content")
Hits=cms.data.rs ("Hits")
Addtime=cms.data.rs ("Addtime")
Else
cms.errorcode=10000
Cms.errortext= "Readdataerror: Could not find data with ID" &ID& "in datasheet [Topic]
End If
Cms.data.rs.close
Set cms.data.rs=nothing

If Err Then
cms.errorcode=10010
cms.errortext= "Readdataerror: Error reading ID data from datasheet [Topic]:" &err.description
End IF
End Sub

' Save method to save the added data content
Public Sub Save ()
On Error Resume Next
Cms.errorcode=0
If not IsObject (cms.data.conn) Then Cms.data.open ()
Set cms.data.rs = Server.CreateObject ("ADODB. Recordset ")
Cms.data.sql= "SELECT top 1 * from [Topic]"
Cms.data.rs.open cms.data.sql,cms.data.conn,1,3
Cms.data.rs.Addnew
Cms.data.rs ("ID") =id
Cms.data.rs ("Title") =title
Cms.data.rs ("Content") =content
Cms.data.rs ("Hits") =hits
Cms.data.rs ("Addtime") =addtime
Cms.data.rs.update
Cms.data.rs.close
Set cms.data.rs=nothing

If Err Then
cms.errorcode=10020
cms.errortext= "Savedataerror: Error adding data to datasheet [Topic]:" &err.description
End IF
End Sub

The ' Update method is used to update specific data content
Public Sub Update ()
On Error Resume Next
Cms.errorcode=0
If not IsObject (cms.data.conn) Then Cms.data.open ()
Set cms.data.rs = Server.CreateObject ("ADODB. Recordset ")
Cms.data.sql= "SELECT top 1 * from [Topic] where id=" &id
Cms.data.rs.open cms.data.sql,cms.data.conn,1,3
If not cms.data.rs.Eof Then
Cms.data.rs ("ID") =id
Cms.data.rs ("Title") =title
Cms.data.rs ("Content") =content
Cms.data.rs ("Hits") =hits
Cms.data.rs ("Addtime") =addtime
Cms.data.rs.update
Else
cms.errorcode=10000
cms.errortext= "Updatedataerror: Cannot find data in datasheet [Topic] with ID" &ID& "
End If
Cms.data.rs.close
Set cms.data.rs=nothing

If Err Then
cms.errorcode=10030
cms.errortext= "Updatedataerror: Error occurred while updating data to datasheet [Topic]:" &err.description
End IF
End Sub

' Delete method to delete specific data contents
Public Sub Delete ()
On Error Resume Next
Cms.errorcode=0
If not IsObject (cms.data.conn) Then Cms.data.open ()
Set cms.data.rs = Server.CreateObject ("ADODB. Recordset ")
Cms.data.sql= "SELECT top 1 * from [Topic] where id=" &id
Cms.data.rs.open cms.data.sql,cms.data.conn,1,3
If not cms.data.rs.eof Then
Cms.data.rs.delete
Cms.data.rs.update
Else
cms.errorcode=10000
cms.errortext= "Deletedataerror: Cannot find data in datasheet [Topic] with ID" &ID& "
End If
Cms.data.rs.close
Set cms.data.rs=nothing

If Err Then
cms.errorcode=10040
cms.errortext= ' deletedataerror: Error removing ID ' &ID& ' from datasheet [Topic]: "&err.description
End IF
End Sub

The ' list function is used to return template lists
Public Function List ()

End Function

' Hit for clicking

Public Sub Hit ()

End Sub

End Class
%>

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.