Bootstraptable paging query

1.Front-end configuration

2.Background output formatted data

1.Front-end configuration

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>SearchGoods</title>
    <link href="~/Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Scripts/bootstrap/bootstrap-table/css/bootstrap-table.min.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap/bootstrap-table/js/bootstrap-table.min.js"></script>
    <script src="~/Scripts/bootstrap/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/layer/layer.js"></script>
    <style>
        body {
            font-size:12px;
            padding:10px;
        }
    </style>
</head>
<body>         
    <input id="search" name="search_text" class="form-control" style="width:215px;" placeholder="After entering, press enter to search " type="text">
    <table id="list"></table>
    <script>
              
        //Project type
        function ProjTypeFormatter(value, row, index) {
            return row.GroupTypeName == null ? row.GoodsTypeName : "Test combination";
        }
        //entry name
        function ProjNameFormatter(value, row, index) {
            return row.GroupName == null ? row.GoodsName : row.GroupName;
        }
        //Stock
        function stockFormatter(value, row, index) {
            try {
                var StockUnitName = row.StockUnitName;
                var GoodsCount = row.GoodsCount;
                var result = '';
                if (row.NotIncludeIntoStock == 1 || row.Id > 0) {
                    result = '-';
                } else {
                    result = GoodsCount + StockUnitName;
                }
                return ' <span>' + result + '</span>';
            } catch (e) {
                return ' <span>0</span>';
            }
        }
        //Unit price interval display
        function PriceFormatter(value, row, index) {
            var price = row.MinSalePrice + "~" + row.MaxSalePrice;
            if(parseFloat(row.MinSalePrice) == parseFloat(row.MinSalePrice)) {
                price = row.MinSalePrice;
            }
            var SaleUnitName = row.SaleUnitName;
            var result = price + '/' + SaleUnitName;
            return row.Id > 0 ? '-' : ' <span>' + result + '</span>';
        }
        //Add operation
        function operationFormatter(value, row, index) {
            var price = row.MinSalePrice + "~" + row.MaxSalePrice;
            return '<a class="glyphicon glyphicon-plus" href="javascript:void(0)"  title="Add "> < /a>";';
        }

        var $table;
        var rows = 10;
        var queryUrl = '/Base/GetGoodListCreateHis';
        var isCheck = '@ViewData["isCheck"]'; //1Check the 0 disposal prescription.
        var typeIds = '@ViewData["typeIds"]'; //Commodity type ID, for example: 5,9,10,11,12,54,55
        var keyWord = '@ViewData["keyWord"]'; //Key words, for example, basic examination, jcjc
        $table = $("#list").bootstrapTable({
            url: queryUrl,
            cache: false,                       // Not caching
            sidePagination: "server",           //Paging mode: client client paging, server server paging (*)
            pagination: true,                   // Open paging function
            pageNumber: 1,                      //The first page begins.
            pageSize: rows,                     // Set default paging to 10
            //search: false,                       // Open search function
            //searchOnEnterKey: true,             //When set to true, press enter to trigger search method, otherwise automatic search method will be triggered.
            //searchText: "",                     //Initializing search text
            toolbar: '#search',
            toolbarAlign: 'right',
            queryParams: function (params) {
                var temp = {
                    rows: params.limit,                         //Page size
                    page: (params.offset / params.limit) + 1,   //Page number
                    typeIds: typeIds,
                    keyWord: keyWord,
                    isCheck: isCheck
                    //sort: params.sort,                          //Sort column name
                    //sortOrder: params.order                     //Rank order (DESC, ASC)
                };
                return temp; //The name of the key and the variable name of the controller must always be the same. This way, the controller needs to be the same.
            },
            columns: [
                            {
                                title: 'Project type',
                                sortable: true,
                                align: 'center',
                                valign: 'middle',
                                formatter: ProjTypeFormatter
                            },
                           {
                               title: 'entry name',
                               align: 'center',
                               valign: 'middle',
                               formatter: ProjNameFormatter

                           },
                            {
                                title: 'Stock',
                                field: 'GoodsCount',
                                align: 'center',
                                valign: 'middle',
                                formatter: stockFormatter
                            },
                            {
                                title: 'Unit Price',
                                sortable: true,
                                field: 'MinSalePrice',
                                align: 'center',
                                valign: 'middle',
                                formatter: PriceFormatter,
                            },
                           {
                               title: 'operation',
                               align: 'center',
                               valign: 'middle',
                               formatter: operationFormatter,
                           }
            ],
            onLoadSuccess: function (data) {

            },
            onClickRow: function (row) {
                //Inspection and testing
                if (isCheck == '1') {
                    parent.addGoods(row);
                    parent.getTotal();
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                } else {
                    //Disposal prescription
                    parent.addItem(row);
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                }
            },
            onSearch: function (text) {
                console.log(text)
            }
        });

        $("#search").keyup(function (event) {
            var searchText = $(this).val();

            var param = $("#list").bootstrapTable('getOptions');
            param.queryParams = function (params) {
                var temp = {
                    rows: params.limit,                         //Page size
                    page: (params.offset / params.limit) + 1,   //Page number
                    //typeIds: typeIds,
                    keyWord: searchText,
                    isCheck: isCheck
                    //sort: params.sort,                          //Sort column name
                    //sortOrder: params.order                     //Rank order (DESC, ASC)
                };
                return temp; //The name of the key and the variable name of the controller must always be the same. This way, the controller needs to be the same.
            }

            if (event.keyCode == 13) {
                $("#list").bootstrapTable("refresh");
            }
        })
    </script>
