小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Session做的購物車

 昵稱15377 2006-12-02

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;

namespace ShopCarTest
{
 /// <summary>
 /// WebForm1 的摘要說明。
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox nametb;
  protected System.Web.UI.WebControls.TextBox idtb;
  protected System.Web.UI.WebControls.TextBox timetbx;
  protected System.Web.UI.WebControls.Button addbtn;
  protected System.Web.UI.WebControls.Button clearbtn;
  protected System.Web.UI.WebControls.Button delbtn;
  protected System.Web.UI.WebControls.TextBox idid;
  protected System.Web.UI.WebControls.Label msg;
  protected System.Web.UI.WebControls.Label carlst;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   this.timetbx.Text=DateTime.Now.ToLongDateString();//綁定時(shí)間
   if(Page.IsPostBack)
   {
    show();//顯示物品
   }
  }
/// <summary>
/// Store類
/// </summary>
  public class store
  {
   private string name;
   private int id;
   private DateTime nowtime;
   public store(string name,int id,DateTime nowtime)
   {
    this.name=name;
    this.id=id;
    this.nowtime=nowtime;
   }
   public string Name
   {
    get{return this.name;}
   }
   public int Id
   {
    get{return this.id;}
   }
   public DateTime Nowtime
   {
    get{return this.nowtime;}
   }
  
  }

  /// <summary>
  /// storelist類
  /// </summary>
  public class storelist
  {
   ArrayList st = new ArrayList();
   public storelist()
   {}
   public void add(store myst)
   {
    st.Add(myst);
   }
   public ArrayList St
   {
    get {return this.st;}
   }
   
   public store this[int Index]//索引器
   {
    get {return (store)this.st[Index];}
   }
   public int count
   {
    get{return this.st.Count;}
   }
  }
  
  #region Web 窗體設(shè)計(jì)器生成的代碼
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內(nèi)容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.addbtn.Click += new System.EventHandler(this.addbtn_Click);
   this.clearbtn.Click += new System.EventHandler(this.clearbtn_Click);
   this.delbtn.Click += new System.EventHandler(this.delbtn_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void addbtn_Click(object sender, System.EventArgs e)
  {
   //這個(gè)try其實(shí)是不需要的,可以在客戶端判斷輸入框的值類型
   try
   {

   //創(chuàng)建購物車
    store al = new store(this.nametb.Text.Trim(),int.Parse(this.idtb.Text.Trim()),DateTime.Parse(timetbx.Text.Trim()));
    if(Session["stall"]==null)
    {
     storelist sl = new storelist();
     Session["stall"]=sl;
    }
   //將Session的值賦給數(shù)組
    storelist ssl =(storelist)Session["stall"];
    ssl.add(al);//添加
    show();
   }
   catch
   {
    this.idtb.Text="請(qǐng)輸入數(shù)字";
   }
   
   
  }
  public void show()
  {
   //顯示購物車的內(nèi)容
   StringBuilder sb = new StringBuilder();
   if(Session["stall"]!=null)
   {
    storelist ssl =(storelist)Session["stall"];
    if(ssl.count!=0)
    {
     for(int i=0;i<ssl.count;i++)
     {
      sb.Append(i+"   "+ssl[i].Name.ToString()+"  "+ssl[i].Id.ToString()+"  "+ssl[i].Nowtime.ToString()+"<br>");
      this.carlst.Text=sb.ToString();
     }
    }
    this.carlst.Text += "總數(shù):"+ssl.count.ToString();
   }
   
  
  }

  private void clearbtn_Click(object sender, System.EventArgs e)
  {
   if(Session["stall"]!=null)
   {
    this.carlst.Text = "";
//    StringBuilder sb = new StringBuilder();
//    this.carlst.Visible=false;
    Session.Clear();


   }
  }

  private void delbtn_Click(object sender, System.EventArgs e)
  { 
   //這個(gè)try和上面的同理
   try
   {
    
   
   storelist sls = (storelist)Session["stall"];//將Session值賦給數(shù)組
   if(this.carlst.Text.Trim().Replace(" ","") != string.Empty && this.idid.Text.Trim() !=string.Empty)
   {
    if(sls.count != int.Parse("1"))
    {
     for(int i=0 ;i<sls.count;i++)//取出數(shù)組的內(nèi)容,并且刪除
     {
      if(sls[i] == sls[int.Parse(this.idid.Text.Trim())])
      {
       sls.St.RemoveAt(i);
      }

     }
    }
    else//數(shù)組長度為1
    {
    
     Session.Clear();
     this.carlst.Text="";
    }
    show();
   }
   else
   {
    msg.Text="都沒有東西啊!";
    msg.ForeColor = Color.Red;
   }
   }
   catch
   {
    this.idid.Text="請(qǐng)輸入行號(hào)";
   }
  }
 }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多