📄 mysell.aspx.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>
/// mybook 的摘要说明。
/// </summary>
public class mybook : System.Web.UI.Page
{
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.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.ImageButton ImageButton5;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
string ec=System.Configuration.ConfigurationSettings.AppSettings["ec"];
SqlConnection conn = new SqlConnection(ec);
conn.Open();
SqlDataAdapter da=new SqlDataAdapter("SELECT * from category_first", conn );
DataSet ds=new DataSet();
da.Fill(ds);
DropDownList1.DataSource=ds.Tables[0].DefaultView;
DropDownList1.DataTextField= "catName";
DropDownList1.DataValueField="catID";
DropDownList1.DataBind();
SqlDataAdapter daa=new SqlDataAdapter("SELECT * FROM category_sec "+
"where cat_ID=(select catid from category_first "+
"where catname='"+DropDownList1.SelectedItem.ToString()+"')", conn );
DataSet dss=new DataSet();
daa.Fill(dss);
DropDownList2.DataSource=dss.Tables[0].DefaultView;
DropDownList2.DataTextField= "cat_secName";
DropDownList2.DataValueField="cat_secID";
DropDownList2.DataBind();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </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.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
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");
}
private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string ec=System.Configuration.ConfigurationSettings.AppSettings["ec"];
Session["catnm"]=DropDownList1.SelectedItem.ToString();
SqlConnection conn = new SqlConnection(ec);
conn.Open();
SqlDataAdapter daa=new SqlDataAdapter("SELECT * FROM category_sec "+
"where cat_ID=(select catid from category_first "+
"where catname='"+Session["catnm"]+"')", conn );DataSet dss=new DataSet();
daa.Fill(dss);
DropDownList2.DataSource=dss.Tables[0].DefaultView;
DropDownList2.DataTextField= "cat_secName";
DropDownList2.DataValueField="cat_secID";
DropDownList2.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string i="1";
string l1="1";
string l2="1";
if(TextBox1.Text=="")
Response.Write("<script>alert('请输入商品名称')</script>");
else
if(TextBox2.Text=="")
Response.Write("<script>alert('请输入商品价格')</script>");
else
if(TextBox3.Text=="")
Response.Write("<script>alert('请输入商品详细说明')</script>");
else
if(UP_FILE.PostedFile.ContentLength==0)
Response.Write("<script>alert('请选择商品上传照片')</script>");
else
{
string ec=System.Configuration.ConfigurationSettings.AppSettings["ec"];
SqlConnection conn = new SqlConnection(ec);
conn.Open();
SqlCommand cmd1 =
new SqlCommand( "select max(commodityID) from commdotyInfo", conn );
SqlDataReader dr=cmd1.ExecuteReader();
if(dr.Read ())
{
i=dr.GetValue(0).ToString();
}
dr.Close();
SqlCommand cmd2 =
new SqlCommand( "select catid from category_first where catname='"+DropDownList1.SelectedItem.ToString()+"'", conn );
SqlDataReader dr1=cmd2.ExecuteReader();
if(dr1.Read ())
{
l1=dr1.GetValue(0).ToString();
}
dr1.Close();
SqlCommand cmd3 =
new SqlCommand( "select cat_secid from category_sec where cat_secname='"+DropDownList2.SelectedItem.ToString()+"' and cat_id=(select catid from category_first where catname='"+DropDownList1.SelectedItem.ToString()+"')", conn );
SqlDataReader dr2=cmd3.ExecuteReader();
if(dr2.Read ())
{
l2=dr2.GetValue(0).ToString();
}
dr2.Close();
DateTime dt=DateTime.Now;
DateTime dt1=DateTime.Now.AddMonths(1);
string s="insert into commdotyInfo(commodityID,USERID,CATID,CAT_SECID,COMNAME,DEAL_AUCTION,date,status,expire_date,introduction,price)"+
"values('"+i+"'+1,'"+Session["ID"]+"','"+l1+"','"+l2+"','"+TextBox1.Text+"','"+RadioButtonList1.SelectedValue+"','"+dt+"','1','"+dt1+"','"+TextBox3.Text+"','"+TextBox2.Text+"')";
try
{
SqlCommand cmmd=new SqlCommand(s,conn);
cmmd.ExecuteNonQuery();
SqlCommand cmd = new SqlCommand( "select commodityID from commdotyInfo where commodityID='"+i+"'+1", conn );
SqlDataReader drr=cmd.ExecuteReader();
if(drr.Read ())
{
Response.Write("<script>alert('发布成功,照片上传中……')</script>");
string adr="images/commodity/";
string myDir=UP_FILE.PostedFile.FileName;
int mypos=myDir.LastIndexOf("\\");
string my_FileName=myDir.Substring(mypos+1);
string myFileName=myDir.Substring(mypos);
int pos=my_FileName.LastIndexOf(".");
string FileName=my_FileName.Substring(pos);
string mySavePath=Server.MapPath("images/commodity/")+drr["commodityID"]+FileName;
SqlCommand cd=new SqlCommand("update commdotyInfo set img='"+adr+drr["commodityID"]+FileName+"' where commodityID='"+drr["commodityID"]+"'",conn);
if(FileName.ToString()==".jpg"||FileName.ToString()==".gif")
{
UP_FILE.PostedFile.SaveAs (mySavePath);
Response.Write("<script>alert('上传成功')</script>");
string ID=drr["commodityID"].ToString();
drr.Close();
cd.ExecuteNonQuery();
Response.Redirect("detail.aspx?commodityID="+ID+"");
}
else
Response.Write("<script>alert('请上传jpg或gif格式的文件')</script>");
}
}
catch(Exception ex)
{
Response.Write("<script>alert('"+ex.Message+"发布失败!')</script>");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -