axaj获取asp.net后台数据List集合

效果图

 

 

 

前端web和axaj:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="zichanmx.aspx.cs" Inherits="xsweb.ERPInfo.zichanmx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>部门资产明细</title>

    <style type="text/css">
        table.altrowstable {
            width:100%;
            font-family: verdana,arial,sans-serif;
            font-size: 13px;
            color: #333333;
            border-width: 1px;
            border-color: #a9c6c9;
            border-collapse: collapse;
            margin: 0 auto;
            text-align:center;
        }

        table.altrowstable th {
            border-width: 2px;
            padding: 9px;
            border-style: solid;
            border-color: #a9c6c9;
            background-color: #F0F8FF;
            font-size: 15px;
        }

        table.altrowstable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
        }

        .oddrowcolor {
            background-color:floralwhite;
        }

        .evenrowcolor {
            background-color: #FFFFF0;
        }

        .divtable {
            text-align: center;
            width: 100%;
        }

        .divtable b {
            font-size: 20px;
        }
    </style>

    <script src="../resources/scripts/jquery-3.4.1.min.js"></script>
    <script>
        var pageSize = 20;
        var pageNum = 1;
        var count = 0;
        var pageCount = 0;
        var yushu = 0;

        //Ajax请求
        var getListByAjax = function () {
            var cnt = 0;
            $.ajax({
                url: "zichanmx.aspx/getJson?" + "pagenum=" + pageNum + "&pagesize=" + pageSize,
                type: "post",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    $("#alternatecolor").html("");
                    //递归获取数据
                    var html = "<tr>" +
                        "<th>序</th>" +
                        "<th>料件编号</th>" +
                        "<th>品名</th>" +
                        "<th>低值易耗品分类</th>" +
                        "<th>产品特征</th>" +
                        "<th>单位</th>" +
                        "<th>数量</th>" +
                        "<th>使用部门</th>" +
                        "<th>存放地点</th>" +
                        "<th>备注</th>" +
                        "<th>资产编码</th>" +
                        "<th>部门负责人</th>" +
                        "<th>申请人</th>" +
                        "<th>低值易耗品状态</th>" +
                        "</tr> ";
                    $.each(data.d, function (i, item) {
                        cnt = 1;
                        if (i % 2 != 0) {
                            html += "<tr class='oddrowcolor'>";
                        }
                        else {
                            html += "<tr>";
                        }
                        html += "<td>" + item["xuhao"] + "</td>" +
                            "<td>" + item["inbbuc007"] + "</td>" +
                            "<td>" + item["imaal003"] + "</td>" +
                            "<td>" + item["inbbuc001"] + "</td>" +
                            "<td>" + item["inbbuc016"] + "</td>" +
                            "<td>" + item["inbbuc017"] + "</td>" +
                            "<td>" + item["inbbuc009"] + "</td>" +
                            "<td>" + item["ooefl003"] + "</td>" +
                            "<td>" + item["inbbuc012"] + "</td>" +
                            "<td>" + item["inbbuc013"] + "</td>" +
                            "<td>" + item["inbbuc019"] + "</td>" +
                            "<td>" + item["ooag011_1"] + "</td>" +
                            "<td>" + item["ooag011_2"] + "</td>" +
                            "<td>" + item["oocql004"] + "</td>" +
                            "</tr>";
                    });
                    if (cnt == 0) {
                        html += "<tr><td colspan='14'>空。</td></tr>";
                    }
                    else {
                        html += "<tr><td colspan='14'>" +
                            "总行数:" + count + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "每页" + pageSize + "行&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "当前页数:" + pageNum + "/" + pageCount + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "<a href='#' onclick='firstPage();return false;'><<首页</a>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "<a href='#' onclick='prePage();return false;'><上一页</a>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "<a href='#' onclick='nextPage();return false;'>下一页></a>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "<a href='#' onclick='lastPage();return false;'>尾页>></a>" + 
                            "</td></tr>";
                    }
                    $("#alternatecolor").html(html);
                    getCurrentDate(1);
                },
                error: function (err) {
                    getCurrentDate(2);
                }
            });
        }


        //Ajax请求
        var getCountByAjax = function () {
            $.ajax({
                url: "zichanmx.aspx/getCount",
                type: "post",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    //alert(data.d);
                    count = data.d;
                    pageCount = parseInt(count / pageSize);
                    yushu = count % pageSize;
                    if (yushu > 0) {
                        pageCount = pageCount + 1;
                    }
                    getListByAjax();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(textStatus + ":" + errorThrown);
                    getCurrentDate(2);
                }
            });
        }

        $(function () {
            getCountByAjax();
            //getListByAjax();
        });

        function prePage() {
            pageNum = pageNum - 1;
            if (pageNum < 1) {
                pageNum = 1;
                return;
            }
            getListByAjax();         
        }
        function nextPage() {
            pageNum = pageNum + 1;
            if (pageNum > pageCount) {
                pageNum = pageCount;
                return;
            }
            getListByAjax();   
        }
        function firstPage() {
            if (pageNum == 1) {
                return;
            }
            pageNum = 1;
            getListByAjax();
        }
        function lastPage() {
            if (pageNum == pageCount) {
                return;
            }
            pageNum = pageCount;
            getListByAjax();
        }


        function getCurrentDate(type) {
            var now = new Date();
            var year = now.getFullYear(); //得到年份
            var month = now.getMonth();//得到月份
            var date = now.getDate();//得到日期
            var day = now.getDay();//得到周几
            var hour = now.getHours();//得到小时
            var minu = now.getMinutes();//得到分钟
            var sec = now.getSeconds();//得到秒
            month = month + 1;
            if (month < 10) month = "0" + month;
            if (date < 10) date = "0" + date;
            if (hour < 10) hour = "0" + hour;
            if (minu < 10) minu = "0" + minu;
            if (sec < 10) sec = "0" + sec;
            var time = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
            if (type == 1) {
                var time = "数据加载完成:" + time;
            }
            else {
                var time = "数据加载失败,请联系信息部!" + time;
            }
            $("#lblloadtime").html(time);
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <br />
        <br />
        <div class="col-sm-12">
            <blockquote class="text-warning" style="font-size: 14px">
                <h1 class="text-danger">
                    <label id="lblcomp" runat="server"></label>
                </h1>
                <h3 class="text-danger">部门资产明细</h3>
                <label id="lblloadtime" style="color:orangered;">数据加载中...</label>
            </blockquote>
        </div>
        <hr />
        <div id="divtable">
            <table class="altrowstable" id="alternatecolor">
            </table>
        </div>
    </form>
</body>
</html>

 

后台cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using xsweb.BLL;
using xsweb.Model;

namespace xsweb.ERPInfo
{
    public partial class zichanmx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null)
            {
                Response.Write("<script>window.alert('用户登录超时,请重新登录!');window.parent.location.href='/Login.aspx';</script>");
            }
            else
            {
                lblcomp.InnerText = ((xsweb.Model.UserInfo)Session["UserInfo"]).UserComp.ToString();
            }
        }

        [WebMethod]
        public static List<ZichanmxInfo> getJson()
        {
            List<ZichanmxInfo> zcmxlist = new List<ZichanmxInfo>();
            string userid = ((UserInfo)HttpContext.Current.Session["UserInfo"]).UserID;
            int pagenum = Convert.ToInt32(HttpContext.Current.Request.QueryString["pagenum"]);
            int pagesize = Convert.ToInt32(HttpContext.Current.Request.QueryString["pagesize"]);
            int sindex = (pagenum - 1) * pagesize;
            int eindex = sindex + pagesize;
            zcmxlist = new ZichanmxBLL().getZichanmxData(userid, sindex, eindex);
            //return JsonConvert.SerializeObject(dklist);
            return zcmxlist;
        }

        [WebMethod]
        public static int getCount()
        {
            string userid = ((UserInfo)HttpContext.Current.Session["UserInfo"]).UserID;
            int cnt = new ZichanmxBLL().getZichanmxCount(userid);
            return cnt;
        }

    }
}

 

posted @ 2021-07-28 11:52  AaronLi  阅读(169)  评论(0编辑  收藏  举报