工作中点滴记录

永远保持学徒心态

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

通常新闻信息板块后台管理程序主要有 图片新闻信息维护,普通新闻信息维护,滚动新闻信息维护。

页面截图如下:

 

 

前台代码
  1 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  2     <link href="../styles/admin.css" rel="stylesheet" type="text/css" />
  3     <script language="javascript" type="text/javascript">
  4         function showDiv(divName, hidValue) {
  5             var childDiv = document.getElementById("parentID").childNodes;
  6             if (typeof (childDiv) != "undefined") {
  7                 for (var i = 0; i < childDiv.length; i++) {
  8                     childDiv[i].style.display = 'none';
  9                 }
 10                 document.getElementById(divName).style.display = 'block';
 11             }
 12             document.getElementById(divName).style.display = 'block';
 13             document.getElementById("MainContent_hidMenu").value = hidValue;
 14         }
 15         
 16     </script>
 17 </asp:Content>
 18 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 19     <div id="icaption">
 20         <div id="title">
 21             新闻管理
 22         </div>
 23     </div>
 24     <div class="icaption">
 25         <div class="title">
 26             <a href="javascript:showDiv('div1','0')">图片新闻</a>|
 27         </div>
 28         <div class="title">
 29             <a href="javascript:showDiv('div2','1')">普通新闻</a>|
 30         </div>
 31         <div class="title">
 32             <a href="javascript:showDiv('div3','2')">滚动新闻</a>
 33         </div>
 34     </div>
 35     <asp:HiddenField ID="hidMenu" runat="server" Value="0" />
 36     <div id="parentID">
 37         <div id="div1" class="itable">
 38             图片新闻
 39             <asp:GridView ID="gv1" runat="server" GridLines="None" BorderWidth="0px" CellPadding="0"
 40                 CellSpacing="1" align="center" AutoGenerateColumns="false">
 41                 <Columns>
 42                     <asp:BoundField HeaderText="标题" DataField="title" />
 43                     <asp:BoundField HeaderText="作者" DataField="author" />
 44                     <asp:BoundField HeaderText="编辑" DataField="editer" />
 45                     <asp:BoundField HeaderText="发布日期" DataField="dates" DataFormatString="{0:yyyy-MM-dd}" />
 46                     <asp:TemplateField HeaderText="查看">
 47                         <ItemTemplate>
 48                             <a href="AddNews.aspx?tb=tb_leftup_pic&id=<%#Eval("id") %>">查看</a>
 49                         </ItemTemplate>
 50                     </asp:TemplateField>
 51                 </Columns>
 52                 <RowStyle CssClass="tr3" Font-Size="12px" Height="28px" />
 53                 <HeaderStyle CssClass="itable_title" />
 54                 <EmptyDataTemplate>
 55                     <tr class="itable_title">
 56                         <th width="20%">
 57                             标题
 58                         </th>
 59                         <th width="20%">
 60                             作者
 61                         </th>
 62                         <th width="20%">
 63                             编辑
 64                         </th>
 65                         <th width="20%">
 66                             发布日期
 67                         </th>
 68                         <th width="20%">
 69                             查看
 70                         </th>
 71                     </tr>
 72                     <tr class="tr3">
 73                         <td class="grid_no_result" colspan="5">
 74                             <span>当前没有查询记录</span>
 75                         </td>
 76                     </tr>
 77                 </EmptyDataTemplate>
 78             </asp:GridView>
 79         </div>
 80         <div id="div2" class="itable" style="display: none;">
 81             普通新闻
 82             <asp:GridView ID="gv2" runat="server" GridLines="None" BorderWidth="0px" CellPadding="0"
 83                 CellSpacing="1" align="center" AutoGenerateColumns="false">
 84                 <Columns>
 85                     <asp:BoundField HeaderText="标题" DataField="title" />
 86                     <asp:BoundField HeaderText="作者" DataField="author" />
 87                     <asp:BoundField HeaderText="编辑" DataField="editer" />
 88                     <asp:BoundField HeaderText="发布日期" DataField="dates" DataFormatString="{0:yyyy-MM-dd}" />
 89                     <asp:TemplateField HeaderText="查看">
 90                         <ItemTemplate>
 91                             <a href="AddNews.aspx?tb=tb_sj_news&id=<%#Eval("id") %>">查看</a>
 92                         </ItemTemplate>
 93                     </asp:TemplateField>
 94                 </Columns>
 95                 <RowStyle CssClass="tr3" Font-Size="12px" Height="28px" />
 96                 <HeaderStyle CssClass="itable_title" />
 97                 <EmptyDataTemplate>
 98                     <tr class="itable_title">
 99                         <th width="20%">
