ASP.NET + EasyUI三层架构实现增删改查之六:表现层之——添加信息界面搭建

之前一段时间有点事情耽搁了,所以今天才更新哈~接着上一篇博客,今天咱们讲添加信息界面的构建。先来看一下效果图,以添加宗地信息为例,其界面如下图所示:
ASP.NET + EasyUI三层架构实现增删改查之六:表现层之——添加信息界面搭建
这其实就是一个Window(窗体),EasyUI中用easyui-window表示,打开cadastre.html,添加如下代码:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <title></title>
    <link href="../Content/themes/default/easyui.css" rel="stylesheet" />
    <link href="../Content/themes/icon.css" rel="stylesheet" />
    <script src="../Scripts/jquery-1.11.3.min.js"></script>
    <script src="../Scripts/jquery.easyui-1.4.5.min.js"></script>
    <script src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
    <table id="dg" class="easyui-datagrid"></table>

    <div id="win" class="easyui-window" data-options="iconCls:'icon-add',title:'添加宗地信息',closed:true,modal:true,minimizable:false,maximizable:false,resizable:false,collapsible:false" style="width:430px;height:auto;overflow:hidden;">
        <div style="text-align:center;">
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标识码:
                <input id="bsm" class="easyui-textbox" type="text" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;要素代码:
                <input id="ysdm" class="easyui-textbox" type="text" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块编码:
                <input id="dkbm" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块类别:
                <input id="dklb" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块东至:
                <input id="dkdz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块西至:
                <input id="dkxz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块南至:
                <input id="dknz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块北至:
                <input id="dkbz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                指界人姓名:
                <input id="zjrxm" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                <a id="btnOk" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="add()" style="width:100px;height:30px;">确定</a>
                <a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="cancel()" style="width:100px;height:30px;">取消</a>
            </p>
        </div>
    </div>
    <script>
        $(document).ready(function ()
        {
            $('#dg').datagrid({
                url: '../Handlers/CadastreHandler.ashx?action=query',
                fit: true,                           // 自适应父容器
                fitColumns: true,                    // 列自适应
                pagination: true,                    // 是否分页
                rownumbers: true,                    // 显示行号
                singleSelect: false,                 // 是否单选
                striped: true,                       // 是否显示条纹
                idField: 'Id',
                pageNumber: 1,
                pageSize: 50,                        // 一页50行
                pageList: [50, 100, 200, 500],       // 一页50行、100行、200行、500行
                columns: [[                          // 列集合
                    { field: 'ck', checkbox: true },
                    { field: 'Id', title: '编号', align: 'center', width: 200 },
                    { field: 'BSM', title: '标识码', align: 'center', width: 200 },
                    { field: 'YSDM', title: '要素代码', align: 'center', width: 200 },
                    { field: 'DKBM', title: '地块编码', align: 'center', width: 200 },
                    { field: 'DKLB', title: '地块类别', align: 'center', width: 200 },
                    { field: 'DKDZ', title: '班级编号', align: 'center', width: 200 },
                    { field: 'DKXZ', title: '地块西至', align: 'center', width: 200 },
                    { field: 'DKNZ', title: '地块南至', align: 'center', width: 200 },
                    { field: 'DKBZ', title: '地块北至', align: 'center', width: 200 },
                    { field: 'ZJRXM', title: '指界人姓名', align: 'center', width: 200 }
                ]],
                toolbar: [                           // 工具条
                    {
                        id: "add",
                        text: '新增',
                        iconCls: 'icon-add',
                        handler: function ()
                        {
                            $('#win').window('open');
                        }
                    },
                    {
                        id: "update",
                        text: '编辑',
                        iconCls: 'icon-edit'
                    },
                    {
                        id: "delete",
                        text: '删除',
                        iconCls: 'icon-cut'
                    }]
            });
        });

        // 添加
        function add()
        {
            var bsm = $('#bsm').textbox('getValue');
            if (bsm == '' || isNaN(bsm))
            {
                $.messager.alert('提示', '请输入标识码', 'warning');
                return;
            }

            var ysdm = $('#ysdm').textbox('getValue');
            if (ysdm == '')
            {
                $.messager.alert('提示', '请输入要素代码', 'warning');
                return;
            }

            var dkbm = $('#dkbm').textbox('getValue');
            if (dkbm == '')
            {
                $.messager.alert('提示', '请输入地块编码', 'warning');
                return;
            }

            var dklb = $('#dklb').textbox('getValue');
            if (dklb == '')
            {
                $.messager.alert('提示', '请输入地块类别', 'warning');
                return;
            }

            var dkdz = $('#dkdz').textbox('getValue');
            if (dkdz == '')
            {
                $.messager.alert('提示', '请输入地块东至', 'warning');
                return;
            }

            var dkxz = $('#dkxz').textbox('getValue');
            if (dkxz == '')
            {
                $.messager.alert('提示', '请输入地块西至', 'warning');
                return;
            }

            var dknz = $('#dknz').textbox('getValue');
            if (dknz == '')
            {
                $.messager.alert('提示', '请输入地块南至', 'warning');
                return;
            }

            var dkbz = $('#dkbz').textbox('getValue');
            if (dkbz == '')
            {
                $.messager.alert('提示', '请输入地块东北至', 'warning');
                return;
            }

            var zjrxm = $('#zjrxm').textbox('getValue');
            if (zjrxm == '')
            {
                $.messager.alert('提示', '请输入指界人姓名', 'warning');
                return;
            }

            $.ajax({
                url: '../Handlers/CadastreHandler.ashx?action=add',
                type: 'post',
                dataType: 'json',
                data: {
                    bsm: bsm,
                    ysdm: ysdm,
                    dkbm: dkbm,
                    dklb: dklb,
                    dkdz: dkdz,
                    dkxz: dkxz,
                    dknz: dknz,
                    dkbz: dkbz,
                    zjrxm: zjrxm
                },
                success: function (data)
                {
                    if (data == 'Yes')
                    {
                        $.messager.alert('提示', '提加宗地信息成功', 'info');
                    }
                    else
                    {
                        $.messager.alert('提示', '添加宗地信息失败', 'error');
                    }
                },
                error: function (data)
                {
                    $.messager.alert('提示', data, 'error');
                }
            })
        }

        // 取消
        function cancel()
        {
            $('#win').window('close');
        }
    </script>

</body>
</html>

可以看到,在这里添加了一个新增按钮的句柄,也就是当点击新增按钮时会弹出一个窗体,EasyUI中利用KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲win').window('o…(’#win’).window(‘close’)关闭一个窗体。脚本里也很简单,先做一些基本的表单验证,然后ajax传值到后台,最后实现添加宗地信息,后台ashx文件代码如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using EasyUIApp.BLL;
using EasyUIApp.Entity;

namespace EasyUIApp.Handlers
{
    /// <summary>
    /// CadastreHandler 的摘要说明
    /// </summary>
    public class CadastreHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string action = context.Request.Params["action"];
            if (action == "query")
            {
                Query(context);
            }
            if (action == "add")
            {
                Add(context);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        // 查询宗地信息
        private void Query(HttpContext context)
        {
            // 获取EasyUI参数
            int page = int.Parse(context.Request.Params["page"]);
            int rows = int.Parse(context.Request.Params["rows"]);
            int total = 0;

            // 查询数据
            CadastreManager manager = new CadastreManager();
            List<CadastreEntity> list = manager.GetCadastreInfo(page, rows, out total);
            var data = new
            {
                total = total,
                rows = list
            };

            // 转换为JSON
            string json = JsonConvert.SerializeObject(data);
            context.Response.Write(json);
        }

        // 添加宗地信息
        private void Add(HttpContext context)
        {
            int bsm = int.Parse(context.Request.Params["bsm"]);
            string ysdm = context.Request.Params["ysdm"];
            string dkbm = context.Request.Params["dkbm"];
            string dklb = context.Request.Params["dklb"];
            string dkdz = context.Request.Params["dkdz"];
            string dkxz = context.Request.Params["dkxz"];
            string dknz = context.Request.Params["dknz"];
            string dkbz = context.Request.Params["dkbz"];
            string zjrxm = context.Request.Params["zjrxm"];

            // 创建实体
            CadastreEntity entity = new CadastreEntity()
            {
                BSM = bsm,
                YSDM = ysdm,
                DKBM = dkbm,
                DKLB = dklb,
                DKDZ = dkdz,
                DKXZ = dkxz,
                DKNZ = dknz,
                DKBZ = dkbz,
                ZJRXM = zjrxm
            };

            // 添加实体
            CadastreManager manager = new CadastreManager();
            bool ok = manager.AddCadastreInfo(entity);
            if (ok)
            {
                context.Response.Write(JsonConvert.SerializeObject("Yes"));
            }
            else
            {
                context.Response.Write(JsonConvert.SerializeObject("No"));
            }
        }
    }
}

可以看到,在原有代码的基础之上又添加了一个Add函数,该函数首先接收前台传过来的参数,然后调用BLL层的方法实现宗地信息的添加,也很简单哈~最终效果如下图所示:
ASP.NET + EasyUI三层架构实现增删改查之六:表现层之——添加信息界面搭建
ASP.NET + EasyUI三层架构实现增删改查之六:表现层之——添加信息界面搭建
最后附上界址点和界址线添加信息的代码:
boundaryPoint.html

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <link href="../Content/themes/default/easyui.css" rel="stylesheet" />
    <link href="../Content/themes/icon.css" rel="stylesheet" />
    <script src="../Scripts/jquery-1.11.3.min.js"></script>
    <script src="../Scripts/jquery.easyui-1.4.5.min.js"></script>
    <script src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
    <table id="dg" class="easyui-datagrid"></table>

    <div id="win" class="easyui-window" data-options="iconCls:'icon-add',title:'添加界址点信息',closed:true,modal:true,minimizable:false,maximizable:false,resizable:false,collapsible:false" style="width:430px;height:auto;overflow:hidden;">
        <div style="text-align:center;">
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标识码:
                <input id="bsm" class="easyui-textbox" type="text" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;要素代码:
                <input id="ysdm" class="easyui-textbox" type="text" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;界址点号:
                <input id="jzdh" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;界标类型:
                <input id="jblx" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                界址点类型:
                <input id="jzdlx" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;地块编码:
                <input id="dkbm" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;横坐标值:
                <input id="xzbz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;纵坐标值:
                <input id="yzbz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                <a id="btnOk" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="add()" style="width:100px;height:30px;">确定</a>
                <a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="cancel()" style="width:100px;height:30px;">取消</a>
            </p>
        </div>
    </div>

    <script>
        $(document).ready(function ()
        {
            $('#dg').datagrid({
                url: '../Handlers/BoundaryPointHandler.ashx?action=query',
                fit: true,
                fitColumns: true,
                pagination: true,
                rownumbers: true,
                singleSelect: false,
                striped: true,
                idField: 'Id',
                pageNumber: 1,
                pageSize: 50,
                pageList: [50, 100, 200, 500],
                columns: [[
                    { field: 'ck', checkbox: true },
                    { field: 'Id', title: '编号', align: 'center', width: 200 },
                    { field: 'BSM', title: '标识码', align: 'center', width: 200 },
                    { field: 'YSDM', title: '要素代码', align: 'center', width: 200 },
                    { field: 'JZDH', title: '界址点号', align: 'center', width: 200 },
                    { field: 'JBLX', title: '界标类型', align: 'center', width: 200 },
                    { field: 'JZDLX', title: '界址点类型', align: 'center', width: 200 },
                    { field: 'DKBM', title: '地块编码', align: 'center', width: 200 },
                    { field: 'XZBZ', title: 'X坐标值', align: 'center', width: 200 },
                    { field: 'YZBZ', title: 'Y坐标值', align: 'center', width: 200 }
                ]],
                toolbar: [
                    {
                        id: "add",
                        text: '新增',
                        iconCls: 'icon-add',
                        handler: function ()
                        {
                            $('#win').window('open');
                        }
                    },
                    {
                        id: "update",
                        text: '编辑',
                        iconCls: 'icon-edit'
                    },
                    {
                        id: "delete",
                        text: '删除',
                        iconCls: 'icon-cut'
                    }]
            });
        });

        // 添加
        function add()
        {
            var bsm = $('#bsm').textbox('getValue');
            if (bsm == '' || isNaN(bsm))
            {
                $.messager.alert('提示', '请输入标识码', 'warning');
                return;
            }

            var ysdm = $('#ysdm').textbox('getValue');
            if (ysdm == '')
            {
                $.messager.alert('提示', '请输入要素代码', 'warning');
                return;
            }

            var jzdh = $('#jzdh').textbox('getValue');
            if (jzdh == '')
            {
                $.messager.alert('提示', '请输入界址点号', 'warning');
                return;
            }

            var jblx = $('#jblx').textbox('getValue');
            if (jblx == '')
            {
                $.messager.alert('提示', '请输入界标类型', 'warning');
                return;
            }

            var jzdlx = $('#jzdlx').textbox('getValue');
            if (jzdlx == '')
            {
                $.messager.alert('提示', '请输入界址点类型', 'warning');
                return;
            }

            var dkbm = $('#dkbm').textbox('getValue');
            if (dkbm == '')
            {
                $.messager.alert('提示', '请输入地块编码', 'warning');
                return;
            }

            var xzbz = $('#xzbz').textbox('getValue');
            if (xzbz == '' || isNaN(xzbz))
            {
                $.messager.alert('提示', '请输入横坐标值', 'warning');
                return;
            }

            var yzbz = $('#yzbz').textbox('getValue');
            if (yzbz == '' || isNaN(yzbz))
            {
                $.messager.alert('提示', '请输入纵坐标值', 'warning');
                return;
            }

            $.ajax({
                url: '../Handlers/BoundaryPointHandler.ashx?action=add',
                type: 'post',
                dataType: 'json',
                data: {
                    bsm: bsm,
                    ysdm: ysdm,
                    jzdh: jzdh,
                    jblx: jblx,
                    jzdlx: jzdlx,
                    dkbm: dkbm,
                    xzbz: xzbz,
                    yzbz: yzbz
                },
                success: function (data)
                {
                    if (data == 'Yes')
                    {
                        $.messager.alert('提示', '提加界址点信息成功', 'info');
                    }
                    else
                    {
                        $.messager.alert('提示', '添加界址点信息失败', 'error');
                    }
                },
                error: function (data)
                {
                    $.messager.alert('提示', data, 'error');
                }
            })
        }

        // 取消
        function cancel()
        {
            $('#win').window('close');
        }
    </script>

</body>
</html>

BoundaryPointHandler.ashx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using EasyUIApp.BLL;
using EasyUIApp.Entity;

namespace EasyUIApp.Handlers
{
    /// <summary>
    /// BoundaryPointHandler 的摘要说明
    /// </summary>
    public class BoundaryPointHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string action = context.Request.Params["action"];
            if (action == "query")
            {
                Query(context);
            }
            if (action == "add")
            {
                Add(context);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        
        // 查询界址点信息
        private void Query(HttpContext context)
        {
            // 获取EasyUI参数
            int page = int.Parse(context.Request.Params["page"]);
            int rows = int.Parse(context.Request.Params["rows"]);
            int total = 0;

            // 查询数据
            BoundaryPointManager manager = new BoundaryPointManager();
            List<BoundaryPointEntity> list = manager.GetBoundaryPointInfo(page, rows, out total);
            var data = new
            {
                total = total,
                rows = list
            };

            // 转换为JSON
            string json = JsonConvert.SerializeObject(data);
            context.Response.Write(json);
        }

        // 添加界址点信息
        private void Add(HttpContext context)
        {
            int bsm = int.Parse(context.Request.Params["bsm"]);
            string ysdm = context.Request.Params["ysdm"];
            string jzdh = context.Request.Params["jzdh"];
            string jblx = context.Request.Params["jblx"];
            string jzdlx = context.Request.Params["jzdlx"];
            string dkbm = context.Request.Params["dkbm"];
            double xzbz = double.Parse(context.Request.Params["xzbz"]);
            double yzbz = double.Parse(context.Request.Params["yzbz"]);

            // 创建实体
            BoundaryPointEntity entity = new BoundaryPointEntity()
            {
                BSM = bsm,
                YSDM = ysdm,
                JZDH = jzdh,
                JBLX = jblx,
                JZDLX = jzdlx,
                DKBM = dkbm,
                XZBZ = xzbz,
                YZBZ = yzbz
            };

            // 添加实体
            BoundaryPointManager manager = new BoundaryPointManager();
            bool ok = manager.AddBoundaryPointInfo(entity);
            if (ok)
            {
                context.Response.Write(JsonConvert.SerializeObject("Yes"));
            }
            else
            {
                context.Response.Write(JsonConvert.SerializeObject("No"));
            }
        }
    }
}

boundaryLine.html

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <link href="../Content/themes/default/easyui.css" rel="stylesheet" />
    <link href="../Content/themes/icon.css" rel="stylesheet" />
    <script src="../Scripts/jquery-1.11.3.min.js"></script>
    <script src="../Scripts/jquery.easyui-1.4.5.min.js"></script>
    <script src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
    <table id="dg" class="easyui-datagrid"></table>

    <div id="win" class="easyui-window" data-options="iconCls:'icon-add',title:'添加界址线信息',closed:true,modal:true,minimizable:false,maximizable:false,resizable:false,collapsible:false" style="width:430px;height:auto;overflow:hidden;">
        <div style="text-align:center;">
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;地块编码:
                <input id="dkbm" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标识码:
                <input id="bsm" class="easyui-textbox" type="text" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;要素代码:
                <input id="ysdm" class="easyui-textbox" type="text" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;界线性质:
                <input id="jxxz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;界址线类别:
                <input id="jzxlb" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;界址线位置:
                <input id="jzxwz" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;界址线号:
                <input id="jzxh" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;起界址点号:
                <input id="qjzdh" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;终界址点号:
                <input id="zjzdh" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;界址线说明:
                <input id="jzxsm" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                毗邻地物权利人:
                <input id="pldwqlr" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                毗邻地物指界人:
                <input id="pldwzjr" class="easyui-textbox" style="width:300px;">
            </p>
            <p>
                <a id="btnOk" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="add()" style="width:100px;height:30px;">确定</a>
                <a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="cancel()" style="width:100px;height:30px;">取消</a>
            </p>
        </div>
    </div>

    <script>
        $(document).ready(function ()
        {
            $('#dg').datagrid({
                url: '../Handlers/BoundaryLineHandler.ashx?action=query',
                fit: true,
                fitColumns: true,
                pagination: true,
                rownumbers: true,
                singleSelect: false,
                striped: true,
                idField: 'Id',
                pageNumber: 1,
                pageSize: 50,
                pageList: [50, 100, 200, 500],
                columns: [[
                    { field: 'ck', checkbox: true },
                    { field: 'Id', title: '编号', align: 'center', width: 200 },
                    { field: 'DKBM', title: '地块编码', align: 'center', width: 200 },
                    { field: 'BSM', title: '标识码', align: 'center', width: 200 },
                    { field: 'YSDM', title: '要素代码', align: 'center', width: 200 },
                    { field: 'JXXZ', title: '界线性质', align: 'center', width: 200 },
                    { field: 'JZXLB', title: '界址线类别', align: 'center', width: 200 },
                    { field: 'JZXWZ', title: '界址线位置', align: 'center', width: 200 },
                    { field: 'JZXH', title: '界址线号', align: 'center', width: 200 },
                    { field: 'QJZDH', title: '起界址点号', align: 'center', width: 200 },
                    { field: 'ZJZDH', title: '终界址点号', align: 'center', width: 200 },
                    { field: 'JZXSM', title: '界址线说明', align: 'center', width: 200 },
                    { field: 'PLDWQLR', title: '毗邻地物权利人', align: 'center', width: 200 },
                    { field: 'PLDWZJR', title: '毗邻地物指界人', align: 'center', width: 200 }
                ]],
                toolbar: [
                    {
                        id: "add",
                        text: '新增',
                        iconCls: 'icon-add',
                        handler: function ()
                        {
                            $('#win').window('open');
                        }
                    },
                    {
                        id: "update",
                        text: '编辑',
                        iconCls: 'icon-edit'
                    },
                    {
                        id: "delete",
                        text: '删除',
                        iconCls: 'icon-cut'
                    }]
            });
        });

        // 添加
        function add()
        {
            var dkbm = $('#dkbm').textbox('getValue');
            if (dkbm == '')
            {
                $.messager.alert('提示', '请输入地块编码', 'warning');
                return;
            }

            var bsm = $('#bsm').textbox('getValue');
            if (bsm == '' || isNaN(bsm))
            {
                $.messager.alert('提示', '请输入标识码', 'warning');
                return;
            }

            var ysdm = $('#ysdm').textbox('getValue');
            if (ysdm == '')
            {
                $.messager.alert('提示', '请输入要素代码', 'warning');
                return;
            }

            var jxxz = $('#jxxz').textbox('getValue');
            if (jxxz == '')
            {
                $.messager.alert('提示', '请输入界线性质', 'warning');
                return;
            }

            var jzxlb = $('#jzxlb').textbox('getValue');
            if (jzxlb == '')
            {
                $.messager.alert('提示', '请输入界址线类别', 'warning');
                return;
            }

            var jzxwz = $('#jzxwz').textbox('getValue');
            if (jzxwz == '')
            {
                $.messager.alert('提示', '请输入界址线位置', 'warning');
                return;
            }

            var jzxh = $('#jzxh').textbox('getValue');
            if (jzxh == '')
            {
                $.messager.alert('提示', '请输入界址线号', 'warning');
                return;
            }

            var qjzdh = $('#qjzdh').textbox('getValue');
            if (qjzdh == '')
            {
                $.messager.alert('提示', '请输入起界址点号', 'warning');
                return;
            }

            var zjzdh = $('#zjzdh').textbox('getValue');
            if (zjzdh == '')
            {
                $.messager.alert('提示', '请输入终界址点号', 'warning');
                return;
            }

            var jzxsm = $('#jzxsm').textbox('getValue');
            if (jzxsm == '')
            {
                $.messager.alert('提示', '请输入界址线说明', 'warning');
                return;
            }

            var pldwqlr = $('#pldwqlr').textbox('getValue');
            if (pldwqlr == '')
            {
                $.messager.alert('提示', '请输入毗邻地物权利人', 'warning');
                return;
            }

            var pldwzjr = $('#pldwzjr').textbox('getValue');
            if (pldwzjr == '')
            {
                $.messager.alert('提示', '请输入毗邻地物指界人', 'warning');
                return;
            }

            $.ajax({
                url: '../Handlers/BoundaryLineHandler.ashx?action=add',
                type: 'post',
                dataType: 'json',
                data: {
                    dkbm: dkbm,
                    bsm: bsm,
                    ysdm: ysdm,
                    jxxz: jxxz,
                    jzxlb: jzxlb,
                    jzxwz: jzxwz,
                    jzxh: jzxh,
                    qjzdh: qjzdh,
                    zjzdh: zjzdh,
                    jzxsm: jzxsm,
                    pldwqlr: pldwqlr,
                    pldwzjr: pldwzjr
                },
                success: function (data)
                {
                    if (data == 'Yes')
                    {
                        $.messager.alert('提示', '提加界址线信息成功', 'info');
                    }
                    else
                    {
                        $.messager.alert('提示', '添加界址线信息失败', 'error');
                    }
                },
                error: function (data)
                {
                    $.messager.alert('提示', data, 'error');
                }
            })
        }

        // 取消
        function cancel()
        {
            $('#win').window('close');
        }
    </script>

</body>
</html>

BoundaryLineHandler.ashx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using EasyUIApp.BLL;
using EasyUIApp.Entity;

namespace EasyUIApp.Handlers
{
    /// <summary>
    /// BoundaryLineHandler 的摘要说明
    /// </summary>
    public class BoundaryLineHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string action = context.Request.Params["action"];
            if (action == "query")
            {
                Query(context);
            }
            if (action == "add")
            {
                Add(context);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        // 查询界址线信息
        private void Query(HttpContext context)
        {
            // 获取EasyUI参数
            int page = int.Parse(context.Request.Params["page"]);
            int rows = int.Parse(context.Request.Params["rows"]);
            int total = 0;

            // 查询数据
            BoundaryLineManager manager = new BoundaryLineManager();
            List<BoundaryLineEntity> list = manager.GetBoundaryLineInfo(page, rows, out total);
            var data = new
            {
                total = total,
                rows = list
            };

            // 转换为JSON
            string json = JsonConvert.SerializeObject(data);
            context.Response.Write(json);
        }

        // 添加界址线信息
        private void Add(HttpContext context)
        {
            string dkbm = context.Request.Params["dkbm"];
            int bsm = int.Parse(context.Request.Params["bsm"]);
            string ysdm = context.Request.Params["ysdm"];
            string jxxz = context.Request.Params["jxxz"];
            string jzxlb = context.Request.Params["jzxlb"];
            string jzxwz = context.Request.Params["jzxwz"];
            string jzxh = context.Request.Params["jzxh"];
            string qjzdh = context.Request.Params["qjzdh"];
            string zjzdh = context.Request.Params["zjzdh"];
            string jzxsm = context.Request.Params["jzxsm"];
            string pldwqlr = context.Request.Params["pldwqlr"];
            string pldwzjr = context.Request.Params["pldwzjr"];

            // 创建实体
            BoundaryLineEntity entity = new BoundaryLineEntity()
            {
                DKBM = dkbm,
                BSM = bsm,
                YSDM = ysdm,
                JXXZ = jxxz,
                JZXLB = jzxlb,
                JZXWZ = jzxwz,
                JZXH = jzxh,
                QJZDH = qjzdh,
                ZJZDH = zjzdh,
                JZXSM = jzxsm,
                PLDWQLR = pldwqlr,
                PLDWZJR = pldwzjr
            };

            // 添加试题
            BoundaryLineManager manager = new BoundaryLineManager();
            bool ok = manager.AddBoundaryLineInfo(entity);
            if (ok)
            {
                context.Response.Write(JsonConvert.SerializeObject("Yes"));
            }
            else
            {
                context.Response.Write(JsonConvert.SerializeObject("No"));
            }
        }
    }
}

添加信息的功能其实很简单,首先前台传递参数,然后后台接收参数,调用相关函数进行添加即可,关键是要熟悉如何利用ajax进行参数传递,下一篇博客介绍如何删除选中的信息。

上一篇:SDKMAN安装使用


下一篇:Java version sdkman