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

📄 admin.aspx.cs

📁 .net环境下开发的,很好哦,这是我门最近做的一个电子商务的作业 实现了很多功能,是典型的C2C模式,很有利用价值,大家下载了多给我提意见
💻 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;
using System.Data.SqlClient;

namespace secondhand
{

	/// <summary>
	/// WebForm62 的摘要说明。
	/// </summary>
	public class WebForm62 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Image Image1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.DataGrid DataGrid2;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Panel Panel2;
		protected System.Web.UI.WebControls.Button Button6;
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
		protected System.Web.UI.WebControls.ImageButton ImageButton2;
		protected System.Web.UI.WebControls.ImageButton ImageButton3;
		protected System.Web.UI.WebControls.ImageButton ImageButton4;
		protected System.Web.UI.WebControls.ImageButton ImageButton5;
		protected System.Web.UI.WebControls.Panel Panel1;
		protected System.Web.UI.WebControls.Button Button5;
		protected System.Web.UI.WebControls.Button Button4;
		protected int lastEditPage;
		private DataSet GetData1()  //获得数据1
		{
			string ec_Data = 
				"Server=(local);"+
				"uid=sa;pwd=sa;"+
				"database=ec";
			SqlConnection conn= 
				new SqlConnection(ec_Data);
			string SQLStatement="SELECT userID ,userName,sex,address ,telephoneNum,e_mail " +
				" FROM userInfo";
			///声明 SqlConnection对象:conn 
			conn.Open();
			///声明Command对象:myCommand  
			SqlDataAdapter myCommand = new SqlDataAdapter(SQLStatement,conn);  
			///设置Command命令的类型为Text类型  
			myCommand.SelectCommand.CommandType=CommandType.Text;  
			///创建DataSet对象实例  
			DataSet myDataSet = new DataSet();  
			myCommand.Fill(myDataSet, "userInfo");  
			///最后返回myDataSet对象  
			return myDataSet;  
		}  

		private DataSet GetData2()  //获得数据2
		{  
			string ec_Data = 
				"Server=(local);"+
				"uid=sa;pwd=sa;"+
				"database=ec";
			SqlConnection conn= 
				new SqlConnection(ec_Data);
			string SQLStatement="SELECT commodityID ,comName ,userID,price,date" +
				" FROM commdotyInfo";
			///声明 SqlConnection对象:conn 
			conn.Open();
			///声明Command对象:myCommand  
			SqlDataAdapter myCommand = new SqlDataAdapter(SQLStatement,conn);  
			///设置Command命令的类型为Text类型  
			myCommand.SelectCommand.CommandType=CommandType.Text;  
			///创建DataSet对象实例  
			DataSet myDataSet = new DataSet();  
			myCommand.Fill(myDataSet,"commdotyInfo");  
			///最后返回myDataSet对象  
			return myDataSet;  
		}  

