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

📄 dp_kaidian.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.Configuration;
using System.Data.SqlClient;
using System.IO;

namespace B2Bsite
{
	/// <summary>
	/// 注册店铺
	/// </summary>
	public class DP_kaidian : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.HtmlControls.HtmlSelect Select1;
		protected System.Web.UI.HtmlControls.HtmlTextArea DJieshao;
		protected System.Web.UI.WebControls.TextBox TextBox3;
		protected System.Web.UI.HtmlControls.HtmlForm form1;
		protected System.Web.UI.HtmlControls.HtmlInputButton Submit2;
		protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;

        public SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);

		private void Page_Load(object sender, System.EventArgs e)
		{
            if( !IsPostBack )
            {
                if( Session["username"] == null )
                {
                    Response.Write ("<script language='JavaScript'>");
                    Response.Write ("alert('请先登录!')");
                    Response.Write ("</script>");
                    Response.End();
                    return;
                }
                //绑定 类别下拉列表框
                String sql="SELECT * FROM PType where parentId=0";
                SqlCommand command=new SqlCommand(sql,conn);
                conn.Open();
                SqlDataReader dr=command.ExecuteReader();
                Select1.DataSource=dr;
                Select1.DataTextField = "category_name";
                Select1.DataValueField = "category_ID";
                Select1.DataBind();
                dr.Close();
                conn.Close();
            }
		}

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

        }
		#endregion
		private void Submit2_ServerClick(object sender, System.EventArgs e)
		{
			string dName=TextBox1.Text;//店铺名称		
			string dClass=Select1.Value;//店铺类别
			////店铺图片
			string dItem=TextBox3.Text;//店铺主要项目
			string dJieshao=DJieshao.Value;//店铺介绍
			if(dName==null) dName="";
			//if(dClass=="请选择类别") dClass="";//if(dClass.ToString()=="请选择类别")	dClass="";
			if(dItem==null) dItem="";
			if(dJieshao==null) dJieshao="";
			SqlConnection connection=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
			string sql="select * from DianPuDetail where DianPuName='"+dName+"'";
			SqlCommand command=new SqlCommand(sql,connection);
			connection.Open();
			SqlDataReader dr=command.ExecuteReader();               

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

			if(dName=="" || dClass=="" ||  dItem=="" || dJieshao=="")
			{
				Response.Write ("<script language='javaScript'>");
				Response.Write("alert('请填写完整!!!')");
				Response.Write("</script>");
			
			}
			else if(dr.Read())
			{
				Response.Write ("<script language='javaScript'>");
				Response.Write("alert('抱歉,此店名已被人注册!!!')");
				Response.Write("</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
			{
				string userName=Session["username"].ToString();

				//string sql="insert into Users(DianPuName,DianPuUser,DianPuLogo,DianPuAdd,DianPuGongGao,DianPuClass,DianItem,DianPuJieshao) values('"+dName+"','"+userName+"','"++"','"++"','"+image+"','"+birthday+"')";
				sql="insert into DianPuDetail(DianPuName,DianPuUser,DianPuClass,DianPuItem,DianPuJieshao) values('"+dName+"','"+userName+"','"+dClass+"','"+dItem+"','"+dJieshao+"')";
				SqlConnection connections=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
				SqlCommand commands=new SqlCommand(sql,connections);
				connections.Open();			
				commands.ExecuteNonQuery();				
				connections.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 [DianPuDetail] set [DianPuLogo]=@imgdata where DianPuId="+
                        "(select top 1 DianPuId from [DianPuDetail] where DianPuUser='" + userName + "' order by DianPuId 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 language='javaScript'>");
				Response.Write("alert('恭喜!!!注册成功!!!')");				
				Response.Write("</script>");
				//Response.Redirect("shop_manage.aspx");				
			}
		}

	}
}

⌨️ 快捷键说明

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