母版页:SiteFont.Master
1 <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteFont.master.cs" Inherits="协同企业管理系统.SiteFont" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title></title> 8 <link href="css/main.css" rel="stylesheet" type="text/css" /> 9 <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> 10 <script type="text/javascript"> 11 // $(function () { 12 // $("#nav li").mouseenter(function () { 13 // $(this).addClass("active").siblings().removeClass("active") 14 // }); 15 // }); 16 </script> 17 <asp:ContentPlaceHolder ID="head" runat="server"> 18 </asp:ContentPlaceHolder> 19 </head> 20 <body> 21 <form id="form1" runat="server"> 22 <div id="mainBox"> 23 <div id="header"> 24 <img src="~/image/banner.jpg" runat="server" alt=""/> 25 <ul id="nav"> 26 <li>我的首页 |</li> 27 <li>关于我们 |</li> 28 <li>资源下载 |</li> 29 <li>我的收藏 |</li> 30 <li>文章动态 |</li> 31 <li>关于我们</li> 32 </ul> 33 34 </div> 35 <br class="clear"/> 36 <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 37 38 </asp:ContentPlaceHolder> 39 <div id="footer"> 40 <br class="clear"/> 41 <hr /> 42 <center> 43 智慧协同版权所有 2013-2013 粤A 44 </center> 45 </div> 46 </div> 47 </form> 48 </body> 49 </html>
母版页CSS文件:main.css
1 body { 2 } 3 .clear 4 { 5 clear:both;} 6 7 #mainBox 8 { 9 width:950px; 10 margin-left:auto; 11 margin-right:auto;} 12 #nav 13 { 14 list-style-type:none; 15 background-color:inherit; 16 } 17 #nav LI 18 { 19 float:left; 20 margin-right:20px; 21 font-size:large; 22 } 23 #nav .active 24 { 25 background-color:Red; 26 }
主页面:News_admin.aspx
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="News_admin.aspx.cs" Inherits="协同企业管理系统.admin.News_admin" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title></title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 12 13 <asp:ObjectDataSource ID="obdNews" runat="server" DeleteMethod="Delete" 14 InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 15 SelectMethod="GetData" 16 TypeName="协同企业管理系统.DAL.DataSetNewsTableAdapters.T_NewsTableAdapter" 17 UpdateMethod="Update"> 18 <DeleteParameters> 19 <asp:Parameter Name="Original_ID" Type="Int64" /> 20 </DeleteParameters> 21 <InsertParameters> 22 <asp:Parameter Name="ID" Type="Int64" /> 23 <asp:Parameter Name="sTitle" Type="String" /> 24 <asp:Parameter Name="sContent" Type="String" /> 25 <asp:Parameter Name="SbuildDate" Type="String" /> 26 <asp:Parameter Name="iType" Type="Int32" /> 27 <asp:Parameter Name="sUser" Type="String" /> 28 <asp:Parameter Name="sNote" Type="String" /> 29 </InsertParameters> 30 <UpdateParameters> 31 <asp:Parameter Name="sTitle" Type="String" /> 32 <asp:Parameter Name="sContent" Type="String" /> 33 <asp:Parameter Name="SbuildDate" Type="String" /> 34 <asp:Parameter Name="iType" Type="Int32" /> 35 <asp:Parameter Name="sUser" Type="String" /> 36 <asp:Parameter Name="sNote" Type="String" /> 37 <asp:Parameter Name="Original_ID" Type="Int64" /> 38 </UpdateParameters> 39 </asp:ObjectDataSource> 40 <a href="News_add.aspx?flag=add">发布文章</a> 41 42 <asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" 43 DataSourceID="obdNews"> 44 <EmptyDataTemplate> 45 <table runat="server" 46 style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"> 47 <tr> 48 <td> 49 暂时没有文章</td> 50 </tr> 51 </table> 52 </EmptyDataTemplate> 53 <ItemTemplate> 54 <tr style="background-color: #FFFBD6;color: #333333;"> 55 <td> 56 <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="删除" /> 57 <a href='News_add.aspx?flag=edit&id=<%# Eval ("ID") %>' >修改</a> 58 </td> 59 <td> 60 <asp:Label ID="sTitleLabel" runat="server" Text='<%# Eval("sTitle") %>' /> 61 </td> 62 <td> 63 <asp:Label ID="SbuildDateLabel" runat="server" 64 Text='<%# Eval("SbuildDate") %>' /> 65 </td> 66 <td> 67 <asp:Label ID="iTypeLabel" runat="server" Text='<%# Eval("iType") %>' /> 68 </td> 69 <td> 70 <asp:Label ID="sUserLabel" runat="server" Text='<%# Eval("sUser") %>' /> 71 </td> 72 </tr> 73 </ItemTemplate> 74 <LayoutTemplate> 75 <table runat="server"> 76 <tr runat="server"> 77 <td runat="server"> 78 <table ID="itemPlaceholderContainer" runat="server" border="1" 79 style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;"> 80 <tr runat="server" style="background-color: #FFFBD6;color: #333333;"> 81 <th runat="server"> 82 </th> 83 <th runat="server"> 84 sTitle</th> 85 <th runat="server"> 86 SbuildDate</th> 87 <th runat="server"> 88 iType</th> 89 <th runat="server"> 90 sUser</th> 91 </tr> 92 <tr ID="itemPlaceholder" runat="server"> 93 </tr> 94 </table> 95 </td> 96 </tr> 97 <tr runat="server"> 98 <td runat="server" 99 style="text-align: center;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;"> 100 </td> 101 </tr> 102 </table> 103 </LayoutTemplate> 104 </asp:ListView> 105 106 107 </form> 108 </body> 109 </html>
文章列表页面:News_list.aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="News_list.aspx.cs" Inherits="协同企业管理系统.admin.News_list" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title></title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <div> 12 13 <asp:ObjectDataSource ID="obdNewslist" runat="server" DeleteMethod="Delete" 14 InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 15 SelectMethod="GetDataPage" SelectCountMethod="NewsQuery" 16 TypeName="协同企业管理系统.DAL.DataSetNewsTableAdapters.T_NewsTableAdapter" 17 UpdateMethod="Update" EnablePaging="True"> 18 <DeleteParameters> 19 <asp:Parameter Name="Original_ID" Type="Int64" /> 20 </DeleteParameters> 21 <InsertParameters> 22 <asp:Parameter Name="sTitle" Type="String" /> 23 <asp:Parameter Name="sContent" Type="String" /> 24 <asp:Parameter Name="SbuildDate" Type="String" /> 25 <asp:Parameter Name="iType" Type="Int32" /> 26 <asp:Parameter Name="sUser" Type="String" /> 27 <asp:Parameter Name="sNote" Type="String" /> 28 </InsertParameters> 29 <UpdateParameters> 30 <asp:Parameter Name="sTitle" Type="String" /> 31 <asp:Parameter Name="sContent" Type="String" /> 32 <asp:Parameter Name="SbuildDate" Type="String" /> 33 <asp:Parameter Name="iType" Type="Int32" /> 34 <asp:Parameter Name="sUser" Type="String" /> 35 <asp:Parameter Name="sNote" Type="String" /> 36 <asp:Parameter Name="Original_ID" Type="Int64" /> 37 </UpdateParameters> 38 </asp:ObjectDataSource> 39 40 </div> 41 <asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" 42 DataSourceID="obdNewslist"> 43 44 <EmptyDataTemplate> 45 暂时没有文章 46 </EmptyDataTemplate> 47 <ItemTemplate> 48 <li><a href='News_detail.aspx?ID=<%#Eval("ID")%>'><%#Eval ("sTitle") %></a></li> 49 </ItemTemplate> 50 <LayoutTemplate> 51 <ul> 52 <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> 53 </ul> 54 <%-- QueryStringField 传页数参数名字--%> 55 <asp:DataPager ID="DataPager1" runat="server" PageSize="5" QueryStringField="pageName"> 56 <Fields> 57 <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" 58 ShowLastPageButton="false" ShowNextPageButton="false" 59 ShowPreviousPageButton="true"/> 60 <asp:NumericPagerField></asp:NumericPagerField> 61 <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" 62 ShowLastPageButton="True" ShowPreviousPageButton="false" ShowNextPageButton="true" /> 63 </Fields> 64 </asp:DataPager> 65 </LayoutTemplate> 66 </asp:ListView> 67 </form> 68 </body> 69 </html>
添加/修改文章页面:News_add.aspx
1<%@ Page Language="C#" AutoEventWireup="true"ValidateRequest="false" CodeBehind="News_add.aspx.cs" Inherits="协同企业管理系统.admin.News_add" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 8 <script src="js/ckeditor/ckeditor.js" type="text/javascript"></script> 9 <title></title> 10 </head> 11 <body> 12 <form id="form1" runat="server"> 13 <div> 14 <table border="0" cellpadding="0" cellspacing="0"> 15 <tr> 16 <td> 17 <asp:Label ID="Label1" runat="server" Text="标题"> 18 </asp:Label><asp:TextBox ID="txtTitle" 19 runat="server"></asp:TextBox> 20 </td> 21 </tr> 22 <tr> 23 <td> 24 <asp:Label ID="Label2" runat="server" Text="正文"></asp:Label> 25 <asp:TextBox ID="txtContent" CssClass="ckeditor" 26 runat="server" TextMode="MultiLine"></asp:TextBox> 27 </td> 28 </tr> 29 <tr> 30 <td> 31 <asp:Button ID="btnSave" runat="server" Text="保存" onclick="btnSave_Click" /> 32 </td> 33 </tr> 34 </table> 35 </div> 36 </form> 37 </body> 38 </html>
添加/修改文章后台代码:News_add.aspx.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using 协同企业管理系统.DAL.DataSetNewsTableAdapters; 8 9 namespace 协同企业管理系统.admin 10 { 11 public partial class News_add : System.Web.UI.Page 12 { 13 protected void Page_Load(object sender, EventArgs e) 14 { 15 if (!IsPostBack) { 16 //传入参数 17 var flag = Request["flag"]; 18 if (flag == "add") { } 19 //如果是表示修改的参数,则根据ID获取数据库中的数据 20 //显示在修改页面上 21 else if (flag == "edit") { 22 int ID = Convert.ToInt32(Request["ID"]); 23 var NewsRow = new T_NewsTableAdapter().GetDataById(ID).Single(); 24 txtContent.Text = NewsRow.sContent; 25 txtTitle.Text = NewsRow.sTitle; 26 } 27 else { throw new Exception("参数传入有误"); } 28 } 29 } 30 31 protected void btnSave_Click(object sender, EventArgs e) 32 { 33 if (!IsValid) { 34 return; 35 } 36 //保存 37 string flag = Request["flag"]; 38 if (flag == "add") { 39 string nowTime=System.DateTime.Now.ToString("G"); 40 new T_NewsTableAdapter().Insert(txtTitle.Text, txtContent.Text, nowTime,1,"admin","无"); 41 } 42 else if(flag=="edit"){ 43 int ID=Convert.ToInt32(Request["ID"]); 44 var newsRow=new T_NewsTableAdapter().GetDataById(ID).Single(); 45 newsRow.sContent=txtContent.Text; 46 newsRow.sTitle=txtTitle.Text; 47 new T_NewsTableAdapter().Update(newsRow); 48 } 49 Response.Redirect("News_admin.aspx"); 50 } 51 } 52 }
文章详情页面:News_detail.aspx
1 <%@ Page Title="" Language="C#" MasterPageFile="~/SiteFont.Master" AutoEventWireup="true" CodeBehind="News_detail.aspx.cs" Inherits="协同企业管理系统.admin.News_detail" %> 2 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 3 </asp:Content> 4 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 5 <center><h2><asp:Literal ID="Literal1" runat="server" ></asp:Literal></h2></center> 6 <p style="float:right">作者:<asp:Literal ID="Literal2" runat="server"></asp:Literal> 7 发布日期:<asp:Literal ID="Literal3" runat="server"></asp:Literal></p> 8 <br class="clear" /> 9 <p><asp:Literal ID="Literal4" runat="server"></asp:Literal></p> 10 </asp:Content>
文章详情后台代码:News_detail.aspx.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using 协同企业管理系统.DAL.DataSetNewsTableAdapters; 8 9 namespace 协同企业管理系统.admin 10 { 11 public partial class News_detail : System.Web.UI.Page 12 { 13 protected void Page_Load(object sender, EventArgs e) 14 { 15 if (!IsPostBack) { 16 int ID = Convert.ToInt32(Request["ID"]); 17 var NewsTable = new T_NewsTableAdapter().GetDataById(ID); 18 if (NewsTable.Count <= 0) 19 { 20 Literal1.Visible = false; 21 Literal2.Visible = false; 22 Literal3.Visible = false; 23 Literal4.Text = "找不到指定新闻,请查看其它新闻。"; 24 } 25 else if(NewsTable.Count>0) { 26 var NewsRows = NewsTable.Single(); 27 Literal1.Text=NewsRows.sTitle; 28 Literal2.Text = NewsRows.sUser; 29 Literal3.Text = NewsRows.SbuildDate; 30 Literal4.Text = NewsRows.sContent; 31 } 32 } 33 } 34 } 35 }
在ascx文件中使用Repeater动态加载数据:News_Tablist.ascx
1 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="News_Tablist.ascx.cs" Inherits="协同企业管理系统.admin.News_Tablist" %> 2 <asp:Repeater ID="Repeater1" runat="server" > 3 <HeaderTemplate><ul></HeaderTemplate> 4 <ItemTemplate><li>标题:<%# Eval("sTitle")%></li></ItemTemplate> 5 <FooterTemplate></u1></FooterTemplate> 6 </asp:Repeater>
News_Tablist.ascx.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using 协同企业管理系统.DAL.DataSetNewsTableAdapters; 8 9 namespace 协同企业管理系统.admin 10 { 11 public partial class News_Tablist : System.Web.UI.UserControl 12 { 13 protected void Page_Load(object sender, EventArgs e) 14 { 15 if (!IsPostBack) { 16 Response.Write("3333"); 17 var data = new T_NewsTableAdapter().GetDataByiType(iType); 18 Repeater1.DataSource = data; 19 Repeater1.DataBind(); 20 } 21 } 22 23 public int iType 24 { 25 get; 26 set; 27 } 28 } 29 }
附件上传页面:Pic_load.aspx
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pic_load.aspx.cs" Inherits="协同企业管理系统.admin.Pic_load" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title></title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <div> 12 <asp:FileUpload ID="FileUpload1" runat="server" /> 13 <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 14 </div> 15 </form> 16 </body> 17 </html>
附件上传后台代码:Pic_load.aspx.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.IO; 8 9 namespace 协同企业管理系统.admin 10 { 11 public partial class Pic_load : System.Web.UI.Page 12 { 13 protected void Page_Load(object sender, EventArgs e) 14 { 15 16 } 17 18 protected void Button1_Click(object sender, EventArgs e) 19 { 20 FileUpload fileload = (FileUpload)form1.FindControl("FileUpload1"); 21 if (fileload.HasFile) { 22 //校验文件类型 23 string ext = Path.GetExtension(fileload.FileName).ToLower(); 24 Response.Write(ext); 25 if (ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".png") 26 { 27 Response.Write("sucess"); 28 //全路径。根目录 29 fileload.SaveAs(Server.MapPath("~/image/" + fileload.FileName)); 30 } 31 else 32 { 33 ClientScript.RegisterStartupScript(GetType(), "alert", "alert('只允许上传jpg/jpeg/gif/png文件');", true); 34 35 return; 36 } 37 } 38 } 39 } 40 }