		public void BindGrid1()    //绑定数据1
		{  
			DataGrid1.DataSource=GetData1().Tables["userInfo"]; 

			DataGrid1.DataBind();  
		} 
		public void BindGrid2()  //绑定数据2
		{  
			DataGrid2.DataSource=GetData2().Tables["commdotyInfo"];  
			DataGrid2.DataBind();  
		} 

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if( Session["ID"]==null||Session["pwd"]==null)
			{
				Server.Transfer("default.aspx");
				
			}
			if(!IsPostBack)  
			{  
				BindGrid1();  
				BindGrid2();  
			}  

		}


		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
	/// WebForm62 的摘要说明。
	/// </summary>
		private void InitializeComponent()
		{    
			this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
			this.ImageButton2.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton2_Click);
			this.ImageButton3.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton3_Click);
			this.ImageButton4.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton4_Click);
			this.ImageButton5.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton5_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button6.Click += new System.EventHandler(this.Button6_Click);
			this.Button5.Click += new System.EventHandler(this.Button5_Click);
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
			this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button4.Click += new System.EventHandler(this.Button4_Click);
			this.DataGrid2.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid2_PageIndexChanged);
			this.DataGrid2.SelectedIndexChanged += new System.EventHandler(this.DataGrid2_SelectedIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button2_Click(object sender, System.EventArgs e)
		{
			Image1.Visible=false;
			Panel1.Visible=true;
			string ec_Data = 
				"Server=(local);"+
				"uid=sa;pwd=sa;"+
				"database=ec";
			SqlConnection conn= 
				new SqlConnection(ec_Data);
			conn.Open();
			SqlDataAdapter da=new SqlDataAdapter ("SELECT * FROM commdotyInfo",conn);
			DataSet ds=new DataSet ();
			DataGrid2.DataSource =ds;
			da.Fill(ds);
			DataGrid2.Visible=true;
			DataGrid1.Visible=false;
			Button4.Visible=true;
			BindGrid2();
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			Panel1.Visible=false;
			DataGrid1.Visible=false;
			Button3.Visible=false;
			Button4.Visible=false;
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
			Panel1.Visible=false;
			DataGrid1.Visible=false;
			Button3.Visible=false;
			Button4.Visible=false;
		}

		private void Button5_Click(object sender, System.EventArgs e)
		{
			
			Session["ID"]=null;
			Session["pwd"]=null;
			Server.Transfer("default.aspx");
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			string ec_Data = 
				"Server=(local);"+
				"uid=sa;pwd=sa;"+
				"database=ec";
			SqlConnection conn= 
				new SqlConnection(ec_Data);
			conn.Open();
			SqlDataAdapter da=new SqlDataAdapter ("SELECT userID ,userName,sex,address ,telephoneNum,e_mail  FROM userInfo",conn);
			DataSet ds=new DataSet ();
			DataGrid1.DataSource =ds;
			da.Fill(ds);
			DataGrid1.Visible=true;
			Panel1.Visible=false;
			Button3.Visible=true;
			Image1.Visible=false;
			BindGrid1();
		}

		private void Button6_Click(object sender, System.EventArgs e)
		{
			Server.Transfer("liuyanban.aspx");
		}

		private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			int userID ; 
			userID=Convert.ToInt32((e.Item.Cells[0].Text));
			string SQLStatement="Delete from userInfo WHERE userID="+userID;
			string ec_Data = 
				"Server=(local);"+
				"uid=sa;pwd=sa;"+
				"database=ec";
			SqlConnection conn= 
				new SqlConnection(ec_Data);
			conn.Open();
			SqlCommand myCommand = new SqlCommand (SQLStatement,conn);              
			myCommand.CommandTimeout = 15; 
			myCommand.CommandType=CommandType.Text; 
			conn.Close();
			try 
			{ 
				conn.Open(); 
				myCommand.ExecuteNonQuery(); 
				lastEditPage=DataGrid1.CurrentPageIndex;
				if((DataGrid1.PageCount-DataGrid1.CurrentPageIndex)==1&&DataGrid1.Items.Count==1)
				{
					if(DataGrid1.PageCount>1)
						lastEditPage=lastEditPage-1;
					else
						lastEditPage=0;
				}
																								
				DataGrid1.CurrentPageIndex=lastEditPage;
				conn.Close(); 
			} 
			catch(Exception ee) 
			{ 
				throw ee; 
			} 
			DataGrid1.EditItemIndex = -1; 
			BindGrid1();   
			conn.Close();
			Response.Write("<script>alert(\"删除成功!\");</script>");

		}

		public void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			DataGrid1.CurrentPageIndex=e.NewPageIndex; 
			BindGrid1(); 
		}

		public void DataGrid2_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			DataGrid2.CurrentPageIndex=e.NewPageIndex; 
			BindGrid2();
		}

		private void DataGrid2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			Server.Transfer("default.aspx");
		}

		private void ImageButton2_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			Server.Transfer("mybuy.aspx");
		}

		private void ImageButton3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if( Session["ID"]==null||Session["pwd"]==null)
		 
				Response.Write ("<script>alert(\"请先登陆!\");</script>");
			else
				Server.Transfer("myyigo.aspx");
		
		}

		private void ImageButton4_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if( Session["ID"]==null||Session["pwd"]==null)
		 
				Response.Write ("<script>alert(\"请先登陆!\");</script>");
			else
				Server.Transfer("myyigo.aspx");
			
		}

		private void ImageButton5_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if( Session["ID"]==null||Session["pwd"]==null)
		 
				Response.Write ("<script>alert(\"请先登陆!\");</script>");
			else
				Server.Transfer("myyigo.aspx");
		 
		}
	}
}

⌨️ 快捷键说明

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