📄 news_add.aspx.cs
字号:
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Data;
using System.Runtime;
using System.Data.SqlClient;
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;
public partial class admin_news_add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["shang_admin"] == null)
{
Response.Redirect("get_your_passport.aspx");
}
Label1.Text = "";
DateTime timenow = DateTime.Now;
TextBox3.Text = timenow.ToString() ;
this.TextBox9.Style.Add("display", "none");
this.eWebEditor1.Attributes.Add("src", "editor/ewebeditor.htm?id=TextBox9&style=gray");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
Label1.Text = "添加新闻出错,可能你的新闻标题未填写";
}
else
{
try
{
SqlConnection con = db.CreateConnection();
con.Open();
string newid;
string strsql = "insert into news (title,time,bigclassname,smallclassname,content,hits,author,url,xiangguan,tag,infor,color,hide,good,middle,bad) values ('" + TextBox1.Text + "','" + Convert.ToDateTime(TextBox3.Text) + "','" + DropDownList1.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "',0,'" + TextBox4.Text + "','" + TextBox2.Text + "','" + TextBox6.Text + "','" + TextBox5.Text + "','','" + DropDownList2.Text + "','not hide','0','0','0') SELECT @@IDENTITY as 'bh'";
SqlCommand cmd = new SqlCommand(strsql, con);
newid = cmd.ExecuteScalar().ToString();
con.Close();
string template;
SqlConnection con1 = db.CreateConnection();
con1.Open();
string strsql1 = "select * from example";
SqlDataAdapter ad1 = new SqlDataAdapter(strsql1, con1);
DataSet ds1 = new DataSet();
ad1.Fill(ds1, "bb");
template = ds1.Tables["bb"].Rows[0]["example"].ToString();
template = Regex.Replace(template, "E_title", TextBox1.Text);
template = Regex.Replace(template, "E_now", TextBox3.Text);
template = Regex.Replace(template, "E_fenlei", DropDownList1.Text);
template = Regex.Replace(template, "E_content", TextBox9.Text);
template = Regex.Replace(template, "E_num", newid);
StreamWriter sw = File.CreateText(Server.MapPath("../articls/" + DropDownList1.Text + "/" + newid + ".aspx"));
sw.Write(template);
sw.Close();
con1.Close();
Response.Redirect("news_manage.aspx?bigclassname=" + DropDownList1.Text + "");
}
catch (Exception ee)
{
Response.Write("Some thing Error happend->NEWS SYSTEM INSERT ERROR:you can enter <a href='http://www.shangducms.cn'>shangducms.cn</a> to find more information." + ee.ToString());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -