码迷,mamicode.com
首页 > Web开发 > 详细

基于ASP.NET的新闻管理系统(三)代码展示

时间:2018-09-16 15:30:57      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:tom   5.2.1   filter   ted   用户管理   tla   The   datetime   检索   

5.1.1栏目部分

增加栏目(addLanMu.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link rel="stylesheet" type="text/css" href="../css/style.css" />

    <style type="text/css">

    body{ background-image:url(‘backgroundimgs/bg003.jpg‘);background-size: cover;}

        #submitLanMu,#backlanmu

        {

            color:White;

            width:100px;

            height: 35px;

        outline: none;

        margin:10px 50px;

        border: none;

        

        line-height: 35px;

        border-radius: 50px;

        position: relative;

        border: rgba(255,255,255,0.2) 2px solid ;

        color: var(--color);

            -webkit-transition: 0.25s;

            transition: 0.25s;

          }

        #submitLanMu:hover,#submitLanMu:focus{box-shadow: inset 0 0 0 2em var(--hover);}

        #submitLanMu{--color: #a972cb;--hover: #cb72aa;}

        #backlanmu:hover,#backlanmu:focus {box-shadow: inset -3.5em 0 0 0 var(--hover), inset 3.5em 0 0 0 var(--hover);}

        #backlanmu{--color: #ff7f82; --hover: #ffdc7f;}

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

         <div id="addLanMuDiv">

            <div style=" text-align:center">增加栏目</div>

            <div class="addUserClass">

                <asp:Label ID="Label1" Text="栏目名:" runat="server" />

                <asp:TextBox ID="addLanMuName" runat="server" style="width:150px;  border:0px"></asp:TextBox>

            </div>

            <br />

            <asp:Button Text="确定" runat="server" ID="submitLanMu" 

                onclick="submitUser_Click" />

             <asp:Button ID="backlanmu" runat="server" onclick="back_Click" Text="返回" />

        </div>

    </div>

    </form>

</body>

</html>

 

编辑栏目(editLanMu.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

         body{ background-image:url(‘backgroundimgs/bg003.jpg‘);background-size: cover;}

         #submitEditLanMu,#backtolanmu

         {

             margin: 30px 20px;

              padding: 15px 20px;

              border-radius: 10px;

              border: 2px solid;

              font: 16px ‘Open Sans‘, sans-serif;

              text-transform: uppercase;

              background: none;

              outline: none;

              cursor: pointer;

              -webkit-transition: all .5s;

              transition: all .5s;

          }

          #submitEditLanMu,#backtolanmu {color: #CEFFF1;border-color: #CEFFF1; overflow: hidden; position: relative;}

          #submitEditLanMu:hover,#backtolanmu:hover {color: #27323A;}

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

         <div id="editLanMuDiv" style=" height:150px; border:0">

            <div style=" text-align:center; color:White">编辑栏目</div>

            <div class="addUserClass">

                <asp:Label ID="Label1" Text="栏目名:" runat="server" />

                <asp:TextBox ID="editLanMu" runat="server" style="width:150px;  border:0px"></asp:TextBox>

            </div>

            <asp:Button Text="确定" runat="server" ID="submitEditLanMu" onclick="submitEditLanMu_Click" />

            <asp:Button ID="backtolanmu" runat="server" Text="返回" onclick="back_Click" />

        </div>

    </div>

    </form>

</body>

</html>

 

栏目管理(lanmuManage.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

        body{ background-image:url(‘backgroundimgs/bg003.jpg‘);background-size: cover;}

        #addLanMu,#backtomanage

        {

            color:White;

            width:100px;

            height: 35px;

        outline: none;

        margin:10px 50px;

        border: none;

        

        line-height: 35px;

        border-radius: 50px;

        position: relative;

        border: rgba(255,255,255,0.2) 2px solid ;

        color: var(--color);

            -webkit-transition: 0.25s;

            transition: 0.25s;

        }

        #addLanMu {box-shadow: 0.3em 0.3em 0 0 var(--color), inset 0.3em 0.3em 0 0 var(--color);}

        #addLanMu:hover, #addLanMu:focus {box-shadow: 0 0 0 0 var(--hover), inset 6em 3.5em 0 0 var(--hover);}

        #addLanMu {--color: #19bc8b;--hover: #1973bc;}

        #backtomanage:hover,#backtomanage:focus{box-shadow: inset 0 -3.25em 0 0 var(--hover);}

        #backtomanage{  --color: #000000;  --hover: #94e458;}

    </style>

</head>

<body>

    <form id="form1" runat="server">

        <div id="addLanMuHeader" style=" height:50px; border:0">

            <div style="float:left">

                <asp:Label ID="bigUser" runat="server"></asp:Label>

            </div>

            <div style="float:right">

                <asp:Button ID="addLanMu" runat="server" Text="添加栏目" onclick="addLanMu_Click" />

            </div>

        </div>

        <div id="showLanMu">

            <div>

                <asp:GridView ID="gvLanMu" runat="server" AutoGenerateColumns="False" 

                    Width="500px" BorderStyle="None">

                    <Columns>

                        <asp:BoundField DataField="lanMuId" HeaderText="栏目ID">

                        <ItemStyle HorizontalAlign="Center" Width="100px" BorderStyle="None" />

                        </asp:BoundField>

                        <asp:BoundField DataField="lanMuName" HeaderText="栏目名称">

                        <ItemStyle HorizontalAlign="Center" Width="100px" BorderStyle="None" />

                        </asp:BoundField>

                        <asp:TemplateField HeaderText="修改">

                            <ItemTemplate>

                                <asp:LinkButton ID="editLanMu" runat="server" onclick="editLanMu_Click">编辑栏目</asp:LinkButton>

                                  

                                <asp:LinkButton ID="delLanMu" runat="server" onclick="delLanMu_Click">删除</asp:LinkButton>

                            </ItemTemplate>

                            <ItemStyle HorizontalAlign="Center" Width="150px" BorderStyle="None" />

                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="管理">

                            <ItemTemplate>

                                <asp:LinkButton ID="setManage" runat="server" onclick="setManage_Click">设置管理员</asp:LinkButton>

                            </ItemTemplate>

                            <ItemStyle HorizontalAlign="Center" Width="100px" BorderStyle="None" />

                        </asp:TemplateField>

                    </Columns>

                </asp:GridView>

            </div>

    </div>

        <asp:Button ID="backtomanage" runat="server" onclick="backtomanage_Click" Text="返回" style=" float:right; position:absolute; right:110px" />

    </form>

    <div id="backfooter">

        <div >

                版权所有:@ 2018 姚锋 地址:江苏省常熟市南三环路99号 <br />

                联系电话:188xxxxxxxx 邮政编码:215500 <br />

            [<a href="yf/index.aspx" target="_blank">后台管理</a>]

        </div>

    </div>

</body>

</html>

5.1.2用户部分

添加用户(addUsers.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

       html,body {padding:0;margin:0}

       canvas { display:block}

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <div id="addUserDiv">

            <div style=" text-align:center; color:White; ">增加用户</div>

            <div class="addUserClass">

                <img src="loginimages/user_icon_copy.png" />

                <asp:TextBox ID="addUserName" runat="server" style="width:150px;  border:0px; color: White;"></asp:TextBox>

            </div>

            <br />

            <div class="addUserClass">

                <img src="loginimages/lock_icon_copy.png" />

                 <asp:TextBox ID="addUserPwd" runat="server" style="width:150px; border:0px; color: White;"></asp:TextBox>

            </div>

            <div class="mb2">

                <asp:Button  Text="确定¨" runat="server" ID="submitUser" onclick="submitUser_Click" />

            </div>

            <div class="mb2">

                <asp:Button ID="back" runat="server" onclick="back_Click" Text="返回" />

            </div>

        </div>

    </div>

    </form>

    <canvas></canvas>

    <script src="loginJavascript/hailang.js" type="text/javascript"></script>

</body>

</html>

编辑用户(editUsers.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

         body{ background-image:url(‘backgroundimgs/bg003.jpg‘);background-size: cover;}

         #backto,#submitEditUser

         {

              margin: 30px 20px;

              padding: 15px 20px;

              border-radius: 10px;

              border: 2px solid;

              font: 16px ‘Open Sans‘, sans-serif;

              text-transform: uppercase;

              background: none;

              outline: none;

              cursor: pointer;

              -webkit-transition: all .5s;

              transition: all .5s;

          }

          #submitEditUser {

              color: #A3F7BF;

              border-color: #A3F7BF;

              background: -webkit-linear-gradient(left, #a3f7bf, #a3f7bf) no-repeat;

              background: linear-gradient(to right, #a3f7bf, #a3f7bf) no-repeat;

              background-size: 0% 100%;

            }

          #submitEditUser:hover {background-size: 100% 100%; color: #27323A;}

          #backto {color: #E4F68F;

              border-color: #E4F68F;

              background: -webkit-linear-gradient(left, #e4f68f, #e4f68f) no-repeat;

              background: linear-gradient(to right, #e4f68f, #e4f68f) no-repeat;

              background-size: 100% 0%;

            }

          #backto:hover {background-size: 100% 100%; color: #27323A;}

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

         <div id="editUserDiv">

            <div style=" text-align:center; color:White;">编辑用户</div>

            <div class="addUserClass">

                <img src="loginimages/user_icon_copy.png" />

                <asp:TextBox ID="editUserName" runat="server" style="width:150px;  border:0px"></asp:TextBox>

            </div>

            <br />

            <div class="addUserClass">

                <img src="loginimages/lock_icon_copy.png" />

                <asp:TextBox ID="editUserPwd" runat="server" style="width:150px;  border:0px"></asp:TextBox>

            </div>

            <asp:Button Text="确定¨" runat="server" ID="submitEditUser" onclick="submitEditUser_Click"/>

            <asp:Button ID="backto" runat="server" onclick="back_Click" Text="返回" />

        </div>

    </div>

    </form>

</body>

</html>

管理用户(userManage.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>用户管理系统</title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

        body{ background-image:url(‘backgroundimgs/bg003.jpg‘); background-size: cover;}

        #Button1

        {

           color:White;

            width:100px;

            height: 35px;

        outline: none;

        margin:10px 50px;

        border: none;

        

        line-height: 35px;

        border-radius: 50px;

        position: relative;

        border: rgba(255,255,255,0.2) 2px solid ;

        color: var(--color);

            -webkit-transition: 0.25s;

            transition: 0.25s;

        }

        #Button1:hover,#Button1:focus {box-shadow: inset 6.5em 0 0 0 var(--hover);}

        #Button1 {--color: #8fc866;--hover: #66c887;}

        #back:hover{ color:Black; ">    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <div id="addUserHeader" style=" height:50px; border:0">

            <div style="float:left">

                <asp:Label ID="bigUser" runat="server" style=" color:White;"></asp:Label>

            </div>

            <div style="float:right">

                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="添加用户" />

            </div>

        </div>

    </div>

    <div id="showUser">

            <asp:GridView ID="gvUser" runat="server" AutoGenerateColumns="False" 

        Width="1000px" BorderStyle="None"  >

        <Columns>

            <asp:BoundField DataField="uid" HeaderText="用户编号">

            <ItemStyle HorizontalAlign="Center" Width="100px" BorderStyle="None" />

            </asp:BoundField>

            <asp:HyperLinkField DataNavigateUrlFields="uid" DataTextField="userName" 

                HeaderText="用户姓名">

            <ItemStyle HorizontalAlign="Center" Width="100px" BorderStyle="None" />

            </asp:HyperLinkField>

            <asp:BoundField DataField="passWord" HeaderText="用户密码">

            <ItemStyle HorizontalAlign="Center" Width="100px" BorderStyle="None" />

            </asp:BoundField>

            <asp:TemplateField HeaderText="修改">

                <ItemTemplate>  

                    <asp:LinkButton ID="editUser" runat="server" onclick="editUser_Click">编辑用户</asp:LinkButton>

                      

                    <asp:LinkButton ID="deleteUser" runat="server" onclick="deleteUser_Click">删除</asp:LinkButton>

                </ItemTemplate>

                <ItemStyle Width="200px" HorizontalAlign="Center" BorderStyle="None" />

            </asp:TemplateField>

        </Columns>

    </asp:GridView>

    </div>

    <asp:Button ID="back" runat="server" onclick="back_Click" Text="返回" style=" position:absolute; right:50px;"/>

    </form>

    <div id="backfooter">

        <div >

                版权所有:@ 2018 姚锋 地址:江苏省常熟市南三环路99号 <br />

                联系电话:188xxxxxxxx 邮政编码:215500 <br />

            [<a href="yf/index.aspx" target="_blank">后台管理</a>]

        </div>

    </div>

</body>

</html>

5.1.3新闻部分

添加新闻(addNews.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>发布信息页面</title>

    <style type="text/css">

         body{ background-image:url(‘backgroundimgs/bg003.jpg‘);background-size: cover;}

    </style>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

     <link rel="stylesheet" href="kde/themes/default/default.css" />

<link rel="stylesheet" href="kde/plugins/code/prettify.css" />

<script charset="utf-8" src="kde/kindeditor.js"></script>

<script charset="utf-8" src="kde/lang/zh_CN.js"></script>

<script charset="utf-8" src="kde/plugins/code/prettify.js"></script>

<script>

    KindEditor.ready(function (K) {

        var editor1 = K.create(‘#content1‘, {

            cssPath: ‘kde/plugins/code/prettify.css‘,

            uploadJson: ‘kde/upload_json.ashx‘,

            fileManagerJson: ‘kde/file_manager_json.ashx‘,

            allowFileManager: true,

            afterCreate: function () {

                var self = this;

                K.ctrl(document, 13, function () {

                    self.sync();

                    K(‘form[name=example]‘)[0].submit();

                });

                K.ctrl(self.edit.doc, 13, function () {

                    self.sync();

                    K(‘form[name=example]‘)[0].submit();

                });

            }

        });

        prettyPrint();

    });

</script>

</head>

<body>

    <form id="example" runat="server">

    <div id="box">

        <div style="width:1000px;margin:10px 0;border:1px #ccc solid;">标题:<asp:TextBox 

                ID="txtTitle" runat="server"></asp:TextBox>

        </div>

        <div style="width:1000px;margin:10px 0;border:1px #ccc solid;">栏目:<asp:DropDownList 

                ID="ddlLanMu" runat="server">

            </asp:DropDownList>

          主页图片:<asp:TextBox ID="txtImgUrl" runat="server" Width="495px"></asp:TextBox>

        </div>

        <div style="width:1000px;margin:10px 0;border:1px #ccc solid;">

            <textarea id="content1" cols="100" rows="8" style="width:1000px;height:500px;visibility:hidden;" runat="server"></textarea>

            <br />

            <asp:Button ID="btnBack" runat="server" onclick="btnBack_Click" Text="返回" />

 <asp:Button ID="btnSubmit" runat="server" Text="提交内容" 

                onclick="btnSubmit_Click" /> (提交快捷键: Ctrl + Enter)

        </div>

    </div>

    </form>

</body>

</html>

编辑新闻(editNews.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>编辑新闻页面</title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

     <link rel="stylesheet" href="kde/themes/default/default.css" />

<link rel="stylesheet" href="kde/plugins/code/prettify.css" />

<script charset="utf-8" src="kde/kindeditor.js"></script>

<script charset="utf-8" src="kde/lang/zh_CN.js"></script>

<script charset="utf-8" src="kde/plugins/code/prettify.js"></script>

<script>

    KindEditor.ready(function (K) {

        var editor1 = K.create(‘#content1‘, {

            cssPath: ‘kde/plugins/code/prettify.css‘,

            uploadJson: ‘kde/upload_json.ashx‘,

            fileManagerJson: ‘kde/file_manager_json.ashx‘,

            allowFileManager: true,

            afterCreate: function () {

                var self = this;

                K.ctrl(document, 13, function () {

                    self.sync();

                    K(‘form[name=example]‘)[0].submit();

                });

                K.ctrl(self.edit.doc, 13, function () {

                    self.sync();

                    K(‘form[name=example]‘)[0].submit();

                });

            }

        });

        prettyPrint();

    });

</script>

</head>

<body>

    <form id="example" runat="server">

    <div id="box">

        <div style="width:1000px;margin:10px 0;border:1px #ccc solid;">标题:<asp:TextBox 

                ID="txtTitle" runat="server"></asp:TextBox>

        </div>

        <div style="width:1000px;margin:10px 0;border:1px #ccc solid;">栏目:<asp:DropDownList 

                ID="ddlLanMu" runat="server">

            </asp:DropDownList>

          主页图片:<asp:TextBox ID="txtImgUrl" runat="server" Width="475px"></asp:TextBox>

        </div>

        <div style="width:1000px;margin:10px 0;border:1px #ccc solid;">

            <textarea id="content1" cols="100" rows="8" style="width:1000px;height:500px;visibility:hidden;" runat="server"></textarea>

            <br />

            <asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click" Text="返回" />

 <asp:Button ID="btnEdit" runat="server" Text="提交内容" onclick="btnEdit_Click" /> (提交快捷键: Ctrl + Enter)

        </div>

    </div>

    </form>

</body>

</html>

 

给新闻设置管理员:(setManage.aspx

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="../css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

            body{ background-image:url(‘backgroundimgs/bg003.jpg‘);}

            #setManage,#backTo

            {

              margin : 30px 20px;

              padding: 15px 20px;

              border-radius: 10px;

              border: 2px solid;

              font: 16px ‘Open Sans‘, sans-serif;

              text-transform: uppercase;

              background: none;

              outline: none;

              cursor: pointer;

              -webkit-transition: all .5s;

              transition: all .5s;}

               #setManage  {color: #A3F7BF;

              border-color: #A3F7BF;

              background: -webkit-linear-gradient(left, #a3f7bf, #a3f7bf) no-repeat;

              background: linear-gradient(to right, #a3f7bf, #a3f7bf) no-repeat;

              background-size: 0% 100%;}

             #setManage:hover {background-size: 100% 100%; color: #27323A;}

             #backTo{color: #E4F68F;

              border-color: #E4F68F;

              background: -webkit-linear-gradient(left, #e4f68f, #e4f68f) no-repeat;

              background: linear-gradient(to right, #e4f68f, #e4f68f) no-repeat;

              background-size: 100% 0%;}

             #backTo:hover,#backTo:focus {background-size: 100% 100%; color: #27323A;}            

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <div id="manageList">

             <div style=" text-align:center; color:White;">设置管理员</div></br>

             <asp:DropDownList ID="userList" runat="server" style="width:100px; height:30px ">

             </asp:DropDownList>

             </br>

             <asp:Button ID="setManage" runat="server" onclick="setManage_Click" Text="确认" />

             <asp:Button ID="backTo" runat="server" onclick="back_Click" Text="返回" />

        </div>

    </div>

    </form>

    <div id="backfooter">

        <div >

                版权所有:@ 2018 姚锋 地址:江苏省常熟市南三环路99号 <br />

                联系电话:188xxxxxxxx 邮政编码:215500 <br />

            [<a href="yf/index.aspx" target="_blank">后台管理</a>]

        </div>

    </div>

</body>

</html>

 

新闻搜索(Search.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <div id="box">

        <div id="header"></div>

        <div class="splitDiv"></div>

        <div id="showLanmu">

             <%=Lanmu.getLanMu()%>

        </div>

        <div class="splitDiv"></div>

        <div id="main">

            <div id="left" style="width:400px;">

                

                <asp:GridView ID="SearchHotNews" runat="server" AutoGenerateColumns="False" 

                    ShowHeader="False" BorderStyle="None" CellPadding="0" GridLines ="None" 

                    Width="400px">

                    <Columns>

                        <asp:HyperLinkField 

                            DataNavigateUrlFormatString="showNews.aspx?id={0}" DataTextField="title" 

                            DataNavigateUrlFields="newid" Target="_blank">

                        <ItemStyle Width="420px" />

                        </asp:HyperLinkField>

                        <asp:BoundField DataField="hitCount" HeaderText="点击量">

                        <ItemStyle HorizontalAlign="Center" Width="50px" />

                        </asp:BoundField>

                        <asp:BoundField DataField="addTime" DataFormatString="{0:[yy-MM-dd]}" 

                            HeaderText="发布时间?">

                        <ItemStyle Width="120px" HorizontalAlign="Center" />

                        </asp:BoundField>

                    </Columns>

                </asp:GridView>

            </div>

            <div id="right" style="width:580px;">

                <asp:GridView ID="SearchNews" runat="server" AutoGenerateColumns="False" 

                    ShowHeader="False" BorderStyle="None" CellPadding="0" GridLines ="None" 

                    Width="580px">

                    <Columns>

                        <asp:HyperLinkField 

                            DataNavigateUrlFormatString="showNews.aspx?id={0}" DataTextField="title" 

                            DataNavigateUrlFields="newid" Target="_blank">

                        <ItemStyle Width="420px" />

                        </asp:HyperLinkField>

                        <asp:BoundField DataField="addTime" DataFormatString="{0:[yy-MM-dd]}">

                        <ItemStyle Width="100px" HorizontalAlign="Center" />

                        </asp:BoundField>

                    </Columns>

                </asp:GridView>

            </div>

        <div class="splitDiv"></div>

        <div id="divLinks">友情链接</div>

        <span id="QLinks">

              <ul style=" border:1px solid #ccc;  margin-top:10px; height:70px">

                <li><a href=‘http://rsc.cslg.cn/rsc/‘ target=‘_blank‘><img src="yf/backgroundimgs/rsc.jpg"  border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://www.hep.com.cn/service/xuanshu‘ target=‘_blank‘><img src=‘yf/backgroundimgs/gdjycbs.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://kjc.cslg.edu.cn/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/kxjs.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://jwc.cslg.cn/jwc/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/jwc.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://www.icourses.cn/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/akc.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://ctl.nju.edu.cn/yanjiuhui/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/jsgx.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

              </ul>

         </span>

         <div class="splitDiv"></div>

        <a href="#top"><img src="images/backTop.png" alt="Alternate Text" id="backTop" title="回到顶部" /></a>

        <div id="footer">

        <div >

                版权所有:@ 2018 姚锋 地址:江苏省常熟市南三环路99号 <br />

                联系电话:188xxxxxxxx 邮政编括码:215500 <br />

            [<a href="yf/index.aspx" target="_blank">后台管理</a>]

        </div>

    </div>

    </form>

</body>

</html>

 

菜单栏目新闻(showlist.aspx):

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <link href="css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

        #sure{color:White;

            width:100px;

            height: 43px;

        outline: none;

        border: none;

        line-height: 43px;

        border-radius: 50px;

        position: relative;

        border: rgba(255,255,255,0.2) 2px solid ;

        color: var(--color);

            -webkit-transition: 0.25s;

            transition: 0.25s;

            }

        #sure:hover,#sure:focus {-webkit-animation: pulse 1s;animation: pulse 1s;box-shadow: 0 0 0 2em rgba(255, 255, 255, 0);}

        #sure {--color: #ef6eae;--hover: #ef8f6e;}

        @-webkit-keyframes pulse {0% {box-shadow: 0 0 0 0 var(--hover);}}

        @keyframes pulse {0% {box-shadow: 0 0 0 0 var(--hover);}}

      </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <div id="box">

        <div id="header"></div>

        <div class="splitDiv"></div>

        <div id="showLanmu">

             <%=Lanmu.getLanMu()%>

             <asp:Button ID="sure" runat="server" Text="搜索" />

             <asp:TextBox ID="Search" runat="server"  style="width:200px; border:1px solid  black; border-radius: 50px; text-align:center"></asp:TextBox>

        </div>

        <div class="splitDiv"></div>

        <div id="main">

            <div id="left" style="width:400px; ">

                <asp:GridView ID="gvHotNews" runat="server" AutoGenerateColumns="False" 

                    ShowHeader="False" BorderStyle="None" CellPadding="0" GridLines ="None" 

                    Width="400px">

                    <Columns>

                        <asp:HyperLinkField 

                            DataNavigateUrlFormatString="showNews.aspx?id={0}" DataTextField="title" 

                            DataNavigateUrlFields="newid" Target="_blank">

                        <ItemStyle Width="420px" />

                        </asp:HyperLinkField>

                        <asp:BoundField DataField="hitCount" HeaderText="点击量">

                        <ItemStyle HorizontalAlign="Center" Width="50px" />

                        </asp:BoundField>

                        <asp:BoundField DataField="addTime" DataFormatString="{0:[yy-MM-dd]}" 

                            HeaderText="发布时间?">

                        <ItemStyle Width="120px" HorizontalAlign="Center" />

                        </asp:BoundField>

                    </Columns>

                </asp:GridView>

            </div>

            <div id="right" style="width:580px; ">

                <asp:GridView ID="gvNews" runat="server" AutoGenerateColumns="False" 

                    ShowHeader="False" BorderStyle="None" CellPadding="0" GridLines ="None" 

                    Width="580px">

                    <Columns>

                        <asp:HyperLinkField 

                            DataNavigateUrlFormatString="showNews.aspx?id={0}" DataTextField="title" 

                            DataNavigateUrlFields="newid" Target="_blank">

                        <ItemStyle Width="420px" />

                        </asp:HyperLinkField>

                        <asp:BoundField DataField="addTime" DataFormatString="{0:[yy-MM-dd]}">

                        <ItemStyle Width="100px" HorizontalAlign="Center" />

                        </asp:BoundField>

                    </Columns>

                </asp:GridView>

            </div>

        <div class="splitDiv"></div>

        <div id="divLinks">友情链接</div>

        <span id="QLinks">

              <ul style=" border:1px solid #ccc;  margin-top:10px; height:70px">

                <li><a href=‘http://rsc.cslg.cn/rsc/‘ target=‘_blank‘><img src="yf/backgroundimgs/rsc.jpg"  border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://www.hep.com.cn/service/xuanshu‘ target=‘_blank‘><img src=‘yf/backgroundimgs/gdjycbs.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://kjc.cslg.edu.cn/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/kxjs.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://jwc.cslg.cn/jwc/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/jwc.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://www.icourses.cn/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/akc.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://ctl.nju.edu.cn/yanjiuhui/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/jsgx.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

              </ul>

         </span>

         <div class="splitDiv"></div>

           

        <a href="#top"><img src="images/backTop.png" alt="Alternate Text" id="backTop" title="回到顶部" /></a>

        <div id="footer">

        <div >

                版权所有:@ 2018 姚锋 地址:江苏省常熟市南三环路99号 <br />

                联系电话:188xxxxxxxx 邮政编括码:215500 <br />

            [<a href="yf/index.aspx" target="_blank">后台管理</a>]

        </div>

    </div>

    </form>

</body>

</html>

 

单篇新闻(shownews.aspx:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>查看新闻页面</title>

    <link href="css/style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

        #shownewssure{color:White;

            width:100px;

            height: 43px;

        outline: none;

        line-height: 43px;

        border-radius: 50px;

        border:  1px solid #000;

        position: relative;

        border: rgba(255,255,255,0.2) 2px solid ;

        color: var(--color);

            -webkit-transition: 0.25s;

            transition: 0.25s;

            }

        #shownewssure:hover,#shownewssure:focus {-webkit-animation: pulse 1s;animation: pulse 1s;box-shadow: 0 0 0 2em rgba(255, 255, 255, 0);}

        #shownewssure {--color: #ef6eae;--hover: #ef8f6e;}

        @-webkit-keyframes pulse {0% {box-shadow: 0 0 0 0 var(--hover);}}

        @keyframes pulse {0% {box-shadow: 0 0 0 0 var(--hover);}}

    </style>

</head>

<body>

    <form id="form1" runat="server">

   <div id="box">

        <div id="header"></div>

        <div class="splitDiv"></div>

        <div id="showLanmu">

            <div id="lanMuList" >

                <%=Lanmu.getLanMu()%>

                <asp:Button ID="shownewssure" runat="server" Text="搜索" 

                    onclick="shownewssure_Click" />

                <asp:TextBox ID="shownewsSearch" runat="server" style="width:200px; border:1px solid  black; border-radius: 50px; text-align:center"></asp:TextBox>

                 

            </div>

        </div>

        <div class="splitDiv"></div>

 

        <div id="main">

            <div id="newsTitle">

                <asp:Label ID="lblTitle" runat="server"></asp:Label>

            </div>

            <div class="line"></div>

            <div id="newsInfo">

                <asp:Label ID="lblAddTime" runat="server"></asp:Label>

        

                <asp:Label ID="lblHitCount" runat="server"></asp:Label>

           

                <asp:Label ID="lblAuthor" runat="server"></asp:Label>

            </div>

            <div id="newsContent">

                <asp:Label ID="lblContent" runat="server"></asp:Label>

            </div>

        <div class="splitDiv"></div>

        <div id="divLinks">友情链接</div>

        <span id="QLinks">

              <ul style=" border:1px solid #ccc;  margin-top:10px; height:70px">

                <li><a href=‘http://rsc.cslg.cn/rsc/‘ target=‘_blank‘><img src="yf/backgroundimgs/rsc.jpg"  border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://www.hep.com.cn/service/xuanshu‘ target=‘_blank‘><img src=‘yf/backgroundimgs/gdjycbs.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://kjc.cslg.edu.cn/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/kxjs.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://jwc.cslg.cn/jwc/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/jwc.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://www.icourses.cn/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/akc.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

                <li><a href=‘http://ctl.nju.edu.cn/yanjiuhui/‘ target=‘_blank‘><img src=‘yf/backgroundimgs/jsgx.jpg‘ border=‘0‘ width=‘106px‘ height=‘46px‘></a></li>

              </ul>

         </span>

         <div class="splitDiv"></div>

        <a href="#top"><img src="images/backTop.png" alt="Alternate Text" id="backTop" title="回到顶部" /></a>

        <div id="footer">

        <div >

                版权所有:@ 2018 姚锋地址:江苏省常熟市南三环路99号<br />

                联系电话:188xxxxxxxx 邮政编码:215500 <br />

            [<a href="yf/index.aspx" target="_blank">后台管理</a>]

        </div>

    </div>

    </form>

</body>

</html>

5.1.4 主要CSS样式部分

*,td,li,ul,body {margin:0;padding:0; }

td,th,table{ border:o;}

#box{width:1000px;margin:0 auto;}

#header{width:1000px;height:170px; background-image:url(../images/toppic.jpg);}

#main{width:1000px;}

#left{float:left;width:490px;height:300px;}

#right{float:right;width:500px;}

.splitDiv{ height:10px; clear:both;}

.line{ width:1000px; height:1px; background:#000; margin:10px 0;}

#divLeft,#divMiddle,#divRight{width:320px;height:200px;float:left;}

#divRight{margin: 10px 10px 10px 0px;  }

#divMiddle{ margin:10px 10px 10px 0px;}

#divLeft{ margin:10px 10px 10px 0px;}

#divLinks{ width:990px; border:1px solid #ccc; padding:5px;}

#footer{ width:1000px; text-align:center;   font-size:14px; }

#backfooter{  width:100%; text-align:center;  background-color:#20B2AA; font-size:14px; position:fixed; bottom:0px}

.smallTitle{ text-align:center;}

#backTop{ position:fixed; right:20px; bottom:15px;height: 154px;}

#lanMuList{ height:30px; width:1000px; }

#lanMuList li{ list-style:none; float:left; margin: 0 5px 0px 0px; width:60px; height:40px; line-height:40px;  text-align:center; }

#lanMuList a{ text-decoration: none; color:White; font-weight:bold;}

#lanMuList li:hover{ }

/*下面为showlist界面导航css样式*/

#showLanmu a:hover{ color:Red;}

#showLanmu{ height:30px; width:1000px; }

#showLanmu li{ list-style:none; float:left; margin: 0 5px 0px 0px; width:60px; height:40px; line-height:40px;  text-align:center; }

#showLanmu a{ text-decoration: none; color:White; font-weight:bold;}

#showLanmu li:hover{ }

#showLanmu a:hover{ color:Red;}

/*下面为搜索框及按钮css样式*/

#sure,#shownewssure{ float:right; height:35px; width:50px;}

#Search,#shownewsSearch{ float:right; width:200px; height:30px; }

#QLinks ul li{ list-style-type:none;float:left; height:60px; width:157px; margin:8px 0 0 8px; *display:inline; overflow:hidden;}

#QLinks ul li img{ width:149px; height:52px; padding:3px; border:1px solid #e6e6e6;}

 /*下面是登陆界面的css样式表*/

#userlogin{width:150px;height:90px;position:absolute;

     left:50%;top:50%;

     border:1px red solid;

     margin-left:-75px;

     margin-top:-45px;}

 /*下面是查看新闻内容页面的样式表*/

#newsTitle{width:1000px;text-align:center;font-size:18pt;}

#newsContent{width:1000px;font-size:12pt;}

#newsInfo{ width:1000px; font-size:12pt; text-align:center; margin-bottom:10px;}

/*下面是管理页面布局样式表*/

#adminHeader{ line-height:25px; height:25px; width:1000px; margin-top:5px;}

#adminMenu{line-height:25px;height:25px;width:1000px;}

#adminContent{width:1000px;}

/*下面是用户管理界面样式表*/

#showUser{ width:1000px; margin:0 auto;}

/*下面是增加用户样式表*/

#addUserDiv 

{width:250px; position:absolute; top:50%;left:50%;  text-align:center;

 box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);opacity: 1;top: 20px;

 position: relative;width: 300px;height: 400px;position: absolute;

 left: 0;right: 0;margin: auto;top: 0;bottom: 0;padding: 100px 40px 40px 40px;

 background: #35394a;

 /* Old browsers */

 /* FF3.6+ */

 background: -webkit-gradient(linear, left bottom, right top, color-stop(0%, #35394a), color-stop(100%, rgb(0, 0, 0)));

 /* Chrome,Safari4+ */

 background: -webkit-linear-gradient(230deg, rgba(53, 57, 74, 0) 0%, rgb(0, 0, 0) 100%);

 /* Chrome10+,Safari5.1+ */

 /* Opera 11.10+ */

 /* IE10+ */

 background: linear-gradient(230deg, rgba(53, 57, 74, 0) 0%, rgb(0, 0, 0) 100%);

 /* W3C */

 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=‘rgba(53, 57, 74, 0)‘, endColorstr=‘rgb(0, 0, 0)‘,GradientType=1 );

 /* IE6-9 fallback on horizontal gradient */}

.addUserClass 

{margin:20px;color:White;height: 46px;outline: none;margin-left: 50px;border: none;line-height: 46px;height: 46px;padding: 0 5px;margin-bottom: 20px;border-radius: 50px;position: relative;border: rgba(255,255,255,0.2) 2px solid ;}

.mb2 #back,#submitUser{text-decoration: none;outline: none;}

#back,#submitUser {padding: 15px;margin-left:30px;float:left;display: block;line-height: 20px;text-align: center;font-size: 20px;border-radius: 50px;background:  rgba(0,0,0,0);border:1px solid #75faff;width:100px;color:#75faff;}

#addUserName,#addUserPwd,#editUserName,#editUserPwd,#editLanMu,#addLanMuName,#Search,#shownewsSearch{height: 40px;outline: none;margin-left: 20px;border: none;line-height: 40px;color: black;}

#addUserHeader{line-height:25px; height:25px; width:1000px; margin:5px auto; border:1px solid #ccc;}

/*下面是编辑用户样式表*/

#editUserDiv{ width:250px; position:absolute; top:50%;left:50%; margin-left:-155px; margin-top:-200px; text-align:center; background: rgba(41, 39, 39, 0.46);-webkit-box-shadow: 0px 35px 44px -22px rgba(0,0,0,0.72);-moz-box-shadow: 0px 35px 44px -22px rgba(0,0,0,0.72);box-shadow: 0px 35px 44px -22px #1f181b;padding: 60px 40px; }

.addUserClass{ margin:20px;}

#eidtUserHeader{line-height:25px; height:25px; width:1000px; margin:5px auto; border:1px solid #ccc;}

/*下面是栏目管理界面样式表*/

#showLanMu{ width:1000px; margin:0 auto;}

#addLanMuHeader{line-height:25px; height:25px; width:1000px; margin:5px auto; border:1px solid #ccc;}

#editLanMuDiv,#addLanMuDiv,#manageList{width:300px; position:absolute; top:50%;left:50%; margin-left:-155px; margin-top:-200px;

              text-align:center; background: rgba(41, 39, 39, 0.46);

              -webkit-box-shadow: 0px 35px 44px -22px rgba(0,0,0,0.72);-moz-box-shadow: 0px 35px 44px -22px rgba(0,0,0,0.72);

              box-shadow: 0px 35px 44px -22px #1f181b;

              padding: 60px 40px;}

 

5.2后台部分主要代码

5.2.1数据库部分

Sqlhelper类:

public class sqlhelper

{

public sqlhelper()

{

}

    /// <summary>

    /// 函数实现建数据库连接,并返回该连接

    /// </summary>

    /// <returns>返回建立好的数据库连接</returns>

    public static SqlConnection createCon()

    {

        //获取配置文件中设置好的连接

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myCon"].ConnectionString);

        return con;

    }

    public static void excuteSql(string sqlString)

    {

        SqlConnection con = createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString, con);

        cmd.ExecuteNonQuery();

        con.Close();

    }

    /// <summary>

    /// 数据检索

    /// </summary>

    /// <param name="sqlString"></param>

    /// <returns></returns>

    public static DataSet excuteDataSet(string sqlString)

    {

        SqlConnection con = createCon();

        con.Open();

        SqlDataAdapter sda = new SqlDataAdapter(sqlString, con);

        DataSet ds = new DataSet();

        sda.Fill(ds);

        con.Close();

        return ds;

    }

    public static int excuteInt(string sqlString)

    {

        SqlConnection con = createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString,con);

        int count=0;

        count = Convert.ToInt32(cmd.ExecuteScalar());

        con.Close();

        return count;

    }

    public static bool excuteBool(string sqlString)

    {

        SqlConnection con = createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString, con);

        bool result = true;

        try 

        {

            cmd.ExecuteNonQuery();

        }

        catch

        {

            result=false;

        }

        con.Close();

        return result;

    }

    public static SqlDataReader ExcuteSqlDataReader(string sql, SqlParameter[] parms)

    {

        SqlDataReader result = null;

        SqlConnection con = createCon();

        try

        {

            con.Open();

            SqlCommand cmd = new SqlCommand(sql, con);

            if (parms != null)

                cmd.Parameters.AddRange(parms);

            result = cmd.ExecuteReader(CommandBehavior.CloseConnection);

        }

        catch

        { }

        return result;

    }

}

public static News getNewsById(string id)//通过新闻id查找新闻    

{

        News news = new News();

        string sqlString="select * from t_news where newid="+id;

        SqlConnection con = sqlhelper.createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString,con);

        SqlDataReader sdr = cmd.ExecuteReader();

        while (sdr.Read())

        {

            news.newid = Convert.ToInt32(sdr[0]);

            news.title = Convert.ToString(sdr[1]);

            news.contents = Convert.ToString(sdr[2]);

            news.newid = Convert.ToInt32(sdr[3]);

            news.addTime =Convert.ToDateTime(sdr[4]);

            news.lanMuId = Convert.ToInt32(sdr[5]);

            news.hitCount = Convert.ToInt32(sdr[6]);

        }

        con.Close();

        return news;

}

News类:

public class News

{

public News()

{

}

    public int newid;

    public string title;

    public string contents;

    public int uid;

    public DateTime addTime;

    public int lanMuId;

    public int hitCount;

    public string img;

    public static void getPics(ref string pics,ref string texts,ref string links)

    {

        string sqlString = "select top 5 newid,title,img from t_news where img<>‘‘ order by addTime DESC";

        SqlConnection con = sqlhelper.createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString, con);

        SqlDataReader sdr = cmd.ExecuteReader();

        while (sdr.Read())

        {

            pics += sdr[2].ToString()+"|";

            texts += sdr[1].ToString() + "|";

            links += "showNews.aspx?id=" +sdr[0].ToString()+ "|";

        }

        pics = pics.Substring(0, pics.Length - 1);

        texts = texts.Substring(0, texts.Length - 1);

        links = links.Substring(0, links.Length - 1);

    }

    public static News getNewsByText(string text)

    {

        News news = new News();

        string sqlString = "select * from news where title like  ‘%" + text + "%‘ order by addTime DESC";

        SqlConnection con = sqlhelper.createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString, con);

        SqlDataReader sdr = cmd.ExecuteReader();

        while (sdr.Read())

        {

            news.newid = Convert.ToInt32(sdr[0]);

            news.title = Convert.ToString(sdr[1]);

            news.contents = Convert.ToString(sdr[2]);

            news.newid = Convert.ToInt32(sdr[3]);

            news.addTime = Convert.ToDateTime(sdr[4]);

            news.lanMuId = Convert.ToInt32(sdr[5]);

            news.hitCount = Convert.ToInt32(sdr[6]);

        }

        con.Close();

        return news;

    }

    public static News getNewsById(string id)

    {

        News news = new News();

        string sqlString="select * from t_news where newid="+id;

        SqlConnection con = sqlhelper.createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString,con);

        SqlDataReader sdr = cmd.ExecuteReader();

        while (sdr.Read())

        {

            news.newid = Convert.ToInt32(sdr[0]);

            news.title = Convert.ToString(sdr[1]);

            news.contents = Convert.ToString(sdr[2]);

            news.newid = Convert.ToInt32(sdr[3]);

            news.addTime =Convert.ToDateTime(sdr[4]);

            news.lanMuId = Convert.ToInt32(sdr[5]);

            news.hitCount = Convert.ToInt32(sdr[6]);

        }

        con.Close();

        return news;

    }

    public static void addHitCount(string id)

    {

        string sqlString = "update t_news set hitCount=hitCount+1 where newid="+id;

        sqlhelper.excuteSql(sqlString);

    }

    public static DataSet getNewsList()

    {

        string sqlString = "select * from View_News order by addTime DESC";

        return sqlhelper.excuteDataSet(sqlString);

    }

    public static DataSet getNewsBymanageId(string id)//管理员管理的页面显示相应栏目的新闻

    {

        string sqlString = "select * from t_user,t_news,t_lanMu where t_user.manageLanmuid=t_news.lanMuId and t_news.lanMuId=t_lanMu.lanMuId and t_user.uid="+id;

        return sqlhelper.excuteDataSet(sqlString);

    }

    public static bool addNews(News n)

    {

        string sqlString = "insert into t_news (title,contents,uid,addTime,lanMuId,hitCount,img) values(‘"+n.title+"‘,‘"+n.contents+"‘,"+n.uid+",‘"+n.addTime+"‘,"+n.lanMuId+","+n.hitCount+",‘"+n.img+"‘)";

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool editNews(News n)

    {

        string sqlString = "update t_news set title=‘" + n.title + "‘, contents=‘" + n.contents + "‘, uid=" + n.uid + ", lanMuId=" + n.lanMuId+",img=‘"+n.img+"‘ where newid=" +n.newid;

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool delNews(string id)

    {

        string sqlString = "delete from t_news where newid=" + id;

        return sqlhelper.excuteBool(sqlString);

    }

}

Users类:

public class Users

{

public Users()

{

}

    public int uid;

    public string userName;

    public string passWord;

    public int manageLanmuid;

    public static Users getUserById(string id)

    {

        Users users = new Users();

        string sqlString = "select * from t_user where uid=" + id;

        SqlConnection con = sqlhelper.createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString, con);

        SqlDataReader sdr = cmd.ExecuteReader();

        while (sdr.Read())

        {

            users.uid = Convert.ToInt32(sdr[0]);

            users.userName = Convert.ToString(sdr[1]);

            users.passWord = Convert.ToString(sdr[2]);

        }

        con.Close();

        return users;

    }

    public static int getuidByName(string userName)

    {

        string sqlString = "select uid from t_user where userName=‘" + userName + "‘";

        SqlConnection con = sqlhelper.createCon();

        con.Open();

        SqlCommand cmd = new SqlCommand(sqlString, con);

        int uid = Convert.ToInt32(cmd.ExecuteScalar());

        con.Close();

        return uid;

    }

    public static DataSet getUserList()//获取用户列表

    {

        string sqlString = "select * from t_user";

        return sqlhelper.excuteDataSet(sqlString);

    }

    public static bool delUser(string id)

    {

        string sqlString = "delete from t_user where uid=" + id;

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool addUser(Users n)

    {

        string sqlString = "insert into t_user (userName,passWord) values(‘" + n.userName + "‘,‘" + n.passWord + "‘ )";

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool editUser(Users n)

    {

        string sqlString = "update t_user set userName =‘" + n.userName + "‘, passWord=‘" + n.passWord + "‘  where uid=" + n.uid;

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool giveUseraddlanmu(Users n)

    {

        string sqlString = "update t_user set userName =‘" + n.userName + "‘, passWord=‘" + n.passWord + "‘, manageLanmuid=‘" + n.manageLanmuid + "‘  where uid=" + n.uid;

        return sqlhelper.excuteBool(sqlString);

    }

}

Lanmu类:

public class Lanmu

{

public Lanmu()

{

}

    public int lanMuId;

    public string lanMuName;

    public static DataSet getLanMuList()//获取用户列表

    {

        string sqlString = "select * from t_lanMu";

        return sqlhelper.excuteDataSet(sqlString);

    }

    public static string getLanMu()//获取动态栏目

    {

        string result = "";

        string sql = "select * from t_lanMu";

        System.Data.SqlClient.SqlDataReader sdr = sqlhelper.ExcuteSqlDataReader(sql, null);

        while (sdr.Read())

        {

            result += "<li><a href=‘showlist.aspx?id=" + sdr["lanMuId"] + "‘>";

            result += sdr["lanMuName"].ToString() + "</a>" + "</li>";

        }

        sdr.Close();

        return result;

    }

    public static bool addLanMu(Lanmu l)

    {

        string sqlString = "insert into t_lanMu (lanMuName) values(‘" + l.lanMuName + "‘)";

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool delLanMu(string id)

    {

        string sqlString = "delete from t_lanMu where lanMuId=" + id;

        return sqlhelper.excuteBool(sqlString);

    }

    public static bool editLanMu(Lanmu l)

    {

        string sqlString = "update t_lanMu set lanMuName=‘" + l.lanMuName + "‘  where lanMuId=" + l.lanMuId;

        return sqlhelper.excuteBool(sqlString);

    }

}

5.2.2栏目部分

增加栏目(addLanMu.aspx.cs):

public partial class yf_addNews : System.Web.UI.Page

{

    Users u;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

        {

            Response.Redirect("index.aspx");

        }

        else

        {

            u=(Users)Session["user"];

        }

        if (!IsPostBack)//防止没有取到下拉菜单值

        {

            ddlLanMu.DataSource = Lanmu.getLanMuList();

            ddlLanMu.DataTextField = "lanMuName";

            ddlLanMu.DataValueField = "lanMuId";

            ddlLanMu.DataBind();

            if (Request.QueryString["id"] != null)

            {

                string id = Request.QueryString["id"].ToString();

                News n = News.getNewsById(id);

                txtTitle.Text = n.title;

                content1.Value = n.contents;

                foreach (ListItem x in ddlLanMu.Items)

                {

                    if (x.Value == n.lanMuId.ToString())

                    {

                        x.Selected = true;

                    }

                }

            }

        }

    }

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

        News n = new News();

        n.title = txtTitle.Text;

        n.contents = content1.Value;

        n.addTime = DateTime.Now;

        n.hitCount = 0;

        n.lanMuId =Convert.ToInt32(ddlLanMu.SelectedValue);

        n.uid = u.uid;

        n.img = txtImgUrl.Text;

        if (News.addNews(n)== true )

            Response.Write("<script>alert(‘发布成功!‘)</script>");

        else

            Response.Write("<script>alert(‘发布失败!‘)</script>");

    }

    protected void btnBack_Click(object sender, EventArgs e)

    {

        Response.Redirect("manage.aspx");

    }

}

编辑栏目(editLanMu.aspx.cs):

public partial class yf_editLanMu : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void submitEditLanMu_Click(object sender, EventArgs e)

    {

        Lanmu l = new Lanmu();

        l.lanMuName = editLanMu.Text;

        l.lanMuId = Convert.ToInt32(Request.QueryString["id"].ToString());

        if (Lanmu.editLanMu(l) == true)

            Response.Write("<script>alert(‘修改成功!‘)</script>");

        else

            Response.Write("<script>alert(‘修改失败!‘)</script>");

    }

    protected void back_Click(object sender, EventArgs e)

    {

        Response.Redirect("lanmuManage.aspx");

    }

}

栏目管理(lanmuManage.aspx.cs):

public partial class yf_LanMumanage : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

        {

            Response.Write("<script>alert(‘您尚未登录!‘)</script>");

            Response.Redirect("index.aspx");

        }

        else

        {

            Users u = (Users)Session["user"];

            bigUser.Text = "欢迎" + u.userName;

        }

        showLanMuList();

    }

 

    public void showLanMuList()

    {

        gvLanMu.DataSource = Lanmu.getLanMuList();

        gvLanMu.DataBind();

    }

    protected void delLanMu_Click(object sender, EventArgs e)

    {

        LinkButton btn = (LinkButton)sender;

        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        string id = gvr.Cells[0].Text;

        if (Lanmu.delLanMu(id) == true && (Convert.ToInt32(id) != 1))

        {

            Response.Write("<script>alert(‘删除成功!‘)</script>");

            showLanMuList();

        }

        else

            Response.Write("<script>alert(‘删除失败!‘)</script>");

    }

    protected void editLanMu_Click(object sender, EventArgs e)

    {

        LinkButton btn = (LinkButton)sender;

        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        string id = gvr.Cells[0].Text;

        Response.Redirect("editLanMu.aspx?id=" + id);

    }

    protected void addLanMu_Click(object sender, EventArgs e)

    {

        Response.Redirect("addLanMu.aspx");

    }

    protected void backtomanage_Click(object sender, EventArgs e)

    {

        Response.Redirect("manage.aspx");

    }

    protected void setManage_Click(object sender, EventArgs e)

    {

        LinkButton btn = (LinkButton)sender;

        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        string id = gvr.Cells[0].Text;

        Response.Redirect("setManage.aspx?id=" + id);

    }

}

5.2.3用户部分

添加用户(addUsers.aspx.cs):

public partial class yf_addUser : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void submitUser_Click(object sender, EventArgs e)

    {

        if (addUserName.Text.Trim() == "" || addUserPwd.Text.Trim() == "")

        {

            Response.Write("<script>alert(‘用户名和密码不能为空。‘);</script>");

        }

        else

        {

            Users n = new Users();

            n.userName = addUserName.Text;

            n.passWord = addUserPwd.Text;

            if (Users.addUser(n) == true)

                Response.Write("<script>alert(‘添加成功‘)</script>");

            else

                Response.Write("<script>alert(‘添加失败‘)</script>");

        }

    }

    protected void back_Click(object sender, EventArgs e)

    {

        Response.Redirect("userManage.aspx");

    }

}

编辑用户(editUsers.aspx.cs):

public partial class yf_editUser : System.Web.UI.Page

{

    Users u;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

            Response.Redirect("index.aspx");

        else

            u = (Users)Session["user"];

        if (!IsPostBack)

        {

            if (Request.QueryString["id"] != null)

            {

                string id = Request.QueryString["id"].ToString();

                Users n = Users.getUserById(id);

                editUserName.Text = n.userName;

                editUserPwd.Text = n.passWord;

            }

        }

    }

    protected void submitEditUser_Click(object sender, EventArgs e)

    {

        Users n = new Users();

        n.userName = editUserName.Text;

        n.passWord = editUserPwd.Text;

        n.uid = Convert.ToInt32(Request.QueryString["id"].ToString());

        if (Users.editUser(n) == true)

            Response.Write("<script>alert(‘修改成功‘)</script>");

        else

            Response.Write("<script>alert(‘修改失败‘)</script>");

    }

    protected void back_Click(object sender, EventArgs e)

    {

        Response.Redirect("manage.aspx");

    }

}

管理用户(userManage.aspx.cs):

public partial class yf_userManage : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

        {

            Response.Write("<script>alert(‘您尚未登录‘)</script>");

            Response.Redirect("index.aspx");

        }

        else

        {

            Users u = (Users)Session["user"];

             bigUser.Text = "欢迎" + u.userName;

        }

        showUserList();

    }

    public void showUserList()

    {

        gvUser.DataSource = Users.getUserList();

        gvUser.DataBind();

    }

    protected void editUser_Click(object sender, EventArgs e)

    {

        LinkButton btn = (LinkButton)sender;

        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        string id = gvr.Cells[0].Text;

        Response.Redirect("editUser.aspx?id=" + id);

    }

    protected void deleteUser_Click(object sender, EventArgs e)

    {

        LinkButton btn = (LinkButton)sender;

        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        string id = gvr.Cells[0].Text;

        if (Users.delUser(id) == true&&(Convert.ToInt32(id)!=1))

        {

            Response.Write("<script>alert(‘删除成功‘)</script>");

            showUserList();

        }

        else

        {

            Response.Write("<script>alert(‘删除失败‘)</script>");

        }

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        Response.Redirect("addUser.aspx");

    }

    protected void back_Click(object sender, EventArgs e)

    {

        Response.Redirect("manage.aspx");

    }

}

5.2.4新闻部分

添加新闻(addNews.aspx.cs):

public partial class yf_addNews : System.Web.UI.Page

{

    Users u;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

        {

            Response.Redirect("index.aspx");

        }

        else

        {

            u=(Users)Session["user"];

        }

        if (!IsPostBack)

        {

            ddlLanMu.DataSource = Lanmu.getLanMuList();

            ddlLanMu.DataTextField = "lanMuName";

            ddlLanMu.DataValueField = "lanMuId";

            ddlLanMu.DataBind();

            if (Request.QueryString["id"] != null)

            {

                string id = Request.QueryString["id"].ToString();

                News n = News.getNewsById(id);

                txtTitle.Text = n.title;

                content1.Value = n.contents;

                foreach (ListItem x in ddlLanMu.Items)

                {

                    if (x.Value == n.lanMuId.ToString())

                    {

                        x.Selected = true;

                    }

                }

            }

        }

    }

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

        News n = new News();

        n.title = txtTitle.Text;

        n.contents = content1.Value;

        n.addTime = DateTime.Now;

        n.hitCount = 0;

        n.lanMuId =Convert.ToInt32(ddlLanMu.SelectedValue);

        n.uid = u.uid;

        n.img = txtImgUrl.Text;

        if (News.addNews(n)== true )

            Response.Write("<script>alert(‘发布成功‘)</script>");

        else

            Response.Write("<script>alert(‘发布失败‘)</script>");

    }

    protected void btnBack_Click(object sender, EventArgs e)

    {

        Response.Redirect("manage.aspx");

    }

}

编辑新闻(editNews.aspx.cs):

public partial class yf_editeNews : System.Web.UI.Page

{

    Users u;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

            Response.Redirect("index.aspx");

        else

            u = (Users)Session["user"];

        if (!IsPostBack)

        {

            ddlLanMu.DataSource = Lanmu.getLanMuList();

            ddlLanMu.DataTextField = "lanMuName";

            ddlLanMu.DataValueField = "lanMuId";

            ddlLanMu.DataBind();

            if (Request.QueryString["id"] != null)

            {

                string id = Request.QueryString["id"].ToString();

                News n = News.getNewsById(id);

                txtTitle.Text = n.title;

                content1.Value = n.contents;

                foreach (ListItem x in ddlLanMu.Items)

                {

                    if (x.Value == n.lanMuId.ToString())

                    {

                        x.Selected = true;

                    }

                }

            }

        }

    }

    protected void btnEdit_Click(object sender, EventArgs e)

    {

        News n = new News();

        n.title = txtTitle.Text;

        n.contents = content1.Value;

        n.uid = u.uid;

        n.lanMuId =Convert.ToInt32(ddlLanMu.SelectedValue);

        n.newid = Convert.ToInt32(Request.QueryString["id"].ToString());

        n.img = txtImgUrl.Text;

        if (News.editNews(n)== true)

            Response.Write("<script>alert(‘修改成功‘)</script>");

        else

            Response.Write("<script>alert(‘修改失败‘)</script>");

    }

    protected void btnCancel_Click(object sender, EventArgs e)

    {

        Response.Redirect("manage.aspx");

    }

}

给新闻设置管理员:(setManage.aspx.cs

public partial class yf_setManage : System.Web.UI.Page

{

    Users u;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["user"] == null)

        {

            Response.Redirect("index.aspx");

        }

        else

        {

            u = (Users)Session["user"];

        }

        if (!IsPostBack)//防止没有正确取到下拉菜单里的值

        {

            userList.DataSource = Users.getUserList();

            userList.DataTextField = "userName";

            userList.DataValueField = "uid";

            userList.DataBind();

            if (Request.QueryString["id"] != null)

            {

                string id = Request.QueryString["id"].ToString();

                Users n = Users.getUserById(id);       

                foreach (ListItem x in userList.Items)

                {

                    if (x.Value == n.manageLanmuid.ToString())

                    {

                        x.Selected = true;

                    }

                }

            }

        }

    }

    protected void setManage_Click(object sender, EventArgs e)

    {

        Users n = new Users();

        n.manageLanmuid = Convert.ToInt32(Request.QueryString["id"].ToString());

        int id = Convert.ToInt32(userList.SelectedValue);

        Users p = Users.getUserById(id.ToString());//根据栏目id找user

 

        n.uid = p.uid;

        n.userName = p.userName;

        n.passWord = p.passWord;

        if (Users.giveUseraddlanmu(n) == true)

            Response.Write("<script>alert(‘设置成功‘)</script>");

        else

            Response.Write("<script>alert(‘设置失败‘)</script>");

    }

    protected void back_Click(object sender, EventArgs e)

    {

        Response.Redirect("lanmuManage.aspx");

    }

}

