简单的增删改查弹窗

这是一个简单的增删改查的弹窗的制作   

对数据库的操作方法BLL

 9     public class QGCatalogBLL : IDisposable
10     {
11         private AllureContext _context;
12 
13         public QGCatalogBLL(string EFConnectionString)
14         {
15             _context = new AllureContext(EFConnectionString);
16         }
17         public QGCatalogBLL(AllureContext Context)
18         {
19             _context = Context;
20         }
21 
22         private bool disposedValue = false;
23         protected virtual void Dispose(bool disposing)
24         {
25             if (!this.disposedValue)
26             {
27                 if (disposing)
28                 {
29                     _context.Dispose();
30                 }
31             }
32             this.disposedValue = true;
33         }
34         public void Dispose()
35         {
36             Dispose(true);
37             GC.SuppressFinalize(this);
38         }
39 
40         public void Create(QGCatalog qgCatalog)
41         {
42             try
43             {
44                 _context.QGCatalogs.AddObject(qgCatalog);
45                 _context.SaveChanges();
46             }
47             catch (Exception E)
48             {
49                 throw E;
50             }
51         }
52 
53         public void Update(QGCatalog qgCatalog)
54         {
55             try
56             {
57                 if (!_context.IsAttached(qgCatalog))
58                     _context.QGCatalogs.Attach(qgCatalog);
59                 _context.ObjectStateManager.ChangeObjectState(qgCatalog, System.Data.EntityState.Modified);
60                 _context.SaveChanges();
61             }
62             catch (Exception E)
63             {
64                 throw E;
65             }
66         }
67 
68         public QGCatalog Retrieve(short QGCatalogID)
69         {
70             return (from i in _context.QGCatalogs
71                     where i.QGCatalogID == QGCatalogID
72                     select i).FirstOrDefault();
73         }
74 
75         public void Delete(short QGCatalogID)
76         {
77             _context.ExecuteStoreCommand("delete QGCatalog where QGCatalogID=" + QGCatalogID.ToString());
78         }
79 
80         public IEnumerable<QGCatalog> ListQGCatalogs()
81         {
82             return (from i in _context.QGCatalogs
83                     select i).ToList();
84         }
85     }

然后就是添加一个控制器  作为程序运行的逻辑

    
        // GET: /QGCatalog/
        /// <summary>
        /// 显示数据
        /// renwei 2013-10-10
        /// </summary>
        /// <returns></returns>
        public ActionResult QGCatalogs()
        {
            QGCatalogBLL qgcatalogBLL = new QGCatalogBLL(HttpContext.Application["EFConnectionString"].ToString());

            IEnumerable<QGCatalog> QGCatalogs = qgcatalogBLL.ListQGCatalogs();
            return View(QGCatalogs);
        }
        /// <summary>
        /// 显示详情
        /// renwei 2013-10-10
        /// </summary>
        /// <param name="QGCatalogID"></param>
        /// <returns></returns>
        public ActionResult RetrieveQGCatalog(short QGCatalogID)
        {
            QGCatalogBLL qgcatalogBLL = new QGCatalogBLL(HttpContext.Application["EFConnectionString"].ToString());

            QGCatalog qGCatalog = qgcatalogBLL.Retrieve(QGCatalogID);
            return View(qGCatalog);
        }


        /// <summary>
        /// 添加一个QGCatalog
        /// renwei 2013-10-11
        /// </summary> 
        /// <returns></returns>
        public ActionResult CreateQGCatalog(QGCatalog qgCatalog)
        {
            QGCatalogBLL qgcatalogBLL = new QGCatalogBLL(HttpContext.Application["EFConnectionString"].ToString());

            qgcatalogBLL.Create(qgCatalog);

            return RedirectToAction("QGCatalogs");
        }

        /// <summary>
        /// 删除QGCatalog
        /// renwei 2013-10-11
        /// </summary>
        /// <returns></returns>
        public ActionResult DeleteQGCatalog(short QGCatalogID)
        {

            QGCatalogBLL qgcatalogBLL = new QGCatalogBLL(HttpContext.Application["EFConnectionString"].ToString());

            qgcatalogBLL.Delete(QGCatalogID);

            return RedirectToAction("QGCatalogs");
        }
        /// <summary>
        /// 修改导入
        /// renwei 2013-10-11
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateQGCatalog(QGCatalog qgCatalog)
        {
            QGCatalogBLL qgcatalogBLL = new QGCatalogBLL(HttpContext.Application["EFConnectionString"].ToString());

            qgcatalogBLL.Update(qgCatalog);

            return RedirectToAction("QGCatalogs");
        }
        

