中华酒网

关于佳酒网修改用到的技术

发表于:2024-04-25 作者:中华酒网编辑
编辑最后更新 2024年04月25日,由于工作原由--对网站中国佳酒招商网9928.tv的功能添加,今天要对C#的ajax技术重新学习一下,由于常时间不太用ajax,以对ajax基类的封装的内容现在有所遗忘。在使用其控件的上面还是有所明白

由于工作原由--对网站中国佳酒招商网9928.tv的功能添加,今天要对C#的ajax技术重新学习一下,由于常时间不太用ajax,以对ajax基类的封装的内容现在有所遗忘。在使用其控件的上面还是有所明白的,以下是基类的内容:
{"dataSet":{
using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using System.Web.Script.Serialization;

namespace Tencent.Itil.Cmsi.Common

{

public class GeneralSearchResult

{

public Header header = new Header();

private DataTable fieldDefine = new DataTable();

///

/// 返回的数据结构定义,无数据

///

public DataTable FieldDefine

{

get { return fieldDefine; }

set { fieldDefine = value; }

}

private DataTable retrunData = new DataTable();

///

/// 返回的数据,格式为DataTable,结构和FieldDefine中的结构一样

///

public DataTable RetrunData

{

get { return retrunData; }

set { retrunData = value; }

}

///

/// 将json数据转换为定义好的对象,数据转换为DataTable

///

///

///

public static GeneralSearchResult GetTransformData(string jsonText)

{

GeneralSearchResult gsr = new GeneralSearchResult();

JavaScriptSerializer s = new JavaScriptSerializer();

Dictionary JsonData = (Dictionary)s.DeserializeObject(jsonText);

Dictionary dataSet = (Dictionary)JsonData["dataSet"];

Dictionary header = (Dictionary)dataSet["header"];

Dictionary fieldDefine = (Dictionary)dataSet["header"];

Dictionary data = (Dictionary)dataSet["data"];

object[] rows = (object[])data["row"];

gsr.header.Version = header["version"].ToString();

gsr.header.ErrorInfo = header["errorInfo"].ToString();

gsr.header.ReturnCode = header["returnCode"].ToString();

gsr.header.ReturnRows = Convert.ToInt16(header["returnRows"]);

gsr.header.TotalRows = Convert.ToInt16(header["totalRows"]);

Dictionary dicFieldDefine = (Dictionary)dataSet["fieldDefine"];

foreach (KeyValuePair ss in dicFieldDefine)

{

gsr.FieldDefine.Columns.Add(ss.Key, typeof(string));

}

gsr.RetrunData = gsr.FieldDefine.Clone();

foreach (object ob in rows)

{

Dictionary val = (Dictionary)ob;

DataRow dr = gsr.RetrunData.NewRow();

foreach (KeyValuePair sss in val)

{

dr[sss.Key] = sss.Value;

}

gsr.RetrunData.Rows.Add(dr);

}

return gsr;

}

///

/// 数据文件头定义

///

public class Header

{

private string version;

///

/// 版本

///

public string Version

{

get { return version; }

set { version = value; }

}

private string returnCode;

///

/// 结果码,0为正常,否则为有错误

///

public string ReturnCode

{

get { return returnCode; }

set { returnCode = value; }

}

private string errorInfo;

///

/// 如果ReturnCode为非0时的错误信息

///

public string ErrorInfo

{

get { return errorInfo; }

set { errorInfo = value; }

}

private int totalRows;

///

/// 查询结果总行数

///

public int TotalRows

{

get { return totalRows; }

set { totalRows = value; }

}

private int returnRows;

///

/// 返回的数据行数

///

public int ReturnRows

{

get { return returnRows; }

set { returnRows = value; }

}

}

}

}

0