⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addtotempstore.aspx.cs

📁 webshop系统,功能齐全,代数据库.压缩包解压时没有密码
💻 CS
字号:
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;

namespace WebShop
{
	/// <summary>
	/// Summary description for AddToTempStore.
	/// </summary>
	public class AddToTempStore : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblInfo;
		protected System.Web.UI.WebControls.DataGrid dg_list;
		protected System.Web.UI.HtmlControls.HtmlForm Form1;

	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				if(Object.Equals(Session["UserName"],null))
				{
					Response.Redirect("Error.aspx");
				}
				else
				{
					ViewState["Sort"] = "";
					try
					{
						int uid = int.Parse(Session["UserID"].ToString());
						int bid;
						try
						{
							bid = int.Parse(Request["bookid"].ToString());
						}
						catch
						{
							throw new Exception("");
						}
						
						DataAccessLayer.TempStore.Add(bid,uid);
					}
					catch(Exception ex)
					{
						ShowMsg(ex.Message,1);
					}					
					Bind();	
				}				
			}	
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.dg_list.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.Dglist_PageIndexChanged);
			this.dg_list.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Dglist_EditCommand);
			this.dg_list.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.Dglist_SortCommand);
			this.dg_list.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Dglist_DeleteCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Bind()
		{
			try
			{
				DataSet ds = DataAccessLayer.TempStore.GetBooks(int.Parse(Session["UserID"].ToString()));
				ds.Tables[0].DefaultView.Sort = ViewState["Sort"].ToString();
				this.dg_list.DataSource = ds.Tables[0].DefaultView;
				this.dg_list.DataBind();
			}
			catch(Exception ex)
			{
				ShowMsg(ex.Message,1);
			}			
		}


		private void ShowMsg(string Message,int MessageType)
		{
			this.lblInfo.Visible = true;
			if(MessageType==0)//Mission accomplished
			{
				this.lblInfo.Text = Message;
				this.lblInfo.ForeColor = Color.Blue;
			}
			else
			{
				this.lblInfo.Text = Message;
				this.lblInfo.ForeColor = Color.Red;
			}			
		}

		private void Dglist_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				string uid = Session["UserID"].ToString();
				string bid = dg_list.DataKeys[e.Item.ItemIndex].ToString();
				DataAccessLayer.TempStore.Delete(int.Parse(bid),int.Parse(uid));
				Response.Redirect("AddToCart.aspx?BookId="+bid+"&BackUrl=AddToTempStore.aspx");
			}
			catch(Exception ex)
			{
				ShowMsg(ex.Message,0);
			}
		}

		private void Dglist_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				int uid = int.Parse(Session["UserID"].ToString());
				int bid = int.Parse(dg_list.DataKeys[e.Item.ItemIndex].ToString());
				DataAccessLayer.TempStore.Delete(bid,uid);
				ShowMsg("Delete successful!",0);
				Bind();
			}
			catch(Exception ex)
			{
				ShowMsg(ex.Message,1);
			}
		}

		private void Dglist_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
		{
			if(ViewState["Sort"].ToString() == e.SortExpression)
			{
				ViewState["Sort"] += " desc";
			}
			else
			{
				ViewState["Sort"] = e.SortExpression;
			}
			Bind();
		}

		private void Dglist_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			dg_list.CurrentPageIndex = e.NewPageIndex;
			Bind();
		}


		
	}
}

⌨️ 快捷键说明

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