您好,
会员登录 快速注册
退出 ( 条未读消息)
关于本站 意见反馈 首页

公告:小宅博客网可以开发票了,需要发票的,去群里找群主哈!!
全部文章分类
  • 人工智能 >

  • 编程语言 >

  • WPF系列 >

  • ASP.NET系列 >

  • Linux >

  • 数据库 >

  • 嵌入式 >

  • WEB技术 >

  • PLC系列 >

  • 微服务与框架 >

  • 小宅DIY >

  • 学习资料 >

OpenCv基础 ANN车牌识别 yolov5车牌识别 指针式仪表识别 ROS系列 YOLO Halcon Detectron2 昇腾AI ChatGPT在线体验 英伟达JETSON ChatGLM ChatTTS FunASR 地平线 ByteTrack 魔搭社区 LangChain
C C# C++ Python Java Go
WPF
ASP.NET小功能 GPS定位系统-MVC GPS定位系统-VUE ASP.NET WebRTC
Linux Linux内核 Shell MakeFile
MySql SqlServer Oracle
STM8 STM32 51单片机
VUE入门 HTML JavaScript CSS layui镜像网站 ElementUi中文官网 element-plus 图标
三菱 欧姆龙 西门子 施耐德 松下 台达
IOTSharp IOTGateway ABP FRAMEWORK Docker
亚克力音响 编程仙途:智驭万法
面试题与技巧 Python入门技能树 微软C#教程
首页 编程之美 工具下载 全国就业 流量地图 文心一言
GPS定位系统-MVC
.NET6.0 GPS定位系统介绍(物联网) 系列源码下载 1、新建.net core web工程 2、添加自定义登录页面 3、添加百度地图页面 4、添加后台日志系统 5、添加mysql数据存储 6、添加SqlServer数据存储(额外内容) 7、用户注册与登录功能实现 8、添加坐标报表页面(用于遍历地图坐标) 9、前后端数据交互与报表数据展示 10、报表数据的编辑与修改 11、用户登录与退出 12、自定义GPRS通讯协议 13、添加TCP通讯功能(接收) 14、添加TCP通讯功能(发送) 15、模拟GPRS数据通讯 16、设备链接状态检测与提示 17、新建Windows Server虚拟机 18、服务器IIS运行环境配置 19、服务器.net程序发布 20、关于如何配置.net3.1框架 21、关于如何配置.net5.0框架 22、WinForm版地图上位机(带数据库和TCP功能) 23、WPF版地图上位机(带数据库和TCP功能) 24、公网映射与外网通讯 25、GPS协议与AT命令流程说明 26、GPRS协议与AT命令流程说明 27、STM32、A9G硬件连接图 28、STM32开发环境搭建 29、STM32 GPS/GPRS通讯功能实现 30、STM32 GPS定位数据上报服务器 31、室外最终效果演示 32、结束语
9、前后端数据交互与报表数据展示
11、用户登录与退出
激萌の小宅 小宅博客网 GPS定位系统-MVC

文章作者:激萌の小宅

促销:¥0

价格:¥0

配送方式: 购买后立即生效(如购买异常,请联系站长)
付款之后一定要等待自动跳转结束,否则购买可能会失败
  • 0 天

    有效期

  • 0

    总销量

  • 0

    累计评价

报表数据的编辑与修改 - (第十讲)

视频讲解如下:


工程源码下载:GPS定位系统系列教程源码下载


1、功能修改

        在上一节中,我们已经实现了如何在前端显示一张报表数据,本章节要讲的内容是,如何实现对报表数据的编辑与删除,当然了,这里不包含新增的操作,新增数据的话,我们这里是要通过下位机来获取的,所以,新增的功能,这里就不写了,如果有需要的童鞋,可以自行添加,操作方法其实和编辑操作是一样的。

        首先呢,同样是在上一讲的基础上,我们先修改HomeController.cs,新增两个方法:编辑与修改,添加内容如下:

/// <summary>
/// 编辑
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public ActionResult Edit(string[] msg)
{
    AjaxResult res = new AjaxResult() { Success = false };
    if (msg == null || msg.Length != 2) return Content(res.ToJson());
    try
    {
        using (MyDbContext db = new MyDbContext() { config = Res.SqlStr })
        {
            GpsData a = db.Tb_GpsData.FirstOrDefault(x => x.ID == int.Parse(msg[0]));
            if (a != null)
            {
                a.gps = msg[1];
                db.SaveChanges();
                res.Success = true;
            }
            else
            {
                throw new Exception($"未查询到ID:{msg[0]}");
            }
        }
    }
    catch (Exception e)
    {
        res.ErrorCode = e.Message;
    }
    return Content(res.ToJson());
}

/// <summary>
/// 删除
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public ActionResult Delete(string msg)
{
    AjaxResult res = new AjaxResult() { Success = false };
    if (msg == null || msg == "") return Content(res.ToJson());
    try
    {
        using (MyDbContext db = new MyDbContext() { config = Res.SqlStr })
        {
            GpsData a = db.Tb_GpsData.FirstOrDefault(x => x.ID == int.Parse(msg));
            if(a != null)
            {
                db.Remove(a);
                db.SaveChanges();
                res.Success = true;
            }
            else
            {
                throw new Exception($"未查询到ID:{msg}");
            }
        }
    }
    catch (Exception e)
    {
        res.ErrorCode = e.Message;
    }
    return Content(res.ToJson());
}


tab.cshtml修改如下:

@using DbEntity.Tables;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    <link rel="stylesheet" href="/css/bootstrap.min.css"  />
    <link rel="stylesheet" href="/css/ace.min.css" />
    <link rel="stylesheet" href="/font/css/font-awesome.min.css" />

    <script src="/js/jquery.min 1.11.3.js"></script>
    <script src="/js/jquery.dataTables.min.js"></script>
    <script src="/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/js/layer/layer.js"></script>
    <title>报表翻页</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="sort_style">
            <!--分类类表-->
            <div class="article_sort_list">
                <table class="table table-striped table-bordered table-hover" id="sample-table">
                    <thead>
                        <tr>
                            <th width="25"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                            <th width="40px">ID</th>
                            <th width="40px">用户</th>
                            <th width="100px">坐标</th>
                            <th width="100px">添加时间</th>
                            <th width="100px">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            List<GpsData> tab = ViewData["tab"] as List<GpsData>;
                            foreach (GpsData p in tab)
                            {
                                <tr>
                                    <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                                    <td>@p.ID</td>
                                    <td>@p.UserId</td>
                                    <td>@p.gps</td>
                                    <td>@p.CreateTime</td>
                                    <td class="td-manage">
                                        <a title="编辑" href="javascript:;" onclick="myEdit('@p.ID','@p.gps')"class="btn btn-xs btn-info"><i class="fa fa-edit bigger-120"></i></a>
                                        <a title="删除" href="javascript:;" onclick="myDelete('@p.ID')" class="btn btn-xs btn-danger"><i class="fa fa-trash  bigger-120"></i></a>
                                    </td>
                                </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!--编辑-->
    <div id="EditId" style="display:none">
        <ul style="margin:10px" >
            <li><label>新坐标:</label><span><input id="edit_id" name="新坐标" type="text"/></span></li>
        </ul>
    </div>

</body>
</html>
<script>
    $(function () {
            if (document.getElementById('sample-table')) {
                $('#sample-table').dataTable({
                    "bAutoWidth": false,       // 关闭自动列宽
                    // "aaSorting": [[0, "asc"]], // 默认第几个排序 正序:asc  倒序:desc
                    //"bStateSave": true,        // 状态保存(与iDisplayLength有冲突)
                    "bFilter": true,          // 开启搜索框
                    //"bLengthChange": false,    // 去掉每页显示多少条数据方法
                    'iDisplayLength': 5,       // 每页初始显示5条记录
                    "bInfo": true,            // 开关,是否显示表格的一些信息(当前显示XX-XX条数据,共XX条)
                    //"responsive": false,     // 关闭响应式效果,否则以上设置无效
                    "bPaginate": true,         // 开启分页
                    "aoColumnDefs": [
                        //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                        { "orderable": false, "aTargets": [0, 2, 3, 5] }// 制定列不参与排序
                    ]
                });
            }

            $('table th input:checkbox').on('click', function () {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function () {
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
            });
        });
    })

    /* 编辑 */
    function myEdit(id, gps) {
        $("#edit_id").val(gps);
        layer.open({
            type: 1,
            title: '修改坐标信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['390px', '180px'],
            content: $('#EditId'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var strArr = [id, $("#edit_id").val()];
                $.post('Edit', { msg: strArr }, function (resJson) {
                    var res = JSON.parse(resJson);
                    if (!res.Success) {
                        layer.alert(res.ErrorCode, { title: '编辑失败', icon: 5 });
                        return;
                    }
                    location.reload();
                });
            }
        });
    }

    /* 删除 */
    function myDelete(id) {
        layer.confirm('确认要删除[' + id + ']吗?', { icon: 0, }, function (index) {
            $.post('Delete', { msg: id }, function (resJson) {
                var res = JSON.parse(resJson);
                if (!res.Success) {
                    layer.alert(res.ErrorCode, { title: '删除失败', icon: 5 });
                    return;
                }
                // 删除成功了,刷新当前页面
                location.reload();
            });
        });
    }
</script>


2、运行演示

home (1).gif



9、前后端数据交互与报表数据展示
11、用户登录与退出

友情链接: CSDN激萌の小宅 95知识库 自考题库 罗分明个人网络博客 精益编程leanboot

小宅博客  www.bilibili996.com All Rights Reserved. 备案号: 闽ICP备2024034575号

网站经营许可证  福建省福州市 Copyright©2021-2025 版权所有

小宅博客
首页 智能家居 地图定位
公告:小宅博客网可以开发票了,需要发票的,去群里找群主哈!!

文章作者:激萌の小宅

促销:¥0

价格:¥0

配送方式: 购买后立即生效(如购买异常,请联系站长)
付款之后一定要等待自动跳转结束,否则购买可能会失败
  • 0 天

    有效期

  • 0

    总销量

  • 0

    累计评价

报表数据的编辑与修改 - (第十讲)

视频讲解如下:


工程源码下载:GPS定位系统系列教程源码下载


1、功能修改

        在上一节中,我们已经实现了如何在前端显示一张报表数据,本章节要讲的内容是,如何实现对报表数据的编辑与删除,当然了,这里不包含新增的操作,新增数据的话,我们这里是要通过下位机来获取的,所以,新增的功能,这里就不写了,如果有需要的童鞋,可以自行添加,操作方法其实和编辑操作是一样的。

        首先呢,同样是在上一讲的基础上,我们先修改HomeController.cs,新增两个方法:编辑与修改,添加内容如下:

/// <summary>
/// 编辑
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public ActionResult Edit(string[] msg)
{
    AjaxResult res = new AjaxResult() { Success = false };
    if (msg == null || msg.Length != 2) return Content(res.ToJson());
    try
    {
        using (MyDbContext db = new MyDbContext() { config = Res.SqlStr })
        {
            GpsData a = db.Tb_GpsData.FirstOrDefault(x => x.ID == int.Parse(msg[0]));
            if (a != null)
            {
                a.gps = msg[1];
                db.SaveChanges();
                res.Success = true;
            }
            else
            {
                throw new Exception($"未查询到ID:{msg[0]}");
            }
        }
    }
    catch (Exception e)
    {
        res.ErrorCode = e.Message;
    }
    return Content(res.ToJson());
}

/// <summary>
/// 删除
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public ActionResult Delete(string msg)
{
    AjaxResult res = new AjaxResult() { Success = false };
    if (msg == null || msg == "") return Content(res.ToJson());
    try
    {
        using (MyDbContext db = new MyDbContext() { config = Res.SqlStr })
        {
            GpsData a = db.Tb_GpsData.FirstOrDefault(x => x.ID == int.Parse(msg));
            if(a != null)
            {
                db.Remove(a);
                db.SaveChanges();
                res.Success = true;
            }
            else
            {
                throw new Exception($"未查询到ID:{msg}");
            }
        }
    }
    catch (Exception e)
    {
        res.ErrorCode = e.Message;
    }
    return Content(res.ToJson());
}


tab.cshtml修改如下:

@using DbEntity.Tables;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    <link rel="stylesheet" href="/css/bootstrap.min.css"  />
    <link rel="stylesheet" href="/css/ace.min.css" />
    <link rel="stylesheet" href="/font/css/font-awesome.min.css" />

    <script src="/js/jquery.min 1.11.3.js"></script>
    <script src="/js/jquery.dataTables.min.js"></script>
    <script src="/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/js/layer/layer.js"></script>
    <title>报表翻页</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="sort_style">
            <!--分类类表-->
            <div class="article_sort_list">
                <table class="table table-striped table-bordered table-hover" id="sample-table">
                    <thead>
                        <tr>
                            <th width="25"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                            <th width="40px">ID</th>
                            <th width="40px">用户</th>
                            <th width="100px">坐标</th>
                            <th width="100px">添加时间</th>
                            <th width="100px">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            List<GpsData> tab = ViewData["tab"] as List<GpsData>;
                            foreach (GpsData p in tab)
                            {
                                <tr>
                                    <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                                    <td>@p.ID</td>
                                    <td>@p.UserId</td>
                                    <td>@p.gps</td>
                                    <td>@p.CreateTime</td>
                                    <td class="td-manage">
                                        <a title="编辑" href="javascript:;" onclick="myEdit('@p.ID','@p.gps')"class="btn btn-xs btn-info"><i class="fa fa-edit bigger-120"></i></a>
                                        <a title="删除" href="javascript:;" onclick="myDelete('@p.ID')" class="btn btn-xs btn-danger"><i class="fa fa-trash  bigger-120"></i></a>
                                    </td>
                                </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!--编辑-->
    <div id="EditId" style="display:none">
        <ul style="margin:10px" >
            <li><label>新坐标:</label><span><input id="edit_id" name="新坐标" type="text"/></span></li>
        </ul>
    </div>

</body>
</html>
<script>
    $(function () {
            if (document.getElementById('sample-table')) {
                $('#sample-table').dataTable({
                    "bAutoWidth": false,       // 关闭自动列宽
                    // "aaSorting": [[0, "asc"]], // 默认第几个排序 正序:asc  倒序:desc
                    //"bStateSave": true,        // 状态保存(与iDisplayLength有冲突)
                    "bFilter": true,          // 开启搜索框
                    //"bLengthChange": false,    // 去掉每页显示多少条数据方法
                    'iDisplayLength': 5,       // 每页初始显示5条记录
                    "bInfo": true,            // 开关,是否显示表格的一些信息(当前显示XX-XX条数据,共XX条)
                    //"responsive": false,     // 关闭响应式效果,否则以上设置无效
                    "bPaginate": true,         // 开启分页
                    "aoColumnDefs": [
                        //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                        { "orderable": false, "aTargets": [0, 2, 3, 5] }// 制定列不参与排序
                    ]
                });
            }

            $('table th input:checkbox').on('click', function () {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function () {
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
            });
        });
    })

    /* 编辑 */
    function myEdit(id, gps) {
        $("#edit_id").val(gps);
        layer.open({
            type: 1,
            title: '修改坐标信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['390px', '180px'],
            content: $('#EditId'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var strArr = [id, $("#edit_id").val()];
                $.post('Edit', { msg: strArr }, function (resJson) {
                    var res = JSON.parse(resJson);
                    if (!res.Success) {
                        layer.alert(res.ErrorCode, { title: '编辑失败', icon: 5 });
                        return;
                    }
                    location.reload();
                });
            }
        });
    }

    /* 删除 */
    function myDelete(id) {
        layer.confirm('确认要删除[' + id + ']吗?', { icon: 0, }, function (index) {
            $.post('Delete', { msg: id }, function (resJson) {
                var res = JSON.parse(resJson);
                if (!res.Success) {
                    layer.alert(res.ErrorCode, { title: '删除失败', icon: 5 });
                    return;
                }
                // 删除成功了,刷新当前页面
                location.reload();
            });
        });
    }
</script>


2、运行演示

home (1).gif