|
public partial class Admin : System.Web.UI.Page
{
GuestBookDataContext ctx = new GuestBookDataContext("server=xxx;database=GuestBook;uid=xxx;pwd=xxx");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetBind();
}
}
private void SetBind()
{
rpt_Message.DataSource = from gb in ctx.tbGuestBooks orderby gb.PostTime descending select gb;
rpt_Message.DataBind();
}
protected void rpt_Message_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "DeleteMessage")
{
StreamWriter sw = new StreamWriter(Server.MapPath("log.txt"), true);
ctx.Log = sw;
tbGuestBook gb = ctx.tbGuestBooks.Single(b => b.ID == new Guid(e.CommandArgument.ToString()));
ctx.tbGuestBooks.Remove(gb);
ctx.SubmitChanges();
SetBind();
sw.Close();
}
if (e.CommandName == "SendReply")
{
StreamWriter sw = new StreamWriter(Server.MapPath("log.txt"), true);
ctx.Log = sw;
tbGuestBook gb = ctx.tbGuestBooks.Single(b => b.ID == new Guid(e.CommandArgument.ToString()));
gb.Reply = ((TextBox)e.Item.FindControl("tb_Reply")).Text;
gb.IsReplied = true;
ctx.SubmitChanges();
SetBind();
sw.Close();
}
}
}
|