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

后台:

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', width: 100 },
{ field: 'Url', title: '主路径', align: 'center', width: 316 },
{ field: 'DateTimePara', title: '日期', align: 'center', width: 120 },
{ field: 'Operator', title: '操作人', align: 'center', width: 80 },
{ field: 'Note', title: '备注', align: 'center', width: 183 },
{ field: 'UpdateDtPara', title: '更新日期', align: 'center', width: 120 },
{ field: 'UpdatePerson', title: '更新人', align: 'center', width: 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;
}

你可能感兴趣的:(反射)