100                             标题
101                         </th>
102                         <th width="20%">
103                             作者
104                         </th>
105                         <th width="20%">
106                             编辑
107                         </th>
108                         <th width="20%">
109                             发布日期
110                         </th>
111                         <th width="20%">
112                             查看
113                         </th>
114                     </tr>
115                     <tr class="tr3">
116                         <td class="grid_no_result" colspan="5">
117                             <span>当前没有查询记录</span>
118                         </td>
119                     </tr>
120                 </EmptyDataTemplate>
121             </asp:GridView>
122         </div>
123         <div id="div3" class="itable" style="display: none;">
124             滚动新闻
125             <asp:GridView ID="gv3" runat="server" GridLines="None" BorderWidth="0px" CellPadding="0"
126                 CellSpacing="1" align="center" AutoGenerateColumns="false">
127                 <Columns>
128                     <asp:BoundField HeaderText="标题" DataField="title" />
129                     <asp:BoundField HeaderText="作者" DataField="author" />
130                     <asp:BoundField HeaderText="编辑" DataField="editer" />
131                     <asp:BoundField HeaderText="发布日期" DataField="dates" DataFormatString="{0:yyyy-MM-dd}" />
132                     <asp:TemplateField HeaderText="查看">
133                         <ItemTemplate>
134                             <a href="AddNews.aspx?tb=tb_jobdynamic&id=<%#Eval("id") %>">查看</a>
135                         </ItemTemplate>
136                     </asp:TemplateField>
137                 </Columns>
138                 <RowStyle CssClass="tr3" Font-Size="12px" Height="28px" />
139                 <HeaderStyle CssClass="itable_title" />
140                 <EmptyDataTemplate>
141                     <tr class="itable_title">
142                         <th width="20%">
143                             标题
144                         </th>
145                         <th width="20%">
146                             作者
147                         </th>
148                         <th width="20%">
149                             编辑
150                         </th>
151                         <th width="20%">
152                             发布日期
153                         </th>
154                         <th width="20%">
155                             查看
156                         </th>
157                     </tr>
158                     <tr class="tr3">
159                         <td class="grid_no_result" colspan="5">
160                             <span>当前没有查询记录</span>
161                         </td>
162                     </tr>
163                 </EmptyDataTemplate>
164             </asp:GridView>
165         </div>
166     </div>
167     <div class="btools">
168         <asp:Button ID="btn_ShowOrder" runat="server" Text="添加" CssClass="btn" OnClick="btn_add_Click" />
169     </div>
170 </asp:Content>

后台代码:

后台
  1   public partial class NewsMgst :BasePage
  2     {
  3         NeoBLL.TbsjNewsBLL tbsjBll = new NeoBLL.TbsjNewsBLL();
  4         NeoBLL.TbjobdynamicBLL jobBll = new NeoBLL.TbjobdynamicBLL();
  5         NeoBLL.TbLeftUpPicBLL picBll = new NeoBLL.TbLeftUpPicBLL();
  6         protected void Page_Load(object sender, EventArgs e)
  7         {
  8             if (!IsPostBack)
  9             {
 10                 BindGrid();
 11                 BindJobDynamicGrid();
 12                 BindLeftUpPic();
 13             }
 14         }
 15 
 16         protected void btn_add_Click(object sender, EventArgs e)
 17         {
 18             string strUrl = "AddNews.aspx";
 19             if (this.hidMenu.Value == "0")
 20             {
 21                 strUrl += "?tb=tb_leftup_pic";
 22             }
 23             else if (this.hidMenu.Value == "1")
 24             {
 25                 strUrl += "?tb=tb_sj_news";
 26             }
 27             else
 28             {
 29                 strUrl += "?tb=tb_jobdynamic";
 30             }
 31             Response.Redirect(strUrl);
 32         }
 33         public void BindGrid()
 34         {
 35             DataTable dt = jobBll.GetTbJobDynamic();
 36             this.gv3.DataSource = dt;
 37             this.gv3.DataBind();
 38         }
 39         public void BindJobDynamicGrid()
 40         {
 41             DataTable dt = tbsjBll.GetTbsjNews();
 42             this.gv2.DataSource = dt;
 43             this.gv2.DataBind();
 44         }
 45 
 46         public void BindLeftUpPic()
 47         {
 48             DataTable dt = picBll.GetTbLeftUpPics();
 49             this.gv1.DataSource = dt;
 50             this.gv1.DataBind();
 51         }
 52     }
 53 ------------------------------------------
 54 namespace NeoBLL
 55 {
 56     public class TbjobdynamicBLL
 57     {
 58         NeoDAL.TbjobdynamicDAL dal = new NeoDAL.TbjobdynamicDAL();
 59         public TbjobdynamicBLL()
 60         {
 61         }
 62         public DataTable GetTbJobDynamic()
 63         {
 64             return dal.GetTbJobDynamic();
 65         }
 66     }
 67 }
 68 ------------------------------
 69 namespace NeoDAL
 70 {
 71     public class TbjobdynamicDAL
 72     {
 73         public TbjobdynamicDAL()
 74         {
 75         }
 76         public DataTable GetTbJobDynamic()
 77         {
 78             string strSql = "SELECT * FROM tb_jobdynamic";
 79             DataSet ds = DbHelperSQL.Query(strSql);
 80             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
 81             {
 82                 return new DataTable();
 83             }
 84             return ds.Tables[0];
 85         }
 86     }
 87 }
 88 ---------------------------
 89 namespace NeoBLL
 90 {
 91     public class TbsjNewsBLL
 92     {
 93         NeoDAL.TbsjNewsDAL dal = new NeoDAL.TbsjNewsDAL();
 94         public TbsjNewsBLL()
 95         {
 96         }
 97 
 98         public bool AddTbsjNews(string strSql, SqlParameter[] sp)
 99         {
100             return dal.AddTbsjNews(strSql,sp);
101         }
102         public DataTable GetTbsjNews()
103         {
104             return dal.GetTbsjNews();
105         }
106     }
107 }
108 ----------------------------
109 namespace NeoDAL
110 {
111     public class TbsjNewsDAL
112     {
113         public TbsjNewsDAL()
114         {
115         }
116 
117 
118         public bool AddTbsjNews(string strSql,SqlParameter[]sp)
119         {
120             return DbHelperSQL.ExecuteSql(strSql, sp) > 0;
121         }
122 
123         public DataTable GetTbsjNews()
124         {
125             string strSql = "SELECT * FROM tb_sj_news";
126             DataSet ds = DbHelperSQL.Query(strSql);
127             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
128             {
129                 return new DataTable();
130             }
131             return ds.Tables[0];
132         }
133     }
134 }
135 --------------------------
136 namespace NeoBLL
137 {
138    public  class TbLeftUpPicBLL
139     {
140        NeoDAL.TbLeftUpPicDAL dal = new NeoDAL.TbLeftUpPicDAL();
141        public TbLeftUpPicBLL()
142        {
143        }
144        public DataTable GetTbLeftUpPics()
145        {
146            return dal.GetTbLeftUpPics();
147        }
148        public DataTable GetNewsByID(string sql)
149        {
150            return dal.GetNewsByID(sql);
151        }
152        public bool UpdateNewsByID(string sql, SqlParameter[] sp)
153        {
154            return dal.UpdateNewsByID(sql, sp);
155        }
156     }
157 }
158 ----------------------------------
159 namespace NeoDAL
160 {
161     public class TbLeftUpPicDAL
162     {
163         public TbLeftUpPicDAL()
164         {
165         }
166         public DataTable GetTbLeftUpPics()
167         {
168             string strSql = "SELECT * FROM tb_leftup_pic";
169             DataSet ds = DbHelperSQL.Query(strSql);
170             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
171             {
172                 return new DataTable();
173             }
174             return ds.Tables[0];
175         }
176         public DataTable GetNewsByID(string sql)
177         {
178             DataSet ds = DbHelperSQL.Query(sql);
179             if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
180             {
181                 return new DataTable();
182             }
183             return ds.Tables[0];
184         }
185         public bool UpdateNewsByID(string sql, SqlParameter[] sp)
186         {
187             return DbHelperSQL.ExecuteSql(sql, sp) > 0;
188         }
189     }
190 }

添加新闻页面

源:

  1 <%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>
  2 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  3     <%--  <link href="../styles/admin1.css" rel="stylesheet" type="text/css" />--%>
  4     <style type="text/css">
  5         .tr4
  6         {
  7             height: 28px;
  8             text-align: left;
  9             font-size: 12px;
 10             line-height: 20px;
 11             background: #ffffff;
 12         }
 13         .tr4 .td1
 14         {
 15             text-align: left;
 16             text-indent: 24px;
 17         }
 18         #icaption
 19         {
 20             width: 1004px;
 21             height: 25px;
 22             margin-left: 10px;
 23             padding: 10px;
 24             font-weight: bold;
 25             font-size: 14px;
 26             text-align: left;
 27             border: 1px dotted #cdcdcd;
 28             background: #FBFBFB;
 29         }
 30         #icaption #title
 31         {
 32             width: 800px;
 33             color: #0B55C4;
 34             font-size: 23px;
 35         }
 36         .btools
 37         {
 38             width: 1024px;
 39             height: 35px;
 40             text-align: center;
 41             font-size: 14px;
 42             line-height: 25px;
 43             border: 1px solid #e7e7e7;
 44             border-top: none;
 45             margin-left: 10px;
 46             background: #ffffff;
 47         }
 48         .btools button
 49         {
 50             width: 30px;
 51             height: 30px;
 52         }
 53         .btn
 54         {
 55             height: 21px;
 56             border: 1px solid #999999;
 57         }#btn_back{width:32px; height:32px; background:url(/Styles/image/btn_back_b.png) no-repeat !important; cursor:pointer; float:right; background-image:none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=image, src=/Styles/image/btn_back_b.png);}
 58     </style>
 59 </asp:Content>
 60 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 61     <div id="icaption">
 62         <div id="title">
 63             添加新闻</div>
 64         <asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox="true" ShowSummary="false"
 65             runat="server" />
 66             <a href="NewsMgst.aspx" id="btn_back"></a>
 67     </div>
 68     <div style="width: 1026px; margin-top: 5px; margin-left: 10px;">
 69         <table cellspacing="1" width="1026" align="center" style="width: 1026px; border: none;
 70             text-align: center; background: #e7e7e7;">
 71             <tr class="tr4">
 72                 <td class="td1" width="15%">
 73                     标题名称:
 74                 </td>
 75                 <td width="85%">
 76                     <asp:TextBox ID="txtTitle" runat="server" Width="426px"></asp:TextBox>
 77                 </td>
 78             </tr>
 79             <tr class="tr4">
 80                 <td class="td1" width="15%">
 81                     内容:
 82                 </td>
 83                 <td width="85%">
 84                     <FTB:FreeTextBox ID="FreeTextBox1" runat="server" ImageGalleryPath="~/Images/" ImageGalleryUrl="ftb.imagegallery.aspx?rif={0}&cif={0}"
 85                         Language="zh-CN" PasteMode="Default" ReadOnly="false" ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage,InsertImageFromGallery,InsertRule|Cut,Copy,Paste;Undo,Redo,Print"
 86                         ToolbarStyleConfiguration="Office2003">
 87                     </FTB:FreeTextBox>
 88                 </td>
 89             </tr>
 90             <tr class="tr4">
 91                 <td class="td1" width="15%">
 92                     作者:
 93                 </td>
 94                 <td width="85%">
 95                     <asp:TextBox ID="txtAuthor" runat="server" Width="426px"></asp:TextBox>
 96                 </td>
 97             </tr>
 98             <tr class="tr4">
 99                 <td class="td1" width="15%">
100                     编辑:
101                 </td>
102                 <td width="85%">
103                     <asp:TextBox ID="txtEditer" runat="server" Width="426px"></asp:TextBox>
104                 </td>
105             </tr>
106             <tr class="tr4">
107                 <td class="td1" width="15%">
108                     来源:
109                 </td>
110                 <td width="85%">
111                     <asp:TextBox ID="txtSource" runat="server" Width="426px"></asp:TextBox>
112                 </td>
113             </tr>
114             <tr class="tr4">
115                 <td colspan="2" class="btools">
116                     <asp:Button ID="btnAdd" runat="server" CssClass="btn" Text="添加" OnClick="btnAdd_Click" />
117                     <asp:Button ID="btnEdit" runat="server" CssClass="btn" Text="编辑" />
118                     <asp:Button ID="btnCancel" runat="server" CssClass="btn" Text="重置" />
119                 </td>
120             </tr>
121         </table>
122     </div>
123 </asp:Content>

后台:

后台
  1 namespace NeoBackground.News
  2 {
  3     public partial class AddNews : BasePage
  4     {
  5         NeoBLL.TbLeftUpPicBLL leftBll = new NeoBLL.TbLeftUpPicBLL();
  6         public string TB
  7         {
  8             get
  9             {
 10                 return string.IsNullOrEmpty(Request.QueryString["tb"]) ? "" : Request.QueryString["tb"];
 11             }
 12         }
 13 
 14 
 15         public string ID
 16         {
 17             get
 18             {
 19                 return string.IsNullOrEmpty(Request.QueryString["id"]) ? "" : Request.QueryString["id"];
 20             }
 21         }
 22         protected void Page_Load(object sender, EventArgs e)
 23         {
 24             if (!IsPostBack)
 25             {
 26                 if (ID != "")
 27                 {
 28                     string strSql = string.Format("SELECT * FROM {0} where ID={1}", TB, ID);
 29                     DataTable dt = leftBll.GetNewsByID(strSql);
 30                     if (dt == null || dt.Rows.Count <= 0)
 31                     {
 32                         return;
 33                     }
 34                     this.txtTitle.Text = dt.Rows[0]["title"].ToString();
 35                     this.txtSource.Text = dt.Rows[0]["source"].ToString();
 36                     this.txtEditer.Text = dt.Rows[0]["editer"].ToString();
 37                     this.txtAuthor.Text = dt.Rows[0]["author"].ToString();
 38                     this.FreeTextBox1.Text = dt.Rows[0]["contents"].ToString();
 39                 }
 40             }
 41         }
 42 
 43         protected void btnAdd_Click(object sender, EventArgs e)
 44         {
 45             if (string.IsNullOrEmpty(this.txtTitle.Text.Trim()))
 46             {
 47                 MessageBox(Page, "新闻标题不能为空!");
 48                 return;
 49             }
 50             if (string.IsNullOrEmpty(this.txtAuthor.Text.Trim()))
 51             {
 52                 MessageBox(Page, "新闻作者不能为空!");
 53                 return;
 54             }
 55             if (string.IsNullOrEmpty(this.FreeTextBox1.Text.Trim()))
 56             {
 57                 MessageBox(Page, "新闻内容不能为空!");
 58                 return;
 59             }
 60             NeoBLL.TbsjNewsBLL bll = new NeoBLL.TbsjNewsBLL();
 61             NeoBLL.TbLeftUpPicBLL leftBll = new NeoBLL.TbLeftUpPicBLL();
 62             NeoModel.TbsjNewsModel model = new NeoModel.TbsjNewsModel();
 63             model.Title = this.txtTitle.Text.Trim();
 64             model.Contents = this.FreeTextBox1.Text.Trim();
 65             model.Author = this.txtAuthor.Text.Trim();
 66             if (string.IsNullOrEmpty(this.txtEditer.Text.Trim()))
 67             {
 68                 model.Editer = "";
 69             }
 70             else
 71             {
 72                 model.Editer = this.txtEditer.Text.Trim();
 73             }
 74             if (string.IsNullOrEmpty(this.txtSource.Text.Trim()))
 75             {
 76                 model.Source = "";
 77             }
 78             else
 79             {
 80                 model.Source = this.txtSource.Text.Trim();
 81             }
 82             if (ID != "")
 83             {
 84                 model.ID = Convert.ToInt32(ID);
 85                 string strSql = string.Format("Update  {0}  set title=@title,contents=@contents,author=@author,editer=@editer,source=@source,dates=getdate() where id=@id", TB);
 86                 SqlParameter[] sp = { 
 87                                     new SqlParameter("@title",model.Title),
 88                                     new SqlParameter("@contents",model.Contents),
 89                                     new SqlParameter("@author",model.Author),
 90                                     new SqlParameter("@editer",model.Editer),
 91                                     new SqlParameter("@source",model.Source),
 92                                     new SqlParameter("@id",model.ID)
 93                                     };
 94                 if (leftBll.UpdateNewsByID(strSql, sp))
 95                 {
 96                     string script = string.Format("alert('新闻修改成功!');window.location.href='NewsMgst.aspx';");
 97                     ScriptManager.RegisterStartupScript(Page, typeof(Page), DateTime.Now.ToString(), script, true);
 98                 }
 99                 else
100                 {
101                     MessageBox(Page, "新闻修改失败!");
102                 }
103             }
104             else
105             {
106                 string strSql = string.Format("INSERT INTO {0}(title,contents,author,editer,source,dates) values(@title,@contents,@author,@editer,@source,GETDATE())",TB);
107                 SqlParameter[] sp = { 
108                                 new SqlParameter("@title",SqlDbType.NVarChar,100),
109                                 new SqlParameter("@contents",SqlDbType.NText),
110                                 new SqlParameter("@author",SqlDbType.NVarChar,50),
111                                 new SqlParameter("@editer",SqlDbType.NVarChar,50),
112                                 new SqlParameter("@source",SqlDbType.NVarChar,100)
113                                 };
114                 sp[0].Value = model.Title;
115                 sp[1].Value = model.Contents;
116                 sp[2].Value = model.Author;
117                 sp[3].Value = model.Editer;
118                 sp[4].Value = model.Source;
119                 if (bll.AddTbsjNews(strSql,sp))
120                 {
121                     string script = string.Format("alert('新闻添加成功!');window.location.href='NewsMgst.aspx';");
122                     ScriptManager.RegisterStartupScript(Page, typeof(Page), DateTime.Now.ToString(), script, true);
123                 }
124                 else
125                 {
126                     MessageBox(Page, "新闻添加失败!");
127                 }
128             }
129         }
130     }
131 }

 

posted on 2012-09-23 00:41  梦里故乡  阅读(1383)  评论(0编辑  收藏  举报