using System;
using System.Collections.Generic;
using System.Text;
using ZeroStudio.DBUtility;
using System.Data;
namespace ZeroStudio.DAL
{
public class GuestBook
{
public GuestBook()
{ }
#region 成员方法
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int G_Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from GuestBook");
strSql.Append(" where G_Id=" + G_Id + " ");
return DbHelperOledb.Exists(strSql.ToString());
}
/// <summary>
/// 返回留言条数
/// </summary>
/// <returns></returns>
public int Count()
{
StringBuilder sql = new StringBuilder();
sql.Append("select count(1) from GuestBook");
return Convert.ToInt32(DbHelperOledb.ExecuteScalar(sql.ToString()));
}
/// <summary>
/// 增加一条数据
/// </summary>
public void Add(ZeroStudio.Model.GuestBook model)
{
StringBuilder strSql = new StringBuilder();
StringBuilder strSql1 = new StringBuilder();
StringBuilder strSql2 = new StringBuilder();
if (model.G_Id != null)
{
strSql1.Append("G_Id,");
strSql2.Append("" + model.G_Id + ",");
}
if (model.G_Title != null)
{
strSql1.Append("G_Title,");
strSql2.Append("'" + model.G_Title + "',");
}
if (model.G_CompanyName != null)
{
strSql1.Append("G_CompanyName,");
strSql2.Append("'" + model.G_CompanyName + "',");
}
if (model.G_Username != null)
{
strSql1.Append("G_Username,");
strSql2.Append("'" + model.G_Username + "',");
}
if (model.G_Tel != null)
{
strSql1.Append("G_Tel,");
strSql2.Append("'" + model.G_Tel + "',");
}
if (model.G_Email != null)
{
strSql1.Append("G_Email,");
strSql2.Append("'" + model.G_Email + "',");
}
if (model.G_QQ != null)
{
strSql1.Append("G_QQ,");
strSql2.Append("'" + model.G_QQ + "',");
}
if (model.G_Content != null)
{
strSql1.Append("G_Content,");
strSql2.Append("'" + model.G_Content + "',");
}
if (model.G_Reply != null)
{
strSql1.Append("G_Reply,");
strSql2.Append("'" + model.G_Reply + "',");
}
if (model.G_Datetime != null)
{
strSql1.Append("G_Datetime,");
strSql2.Append("'" + model.G_Datetime + "',");
}
strSql.Append("insert into GuestBook(");
strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
strSql.Append(")");
strSql.Append(" values (");
strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
strSql.Append(")");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(ZeroStudio.Model.GuestBook model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update GuestBook set ");
if (model.G_Id != null)
{
strSql.Append("G_Id=" + model.G_Id + ",");
}
if (model.G_Title != null)
{
strSql.Append("G_Title='" + model.G_Title + "',");
}
if (model.G_CompanyName != null)
{
strSql.Append("G_CompanyName='" + model.G_CompanyName + "',");
}
if (model.G_Username != null)
{
strSql.Append("G_Username='" + model.G_Username + "',");
}
if (model.G_Tel != null)
{
strSql.Append("G_Tel='" + model.G_Tel + "',");
}
if (model.G_Email != null)
{
strSql.Append("G_Email='" + model.G_Email + "',");
}
if (model.G_QQ != null)
{
strSql.Append("G_QQ='" + model.G_QQ + "',");
}
if (model.G_Content != null)
{
strSql.Append("G_Content='" + model.G_Content + "',");
}
if (model.G_Reply != null)
{
strSql.Append("G_Reply='" + model.G_Reply + "',");
}
if (model.G_Datetime != null)
{
strSql.Append("G_Datetime='" + model.G_Datetime + "',");
}
int n = strSql.ToString().LastIndexOf(",");
strSql.Remove(n, 1);
strSql.Append(" where G_Id=" + model.G_Id + " ");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 删除一条数据
/// </summary>
public void Delete(int G_Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from GuestBook ");
strSql.Append(" where G_Id=" + G_Id + " ");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public ZeroStudio.Model.GuestBook GetModel(int G_Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
strSql.Append(" G_Id,G_Title,G_CompanyName,G_Username,G_Tel,G_Email,G_QQ,G_Content,G_Reply,G_Datetime ");
strSql.Append(" from GuestBook ");
strSql.Append(" where G_Id=" + G_Id + " ");
ZeroStudio.Model.GuestBook model = new ZeroStudio.Model.GuestBook();
DataSet ds = DbHelperOledb.Query(strSql.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["G_Id"].ToString() != "")
{
model.G_Id = int.Parse(ds.Tables[0].Rows[0]["G_Id"].ToString());
}
model.G_Title = ds.Tables[0].Rows[0]["G_Title"].ToString();
model.G_CompanyName = ds.Tables[0].Rows[0]["G_CompanyName"].ToString();
model.G_Username = ds.Tables[0].Rows[0]["G_Username"].ToString();
model.G_Tel = ds.Tables[0].Rows[0]["G_Tel"].ToString();
model.G_Email = ds.Tables[0].Rows[0]["G_Email"].ToString();
model.G_QQ = ds.Tables[0].Rows[0]["G_QQ"].ToString();
model.G_Content = ds.Tables[0].Rows[0]["G_Content"].ToString();
model.G_Reply = ds.Tables[0].Rows[0]["G_Reply"].ToString();
if (ds.Tables[0].Rows[0]["G_Datetime"].ToString() != "")
{
model.G_Datetime = DateTime.Parse(ds.Tables[0].Rows[0]["G_Datetime"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select G_Id,G_Title,G_CompanyName,G_Username,G_Tel,G_Email,G_QQ,G_Content,G_Reply,G_Datetime ");
strSql.Append(" FROM GuestBook ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by G_ID desc");
return DbHelperOledb.Query(strSql.ToString());
}
/*
*/
#endregion 成员方法
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using ZeroStudio.DAL;
namespace ZeroStudio.BLL
{
public class GuestBook
{
private readonly DAL.GuestBook dal = new ZeroStudio.DAL.GuestBook();
public GuestBook()
{ }
#region 成员方法
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int G_Id)
{
return dal.Exists(G_Id);
}
/// <summary>
/// 返回留言条数
/// </summary>
/// <returns></returns>
public int Count()
{
return dal.Count();
}
/// <summary>
/// 增加一条数据
/// </summary>
public void Add(ZeroStudio.Model.GuestBook model)
{
dal.Add(model);
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(ZeroStudio.Model.GuestBook model)
{
dal.Update(model);
}
/// <summary>
/// 删除一条数据
/// </summary>
public void Delete(int G_Id)
{
dal.Delete(G_Id);
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public ZeroStudio.Model.GuestBook GetModel(int G_Id)
{
return dal.GetModel(G_Id);
}
/// <summary>
/// 得到一个对象实体,从缓存中。
/// </summary>
public ZeroStudio.Model.GuestBook GetModelByCache(int G_Id)
{
/*
string CacheKey = "GuestBookModel-" + G_Id;
object objModel = LTP.Common.DataCache.GetCache(CacheKey);
if (objModel == null)
{
try
{
objModel = dal.GetModel(G_Id);
if (objModel != null)
{
int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
}
}
catch { }
}
return (ZeroStudio.Model.GuestBook)objModel;
*/
return null;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
return dal.GetList(strWhere);
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
//return dal.GetList(Top, strWhere, filedOrder);
return null;
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<ZeroStudio.Model.GuestBook> GetModelList(string strWhere)
{
DataSet ds = dal.GetList(strWhere);
return DataTableToList(ds.Tables[0]);
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<ZeroStudio.Model.GuestBook> DataTableToList(DataTable dt)
{
List<ZeroStudio.Model.GuestBook> modelList = new List<ZeroStudio.Model.GuestBook>();
int rowsCount = dt.Rows.Count;
if (rowsCount > 0)
{
ZeroStudio.Model.GuestBook model;
for (int n = 0; n < rowsCount; n++)
{
model = new ZeroStudio.Model.GuestBook();
if (dt.Rows[n]["G_Id"].ToString() != "")
{
model.G_Id = int.Parse(dt.Rows[n]["G_Id"].ToString());
}
model.G_Title = dt.Rows[n]["G_Title"].ToString();
model.G_CompanyName = dt.Rows[n]["G_CompanyName"].ToString();
model.G_Username = dt.Rows[n]["G_Username"].ToString();
model.G_Tel = dt.Rows[n]["G_Tel"].ToString();
model.G_Email = dt.Rows[n]["G_Email"].ToString();
model.G_QQ = dt.Rows[n]["G_QQ"].ToString();
model.G_Content = dt.Rows[n]["G_Content"].ToString();
model.G_Reply = dt.Rows[n]["G_Reply"].ToString();
if (dt.Rows[n]["G_Datetime"].ToString() != "")
{
model.G_Datetime = DateTime.Parse(dt.Rows[n]["G_Datetime"].ToString());
}
modelList.Add(model);
}
}
return modelList;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetAllList()
{
return GetList("");
}
/// <summary>
/// 获得数据列表
/// </summary>
//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
//{
//return dal.GetList(PageSize,PageIndex,strWhere);
//}
#endregion 成员方法
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ZeroStudio.Model
{
public class GuestBook
{
public GuestBook()
{ }
#region Model
private int? _g_id;
private string _g_title;
private string _g_companyname;
private string _g_username;
private string _g_tel;
private string _g_email;
private string _g_qq;
private string _g_content;
private string _g_reply;
private DateTime _g_datetime;
/// <summary>
///
/// </summary>
public int? G_Id
{
set { _g_id = value; }
get { return _g_id; }
}
/// <summary>
///
/// </summary>
public string G_Title
{
set { _g_title = value; }
get { return _g_title; }
}
/// <summary>
///
/// </summary>
public string G_CompanyName
{
set { _g_companyname = value; }
get { return _g_companyname; }
}
/// <summary>
///
/// </summary>
public string G_Username
{
set { _g_username = value; }
get { return _g_username; }
}
/// <summary>
///
/// </summary>
public string G_Tel
{
set { _g_tel = value; }
get { return _g_tel; }
}
/// <summary>
///
/// </summary>
public string G_Email
{
set { _g_email = value; }
get { return _g_email; }
}
/// <summary>
///
/// </summary>
public string G_QQ
{
set { _g_qq = value; }
get { return _g_qq; }
}
/// <summary>
///
/// </summary>
public string G_Content
{
set { _g_content = value; }
get { return _g_content; }
}
/// <summary>
///
/// </summary>
public string G_Reply
{
set { _g_reply = value; }
get { return _g_reply; }
}
/// <summary>
///
/// </summary>
public DateTime G_Datetime
{
set { _g_datetime = value; }
get { return _g_datetime; }
}
#endregion Model
}
}
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Manage.aspx.cs" Inherits="ZeroStudio.Web.Admin.GuestBook.Manage" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="../Css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="800" align="center" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse">
<tr>
<td class="lanyuss" align="center" colspan="6" style="height: 22px">
留言管理</td>
</tr>
<asp:Repeater ID="rpt_list" runat="server">
<ItemTemplate>
<tr>
<td height="1"></td>
</tr>
<tr>
<td class="lanyuds" align="left" width="44%">
主题:<%#Eval("G_title") %></td>
<td width="16%" align="center" class="lanyuds">
留言人:<%#Eval("G_username") %></td>
<td width="11%" align="center" class="lanyuds">
电话:<%#Eval("G_tel") %></td>
<td width="7%" align="center" class="lanyuds">
QQ:<%#Eval("G_QQ")%></td>
<td width="7%" align="center" class="lanyuds">
Email:<%#Eval("G_email")%></td>
<td width="15%" rowspan="2" align="center" class="lanyuds">
<asp:LinkButton ID="Del" CommandName='<%#Eval("G_id") %>' runat="server" OnCommand="Del_Click"
OnClientClick="return confirm('确定删除?')">删除
</asp:LinkButton></td>
</tr>
<tr>
<td colspan="5" align="left" class="lanyuds">
留言内容:<br />
<%#Eval("G_content") %></td>
</tr>
<tr>
<td colspan="6" align="left" class="lanyuds">留言时间:<%#Eval("G_datetime") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td class="lanyuds" colspan="6" align="center">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" LastPageText="尾页"
NextPageText="下一页" PrevPageText="上一页" OnPageChanged="AspNetPager1_PageChanged">
</webdiyer:AspNetPager>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
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;
using ZeroStudio.Helper;
namespace ZeroStudio.Web.Admin.GuestBook
{
public partial class Manage : System.Web.UI.Page
{
BLL.GuestBook bll = new BLL.GuestBook();
protected void Page_Load(object sender, EventArgs e)
{
CommonFunction.IsAdmin();
AspNetPager1.RecordCount = bll.Count();
Bind();
}
protected void Bind()
{
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = bll.GetAllList().Tables[0].DefaultView;
rpt_list.DataSource = pds;
rpt_list.DataBind();
}
protected void Del_Click(object sender, CommandEventArgs e)
{
string id = e.CommandName;
bll.Delete(Convert.ToInt32(id));
Bind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Bind();
}
}
}