• 反射(前台到后台,后台到前台)


    后台:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Web;
    using System.Web.Script.Serialization;
    using HotelCheckIn_PlatformSystem.DataService.BLL;
    using HotelCheckIn_PlatformSystem.DataService.Bll;
    using HotelCheckIn_PlatformSystem.DataService.Dal;
    using HotelCheckIn_PlatformSystem.DataService.Model;
    using HotelCheckIn_PlatformSystem.DataService.Model.Parameter;
    using log4net;

    namespace HotelCheckIn_PlatformSystem.DataService.WebService.Material
    {
      /// <summary>
      /// Summary description for MaterialService
      /// </summary>
      public class MaterialService : IHttpHandler
      {
        protected ILog Log = LogManager.GetLogger("PriceAdjustmentService");
        readonly JavaScriptSerializer _jss = new JavaScriptSerializer();
        public void ProcessRequest(HttpContext context)
        {
          context.Response.ContentType = "text/plain";
          var action = context.Request.Params["action"];
          Type curType = GetType();
          MethodInfo method = curType.GetMethod(action, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
          if (method != null)
          {
            method.Invoke(this, new object[] { HttpContext.Current });
          }
          else
          {
            context.Response.Write("没有这个方法!");
          }
      }

      /// <summary>
      /// 页面初始化素材表数据
      /// </summary>
      /// <param name="context"></param>
      private void InitMaterialGrid(HttpContext context)
      {
        string strjson = null;
        var json = new ZwJson<InitMaterialGrid>();
        var materialdal = new MaterialDal();
        var page = context.Request.Params["page"];
        var rows = context.Request.Params["rows"];
        var mypage = 0;
        var mysize = 0;
        var count = 0;
        if (!string.IsNullOrEmpty(page))
          mypage = int.Parse(page);
        if (!string.IsNullOrEmpty(rows))
          mysize = int.Parse(rows);
        try
        {

          var dt = materialdal.QueryByPage(new Model.Material(), mypage, mysize, ref count);
          var list = ConvertHelper<InitMaterialGrid>.ConvertToList(dt);
          json.Rows = list;
          json.Total = count;
          strjson = _jss.Serialize(json);
          strjson = strjson.Replace("Total", "total");
          strjson = strjson.Replace("Rows", "rows");
        }
        catch (Exception e)
        {
          Log.Error(e);
        }
        if (strjson != null) context.Response.Write(strjson);
      }

      public bool IsReusable
      {
        get
        {
          return false;
        }
      }
      }
    }

    前台:

    var myurl;
    var mydata;
    var postype = "POST";
    var getype = "GET";
    var jsontype = "json";
    var htmltype = "html";
    var contentype = "application/json; charset=utf-8";

    //---------------------------- 初始化 ---------------------------------
    $(function () {
    initGrid(); //初始化datagrid
    });
    /**
    * *设置datagrid对象
    **/
    var dgObj = {
    url: '../../DataService/WebService/Material/MaterialService.ashx',
    queryParams: { action: 'InitMaterialGrid' },
    fit: true,
    pagination: true,
    pageSize: 20,
    singleSelect: true,
    border: false,
    striped: true,
    toolbar: "#tb"
    };

    //---------------------------- 页面方法 ---------------------------------

    /**
    * *初始化datagrid
    **/
    function initGrid() {
    dgObj.columns = [[
    { field: 'Id', hidden: true },
    { field: 'Name', title: '素材名称', align: 'center', 100 },
    { field: 'Url', title: '主路径', align: 'center', 316 },
    { field: 'DateTimePara', title: '日期', align: 'center', 120 },
    { field: 'Operator', title: '操作人', align: 'center', 80 },
    { field: 'Note', title: '备注', align: 'center', 183 },
    { field: 'UpdateDtPara', title: '更新日期', align: 'center', 120 },
    { field: 'UpdatePerson', title: '更新人', align: 'center', 80 }
    ]];
    $('#dg').datagrid(dgObj);
    }
    //---------------------------- 页面事件 ---------------------------------

    /**
    * *添加
    **/
    function add_click() {

    }
    /**
    * *修改
    **/
    function edit_click() {

    }

    /**
    * *删除
    **/
    function del_click() {

    }

    /**
    * *上传文件
    **/
    function upload_click() {

    }


    /**
    * *关闭告警处理界面
    **/
    function close_click() {
    $('#dlg').dialog('close');
    }

    //---------------------------- ajax方法 ---------------------------------

    /**
    * *ajax增删改查方法
    **/
    function ajaxData() {
    $.ajax({
    url: myurl,
    type: postype,
    async: false,
    data: mydata,
    dataType: jsontype,
    success: serviceSuccess,
    error: serviceError
    });
    }

    /**
    * *ajax成功时返回resultObject是json数据
    **/
    function serviceSuccess(resultObject) {
    if (resultObject == null) {
    return true;
    }
    if (resultObject.IsSuccess) {
    eval(resultObject.JsExecuteMethod + "(resultObject)");
    } else {
    parent.messager("提示", resultObject.Msg);
    }
    return true;
    }

    /**
    * *ajax失败时返回
    **/
    function serviceError(result) {
    return false;
    }

  • 相关阅读:
    PAT 05-树7 File Transfer
    PAT 05-树6 Path in a Heap
    PAT 10-2 删除字符串中的子串
    PAT 10-1 在字符串中查找指定字符
    PAT 10-0 说反话
    PAT 08-2 求矩阵的局部最大值
    PAT 07-3 求素数
    PAT 07-2 A+B和C
    PAT 07-0 写出这个数
    PAT 06-3 单词长度
  • 原文地址:https://www.cnblogs.com/zhangwei595806165/p/3424693.html
Copyright © 2020-2023  润新知