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


后台:

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;
}


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com