📄 show.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;
using System.Configuration;
namespace WebNews
{
/// <summary>
/// show 的摘要说明。
/// </summary>
public class show : System.Web.UI.Page
{
public string title;
public string content;
public Int64 aid;
public string classname;
public string Nkey;
public string writer;
public DateTime de;
public string source;
protected System.Web.UI.WebControls.Repeater myrt;
protected System.Web.UI.HtmlControls.HtmlTextArea body;
protected System.Web.UI.HtmlControls.HtmlInputText username;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label PageLabel;
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.Label BackLabel;
protected System.Web.UI.WebControls.Label AuthorLabel;
protected System.Web.UI.WebControls.Label BodyLabel;
protected System.Web.UI.WebControls.Label SourceLabel;
protected System.Web.UI.WebControls.Label HitsLabel;
protected System.Web.UI.WebControls.Label TimeLabel;
protected System.Web.UI.WebControls.HyperLink PreviousLink;
protected System.Web.UI.WebControls.HyperLink NextLink;
protected System.Web.UI.WebControls.RadioButtonList face;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
public Int64 hints;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
addHints();
getArticle();
getRemark();
//content=HtmlEcode(content);
}
}
public void ListClass(string de) //显示分类
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_selFclassAll",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();
while (rd.Read())
{
Response.Write(de+"<a href=../list.aspx?classname="+rd.GetString(1)+">"+rd.GetString(1)+"</a>");
}
rd.Close();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
private void getArticle() //取得新闻内容
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cd=new SqlCommand("sp_selArticleById",conn);
cd.CommandType=CommandType.StoredProcedure;
SqlParameter ids=cd.Parameters.Add("@articleid",SqlDbType.BigInt);
ids.Value =Request["articleid"] ;
SqlDataReader rd;
rd=cd.ExecuteReader();
if(rd.Read()==true)
{
aid=rd.GetInt64(0);
title=rd.GetString(2);
content=rd.GetString(1);
classname=rd.GetString(3);
Nkey=rd.GetString(8);
writer=rd.GetString(9);
source=rd.GetString(10);
hints=rd.GetInt64(11);
de=rd.GetDateTime(12) ;
rd.Close();
}
else Response.Write("fdfddf");
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
private void addHints()
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"]; //取得DSN字符
SqlConnection conn= new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_addArticleHints",conn);
SqlParameter id1=cmd.Parameters.Add("@articleid",SqlDbType.BigInt);
cmd.CommandType=CommandType.StoredProcedure;
id1.Value=Request["articleid"];
int i=cmd.ExecuteNonQuery();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
private void getRemark() //获得评论
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //创建SqlDataAdapter 类
myCommand.SelectCommand=new SqlCommand("sp_selRemarkByArticleId",conn);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlParameter artid=myCommand.SelectCommand.Parameters.Add("@articleid",SqlDbType.BigInt);
artid.Value=Request["articleid"];
DataSet ds=new DataSet(); //建立并填充数据集
myCommand.Fill(ds,"Article");
DataList1.DataSource=ds;
DataList1.DataBind();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
private void addRemark()
{
try
{ string a=username.Value;
string b=face.SelectedItem.Value;
string c=body.Value;
string d=(string)Request.UserHostAddress.ToString();
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_addRemark",conn) ;
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter articleid=cmd.Parameters.Add("@articleid",SqlDbType.BigInt) ;
articleid.Value=Request["articleid"];
SqlParameter ue=cmd.Parameters.Add("@username",SqlDbType.Char,200);
ue.Value =a.Trim();
SqlParameter by=cmd.Parameters.Add("@body",SqlDbType.Char,1000);
by.Value =c.Trim();
SqlParameter fe=cmd.Parameters.Add("@face",SqlDbType.Char,50);
fe.Value=b.Trim();
SqlParameter ip=cmd.Parameters.Add("@ip",SqlDbType.Char,100);
ip.Value =d.Trim();
int i=cmd.ExecuteNonQuery();
conn.Close() ;
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
public string show1(object de)
{
string g;
g=(string)de;
return g.Trim() ;
}
#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()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
if(body.Value.Length>200)
{
Label1.Text="评论太长了!";
}
else
{
addRemark();
getRemark();
getArticle();
}
}
//
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -