📄 fbnews.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class admin_FbNews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["adminAccount"] != null)
{
if (Session["adminAccount"] != "")
{
}
else
{
Response.Redirect("adminErr.aspx?errMsg=没有登陆或者登陆超时.<a href='adminlogin.aspx'>现在登陆</a>");
}
}
else
{
Response.Redirect("adminErr.aspx?errMsg=没有登陆或者登陆超时.<a href='adminlogin.aspx'>现在登陆</a>");
}
int classId = Convert.ToInt32(Request.QueryString["ClassId"]);
string sql = "select * from [NcClass] Where [ClassId]="+classId;
WebConfig.CreateCon();
OleDbDataAdapter daa = new OleDbDataAdapter(sql, WebConfig.con);
DataSet ds1 = new DataSet();
daa.Fill(ds1);
DataTable dt = ds1.Tables[0];
this.Label1.Text = dt.Rows[0]["ClassName"].ToString();
this.HiddenField1.Value = classId.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
string ProductIntro = this.TextBox2.Text.Replace("'", "‘");
string picPath = "";
//定义一个变量,取全部文件名
string fileFullname = this.FileUpload1.FileName;
//取出当前日期
string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
//取文件扩展名
string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
//截取上传文件的扩展名既"."后面的字母所以+1
string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1);
//类型控制,想上传什么类型,可以在这里类似添加
if (type == "jpg" || type == "gif" || type == "bmp")
{
this.FileUpload1.SaveAs(Server.MapPath("/upload") + "\\" + dataName + fileName);
picPath = dataName + fileName;
//image1输出上传图片,可以在这里控制图片大小
//this.Image1.ImageUrl = "../upload/" + picPath;
}
else
{
picPath = "";
}
string nameList = "";
string valueList = "";
if (picPath != "")
{
nameList = ", [NewsPic] ";
valueList = ",'" + picPath + "'";
}
string sql = "insert into [NcNews] ([NewsTitle],[NewsContent],[NewsClassId]"+nameList+") values ('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "'," + Convert.ToInt32(this.HiddenField1.Value) + ""+valueList+")";
Response.Write(sql);
WebConfig.CreateCon();
OleDbCommand cmd = new OleDbCommand(sql, WebConfig.con);
cmd.ExecuteNonQuery();
Response.Redirect("adminErr.aspx?errMsg=发布成功!<a href='adminIndex.aspx'>返回</a>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -