后台模块--公告管理

1、今日完成任务:

(1)公告管理界面

(2)对公告进行增删改查操作

2、核心源码:

 

<body>
    <div class="pd-20">
        <form action="" method="post" class="form form-horizontal" id="form_article_add" runat="server">
            <div class="row cl">
                <label class="form-label col-2"><span class="c-red">*</span>公告标题:</label>
                <div class="formControls col-10">
                    <asp:TextBox ID="txt_title" runat="server"  class="input-text"></asp:TextBox>
                </div>
            </div>
           
            <div class="row cl">
                <label class="form-label col-2"><span class="c-red">*</span>公告分类:</label>
                <div class="formControls col-4">
                    <asp:DropDownList ID="ddl_CategoryName" runat="server" class="input-text" Width="80%">
                        <asp:ListItem Selected="True">公告</asp:ListItem>
                        <asp:ListItem>通知</asp:ListItem>
                        <asp:ListItem>其它</asp:ListItem>
                    </asp:DropDownList>
                </div>
            </div> 
            <div class="row cl">
                <label class="form-label col-2">公告内容:</label>
                <div class="formControls col-10 ">
                    <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" style="width: 100%; height: 400px; visibility: hidden;"></asp:TextBox>
                </div>
            </div>
            <div class="row cl">
                <div class="col-10 col-offset-2">
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <asp:Button ID="btn_submit" runat="server" Text="提交" class="btn btn-primary radius" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" OnClick="btn_submit_Click"/>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script>
    <script type="text/javascript" src="js/H-ui.js"></script>
    <script type="text/javascript" src="js/H-ui.admin.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });
        });
    </script>
</body>

DAL

 //创建数据库上下文对象
        carDBDataContext db = new carDBDataContext();

        /// <summary>
        /// 根据标题查询公告信息
        /// </summary>
        /// <param name="uname">公告标题</param>
        /// <returns>公告信息</returns>
        public object selectnotices(string title = null)
        {
            object notice = null;
            if (!string.IsNullOrEmpty(title))
            {
                notice = db.notices.Where(m => m.noticesTitle.Contains(title)).ToList();
            }
            else
            {
                notice = db.notices.ToList();
            }
            return notice;
        }

        /// <summary>
        /// 根据公告ID查询公告信息
        /// </summary>
        /// <param name="id">公告ID</param>
        /// <returns>公告实体</returns>
        public notices selectnoticesByID(int id)
        {
            return db.notices.Where(m => m.noticesId == id).FirstOrDefault();
        }


        /// <summary>
        /// 新增公告信息
        /// </summary>
        /// <param name="u">公告实体</param>
        /// <returns>是否新增成功true/false</returns>
        public bool Addnotices(notices n)
        {
            int count = db.notices.Count(); //初始公告数量
            db.notices.InsertOnSubmit(n); //新增
            db.SubmitChanges(); //提交并更改数据库
            if (count < db.notices.Count()) //如果初始公告数量 < 新增后数量
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除公告信息
        /// </summary>
        /// <param name="id">公告ID</param>
        /// <returns>是否删除成功true/false</returns>
        public bool Delnotices(int id)
        {
            int count = db.notices.Count(); //初始公告数量

            //根据id获取要删除的公告实体
            notices u = db.notices.Where(m => m.noticesId == id).FirstOrDefault();
            if (u != null)
            {
                db.notices.DeleteOnSubmit(u); //删除
                db.SubmitChanges();//提交并更改数据库
            }

            if (count > db.notices.Count()) //如果初始公告数量 > 删除后数量
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        /// <summary>
        /// 修改公告信息
        /// </summary>
        /// <param name="u">公告实体</param>
        /// <returns>是否修改成功true</returns>
        public bool Editnotices(notices n)
        {
            notices n1 = db.notices.Single(m => m.noticesId== n.noticesId); //找到数据库中要修改的实体对象
            n1.noticesId = n.noticesId;
            n1.noticesTitle = n.noticesTitle;
            n1.noticesContents = n.noticesContents;
            n1.CategoryName = n.CategoryName;
            n1.PublishTime = n.PublishTime;

            db.SubmitChanges(); //提交并更改数据库
            return true;
        }

 

<body>    <div class="pd-20">        <form action="" method="post" class="form form-horizontal" id="form_article_add" runat="server">            <div class="row cl">                <label class="form-label col-2"><span class="c-red">*</span>公告标题:</label>                <div class="formControls col-10">                    <asp:TextBox ID="txt_title" runat="server"  class="input-text"></asp:TextBox>                </div>            </div>                       <div class="row cl">                <label class="form-label col-2"><span class="c-red">*</span>公告分类:</label>                <div class="formControls col-4">                    <asp:DropDownList ID="ddl_CategoryName" runat="server" class="input-text" Width="80%">                        <asp:ListItem Selected="True">公告</asp:ListItem>                        <asp:ListItem>通知</asp:ListItem>                        <asp:ListItem>其它</asp:ListItem>                    </asp:DropDownList>                </div>            </div>             <div class="row cl">                <label class="form-label col-2">公告内容:</label>                <div class="formControls col-10 ">                    <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" style="width: 100%; height: 400px; visibility: hidden;"></asp:TextBox>                </div>            </div>            <div class="row cl">                <div class="col-10 col-offset-2">                    <asp:HiddenField ID="HiddenField1" runat="server" />                    <asp:Button ID="btn_submit" runat="server" Text="提交" class="btn btn-primary radius" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" OnClick="btn_submit_Click"/>                </div>            </div>        </form>    </div>    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>    <script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script>    <script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>    <script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script>    <script type="text/javascript" src="js/H-ui.js"></script>    <script type="text/javascript" src="js/H-ui.admin.js"></script>    <script type="text/javascript">        $(function () {            $('.skin-minimal input').iCheck({                checkboxClass: 'icheckbox-blue',                radioClass: 'iradio-blue',                increaseArea: '20%'            });        });    </script></body>

posted @ 2020-07-23 18:18  小花娟  阅读(647)  评论(0编辑  收藏  举报