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

📄 product_add.aspx.cs

📁 b to b 模式 电子商务系统
💻 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;
using System.Configuration;
using System.IO;


namespace B2Bsite
{
	/// <summary>
	/// 添加商品
	/// </summary>
	public class product_add : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.TextBox TextBox5;
		protected System.Web.UI.WebControls.TextBox TextBox3;
		protected System.Web.UI.WebControls.TextBox TextBox4;
		protected System.Web.UI.WebControls.RadioButton RadioButton1;
		protected System.Web.UI.WebControls.RadioButton RadioButton2;
		protected System.Web.UI.WebControls.RadioButton Radiobutton7;
		protected System.Web.UI.WebControls.RadioButton Radiobutton8;
		protected System.Web.UI.WebControls.RadioButton Radiobutton5;
		protected System.Web.UI.WebControls.RadioButton Radiobutton6;
		protected System.Web.UI.HtmlControls.HtmlTextArea TEXTAREA1;
		protected System.Web.UI.HtmlControls.HtmlSelect Select1;
		protected System.Web.UI.HtmlControls.HtmlSelect Select2;
		protected System.Web.UI.HtmlControls.HtmlSelect Select3;
		protected System.Web.UI.HtmlControls.HtmlInputButton Button1;
        protected System.Web.UI.WebControls.DropDownList DropDownList2;
        protected System.Web.UI.WebControls.DropDownList DropDownList1;
        protected System.Web.UI.WebControls.DropDownList DropDownList3;
        protected System.Web.UI.WebControls.RadioButton RadioButton3;
        protected System.Web.UI.WebControls.Label Label1;
        protected System.Web.UI.WebControls.DropDownList Dropdownlist4;
		protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;

		public string productname;
		public string describe;//描述
		public int quantity; //数量
		public string validity;//有效期
		public string province; //省
		public string city;//城市
		public float post;//平邮
		public float fax;//快递
		public int payment;//付款方式
		public int invoice; //发票
		public int repair;//保修
		public string address;//所在地
		public float price;//价钱

		public string name;
		public string aa;

		public string date;
		public string hour;
		public string minute;
		public string second;
		public string time;
		public int n;

		public int j;
		public string img;
		
		DateTime beginTime;
       
		
        public string strID;
        public string strUserName;
		

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

            if( Session["username"] == null )
            {
                Response.Redirect("User_login.aspx");
            }

			name=Request.QueryString["categoryname"].ToString();
			Label1.Text=Server.UrlDecode(name);

            strID = Request.QueryString["categoryid"].ToString();
	
			beginTime=DateTime.Now.Date;

			n=DateTime.Now.Year;
			j=DateTime.Now.Month;

			for(int i=1;i<=30;i++)
			{
				DropDownList1.Items.Add(new ListItem(n.ToString()+"-"+j.ToString()+"-"+i.ToString(),i.ToString()));
			}	
			for(int i=1;i<=24;i++)
			{
				DropDownList2.Items.Add(new ListItem(i.ToString(),i.ToString()));
			}
			for(int i=1;i<=60;i++)
			{
				DropDownList3.Items.Add(new ListItem(i.ToString(),i.ToString()));
			}
			for(int i=1;i<=60;i++)
			{
				Dropdownlist4.Items.Add(new ListItem(i.ToString(),i.ToString()));
				
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
            this.Button1.ServerClick += new System.EventHandler(this.Button1_ServerClick);
            this.Load += new System.EventHandler(this.Page_Load);

        }
		#endregion

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

            if( Session["username"] == null )
            {
                Response.Redirect("User_login.aspx");
            }
            else
            {
                strUserName = Session["username"].ToString();
            }

            // 检查是否开了店铺 ----
            SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
            string sql2="select * from DianPuDetail where DianPuUser='"+strUserName+"'";	
            SqlCommand command2=new SqlCommand(sql2,conn);
            conn.Open();
            SqlDataReader dr2=command2.ExecuteReader();

            if(!dr2.Read())
            {
                Response.Write ("<script language='JavaScript'>");
                Response.Write ("alert('你还没开店!');");
                Response.Write ("</script>");
                //Response.Redirect("shop_manage.aspx");
                dr2.Close();
                conn.Close();
                return;
            }
            dr2.Close();
            conn.Close();

            //----

			string imgPath=uploadFile.PostedFile.FileName;
			System.Drawing.Image imgupload=null;
			try
			{
				imgupload=System.Drawing.Image.FromFile(imgPath);
			}
			catch
			{
				//Response.Write("请注意:因为系统桌面上以及我的文档里面的文件具有特殊权限,所以在选择图片时请选择其他地方的图片。");
			}

			if(TextBox1.Text.Equals("") || TextBox2.Text.Equals("") || TextBox3.Text.Equals("") || TextBox4.Text.Equals("") || TextBox5.Text.Equals("") || Select2.Value.Equals("--请选择所在省份--") )
			{
				Response.Write("<Script>alert('内容不能为空!')</Script>");
			}
			else if(uploadFile.PostedFile.FileName!="" && (Path.GetExtension(uploadFile.PostedFile.FileName)!=".gif" && Path.GetExtension(uploadFile.PostedFile.FileName)!=".jpg"))
			{
				Response.Write("<Script>alert('上传的图片格式必须为gif或jpg!!')</Script>");
			}/*
			else if(uploadFile.PostedFile.FileName!="" && imgupload.Height>200 && imgupload.Width>200)
			{
				Response.Write("<script>alert('上传的图片的高不的超过200 宽不的超过200!!')</script>");
			}*/
			else
			{
				
				productname=TextBox1.Text;
				describe= TEXTAREA1.Value;
				quantity=Int32.Parse(TextBox2.Text);
				validity=Select1.Value;
				province=Select2.Value;
				city=Select3.Value;
	
				date=DropDownList1.SelectedValue;
				hour=DropDownList2.SelectedValue;
				minute=DropDownList3.SelectedValue;
				second=Dropdownlist4.SelectedValue;
				time=n+"-"+j+"-"+date+" "+hour+":"+minute+":"+second;	
		
				price=float.Parse(TextBox5.Text);			
				post=float.Parse(TextBox3.Text);
				fax=float.Parse(TextBox4.Text);
				address=province +"省"+ city;

				if(RadioButton1.Checked)
				{
					payment=1;
				}
				else if(RadioButton2.Checked)
				{
					payment=0;
				}
				else
				{
					payment=2;
				}
				if(Radiobutton5.Checked)
				{
					repair=1;
				}
				else
				{
					repair=0;
				}
				if(Radiobutton7.Checked)
				{
					invoice=1;
				}
				else
				{
					invoice=0;
				}

				SqlConnection connection=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
				string sql="insert into Products(ProductName,ProductPrice,ProductType,ProductQuantity,ProductAddress,ProductPost,ProductFax,"+
					"ProductBegin,ProductDetail,ProductState,ProductStart,ProductLeft,ProductInvoice,ProductRepair,ProductPayment,UserName)"+
					"values('"+productname+"',"+price+","+strID+","+quantity+",'"+address+"',"+post+","+fax+",'"+beginTime+"','"+describe+"','1',"+
					"'"+time+"','"+validity+"','"+invoice+"','"+repair+"','"+payment+"','" + strUserName + "')";
				SqlCommand command=new SqlCommand(sql,connection);

				connection.Open();
				command.ExecuteNonQuery();
				connection.Close();

                if (uploadFile.PostedFile.FileName!="")
                {
                    //----------- update图片
                    Stream imagedatastream;
                    SqlConnection myConn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
                    imagedatastream = Request.Files["uploadFile"].InputStream ;
                    int imagedatalen = Request.Files["uploadFile"].ContentLength ;
                    string imagedatatype = Request.Files["uploadFile"].ContentType ;

                    byte[] image = new byte[imagedatalen];
                    imagedatastream.Read(image,0,imagedatalen);

                    //String sql="insert into image(image) values(@imgdata)";
                    String Psql="update [Products] set [ProductPicture]=@imgdata where ProductId="+
                        "(select top 1 ProductId from [Products] where UserName='"+strUserName+"' order by ProductId desc)";

                    SqlCommand Pcommand=new SqlCommand(Psql,myConn);

                    SqlParameter imgdata = new SqlParameter("@imgdata",SqlDbType.Image);
                    imgdata.Value=image;
                    Pcommand.Parameters.Add (imgdata);

                    myConn.Open();
                    Pcommand.ExecuteReader();
                    myConn.Close();
                    //-----------
                }

				Response.Write("<Script>alert('添加成功,确定请返回!')</Script>");
				
			}
			
		}



	}
}

⌨️ 快捷键说明

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