最后  就是制作一个页面   并在页面上添加入script 制作弹窗

@model IEnumerable<Allure.DataModels.QGCatalog>

@{
    ViewBag.Title = "QGCatalog";
}

<!--Jquery 皮肤-->
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.2/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css" />
<!--Jquery UI 1.10.2-->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.2/jquery-ui.min.js" type="text/javascript"></script>


<h2>QGCatalog</h2>
<p>
    <a id="PersonCreate" href="javascript:void(0)">添加 </a>
</p>
@if (Model != null && Model.Count() > 0)
{
    <table class="gridtable">
        <tr>
            <th>QGCatalogID
            </th>
            <th>CatalogName
            </th>
            <th>Operation
            </th>
        </tr>
        @foreach (var user in Model)
        {
            <tr>

                <td>
                    <a id="@("QGCatalogID" + user.QGCatalogID)">@user.QGCatalogID</a>
                </td>
                <td>
                    <a id="@("CatalogName" + user.QGCatalogID)">@user.CatalogName</a>
                </td>
                <td>
                    <a class="editButton" id="@user.QGCatalogID" href="javascript:void(0)">编辑</a>
                    |
                    <a class="DeleteButton" id="@user.QGCatalogID" href="javascript:void(0)">删除</a>

                </td>

            </tr>

        }

    </table>
}

<div id="PersonCreateTable">

    <form action="@Url.Action("CreateQGCatalog", "QGCatalog")" method="post" name="form" id="form">
        QGCatalogID:
    <input type="number" name="QGCatalogID" id="QGCatalogID">
        <br />
        <br />
        CatalogName:
    <input type="text" name="CatalogName" id="CatalogName">

        <p>
            <input type="submit" value="添加" />
        </p>
    </form>
</div>

<div id="PersonEditTable">

    <form action="@Url.Action("UpdateQGCatalog", "QGCatalog")" name="form" >
        <table class="gridtable">
            <tr>
                <th>QGCatalogID
                </th>
                <th>CatalogName
                </th>
                <th>Operation
                </th>
            </tr>
            <tr>

                <td>
                    <input id="UpdateQGCatalogID" name="QGCatalogID" type="text" />
                </td>
                <td>
                    <input id="UpdateCatalogName" name="CatalogName" class="text-box single-line" type="text" />
                </td>
                <td>
                    <input type="submit" value="保存" />

                </td>

            </tr>


        </table>
    </form>

</div>

<div id="PersonDeleteTable">

    <form action="@Url.Action("DeleteQGCatalog", "QGCatalog")" method="post" name="form">
        QGCatalogID:
    <input type="text" name="QGCatalogID" id="DeleteQGCatalogID" readonly="readonly">
        <br />
        <br />
        CatalogName:
    <input type="text" name="CatalogName" id="DeleteCatalogName" readonly="readonly">

        <p style="color: red;">Are you sure?</p>
        <p>
            <input type="submit" value="删除" />
        </p>
    </form>
</div>

<script type="text/javascript">
    //添加
    $("#PersonCreateTable").dialog({
        autoOpen: false,
        height: 220,
        width: 185,
        modal: true,
        show: {
            effect: "blind",
            duration: 500
        },
        hide: {
            effect: "explode",
            duration: 500
        }
    });

    //点击添加 弹出 对话框
    $("#PersonCreate").click(function () {
        $("#PersonCreateTable").dialog("open");
    });



    //编辑
    $("#PersonEditTable").dialog({
        autoOpen: false,
        height: 120,
        width: 450,
        modal: true,
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "explode",
            duration: 1000
        }
    });

    $(".editButton").click(function () {

        var id = $(this).attr("id");

        $("#UpdateQGCatalogID").val($("#QGCatalogID" + id).text());

        $("#UpdateCatalogName").val($("#CatalogName" + id).text());

        $("#PersonEditTable").dialog("open");
    });


    //删除
    $("#PersonDeleteTable").dialog({
        autoOpen: false,
        height: 220,
        width: 185,
        modal: true,
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "explode",
            duration: 1000
        }
    });

    $(".DeleteButton").click(function () {
        var id = $(this).attr("id");

        $("#DeleteQGCatalogID").val($("#QGCatalogID" + id).text());
        $("#DeleteCatalogName").val($("#CatalogName" + id).text());

        $("#PersonDeleteTable").dialog("open");
    });




</script>

至此  一个简单的对数据库的增删改查的弹窗就做好了

 

posted @ 2013-10-14 10:18  黑色白沙  阅读(502)  评论(0编辑  收藏  举报