cart.ascx.cs

来自「ibatis源码及帮助文档(IBatis源码+xsd+帮助)」· CS 代码 · 共 144 行

CS
144
字号
namespace NPetshop.Web.UserControls.Shopping
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	using NPetshop.Domain.Shopping;
	using NPetshop.Presentation.Core;
	using NPetshop.Presentation.UserActions;

	/// <summary>
	/// Description r閟um閑 de Cart.
	/// </summary>
	public partial class Cart : NPetshop.Presentation.UserControl
	{
		protected System.Web.UI.WebControls.Literal LiteralTotal;
		private ShoppingCart _cart = null; 

		//Property to show total
		protected decimal Total
		{
			get { return _cart.Total; }
		}

		protected void Page_Load(object sender, System.EventArgs e)
		{
			_cart = this.WebLocalSingleton.CurrentShoppingCart;
		}

		public override void DataBind()
		{
			bool empty = ((_cart == null) || _cart.IsEmpty);
			if (! empty)
			{
				RepeaterCart.DataSource = _cart;
				RepeaterCart.DataBind();

				if (_cart.Lines.IsNextPageAvailable)
				{
					LinkbuttonNext.Visible = true;
				}
				else
				{
					LinkbuttonNext.Visible = false;
				}
				if (_cart.Lines.IsPreviousPageAvailable)
				{
					LinkButtonPrev.Visible = true;
				}
				else
				{
					LinkButtonPrev.Visible = false;
				}
			}	
			else
			{
				LinkbuttonNext.Visible = false;
				LinkButtonPrev.Visible = false;
				LinkbuttonProceedCheckout.Visible = false;
			}
		}

		protected void QuantityChanged(object o, System.EventArgs e)
		{
			Page.Validate();
			if (Page.IsValid)
			{
				TextBox textboxQuantity = o as System.Web.UI.WebControls.TextBox;
				LinkButton linkButtonRemove = textboxQuantity.Parent.FindControl("LinkButtonRemove") as LinkButton;			

				int quantity = int.Parse(textboxQuantity.Text);
				string itemId = linkButtonRemove.CommandArgument.ToString();

				ShoppinAction action = new ShoppinAction(this.Context);
				action.UpdateQuantityByItemId(itemId, quantity);
			}
		}

		protected void RepeaterCart_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
		{
			if (e.CommandName == "RemoveItem")
			{
				ShoppinAction action = new ShoppinAction(this.Context);
				action.RemoveItemFromCart(e.CommandArgument.ToString());
				this.CurrentController.NextView = action.NextViewToDisplay;
			}
			else if (e.CommandName == "Update")
			{
				this.CurrentController.NextView = WebViews.CART;		
			}
			else if (e.CommandName == "ShowItem")
			{
				CatalogAction action = new CatalogAction(this.Context);
				action.ShowItem(e.CommandArgument.ToString());
				this.CurrentController.NextView = action.NextViewToDisplay;
			}
		}

		protected void LinkButtonPrev_Click(object sender, System.EventArgs e)
		{
			_cart.Lines.PreviousPage();
			this.CurrentController.NextView = WebViews.CART;
		}

		protected void LinkbuttonNext_Click(object sender, System.EventArgs e)
		{
			_cart.Lines.NextPage();
			this.CurrentController.NextView = WebViews.CART;
		}

		protected void LinkbuttonProceedCheckout_Click(object sender, System.EventArgs e)
		{
			ShoppinAction action = new ShoppinAction(this.Context);
			action.ProceedCheckout();
			this.CurrentController.NextView = action.NextViewToDisplay;
		}

		#region Code g閚閞?par le Concepteur Web Form
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN? Cet appel est requis par le Concepteur Web Form ASP.NET.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		M閠hode requise pour la prise en charge du concepteur - ne modifiez pas
		///		le contenu de cette m閠hode avec l'閐iteur de code.
		/// </summary>
		private void InitializeComponent()
		{

		}
		#endregion


	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?