zoukankan      html  css  js  c++  java
  • 向弹出的窗口中传参,后绑定数据

    前台:

    //绑定详细内容
        function clientInfoShow(clientId,types) {
            if (!clientId) {
                return;
            }
            $.getJSON("../ajax/MoneyInfoHandler.ashx", { "clientId": clientId,"types":types,"beginDate":$("#txtTime").val(),"endDate":$("#txtEndTime").val() }, function(data) {
              
                if (data) {
                //清空div内容
                $("#jexxInfo").empty();
                      var jsonTextDiv = document.getElementById("jexxInfo");             
                      var str="<table width='100%' class='align_c'><tr><td>类型</td><td>金额(万元)</td></tr>";                            
                      for (var i = 0; i < data.length; i++) {
                                var item = data[i];
                                str += ("<tr>");
                                str+="<td> "+item.leixing + "</td><td>" + (item.totMoney)/10000 + "</td>";                            
                            }                        
                    str+="</table>"
                    //添加容器str到jsontextdiv
                    $(jsonTextDiv).append(str);  
                    
                    if (data) {
                        //开启弹出层
                        $.blockUI({ message: $('#wind') });
                        $('#btnCancle').show();
                    } 
                }
            });
        }        
           $('#btnCancle').click(function() {
            $.unblockUI();
        });

    后台(一般处理事件):

    <%@ WebHandler Language="C#" Class="MoneyInfoHandler" %>
    
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Reflection;
    using System.Web;
    using System.Data;
    using System.Linq;
    using Newtonsoft.Json;
    using ZAB_BLL;
    
    public class MoneyInfoHandler : IHttpHandler
    {
        pro proB = new pro(); 
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
    
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string callback = string.IsNullOrEmpty(request["callback"]) ? string.Empty : request["callback"];
            string json;
            int clientId;
            int.TryParse(request["clientId"].Split('_')[1], out clientId);
            string types = request["types"].ToString();
            string beginDate = Convert.ToDateTime(request["beginDate"]).ToShortDateString().ToString();
            string endDate =Convert.ToDateTime(request["endDate"]).ToShortDateString().ToString();
            DataTable dt = new DataTable();
    
            try
            {
                if (clientId == 0)
                {
                    throw new ArgumentException("clientId");
                }
    
                string[] param = { 
                                    "@userId?"+clientId,
                                    "@types?"+types,
                                    "@beginDate?"+beginDate,
                                    "@endDate?"+endDate,
                                    "@control?GL"
                                 };
                //得到数据到datatable
                dt = proB.GetProcedureTable("pro_jetjxx", param, "pro_jetjxx");
            }
            catch (Exception)
            {
            }
    
            //将数据转换到list中
            List<MoneyInfo> list = DtConverToListM<MoneyInfo>.DtToList(dt);
            //将数据序列化到json
            json = JsonConvert.SerializeObject(list);
            //返回数据
            response.Write(string.IsNullOrEmpty(callback) ? json : string.Format("{0}({1})", callback, json));
        }
    
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
    }
    
    
    public  class  MoneyInfo
    { 
           /// <summary>
           /// 类型
           /// </summary>
           public string leixing{ get; set; }
           /// <summary>
           /// 金额
           /// </summary>
           public string totMoney { get; set; }
       }
    
    
    #region DataTable convert to list
    
    public class DtConverToListM<T> where T : new()
    {
        public static List<T> DtToList(DataTable dt)
        {
            //定义集合
            List<T> listCollection = new List<T>(dt.Rows.Count);
            //获得 T 模型类型
            Type T_type = typeof(T);
            //获得 T 模型类型公共属性
            PropertyInfo[] proper = T_type.GetProperties();
            //临时变量,存储变量模型公共属性Name
            //遍历参数 DataTable的每行
            foreach (DataRow dr in dt.Rows)
            {
                //实例化 T 模版类
                T t = new T();
                //遍历T 模版类各个属性
                #region
                foreach (PropertyInfo p in proper)
                {
                    //取出类属性之一
                    string tempname = p.Name;
                    //判断DataTable中是否有此列
                    if (dt.Columns.Contains(tempname))
                    {
                        //判断属性是否可写属性
                        if (!p.CanWrite)
                        {
                            continue;
                        }
                        //得到Datable单元格中的值
                        object value = dr[tempname];
                        //得到 T 属性类型
                        Type proType = p.PropertyType;
                        //判断类型赋值
                        if (value != DBNull.Value)
                        {
                            //
                            if (value.GetType() == proType)
                            {
                                p.SetValue(t, value, null);
                            }
                            else
                            {
                                if (proType == typeof(string))
                                {
                                    string temp = value.ToString();
                                    p.SetValue(t, temp, null);
                                }
                                else if (proType == typeof(byte))
                                {
                                    byte temp = Convert.ToByte(value);
                                    p.SetValue(t, temp, null);
                                }
                                else if (proType == typeof(short))
                                {
                                    short temp = short.Parse(value.ToString());
                                    p.SetValue(t, temp, null);
                                }
                                else if (proType == typeof(long))
                                {
                                    long temp = long.Parse(value.ToString());
                                    p.SetValue(t, temp, null);
                                }
     
                                else if (proType == typeof(Int64))
                                {
                                    Int64 temp = Convert.ToInt64(value);
                                    p.SetValue(t, temp, null);
                                }
                                else if (proType == typeof(Int32))
                                {
                                    Int32 temp = Convert.ToInt32(value);
                                    p.SetValue(t, temp, null);
                                }
                                else if (proType == typeof(Int16))
                                {
                                    Int16 temp = Convert.ToInt16(value);
                                    p.SetValue(t, temp, null);
                                }
                                else
                                {
                                    object temp = Convert.ChangeType(value, proType);
                                    p.SetValue(t, temp, null);
                                }
                            }
                        }
                    }
                }
    
                #endregion
                listCollection.Add(t);
            }
            return listCollection;
        }
    }
    #endregion
  • 相关阅读:
    将配置文件自动复制到vs的测试项目中
    用索引器简化的C#类型信息访问
    Requested Clipboard operation did not succeed的解决办法
    在win2003上IIS部署可能出现的问题的解决方案
    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
    在Ubuntu虚拟机中配置bridge共享上网
    Ajax学习日志
    Workflow architecture in Windows SharePoint Services (version 3):WWF和WSS V3 的关系 无为而为
    使用BizTalk的必须关注:HWS已经死了,微软已经放弃HWS了,估计替代产品就WWF。(外加其它的宣告死亡的工具和API列表) 无为而为
    我想要求主管给我们升级电脑,但是主管不肯,大家报一报公司电脑的配置,我看我的电脑是不是最差的,顺便谈谈你们公司电脑硬件升级策略 无为而为
  • 原文地址:https://www.cnblogs.com/tianrui/p/3326780.html
Copyright © 2011-2022 走看看