新闻搜索(Search.aspx.cs):

public partial class Search : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Request.QueryString["text"] != null)

        {

            string search = Request.QueryString["text"];

            SearchHotNews.DataSource = sqlhelper.excuteDataSet("select * from t_news where title like  ‘%" + search + "%‘ or contents like ‘%" + search + "%‘ order by hitCount DESC");

            SearchHotNews.DataBind();

            SearchNews.DataSource = sqlhelper.excuteDataSet("select * from t_news where title like  ‘%" + search + "%‘ or contents like ‘%" + search + "%‘ order by addTime DESC");

            SearchNews.DataBind();

        }

        else

        {

        }

    }

}

菜单栏目新闻(showlist.aspx.cs):

public partial class showlist : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Request.QueryString["id"] != null)

        {

            //将栏目id作为参数,根据传递的栏目id值显示

            string id = Request.QueryString["id"].ToString();

            SqlConnection con = sqlhelper.createCon();

            con.Open();

            string sql = "select * from t_news where lanMuId=@lanMuId order by hitCount DESC";

            SqlCommand cmd = con.CreateCommand();

            cmd.CommandText = sql;

            cmd.Parameters.Add(new SqlParameter("@lanMuId", id));

            SqlDataAdapter sda = new SqlDataAdapter(cmd);

            DataSet ds = new DataSet();

            sda.Fill(ds);

            con.Close();

            gvHotNews.DataSource = ds;

            gvHotNews.DataBind();

            gvNews.DataSource = sqlhelper.excuteDataSet("select * from t_news order by addTime DESC");

            gvNews.DataBind();

        }

    }

}

单篇新闻(shownews.aspx.cs:

public partial class shownews : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if(Request.QueryString["id"]!=null)

        {

            string id=Request.QueryString["id"].ToString();

            News.addHitCount(id);

            News n = News.getNewsById(id);

            lblTitle.Text = n.title;

            lblContent.Text = n.contents;

            lblAddTime.Text = "发布时间"+n.addTime.ToString();

            lblAuthor.Text ="发布者"+ n.uid.ToString();

            lblHitCount.Text ="点击次数"+ n.hitCount;

        }

    }

    protected void shownewssure_Click(object sender, EventArgs e)

    {

        if (shownewssure.Text.Trim() == "")

        {

            Response.Write("<script>alert(‘输入为空‘)</script>");

        }

        else

        {

            Response.Redirect("Search.aspx?text=" + shownewsSearch.Text);

        }

    }

}

基于ASP.NET的新闻管理系统(三)代码展示

标签:tom   5.2.1   filter   ted   用户管理   tla   The   datetime   检索   

原文地址:https://www.cnblogs.com/mookking/p/9655240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!