.net里ajax调用后台方法返回LIST集合

JS部分

function GetPageInfo() {
            var loadid = layer.load(1, { shade: 0.1 });
            var url = "ReservePlanTotal.aspx?act=GetTotal";
            var search_date = $("#search_date").val();
            var DepartmentClassID = $(".DepartmentClassID").val();
            var groupName = $(".GroupID option:selected").text();
            $(".dateTitle").text(search_date);
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: { search_date: search_date, groupName: groupName, DepartmentClassID: DepartmentClassID },
                success: function (r) {
                    try {
                        //alert(JSON.stringify(r));
                        console.log(r);
                        //debugger;
                        if (r.code == 200) {
                            $(".tbody").html(r.list);
                        }
                        else {
                            layer.msg(r.ErrorMsg, { icon: 5 });
                            layer.close(loadid);
                        }
                    } catch (e) {
                        layer.close(loadid);
                    }
                }, complete: function (r) {
                    layer.close(loadid);
                }
            });
        }

HTML部分

<tbody class="tbody">                   
                   
                </tbody>

后台方法部分

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckLoginInfo();//检查登录
                if (!string.IsNullOrEmpty(Request["act"]))
                {
                    act = Request.QueryString["act"];
                }
                switch (act)
                {
                    case "GetTotal":
                        GetTotal();
                        break;
                    default:
                        
                        break;
                }
                PageLoad();
            }
            
        }

private void GetTotal()
        {
            ResultInfo resultInfo = new ResultInfo() { State = false };
            StringBuilder sb = new StringBuilder();
            try
            {
                string search_date = Request["search_date"];
                string DepartmentClassID = Request["DepartmentClassID"];//院区
                string groupName = Request["groupName"];//分诊组
                string searchStr = " and leibie=1 and [SickID] =0 and zhenshi<>'协同诊疗' ";
                if (!string.IsNullOrEmpty(groupName))
                {
                    if (groupName!= "全部治疗组")
                    {
                        searchStr += " and zhenshi='" + groupName + "'";
                    }
                    
                }
                if (!string.IsNullOrEmpty(DepartmentClassID))
                {
                    if (DepartmentClassID != "0")
                    {
                        searchStr += " and zhenshi in(select groupName from MyMedicalGroup where ID=" + DepartmentClassID + " )";
                    }
                    
                }
                if (!string.IsNullOrEmpty(search_date))
                {
                    DateTime startDate = Convert.ToDateTime(search_date.Trim(' ').Split('到')[0]);
                    DateTime endDate = Convert.ToDateTime(search_date.Trim(' ').Split('到')[1]);
                    searchStr += " and t>='"+ startDate + "' and t<'"+ endDate + "'";
                }
                List<MyWeb.Model.MyPlanTongJi> list = myPlanBLL.GetList02(searchStr);
                sb.Append("<tr><td colspan=\"4\" style=\"text-align:center; \"><span class=\"dateTitle\"></span>预约来诊数据</td></tr>");
                if (list!=null)
                {
                    sb.Append("<tr><td>科室</td><td>预约病人数量</td><td>已来诊病人数</td><td>未来诊病人数</td></tr>");
                    foreach (MyWeb.Model.MyPlanTongJi model in list)
                    {
                        sb.Append("<tr><td>" + model.Zhenshi + "</td><td>" + model.YuyueNum + "</td><td>" + model.YilaizhenNum + "</td><td>" + model.WeilaizhenNum + "</td></tr>");
                    }
                }
                else
                {
                    sb.Append("<tr><td colspan=\"4\" style=\"text-align:center; \"><span class=\"dateTitle\"></span>暂无数据</td></tr>");
                }
                //int allNum= myPlanBLL.GetRecordCount(searchStr + " and status!='已完成' ");//
                //int comeingNum = myPlanBLL.GetRecordCount(searchStr+" and status='已来诊' ");//记录总数
                //int noComeingNum = myPlanBLL.GetRecordCount(searchStr + " and status<>'已来诊' " );//记录总数
                
                resultInfo.Data = sb.ToString();
                resultInfo.State = true;
            }
            catch (Exception ex)
            {

                resultInfo.State = false;
                resultInfo.ErrorMsg = ex.Message;
            }
            var rsp_obj = new
            {
                code = 200,
                list = sb.ToString()
            };
            Response.Write(JsonConvert.SerializeObject(rsp_obj));//将rsp_obj转化为json并输出
            Response.End();
            //string resultJson = JsonHelper.ObjectToJSON(resultInfo);
            //Response.Write(resultJson);
            //Response.End();
        }

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2020-06-07 14:12  离。  阅读(114)  评论(0编辑  收藏