📄 guestbookadmin.ascx.cs
字号:
namespace Seaskyer.WebApp.skyNews.Pages.UserMSC
{
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// GuestbookAdmin : 留言信息管理。
/// </summary>
public class GuestbookAdmin : basePage
{
protected DataGrid DataGrid1;
protected Label searchLabel, label1 ,pageLabel;
protected Panel Replay;
protected Label Title;
protected TextBox ReplayContent;
protected RadioButtonList isDisplay;
private void Page_Load(object sender, System.EventArgs e)
{
if( !power.GPB("Admin") )
{
base.strError.Add(lang["sharePage", "denyViewErrorInfo"]);
return;
}
this.InitPage();
if( !Object.Equals(Request.QueryString["id"], null) && !Object.Equals(Request.QueryString["id"], "") )
{
// == 开始回复留言 ==
Replay.Visible = true;
dp.CommandText = cmd["Guestbook", "SELECT_INDEX"];
dp.Parameter.Add("id", Request.QueryString["id"]);
DataTable dt = dp.DataTableSQL();
// 数据绑定
if( dt.Rows.Count == 1 )
{
Title.Text = dt.Rows[0]["title"].ToString();
ReplayContent.Text = dt.Rows[0]["replay"].ToString();
for( int i = 0; i < isDisplay.Items.Count; i++ )
{
if( isDisplay.Items[i].Value == dt.Rows[0]["isdisplay"].ToString() )
isDisplay.Items[i].Selected = true;
else
isDisplay.Items[i].Selected = false;
}
}
dt.Clear();
dt.Dispose();
}
else
{
this.BindData();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
/// <summary>
/// 初始化页面
/// </summary>
void InitPage()
{
//searchLabel.Visible = false;
label1.Visible = false;
pageLabel.Visible = false;
DataGrid1.Visible = false;
Replay.Visible = false;
}
#endregion
void BindData()
{
if( Object.Equals(Request.QueryString["type"], null) || Object.Equals(Request.QueryString["type"], "") )
{
// 非搜索页面数据绑定
this.GridBind();
}
else
{
// 搜索页面数据绑定
//this.SearchGridBind();
}
}
#region 绑定数据
void GridBind()
{
dp.CommandText = cmd["Guestbook", "COUNT"];
bind.totalRecord = dp.ScalarSQL();
if( bind.totalRecord == 0 )
{
label1.Text = "还没有任何留言信息"; label1.ForeColor = Color.Red;
label1.Visible = true;
}
else
{
dp.CommandText = cmd["Guestbook", "SELECT"];
bind.BindInfo_SplitPageDataGrid(DataGrid1, dp, "");
pageLabel.Text = base.GetSplitPageString("/skyNews/UserMSC/GuestbookAdmin.aspx?");
pageLabel.Visible = true;
}
}
#endregion
#region 去掉DataGrid1的EnableViewState属性,减少发向客户端的数据
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
//DataGrid1.Controls[0].EnableViewState = false;
}
#endregion
#region 响应删除事件
protected void Delete_OnClick(object sender, EventArgs e)
{
if( Object.Equals(Request.Form["chk"], null) || Object.Equals(Request.Form["chk"], "") )
{
label1.Text = "请先选中要删除的记录(可多选)"; label1.ForeColor = Color.Red;
}
else
{
dp.CommandText = String.Format(cmd["Guestbook", "DELETE"], Request.Form["chk"].ToString());
int delNum = dp.NonQuerySQL();
if( delNum > 0)
{
label1.Text = delNum + "条记录删除成功!"; label1.ForeColor = Color.BlueViolet;
this.BindData();
}
else
{
label1.Text = "删除失败 ..."; label1.ForeColor = Color.Red;
}
}
label1.Visible = true;
}
#endregion
#region 响应回复留言事件
protected void Submit_OnClick(object sender, EventArgs e)
{
this.InitPage();
// 数据更新
dp.CommandText = "UPDATE [Guestbook] SET replay = @replay, isdisplay = @isdisplay WHERE id = @id";
dp.Parameter.Add("replay", ReplayContent.Text);
dp.Parameter.Add("isdisplay", isDisplay.SelectedValue);
dp.Parameter.Add("id", Request.QueryString["id"]);
if( dp.NonQuerySQL() == 1 )
{
label1.Text = "回复留言成功!"; label1.ForeColor = Color.BlueViolet;
this.BindData();
}
else
{
label1.Text = "回复留言失败"; label1.ForeColor = Color.Red;
}
label1.Visible = true;
this.GridBind();
}
#endregion
#region 初始化DataGrid中子控件的属性
protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemIndex >= 0)
{
e.Item.Attributes.Add("onmouseover","this.className='tdbg-dark';");
e.Item.Attributes.Add("onmouseout","this.className='tdbg';");
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -