留言本制作

留言管理页面

留言添加

回复留言页面

页面源码

留言管理页面源码

留言管理源码
  1 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  2     <script language="javascript" type="text/javascript">
  3         function ShowDiv(divName) {
  4             var chNodel = document.getElementById("itable").childNodes;
  5             if (typeof (chNodel) != "undefined") {
  6                 for (var i = 0; i < chNodel.length; i++) {
  7                     chNodel[i].style.display = 'none';
  8                 }
  9             }
 10             document.getElementById(divName).style.display = 'block';
 11         }
 12     </script>
 13 </asp:Content>
 14 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 15     <div id="icaption">
 16         <div id="title">
 17             客户留言板
 18         </div>
 19         <a href="AddLiuyan.aspx" id="btn_add"></a>
 20     </div>
 21     <div class="icaption">
 22         <div class="title">
 23             <a href="javascript:ShowDiv('div1')">未回复留言</a>|</div>
 24         <div class="title">
 25             <a href="javascript:ShowDiv('div2')">已回复留言</a>|</div>
 26         <div class="title">
 27             <a href="AddLiuyan.aspx" title="发布留言">发布留言</a></div>
 28     </div>
 29     <div id="itable">
 30         <div id="div1">
 31             <asp:DataList ID="dl" runat="server">
 32                 <ItemTemplate>
 33                     <table cellpadding="0" cellspacing="0">
 34                         <tr class="tr4">
 35                             <td class="td1" width="15%">
 36                                 留言人:
 37                             </td>
 38                             <td class="td1" width="85%">
 39                                 <%#Eval("username")%>
 40                             </td>
 41                         </tr>
 42                         <tr class="tr4">
 43                             <td class="td1" width="15%">
 44                                 留言日期:
 45                             </td>
 46                             <td class="td1" width="85%">
 47                                 <%#Eval("inpurttime")%>
 48                             </td>
 49                         </tr>
 50                         <tr class="tr4">
 51                             <td class="td1" width="15%">
 52                                 邮箱:
 53                             </td>
 54                             <td class="td1" width="85%">
 55                                 <%#Eval("useremail")%>
 56                             </td>
 57                         </tr>
 58                         <tr class="tr4">
 59                             <td class="td1" width="15%">
 60                                 留言内容:
 61                             </td>
 62                             <td class="td1" width="85%">
 63                                 <%#Eval("contents")%>
 64                             </td>
 65                         </tr>
 66                         <tr class="tr4">
 67                             <td class="td1" colspan="2">
 68                                 <a href="ReplayLiuYan.aspx?ID=<%#Eval("ID") %>" style="color: Blue;" title="回复留言">回复留言</a>
 69                             </td>
 70                         </tr>
 71                     </table>
 72                 </ItemTemplate>
 73             </asp:DataList></div>
 74         <div id="div2" style="display: none;">
 75             <asp:DataList ID="dl2" runat="server">
 76                 <ItemTemplate>
 77                     <table cellpadding="0" cellspacing="0">
 78                         <tr class="tr4">
 79                             <td class="td1" width="15%">
 80                                 留言人:
 81                             </td>
 82                             <td class="td1" width="85%">
 83                                 <%#Eval("username")%>
 84                             </td>
 85                         </tr>
 86                         <tr class="tr4">
 87                             <td class="td1" width="15%">
 88                                 留言日期:
 89                             </td>
 90                             <td class="td1" width="85%">
 91                                 <%#Eval("inpurttime")%>
 92                             </td>
 93                         </tr>
 94                         <tr class="tr4">
 95                             <td class="td1" width="15%">
 96                                 邮箱:
 97                             </td>
 98                             <td class="td1" width="85%">
 99                                 <%#Eval("useremail")%>
100                             </td>
101                         </tr>
102                         <tr class="tr4">
103                             <td class="td1" width="15%">
104                                 留言内容:
105                             </td>
106                             <td class="td1" width="85%">
107                                 <%#Eval("contents")%>
108                             </td>
109                         </tr>
110                     </table>
111                 </ItemTemplate>
112             </asp:DataList>
113         </div>
114     </div>
115 </asp:Content>

后台代码

View Code
 1   public partial class LiuYanMgst :  BasePage
 2     {
 3         NeoBLL.LiuYanBLL bll = new NeoBLL.LiuYanBLL();
 4         protected void Page_Load(object sender, EventArgs e)
 5         {
 6             if (!IsPostBack)
 7             {
 8                 BindGrid();
 9                 BindGrid1();
10             }
11         }
12 
13         public void BindGrid()
14         {
15             DataTable dt = bll.GetLiuYans("0");
16             this.dl.DataSource = dt;
17             this.dl.DataBind();
18         }
19         public void BindGrid1()
20         {
21             DataTable dt = bll.GetLiuYans("1");
22             this.dl2.DataSource = dt;
23             this.dl2.DataBind();
24         }
25     }

BLL

BLL
 1 namespace NeoBLL
 2 {
 3     public class LiuYanBLL
 4     {
 5         NeoDAL.LiuYanDAL dal = new NeoDAL.LiuYanDAL();
 6         public bool AddLiuYan(NeoModel.LiuyanModel model)
 7         {
 8             return dal.AddLiuYan(model);
 9         }
10         public DataTable GetLiuYans(string states)
11         {
12             return dal.GetLiuYans(states);
13         }
14         public DataTable GetLiuYanByID(string id)
15         {
16             return dal.GetLiuYanByID(id);
17         }
18         public bool UpdateLiuYan(NeoModel.LiuyanModel model)
19         {
20             return dal.UpdateLiuYan(model);
21         }
22     }
23 }

DAL

DAL
 1 namespace NeoDAL
 2 {
 3     public class LiuYanDAL
 4     {
 5         public LiuYanDAL()
 6         {
 7         }
 8 
 9         public bool AddLiuYan(NeoModel.LiuyanModel model)
10         {
11             string strSql = "insert into liuyan(username,useremail,contents,inpurttime,isreturn) values(@username,@useremail,@contents,GETDATE(),0)";
12             SqlParameter[] sp = { 
13                                 new SqlParameter("@username",model.UserName),
14                                 new SqlParameter("@useremail",model.UserEmail),
15                                 new SqlParameter("@contents",model.Contents)
16                                 };
17             return DbHelperSQL.ExecuteSql(strSql, sp)>0;
18         }
19 
20         public DataTable GetLiuYans(string states)
21         {
22             string strSql = string.Format("SELECT * from liuyan where isreturn={0} order by inpurttime desc", states);
23             DataSet ds = DbHelperSQL.Query(strSql);
24             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
25             {
26                 return new DataTable();
27             }
28             return ds.Tables[0];
29         }
30         public DataTable GetLiuYanByID(string id)
31         {
32             string strSql = string.Format("SELECT * from liuyan where ID={0}", id);
33             DataSet ds = DbHelperSQL.Query(strSql);
34             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
35             {
36                 return new DataTable();
37             }
38             return ds.Tables[0];
39         }
40 
41         public bool UpdateLiuYan(NeoModel.LiuyanModel model)
42         {
43             string strSql = "UPDATE  liuyan set isreturn=1 ,redate=GETDATE(),rename=@rename,recontents=@recontents where ID=@id";
44             SqlParameter[] sp = {
45                                 new SqlParameter("@rename",model.ReName),
46                                 new SqlParameter("@recontents",model.ReContents),
47                                 new SqlParameter("@id",model.ID)
48                                 };
49 
50             return DbHelperSQL.ExecuteSql(strSql, sp)>0;
51         }
52     }
53 }

留言添加页面源码

留言添加页面源码
 1 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 2     <style type="text/css">
 3         .publish_schedule
 4         {}
 5     </style>
 6 </asp:Content>
 7 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 8     <div id="icaption">
 9         <div id="title">
10             客户留言操作</div>
11         <asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox="true" ShowSummary="false"
12             runat="server" />
13         <a href="LiuYanMgst.aspx" id="btn_back"></a>
14     </div>
15     <div id="itable">
16         <table cellspacing="1" width="1026" align="center">
17             <tr class="tr4">
18                 <td class="td1" width="15%">
19                     用户名称:
20                 </td>
21                 <td width="85%">
22                     <asp:TextBox ID="txtUserName" CssClass="publish_schedule" runat="server" 
23                         Width="252px"></asp:TextBox>
24                 </td>
25             </tr>
26             <tr class="tr4">
27                 <td class="td1" width="15%">
28                     邮件:
29                 </td>
30                 <td width="85%">
31                     <asp:TextBox ID="txtEmail" runat="server" CssClass="publish_schedule" 
32                         Width="252px"></asp:TextBox>
33                 </td>
34             </tr>
35             <tr class="tr4">
36                 <td class="td1" width="15%">
37                     内容:
38                 </td>
39                 <td width="85%">
40                     <asp:TextBox ID="txtContent" CssClass="publish_schedule" runat="server" 
41                         Height="73px" TextMode="MultiLine" Width="252px"></asp:TextBox>
42                 </td>
43             </tr>
44             <tr class="btools">
45                 <td colspan="2">
46                     <asp:Button ID="btnSave" runat="server" Text="保存" CssClass="btn" OnClick="btnSave_Click" />
47                     <input type="button" name="btnCancel" class="btn" onclick="window.location.href='LiuYanMgst.aspx';"
48                         value="返回" />
49                 </td>
50             </tr>
51         </table>
52     </div>
53 </asp:Content>

后台

View Code
 1  public partial class AddLiuyan :BasePage
 2     {
 3         NeoBLL.LiuYanBLL bll = new NeoBLL.LiuYanBLL();
 4         protected void Page_Load(object sender, EventArgs e)
 5         {
 6 
 7         }
 8 
 9         protected void btnSave_Click(object sender, EventArgs e)
10         {
11             if (string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
12             {
13                 MessageBox(Page, "用户名称不能为空!");
14                 return;
15             }
16             if (string.IsNullOrEmpty(this.txtEmail.Text.Trim()))
17             {
18                 MessageBox(Page, "用户邮箱不能为空!");
19                 return;
20             }
21             if (string.IsNullOrEmpty(this.txtContent.Text.Trim()))
22             {
23                 MessageBox(Page, "留言内容不能为空!");
24                 return;
25             }
26             NeoModel.LiuyanModel model = new NeoModel.LiuyanModel();
27             model.Contents = this.txtContent.Text.Trim();
28             model.UserEmail = this.txtEmail.Text.Trim();
29             model.UserName = this.txtUserName.Text.Trim();
30             if (bll.AddLiuYan(model))
31             {
32                 string script = string.Format("alert('添加留言成功!');window.location.href='LiuYanMgst.aspx';");
33                 ScriptManager.RegisterStartupScript(Page, typeof(Page), DateTime.Now.ToString(), script, true);
34             }
35             else
36             {
37                 MessageBox(Page, "留言失败!");
38             }
39         }
40     }

回复留言源码

源码
 1 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 2 </asp:Content>
 3 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 4     <div id="icaption">
 5         <div id="title">
 6             回复客户留言操作</div>
 7         <asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox="true" ShowSummary="false"
 8             runat="server" />
 9         <a href="LiuYanMgst.aspx" id="btn_back"></a>
10     </div>
11     <div id="itable">
12         <table cellspacing="1" width="1026" align="center">
13             <tr class="tr4">
14                 <td class="td1" width="15%">
15                     留言人:
16                 </td>
17                 <td width="85%">
18                     <asp:TextBox ID="txtUserName" CssClass="publish_schedule" runat="server" Width="252px"></asp:TextBox>
19                 </td>
20             </tr>
21             <tr class="tr4">
22                 <td class="td1" width="15%">
23                     留言时间:
24                 </td>
25                 <td width="85%">
26                     <asp:TextBox ID="txtInputDate" runat="server" CssClass="publish_schedule" Width="252px"></asp:TextBox>
27                 </td>
28             </tr>
29             <tr class="tr4">
30                 <td class="td1" width="15%">
31                     留言内容:
32                 </td>
33                 <td width="85%">
34                     <asp:TextBox ID="txtContent" CssClass="publish_schedule" runat="server" Height="73px"
35                         TextMode="MultiLine" Width="252px"></asp:TextBox>
36                 </td>
37             </tr>
38             <tr class="tr4">
39                 <td class="td1" width="15%">
40                     回复人:
41                 </td>
42                 <td width="85%">
43                     <asp:TextBox ID="txtRePerson" runat="server" CssClass="publish_schedule" Width="252px"></asp:TextBox>
44                 </td>
45             </tr>
46             <tr class="tr4">
47                 <td class="td1" width="15%">
48                     回复内容:
49                 </td>
50                 <td width="85%">
51                     <asp:TextBox ID="txtReContent" runat="server" Height="73px"  Width="252px" CssClass="publish_schedule" TextMode="MultiLine"></asp:TextBox>
52                 </td>
53             </tr>
54             <tr class="btools">
55                 <td colspan="2">
56                     <asp:Button ID="btnSave" runat="server" Text="保存" CssClass="btn" OnClick="btnSave_Click" />
57                     <input type="button" name="btnCancel" class="btn" onclick="window.location.href='LiuYanMgst.aspx';"
58                         value="返回" />
59                 </td>
60             </tr>
61         </table>
62     </div>
63 </asp:Content>

后台

后台
 1  public partial class ReplayLiuYan : BasePage
 2     {
 3         NeoBLL.LiuYanBLL bll = new NeoBLL.LiuYanBLL();
 4         protected void Page_Load(object sender, EventArgs e)
 5         {
 6             if (!IsPostBack)
 7             {
 8                 BindData();
 9             }
10         }
11         public string ID
12         {
13             get { return Request.QueryString["ID"]; }
14         }
15         public void BindData()
16         {
17             DataTable dt = bll.GetLiuYanByID(ID);
18             if (dt == null || dt.Rows.Count <= 0)
19             {
20                 return;
21             }
22             this.txtUserName.Text = dt.Rows[0]["username"].ToString();
23             this.txtContent.Text = dt.Rows[0]["contents"].ToString();
24             this.txtInputDate.Text = dt.Rows[0]["inpurttime"].ToString();
25             this.txtUserName.Enabled = false;
26             this.txtContent.Enabled = false;
27             this.txtInputDate.Enabled = false;
28         }
29 
30         protected void btnSave_Click(object sender, EventArgs e)
31         {
32             if (string.IsNullOrEmpty(this.txtRePerson.Text.Trim()))
33             {
34                 return;
35             }
36             if (string.IsNullOrEmpty(this.txtReContent.Text.Trim()))
37             {
38                 return;
39             }
40             NeoModel.LiuyanModel model = new NeoModel.LiuyanModel();
41             model.ID = int.Parse(ID);
42             model.ReName = this.txtRePerson.Text.Trim();
43             model.ReContents = this.txtReContent.Text.Trim();
44             if (bll.UpdateLiuYan(model))
45             {
46                 string script = string.Format("alert('回复留言成功!');window.location.href='LiuYanMgst.aspx';");
47                 ScriptManager.RegisterStartupScript(Page, typeof(Page), DateTime.Now.ToString(), script, true);
48             }
49             else
50             {
51                 MessageBox(Page, "回复留言失败!");
52             }
53         }
54     }
原文地址:https://www.cnblogs.com/hfliyi/p/2699299.html