</body>
</html>

 

2.Background output formatted data


#region Query parameters
int pageSize = 10; //The default is 10 pages per page.
int pageNumber = 1; //Default query page 1
string keyWord = string.Empty; //Search keywords
string typeIds = string.Empty; //Commodity type ID, for example: 5,9,10,11,12,54,55
string isCheck = string.Empty; //1Check the 0 disposal prescription.


if (Request.QueryString[“rows”] != null)
{
pageSize = int.Parse(Request.QueryString[“rows”]);
}
if (Request.QueryString[“page”] != null)
{
pageNumber = int.Parse(Request.QueryString[“page”]);
}
if (Request.QueryString[“keyWord”] != null)
{
keyWord = Request.QueryString[“keyWord”];
}
if (Request.QueryString[“typeIds”] != null)
{
typeIds = Request.QueryString[“typeIds”];
}
if (Request.QueryString[“isCheck”] != null)
{
isCheck = Request.QueryString[“isCheck”];
}
#endregion


#region Query result
string sqlCount = @”SELECT count(1)
FROM goods AS g
INNER JOIN goodstype AS gt ON gt.Id = g.TypeId
INNER JOIN pethospitalgoods AS p ON p.ArticleNum = g.ArticleNumber “;
string sqlData = @”SELECT g.JoinDiscount,g.ArticleNumber,g.GoodsName,g.TypeId AS GoodsType,gt.GoodsTypeName,
g.ShortSpell,g.Specification,g.UnitGroup,p.Stock AS GoodsCount,p.StockUnitId,g.NotIncludeIntoStock,
p.MinSalePrice,p.MaxSalePrice,g.RecipeUnit,g.SaleUnit FROM goods AS g
INNER JOIN goodstype AS gt ON gt.Id = g.TypeId
INNER JOIN pethospitalgoods AS p ON p.ArticleNum = g.ArticleNumber “;
//query criteria

string whereStr = @” WHERE g.GoodsStatus in(1,3,4) AND p.DeptId=” + userinfo.DeptId;
//Commodity type search
if(typeIds.Length >0)
{
whereStr += ” AND gt.`Id` IN(” + typeIds + “)”;
}
else
{
//Keyword search
//Check all products ID
GoodsForOperator gfo = new GoodsForOperator();
List<GoodsType> checkTypeItem = new List<GoodsType>();
List<int> checkIDList = new List<int>();
checkTypeItem = gfo.GetGoodsType(1);
checkIDList = checkTypeItem.Select(x => x.Id).ToList();


//Consumables disposal prescription all commodity types
var findic = gfo.GetGoodsTypeDisposalManagement();
var czhccfIDList = GetChildList(findic).Select(x => x.Id);


whereStr += ” AND gt.`Id` IN(” + (isCheck == “1” ? string.Join(“,”, checkIDList) : string.Join(“,”, czhccfIDList)) + “)”;


if(keyWord.Length > 0)
{
whereStr += ” AND (g.`GoodsName` LIKE ‘%” + keyWord + “%’ or g.ShortSpell like ‘%” + keyWord + “%’)”;
}
}


string orderStr = ” ORDER BY g.NotIncludeIntoStock,p.Stock DESC”; //sort
string pageStr = ” LIMIT ” + ((pageNumber – 1) * pageSize) + “,” + pageSize; //paging


sqlCount += whereStr;


int total = DbContext.Database.SqlQuery<int>(sqlCount, new object() { }).FirstOrDefault(); //Total number of records
var sql = (sqlData + whereStr + orderStr + pageStr);
List<GetMedicalGroup> list = DbContext.Database.SqlQuery<GetMedicalGroup>(sql, new object() { }).ToList(); //Current page data
if (total > 0 && list.Count == 0)
{
pageStr = ” LIMIT 0,” + pageSize; //paging
sql = (sqlData + whereStr + orderStr + pageStr);
list = DbContext.Database.SqlQuery<GetMedicalGroup>(sql, new object() { }).ToList(); //Current page data
}
#endregion


#region Processing results
if (list.Count > 0)
{
var unitList = DbContext.Unit.ToList(); //Company
//Inspection and testing
if (isCheck == “1”)
{
for (int i = 0; i < list.Count; i++)
{
//Sales unit
var findSale = unitList.FirstOrDefault(x => x.Id == list[i].SaleUnit);
list[i].SaleUnitName = findSale?.Name;
list[i].StockUnitId = list[i].SaleUnit;
list[i].StockUnitName = findSale?.Name;


//Prescription unit
var findRecipe = unitList.FirstOrDefault(x => x.Id == list[i].RecipeUnit);
list[i].RecipeUnitName = findRecipe?.Name;
}
}
else //Prescription of disposal consumables
{
List<int> listHC = new List<int>();
List<int> listCZ = new List<int>();
List<int> listCF = new List<int>();


GoodsForOperator gfo = new GoodsForOperator();
listHC = gfo.GetGoodsType(2).Select(x => x.Id).ToList(); //Consumables
listCZ = gfo.GetGoodsType(3).Select(x => x.Id).ToList(); //Management
listCF = gfo.GetGoodsType(4).Select(x => x.Id).ToList(); //prescription

List<GetMedicalGroup> good = new List<GetMedicalGroup>();
for (int i = 0; i < list.Count; i++)
{
//Sales unit
var findSale = unitList.FirstOrDefault(x => x.Id == list[i].SaleUnit);
list[i].SaleUnitName = findSale?.Name;
list[i].StockUnitId = list[i].SaleUnit;
list[i].StockUnitName = findSale?.Name;


//Prescription unit
var findRecipe = unitList.FirstOrDefault(x => x.Id == list[i].RecipeUnit);
list[i].RecipeUnitName = findRecipe?.Name;


if (listCF.Exists(x => x == list[i].GoodsType))
{
list[i].Type = 1; //prescription
good.Add(list[i]);
}
else if (listHC.Exists(x => x == list[i].GoodsType))
{
list[i].Type = 2; //Consumables
good.Add(list[i]);
}
else if (listCZ.Exists(x => x == list[i].GoodsType))
{
list[i].Type = 0;//Management
good.Add(list[i]);
}
}
list = list.OrderBy(x=>x.Type).ToList();
}
}


var obj = new { total = total, rows = list };


return JsonConvert.SerializeObject(obj);
#endregion
}
catch (Exception ex)
{
LogInfo.Error(“Base->SearchGoodsByTypeId”, “Paging query product list failed, error message: “+ ex.Message,” “,” userinfo.Id;
var obj = new { total = 0, rows = new object() { } };


return JsonConvert.SerializeObject(obj);
}


Leave a Reply

Your email address will not be published. Required fields are marked *