.Net CoreDBHelper实现数据列表显示
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了.Net CoreDBHelper实现数据列表显示,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3545字,纯文字阅读大概需要6分钟。
内容图文
System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace IOT.Month5.API.Controllers { [EnableCors("any")] [Route("goods")] [ApiController] public class GoodsController : ControllerBase { BLL.BaseBLL bll = new BLL.BaseBLL(); List<Model.JiLuModel> list = new List<Model.JiLuModel>(); [Route("list")] [HttpGet] public List<Model.JiLuModel> GetJiLuModels(string name) { list = bll.GetJiLuModels(name); return list; } [Route("add")] [HttpPost] public int Add(Model.YouHuiModel model) { int code = 0; code = bll.Add(model); if(code > 0) { //添加成功 return 1; } else { //添加不成功返回-1 return -1; } } } }BLL 代码
using System; using System.Collections.Generic; using System.Data; using Model; using Newtonsoft.Json; namespace BLL { public class BaseBLL { DAL.DBHelper Helper = new DAL.DBHelper(); /// <summary> /// 显示领取记录表并按领取时间排序 /// </summary> /// <returns></returns> public List<Model.JiLuModel> GetJiLuModels(string name) { string sql = "select u.User_Name,y.You_Name,y.You_Type,y.You_TiaoJian,y.ID,j.CreateDate,j.IsUp from Base_jilu j join Base_User u on u.ID = j.User_ID join Base_YouHui y on y.ID = j.You_ID where 1=1 "; //优惠券名称查询 if(!string.IsNullOrEmpty(name)) { sql += $" and You_Name like ‘%{name}%‘ order by j.CreateDate desc"; } DataTable table = Helper.ExecSql(sql); //转成Json对象 string strJson = JsonConvert.SerializeObject(table); //转为List List<Model.JiLuModel> list = JsonConvert.DeserializeObject<List<Model.JiLuModel>>(strJson); return list; } /// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Model.YouHuiModel model) { string sql = $"insert into Base_YouHui values ({Guid.NewGuid()},‘{model.You_Name}‘,‘{model.You_Type}‘,‘{model.You_TiaoJian}‘,‘{model.You_Fangshi}‘,‘{model.You_Number}‘,‘{model.You_Lei}‘)"; return Helper.ExecuteNonQuery(sql); } } }
cshtml
@{ ViewData["Title"] = "Index"; } <script src="~/lib/jquery/dist/jquery.js"></script> <h1>记录表显示</h1> <a href="#" onclick="tian()" style="margin-left:500px">新增优惠券</a> <div> <div> <input type="text" placeholder="搜索优惠券" id="chaName" /> <a href="#" id="Search">??</a> </div> <table class="layui-table"> <tr> <th>用户昵称</th> <th>优惠券名称</th> <th>优惠券类型</th> <th>使用门槛</th> <th>优惠额度</th> <th>优惠券编号</th> <th>领取时间</th> <th>核销状态</th> </tr> <tbody id="tb"></tbody> </table> </div> <script> var tr = ""; function ReLoad() { $(‘#tb‘).empty(); $.get(‘http://localhost:53468/goods/list?name=‘ + $(‘#chaName‘).val(), function (data) { $.each(data, function (index, item) { $(‘#tb‘).empty(); tr += ‘<tr><td>‘ + item.user_Name + ‘</td>‘; tr += ‘<td>‘ + item.you_Name + ‘</td>‘; tr += ‘<td>‘ + item.you_Type + ‘</td>‘; tr += ‘<td>‘ + item.you_TiaoJian + ‘</td>‘; tr += ‘<td>‘ + 3.00 + ‘</td>‘; tr += ‘<td>‘ + item.you_ID + ‘</td>‘; tr += ‘<td>‘ + item.createDate + ‘</td>‘; tr += ‘<td>‘ + (item.isUp == "0" ? "未核销" : "已核销") + ‘</td></tr>‘; }) $(‘#tb‘).append(tr); }); } //点击查询优惠券名称 $(‘#Search‘).click(function () { $(‘#tb‘).empty(); var name = $(‘#chaName‘).val(); ReLoad(name); }); //点击添加跳转到添加页面 function tian() { window.location.href = ‘shopping/add‘; } </script>
.Net CoreDBHelper实现数据列表显示
标签:div create html get function UNC cli exe margin
本文系统来源:https://www.cnblogs.com/lina0621/p/13061706.html
内容总结
以上是互联网集市为您收集整理的.Net CoreDBHelper实现数据列表显示全部内容,希望文章能够帮你解决.Net CoreDBHelper实现数据列表显示所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。