📄 index.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
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.Text.RegularExpressions;
namespace ST_GROUP.Blog
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public partial class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlForm Form1;
OleDbConnection ST_myConn;
public string ST_bgcolor;
protected System.Web.UI.WebControls.Calendar Calendar1;
public string ST_tcolor;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string ST_dns = ConfigurationSettings.AppSettings["conn"];
//最新推荐文章
string ST_cmd_sql = "select top 10 * from ST_news where ST_n_iscmd=1 order by ST_n_date desc";
ST_myConn = new OleDbConnection(ST_dns);
OleDbDataAdapter ST_classCmd = new OleDbDataAdapter("select ST_c_id,ST_c_name from ST_class",ST_myConn);
OleDbDataAdapter ST_cmdCmd = new OleDbDataAdapter(ST_cmd_sql,ST_myConn);
DataSet ST_classds = new DataSet();
ST_classCmd.Fill(ST_classds,"类别列表");
DataSet ST_cmdds = new DataSet();
ST_cmdCmd.Fill(ST_cmdds,"推荐文章");
ClassList.DataSource = new DataView(ST_classds.Tables[0]);
ClassList.DataBind();
CmdList.DataSource = new DataView(ST_cmdds.Tables[0]);
CmdList.DataBind();
NewsList_Bind();
if (Request.Cookies["colors"]!=null)
{
string ST_test = Request.Cookies["colors"].Value;
String[] ST_colorList = ST_test.Split(new char[] { ',' });
ST_bgcolor = ST_colorList[0];
ST_tcolor = ST_colorList[1];
}
else
{
ST_bgcolor = "#FFDE94";
ST_tcolor = "#efe3ce";
}
Page.DataBind();
}
public void ST_get_Replay()
{
Response.Write ("<table width=100% border=0 cellspacing=0 cellpadding=0>");
OleDbCommand ST_myCmd = new OleDbCommand("select top 10 * from ST_replay order by ST_r_date desc",ST_myConn);
ST_myConn.Open();
OleDbDataReader ST_read = ST_myCmd.ExecuteReader();
while (ST_read.Read())
{
Response.Write ("<tr ><td height=25 bgColor=#f8f8f8><div align=center><font style='FONT-SIZE: 12px' color=red><a href="+ ST_read[5].ToString() +".aspx title="+ ST_read[3].ToString() +">"+ ST_read[2].ToString() +"</a></font></div></td></tr><tr><td><div align=right><em><font style='FONT-SIZE: 12px'>"+ ST_read[1].ToString() +"评论于"+ ST_read[4].ToString() +"</font></em></div></td></tr>");
}
Response.Write ("</table>");
ST_myConn.Close();
}
public void get_Link()
{
Response.Write ("<table width=100% border=0 cellspacing=0 cellpadding=0>");
OleDbCommand ST_myCmd = new OleDbCommand("select * from ST_link",ST_myConn);
ST_myConn.Open();
OleDbDataReader ST_read = ST_myCmd.ExecuteReader();
while (ST_read.Read())
{
Response.Write ("<tr><td height=20><div align=center><font size=-1 color=red><a href="+ ST_read[2].ToString() +" target=_blank>"+ ST_read[1].ToString() +"</a></font></div></td></tr>");
}
Response.Write ("</table>");
ST_myConn.Close();
}
public void NewsList_Bind()
{
string ST_sql;
if (Request.QueryString["c_id"]==null)
{
ST_sql = "select * from ST_news order by ST_n_date desc";
}
else
{
if (IsSafe(Request.QueryString["c_id"],2)==true)
{
ST_sql = "select * from ST_news where ST_c_id="+ Request.QueryString["c_id"] +" order by ST_n_date desc";
}
else
{
ST_sql="";
Response.Write("非法参数");
Response.End();
}
}
OleDbDataAdapter ST_myCmd = new OleDbDataAdapter(ST_sql,ST_myConn);
DataSet ST_ds = new DataSet();
ST_myCmd.Fill(ST_ds,"新闻列表");
NewsList.DataSource = new DataView(ST_ds.Tables[0]);
NewsList.DataBind();
}
public bool IsSafe (string str, int prama)
{
if (prama==1)
{
if (Regex.IsMatch(str,"[0-9]"))
{
return true;
}
else
{
return false;
}
}
else
{
if (str.IndexOf("and")>0 || str.IndexOf("or")>0 || str.IndexOf("'")>0)
{
return false;
}
else
{
return true;
}
}
}
public void Get_Page(object sender, DataGridPageChangedEventArgs e)
{
NewsList.CurrentPageIndex = e.NewPageIndex;
NewsList_Bind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -