/// <summary>
/// 分页查询
/// </summary>
/// <param name="page"></param>
/// <param name="limit"></param>
/// <returns></returns>
public JsonResult fenye(int page, int limit, string op, string pName, string statu)
{
string sql = "select * from pwaitin,oplist where statu is null and pModel=id";
DataTable dt = DBHelper.Find(sql);
int count = dt.Rows.Count;
int pages = count % limit == 0 ? (count / limit) : (count / limit) + 1;
//string sql2 = "select * from pwaitin limit" + (page - 1) + "*" + limit + "," + limit;
//DataTable dt2 = DBHelper.Find(sql);
string sql1 = null;
if (!string.IsNullOrEmpty(op) && string.IsNullOrEmpty(pName) && string.IsNullOrEmpty(statu))
{
sql1 = string.Format("select * from pwaitin,oplist where statu is null and pModel=id and op like'%{0}%'", op);
dt = DBHelper.Find(sql1);
count = dt.Rows.Count;
}
else if (!string.IsNullOrEmpty(pName) && string.IsNullOrEmpty(statu) && string.IsNullOrEmpty(op))
{
sql1 = string.Format("select * from pwaitin,oplist where statu is null and pModel=id and pName like'%{0}%'", pName);
dt = DBHelper.Find(sql1);
count = dt.Rows.Count;
}
else if (!string.IsNullOrEmpty(statu) && string.IsNullOrEmpty(pName) && string.IsNullOrEmpty(op))
{
sql1 = string.Format("select * from pwaitin,oplist where statu is null and pModel=id and statu like'%{0}%'", statu);
dt = DBHelper.Find(sql1);
count = dt.Rows.Count;
}
else if (!string.IsNullOrEmpty(pName) && !string.IsNullOrEmpty(op) && string.IsNullOrEmpty(statu))
{
sql1 = string.Format("select * from pwaitin,oplist where statu is null and pModel=id and op like'%{0}%' and pName like'%{1}%'", op, pName);
dt = DBHelper.Find(sql1);
count = dt.Rows.Count;
}
else if (!string.IsNullOrEmpty(statu) && !string.IsNullOrEmpty(op) && string.IsNullOrEmpty(pName))
{
sql1 = string.Format("select * from pwaitin,oplist where statu is null and pModel=id and op like'%{0}%' and statu like'%{1}%' ", op, statu);
dt = DBHelper.Find(sql1);
count = dt.Rows.Count;
}
else if (!string.IsNullOrEmpty(statu) && !string.IsNullOrEmpty(pName) && string.IsNullOrEmpty(op))
{
sql1 = string.Format("select * from pwaitin,oplist where statu is null and pModel=id and pName like'%{0}%' and statu like'%{1}%' ", pName, statu);
dt = DBHelper.Find(sql1);
count = dt.Rows.Count;
}
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow dr in dt.Rows)//每一行信息,新建一个Dictionary<string,object>,将该行的每列信息加入到字典
{
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns)
{
result.Add(dc.ColumnName, dr[dc].ToString());
}
list.Add(result);
}
list = list.Skip((page - 1) * limit).Take(limit).ToList();
return Json(new { code = 0, msg = "", count = count, data = list }, JsonRequestBehavior.AllowGet);
}
//C#mvc,layui上部分是后台,下部分页面和js
<link href="~/layui/css/layui.css" rel="stylesheet" />
</head>
<body class="childrenBody">
<form class="layui-form">
<blockquote class="layui-elem-quote quoteBox mod_default_box">
<form class="layui-form">
<div class="layui-inline">
<span>类别:</span>
<div class="layui-input-inline">
<input type="text" id="op" class="layui-input searchVal" placeholder="请输入" />
</div>
<span>状态:</span>
<div class="layui-input-inline">
<input type="text" id="statu" class="layui-input searchVal" placeholder="请输入" />
</div>
<span>名称:</span>
<div class="layui-input-inline">
<input type="text" id="pName" class="layui-input searchVal" placeholder="请输入" />
</div>
<a class="layui-btn search_btn" data-type="reload">搜索</a>
</div>
</form>
</blockquote>
<table id="newsList" lay-filter="newsList"></table>
<!--操作-->
<script type="text/html" id="ListBar">
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-primary layui-btn-xs " lay-event="del">删除</a>
</script>
<script id="thumbnailImages" type="text/html">
<div class="thumbnailImages" style="display: inline-block;">
<img class="imgtemp" style="width:40px;height:40px;cursor: zoom-in;" src="/image/{{d.pPic}}" />
</div>
</script>
</form>
<script src="~/js/jquery-3.1.0.js"></script>
<script src="~/layui/layui.js"></script>
<script>
$(function () {
layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function () {
var form = layui.form,
$ = layui.jquery,
laydate = layui.laydate,
laytpl = layui.laytpl,
table = layui.table;
//列表
var tableIns = table.render({
elem: '#newsList',
url: '/Home/fenye',
cellMinWidth: 95,
page: true,
//toolbar: '#toolbarDemo', //开启头部工具栏,并为其绑定左侧模板
defaultToolbar: ['filter', 'exports', 'print'],
limit: 10,
limits: [10, 15, 20, 25],
id: "newsListTable",
cols: [[
{ field: "pId", title: '编号' },
{ field: 'pType', title: '型号', align: "center", },
{ field: 'pName', title: '名字', },
{ field: 'op', title: '类别', align: 'center' },
{ field: 'pNum', title: '数量', align: 'center', align: 'center' },
{ field: 'pBuyUser', title: '购买人', align: 'center' },
{ field: 'buyData', title: '购买日期', align: 'center' },
{ field: 'statu', title: '状态', align: 'center' },
{ field: 'pInfo', title: '备注', align: 'center', width: 70 },
{ field: 'pPic', title: '附件图片(点击放大)', align: 'center', templet: '#thumbnailImages' },
{ title: '操作', width: 130, templet: '#ListBar', fixed: "right", align: "center" }
]],
done: function (res, curr, count) {
//图片放大预览
var ids;
for (var j in res.data) {
//ids = res.data[j];
layer.photos({
photos: '.thumbnailImages' //+ ids
});
}
}
});
$(".search_btn").on("click", function () {
tableIns.reload({///卡死在加了ID
// url: '/Home/fenye3',
page: {
curr: 1 //重新从第 1 页开始
},
where: {
op: $("#op").val(),
statu: $("#statu").val(),
pName: $("#pName").val(),
}
})
});
//列表操作
table.on('tool(newsList)', function (obj) {
var layEvent = obj.event,
data = obj.data;
console.log(obj)
if (layEvent === 'edit') { //编辑
addNews(data);
} else if (layEvent === 'del') { //删除
layer.confirm('确定删除?', { icon: 3, title: '提示信息' }, function (index) {
console.info(data.pId);
layer.load(3);
$.ajax({
url: "/Home/delMes?pid=" + data.pId,
success: function (flag) {
layer.closeAll('loading');
if (flag) {
layer.alert("成功!", "提示");
tableIns.reload();
layer.close(index);
} else {
layer.alert("失败!", "提示");
}
}
});
});
}
});
function addNews(edit) {
var index = layui.layer.open({
title: "申请入库",
type: 2,
area: ['90%', '90%'],
fixed: false, //不固定
maxmin: true,
content: "checkIn",
success: function (layero, index) {
var body = layui.layer.getChildFrame('body', index);
if (edit) {
body.find(".pId").val(edit.pId);
body.find(".pType").val(edit.pType);
body.find(".pName").val(edit.pName);
body.find(".op").val(edit.op);
body.find(".pNum").val(edit.pNum);
body.find(".pBuyUser").val(edit.pBuyUser);
body.find(".buyData").val(edit.buyData);
body.find(".pInfo").val(edit.pInfo);
body.find(".pPic").val(edit.pPic);
form.render();
}
}
})
//layui.layer.full(index);
window.sessionStorage.setItem("index", index);
//改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
}
$(".addNews_btn").click(function () {
addUser();
})
});
});
</script>