<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" Inherits="Ycbw.Data.OleDbClient"  %>

<%@ Register TagPrefix="Rajah" TagName="Head" src="../ctrls/Head.ascx" %>
<%@ Register TagPrefix="Rajah" TagName="Foot" src="../ctrls/Foot.ascx" %>

<script language="c#" runat="server">

private void Page_Load(object sender,EventArgs e)
{
	if( !Page.IsPostBack )
	{
		this.DataBind();
	
		if( Request.QueryString["add"] != null )
			Page.RegisterStartupScript("Add","<SCRIPT language=javascript>showAdd()<"+"/SCRIPT>");
	}
}

private void DataBind()
{
	//DataSource
	string sql = "Select * From [b_messages]";
	string filter = "";
	string order = " order by addtime desc";
	
	if( Request.QueryString["verify"] != null &&  Request.QueryString["verify"] != "")
		filter += " where verify = "+ Request.QueryString["verify"];

	this.BindGrid( sql + filter + order, "data_list", data_list, 18, text_pages);
}

private void data_list_PageChanged(object sender,DataGridPageChangedEventArgs e)
{
	((DataGrid)sender).CurrentPageIndex = e.NewPageIndex;
	this.DataBind();
}

private void button_edit_click(object sender,DataGridCommandEventArgs e)
{
	((DataGrid)sender).EditItemIndex = (int)e.Item.ItemIndex;
	this.DataBind();
}

private void button_update_click(object sender,DataGridCommandEventArgs e)
{
	string id       = ((TextBox)e.Item.FindControl("text_id")).Text;
	string reply  = ((TextBox)e.Item.FindControl("reply")).Text;

	this.Execute( "Update [b_messages] set [reply] = '"+ reply +"', verify = 1 where id = "+ id );
	
	((DataGrid)sender).EditItemIndex = -1;
	this.DataBind();	
}

private void button_cancel_click(object sender,DataGridCommandEventArgs e)
{
	((DataGrid)sender).EditItemIndex = -1;
	this.DataBind();	
}

private void data_delete_click(object sender,DataGridCommandEventArgs e)
{
	string id    = ((TextBox)e.Item.FindControl("text_id")).Text;
	
	this.Execute( "Delete from [b_messages] where id = "+ id );

	this.DataBind();	
}

private void button_delete_click(object sender, EventArgs e)
{
	this.Execute("delete from [b_messages] where id in ("+ Request["ids"] +")");
	
	this.DataBind();
}

private void button_verify_click(object sender,EventArgs e)
{
	this.Execute( "update [b_messages] set verify = 1 where id in ("+ Request["ids"] +")" );

	this.DataBind();	
}
</script>

<Rajah:Head ID="Head" Runat="Server" />
<form id="form1" runat="server">
<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="title3"><div style="float:left">留言管理</div>
      <div style="float:right"></div></td>
  </tr>
</table>

<table width="100%" align="center" border="0" cellspacing="8" cellpadding="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="table3">
        <tr>
          <td height="25">&nbsp;</td>
          <td align="right"><asp:Label ID="text_pages1" runat="server" /></td>
        </tr>
      </table>
      <asp:DataGrid ID="data_list" Width="100%" BorderWidth="0" CellPadding="0" CellSpacing="0" AutoGenerateColumns="false" runat="server" 
		CssClass="autotext" HeaderStyle-CssClass="header1" ItemStyle-CssClass="item1" 
		OnEditCommand="button_edit_click" OnUpdateCommand="button_update_click" OnCancelCommand="button_cancel_click" OnDeleteCommand="data_delete_click">
		<columns>
        <asp:TemplateColumn HeaderStyle-Width="24">
          <headertemplate>
            <input type="checkbox" onclick="checkAll(this)">
          </headertemplate>
          <itemtemplate>
            <input type="checkbox" name="ids" value="<%# Eval("id") %>">
            <asp:TextBox ID="text_id" Text='<%# DataBinder.Eval( Container.DataItem, "id" ) %>' Visible="false" runat="server" />
          </itemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderStyle-Width="100">
          <headertemplate>姓名</headertemplate>
          <itemtemplate><%# Eval( "nickname" ) %></itemtemplate>
          <edititemtemplate><%# Eval( "nickname" ) %></edititemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderStyle-Width="500">
          <headertemplate>留言内容</headertemplate>
          <itemtemplate><div class="hg20"><%# Eval( "content" ) %></div></itemtemplate>
          <edititemtemplate>
		  <div style="padding:5px; background:#FFFFEE; border:1px solid #cccccc">
		  <table width="90%" border="0" cellspacing="0" cellpadding="5">
			  <tr>
				<td>留言：</td>
				<td class="hg20"><%# Eval( "content" ) %></td>
			  </tr>
			  <tr>
				<td nowrap="nowrap" style="border-bottom:0">回复内容：</td>
				<td style="border-bottom:0"><asp:TextBox ID="reply" CssClass="text1" Text='<%# DataBinder.Eval( Container.DataItem, "reply" ).ToString() %>' Width="360" TextMode="MultiLine" Height="70" runat="server" /></td>
			  </tr>
			</table>
		  </div>
		  </edititemtemplate>
        </asp:TemplateColumn>

 
        <asp:TemplateColumn HeaderStyle-Width="100">
          <headertemplate>联系方式</headertemplate>
          <itemtemplate><%# Eval( "qq" ) %></itemtemplate>
          <edititemtemplate><%# Eval( "qq" ) %></edititemtemplate>
        </asp:TemplateColumn>

       <asp:TemplateColumn HeaderStyle-Width="100">
          <headertemplate>状态</headertemplate>
          <itemtemplate><%# Ycbw.Articles.GetVerify(Eval( "verify" )) %></itemtemplate>
          <edititemtemplate></edititemtemplate>
        </asp:TemplateColumn>

		<asp:TemplateColumn HeaderStyle-Width="130">
			<headertemplate>留言时间</headertemplate>
			<itemtemplate>
			  <span style="width:120px"><%# Eval("addtime") %></span>
			</itemtemplate>
		</asp:TemplateColumn>

        <asp:TemplateColumn HeaderStyle-Width="100%">
          <itemtemplate>
            <asp:LinkButton Text="回复" CommandName="edit" runat="server" />
            <span onclick="return confirm('确定要删除该条资料吗?')"><asp:LinkButton Text="删除" CommandName="delete" runat="server" /></span>
		  </itemtemplate>
          <edititemtemplate>
            <asp:LinkButton Text="确定" ForeColor="#FF0000" CommandName="update" runat="server" />
            <asp:LinkButton Text="取消" ForeColor="#FF0000" CommandName="cancel" runat="server" />
          </edititemtemplate>
        </asp:TemplateColumn>

		</columns>
	</asp:DataGrid>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="table3">
        <tr>
          <td>	<span onclick="return confirm('确定要删除吗？')"><asp:Button Text=" 删除所选 " OnClick="button_delete_click" runat="server" /></span>
	<span onclick="return confirm('确定要审核吗？')"><asp:Button Text=" 审核所选 " OnClick="button_verify_click" runat="server" /></span>
</td>
          <td align="right"><asp:Label ID="text_pages" runat="server" /></td>
        </tr>
      </table></td>
  </tr>
</table>
</form>
<Rajah:Foot ID="Foot" Runat="Server" />