📄 addcollection.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;
namespace WebNews
{
/// <summary>
/// AddCollention 的摘要说明。
/// </summary>
public class AddCollention : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label LabMessage;
protected System.Web.UI.WebControls.TextBox TextTitle;
protected System.Web.UI.WebControls.TextBox TextLink;
protected System.Web.UI.WebControls.TextBox TextLab;
protected System.Web.UI.WebControls.TextBox TextBrief;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Label LabUserName;
protected System.Web.UI.WebControls.LinkButton LinkButtonSaveCollection;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
// string title = Request.QueryString["title"].ToString();
// string link = Request.QueryString["link"].ToString();
bool login = isLogin();
if(login)
{
string title = Session["title"].ToString();
string link = Session["link"].ToString();
this.TextTitle.Text = title;
this.TextLink.Text = link;
}
else
{
this.LabUserName.Text = "尚未登录";
Response.Redirect("Login.aspx");
}
}
public bool isLogin()
{
string userId = Session["userId"].ToString();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = App_Data.ClassConnection.CONN_STRING;
conn.Open();
SqlCommand cmd = new SqlCommand("select * from users where userID='"+userId+"'",conn);
SqlDataReader reader = cmd.ExecuteReader();
if(reader.Read())
{
this.LabUserName.Text = "您好," + reader.GetString(1);
reader.Close();
return true;
}
else
{
reader.Close();
return false;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LinkButtonSaveCollection.Click += new System.EventHandler(this.LinkButtonSaveCollection_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LinkButtonSaveCollection_Click(object sender, System.EventArgs e)
{
string userId = Session["userId"].ToString();
string title = this.TextTitle.Text.Trim();
string link = this.TextLink.Text.Trim();
string lab = this.TextLab.Text.Trim();
string brief = this.TextBrief.Text.Trim();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = App_Data.ClassConnection.CONN_STRING;
conn.Open();
SqlCommand cmd = new SqlCommand("insert into collection(userID,title,link,lab,brief) values ('"+userId+"','"+title+"','"+link+"','"+lab+"','"+brief+"')",conn);
cmd.ExecuteNonQuery();
this.LabMessage.Text = "保存网摘成功";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -