?? mero.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;
public partial class admin_mero : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["qx"] == null || Session["qx"].ToString() != "0" && Session["qx"].ToString() != "1")
Response.Redirect("login.aspx");
int id = Convert.ToInt32(Request.QueryString["id"]);
titletb.Text = "Ra:" + odb.scr("select title from guest where id=" + id + "");
Page.Title = odb.scr("select title from guest where id=" + id + "");
}
protected void FormView1_ItemCreated(object sender, EventArgs e)
{//處理圖標(biāo)
int id = Convert.ToInt32(Request.QueryString["id"]);
Image qq = (Image)FormView1.FindControl("Image2");
qq.Visible = odb.img("select qq from guest where id=" + id + "");
//email
Image email = (Image)FormView1.FindControl("Image3");
email.Visible = odb.img("select email from guest where id=" + id + "");
//MSN
Image msn = (Image)FormView1.FindControl("Image4");
msn.Visible = odb.img("select msn from guest where id=" + id + "");
//url
Image url = (Image)FormView1.FindControl("Image5");
url.Visible = odb.img("select url from guest where id=" + id + "");
Label concent = (Label)FormView1.FindControl("Label4");
concent.Text = Server.HtmlDecode(odb.scr("select concent from guest where id=" + id + "")).ToString();
if (Convert.ToInt32(odb.scr("select count(*) from [read] where lid=" + id + "")) > 0)
{//如果有回復(fù)的話就把回復(fù)panel以及下面的東西都找出來,然后綁上數(shù)據(jù),顯示出來
Panel re = (Panel)FormView1.FindControl("Panel1");
re.Visible = true;
fill();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int lid = Convert.ToInt32(Request.QueryString["id"]);
string name = Server.HtmlEncode(nametb.Text.ToString().Replace("'", "!"));
string title = Server.HtmlEncode(titletb.Text.ToString().Replace("'", "!"));
string concent = Server.HtmlEncode(concentdx.Text.ToString().Replace("'", "!"));
DateTime dtt = DateTime.Now;
string que = "INSERT INTO [read] ([lid], [name], [title], [concent], [dtt]) VALUES ('" + lid + "','" + name + "','" + title + "','" + concent + "','" + dtt + "')";
if (odb.insert(que))
{//調(diào)用ODB類的插入方法,并把SQL語句作為參數(shù)傳給類,讓他幫助完成
Response.Redirect("../cg.aspx?cg=c&id=" + lid);
}
}
protected void Button2_Click(object sender, EventArgs e)
{//刪除留言
int id = Convert.ToInt32(Request.QueryString["id"]);
if (odb.insert("DELETE FROM [guest] WHERE id = " + id + ""))
{
odb.insert("DELETE FROM [read] WHERE lid = " + id + "");//刪除本留言的所有回復(fù)
Response.Redirect("../cg.aspx?cg=d");
}
}
private void fill()
{//綁定回復(fù)列表的數(shù)據(jù),方便頁內(nèi)多次調(diào)用
int id = Convert.ToInt32(Request.QueryString["id"]);
read.DataSource = odb.ds("select * from [read] where lid=" + id + "");
read.DataKeyField = "id";
read.DataBind();
}
private DataList read
{//因為頁內(nèi)要多次使用這個DataList做的回復(fù)列表,但是每次都去找難免有點笨笨
get
{
DataList re = (DataList)FormView1.FindControl("DataList2");
return re;
}
}
protected void DataList2_CancelCommand(object source, DataListCommandEventArgs e)
{//取消編輯
read.EditItemIndex = -1;
fill();
}
protected void DataList2_DeleteCommand(object source, DataListCommandEventArgs e)
{//刪除回復(fù)
int id = Convert.ToInt32(read.DataKeys[e.Item.ItemIndex]);//找出該回復(fù)記錄的ID
if (odb.insert("DELETE FROM [read] WHERE id = " + id + ""))
{
fill();
}
}
protected void DataList2_EditCommand(object source, DataListCommandEventArgs e)
{//進(jìn)入編輯狀態(tài)
read.EditItemIndex = e.Item.ItemIndex;
fill();
}
protected void DataList2_UpdateCommand(object source, DataListCommandEventArgs e)
{//更新當(dāng)前回復(fù)
int id = Convert.ToInt32(read.DataKeys[e.Item.ItemIndex]);//找出該回復(fù)記錄的ID
string title = ((TextBox)read.Items[e.Item.ItemIndex].FindControl("titletb")).Text.ToString();
string concent = ((TextBox)read.Items[e.Item.ItemIndex].FindControl("concenttb")).Text.ToString();
string dtt = DateTime.Now.ToString();
odb.insert("UPDATE [read] SET title = '" + title + "', concent = '" + concent + "', dtt ='" + dtt + "' WHERE ([read].id = " + id + ")");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -