小鎮樹妖--住在樹上的妖

          To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master.

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            10 Posts :: 50 Stories :: 7 Comments :: 0 Trackbacks

          castclass.asp

          <%
          Class ShopBag

           '放商品的空間
           Private ProSpace

           '商品信息個數
           Private ItemsCout


          '=============================================================
          '                     共有的
          '=============================================================

           '方法名:PutAPro
           '參數:一個存有商品信息的數組--ProData
           '作用:將一個商品放入購物車
           '返回值:
           '成功放入商品,返回true
           '商品存在,返回false    
           Public Function PutAPro(ByRef ProData)
           'size:'最后一個
           dim size,result,flag
           ItemsCout = ubound(ProData)  '商品信息個數
           GetPro

           if CreateSpace then
           '有商品需要檢測商品是否存在
           MyPrint "有商品需要檢測商品是否存在"
            flag = CheckProExists(ProData(0)) 
           else
            flag = false '購物車沒有商品
            MyPrint "購物車沒有商品"
           end if

           if not flag then

             size = Ubound(ProSpace)

             for i = 0 to ItemsCout
              ProSpace(size,i) = ProData(i)
             next
             MyPrint "放入一個商品....<br>"
             SavePro
             result = true
           else
           result = false
           end if

           PutAPro = result  
           End Function
           '----------------------------------------------
           

           '得到所有商品
           Public Function GetAllPro(ByRef ProList)
            ProList  = Session("ProID")
           End Function
           '----------------------------------------------

           '更新產品個數
           Public Function UpdatePro(ByRef ProNumList)

           dim ProNumData
           GetPro
            ProNumData = split(ProNumList,",")

            for i =0 to Ubound(ProNumData)
             ProSpace(i,3) = Cint(trim(ProNumData(i)))
            next  
           SavePro
           MyPrint "更新了所有商品個數"
           End Function


           '刪除一個商品
           Public Function DeleteAPro(id)
           MyPrint "準備刪除一個商品"
           dim count
           GetPro
           count = UBound(ProSpace)
           
           if count=0 then
           MyPrint "商品已經是最后一個了, 將session設為null"
            Session("ProID") = null
           else
            redim tempAr(count-1,3)
             MyPrint "開始查找要刪除的商品id..."
             for i = 0 to count
              if Cint(ProSpace(i,0)) = Cint(id) then
               MyPrint "找到ID,刪除!"
                for j=i to count-1
                 ProSpace(j,0) = ProSpace(j+1,0)
                 ProSpace(j,1) = ProSpace(j+1,1)
                 ProSpace(j,2) = ProSpace(j+1,2)
                 ProSpace(j,3) = ProSpace(j+1,3)
                next

               exit for
              end if
             next

             for i = 0 to count-1
              tempAr(i,0) = ProSpace(i,0)
              tempAr(i,1) = ProSpace(i,1)
              tempAr(i,2) = ProSpace(i,2)
              tempAr(i,3) = ProSpace(i,3)
             next 
             Session("ProID") = tempAr
            end if
            
           End Function
           '---------------------------------------------
           
           '得到商品的某項信息列表 , 號隔開
           Public Function GetProList(n)
           dim result
            GetPro
            if isnull(ProSpace) then
             result = null
            else
             for i =0 to ubound(ProSpace)
              if i = 0 then
               result = ProSpace(i,n)
              else
               result =result&","&ProSpace(i,n)
              end if
            next
            end if 
            KillMe
           GetProList = result
           End Function

          '==================================================================

           

          '=================================================================
          '                       私有的
          '=================================================================
           '檢測商品是否已經存在
           '存 在 返回  true
           '不存在返回 false
           Private Function CheckProExists(ProID)
           MyPrint "檢測商品是否存在?<br>"
           dim result
            result = false

            for i = 0 to  Ubound(ProSpace)
             if Cint(ProSpace(i,0)) = Cint(ProID) then
              result = true
             End if
            next
           CheckProExists = result
           End Function
           '------------------------------------------------

           '作用:
           '開辟存放物品的空間
           '返回值:
           '新開大小返回 false
           '重構空間大小返回 true
           Private Function CreateSpace()
           dim result
           MyPrint "開始開辟空間...<br>"
            'ReSize: 空間大小
            dim ReSize

            '計算需要空間大小
            if isarray(ProSpace) then '已經有商品了
             MyPrint "已有空間,需要重構空間大小!<br>"
             ReSize = UBound(ProSpace)+1
             MyRedim ProSpace,ReSize
             result  = true
             MyPrint "重構了空間大小=+1...<br>"
            else   
             redim ProSpace(0,ItemsCout)
             result  = false
             MyPrint "沒有空間,開辟!...<br>"
            End if  
           CreateSpace = result
           End Function
           '----------------------------------------------
           
           '重新構造一個數組
           private Function MyRedim(byRef aArray,ByVal Size)
            MyPrint "開始重構空間大小...<br>"
             redim TmpArray(Size,ItemsCout)
             
             '備份信息
             for i = 0 to Ubound(aArray)
              for j =0 to ItemsCout
               TmpArray(i,j) = aArray(i,j)
              next
             next
             
             redim aArray(Size,ItemsCout)

             '還原信息
             for j = 0 to ubound(TmpArray)
              for k =0 to ItemsCout
              aArray(j,k) = TmpArray(j,k)
              next
             next

           End Function
           '-----------------------------------------------


           '保存商品
           Private Function SavePro
            Session("ProID") = ProSpace
            MyPrint "保存購物車....<br>" 
            KillMe
            MyPrint "釋放了空間..<br>"
           End Function
           '----------------------------------------------
           
           '從Session中取出商品
           Private Function GetPro
            ProSpace = Session("ProID")
            MyPrint "將Session中的商品放入了購物車....<br>"
           End Function
           '----------------------------------------------
           

           '釋放空間
           private Function KillMe
            ProSpace = null
           End Function
           '----------------------------------------------
          End Class
          %>

          使用:

           

          <!--#include file="CastClass.asp"-->
          <%

          '顯示操作過程
          Function MyPrint(str)
           Response.write str
          End Function

          dim aShowBag,ProData,ProList


          ProData = Array(1,"ProName","ProPrice","ProNum")


          set aShowBag = new ShopBag

           state = aShowBag.PutAPro(ProData) '放入一個商品
           ProData= null
           aShowBag.GetAllPro ProList

           if state then
            Response.Write "放入一個商品<br>"
           else
            Response.Write "商品已經存在<br>"
           end if
          Set ShowBag = nothing

          if isarray(ProList) then
           for i = 0 to ubound(ProList)
            for j =0 to 3
             Response.Write ProList(i,j)&"=="
            next
            Response.Write "<br>============<br>"
           next
          else
          Response.write "沒有商品"
          End If

          %>

          posted on 2005-07-12 12:56 jacky wu 閱讀(308) 評論(1)  編輯  收藏 所屬分類: Web(asp, javascript, css ...)

          Feedback

          # re: 購物車類[未登錄] 2009-10-17 12:04 強仔
          可以注明詳細的調用方法嗎?
          我看了幾次都看不到變量在哪里
          請懂的聯系一下
          QQ:5297405  回復  更多評論
            

          主站蜘蛛池模板: 临沧市| 瑞昌市| 甘肃省| 景泰县| 临漳县| 西和县| 兴国县| 卓资县| 三亚市| 肥城市| 荆门市| 菏泽市| 寻乌县| 镇康县| 惠东县| 辽阳市| 大厂| 南昌市| 宁河县| 陆河县| 江孜县| 龙山县| 永平县| 龙游县| 黄平县| 锡林郭勒盟| 平阳县| 镇安县| 永济市| 汝南县| 道孚县| 太谷县| 宝应县| 怀化市| 清新县| 新沂市| 清流县| 肇州县| 辽中县| 大足县| 鄂州市|