protected void Button1_Click(object sender, EventArgs e) { string NBANewsTitle = this.TextBox1.Text; string NBANewsInfo = this.TextBox2.Text; string Picture = this.FileUpload1.FileName; string NBASortID = this.DropDownList1.SelectedValue; if (NBANewsTitle == "" || NBANewsInfo == "") { this.Label1.Text = "请将信息填写完整!"; } if (!(Picture.EndsWith(".jpg") || Picture.EndsWith(".png"))) { Response.Write("<script>alert('上传图片格式不正确!')</script>"); return; } else { Entity.NBANews NBANews = new Entity.NBANews(); NBANews.NBANewsTitle = NBANewsTitle; NBANews.NBANewsInfo = NBANewsInfo; NBANews.Picture = Picture; NBANews.NBASortID = NBASortID; NBANews.ClickRate = "0"; NBANews.UserID = Session["UserID"].ToString(); if (BLL.NBANews_BLL.insertNBANews(NBANews) > 0) { string strPath = Server.MapPath(@"\img\newsImg\" + Picture); this.FileUpload1.SaveAs(strPath); Response.Write("<script>alert('发布成功!');window.location.href='Main.aspx';</script>"); } } }
public static int insertNBANews(Entity.NBANews NBANews) { string sql = string.Format("insert into NBANews (NBANewsTitle,NBANewsInfo,ReleaseTime,UserID,ClickRate,Picture,NBASortID) values('{0}','{1}','{2}',{3},{4},'{5}',{6})", NBANews.NBANewsTitle, NBANews.NBANewsInfo, DateTime.Now, NBANews.UserID, NBANews.ClickRate, NBANews.Picture, NBANews.NBASortID); return(DBHelper.ExecuteNonQuery(sql)); }
public static int insertNBANews(Entity.NBANews NBANews) { return(DAL.NBANews_DAL.insertNBANews(NBANews)); }