ceg template of asp

來源:互聯網
上載者:User

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

' 類名:C@objectname

' Memo:

'

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

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

class C@objectname

 {public @fieldname   '@fieldmemo}

end class

'擷取列表數組

'conn 資料庫連接

'site 網站

'return C@objectname對象的數組

'備忘: 如果沒有資料,對傳回值執行typeof運算的結果就不是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

'讀取對象

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

'顯示下拉式清單

'conn 資料庫連接

'site 網站

'selected 選中的內容

'注: 輸出形如: <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

'新增對象

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")  '取得自動編號

 rs.close

 set rs = nothing

end sub

'修改對象

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

'刪除對象

'conn 資料庫連接

'idArray 編號數組

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.execute sql 

end sub

'把對象的內容填充到記錄集中去

public sub init@objectnameRecord(object,rs)

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

end sub

'把記錄集的內容填充到對象中去

public sub init@objectnameObject(object,rs)

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

end sub

'從request.form初始化對象

public sub init@objectnameFromRequest(object)

 {object.@fieldname = request.form("@fieldname")}

end sub

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.