You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
4.3 KiB
C#
113 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
using DSWeb.TruckMng.Helper;
|
|
using HcUtility.Comm;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
namespace DSWeb.Areas.RptMng.Comm
|
|
{
|
|
public class RptHelper
|
|
{
|
|
public static string GetRptJsonResult(int start, int limit,
|
|
DBDataSetResult dbRptResult, string tableName)
|
|
{
|
|
return GetRptJsonResult(start, limit, dbRptResult, tableName, true);
|
|
}
|
|
|
|
public static string GetRptJsonResult(DBDataSetResult dbRptResult, string tableName)
|
|
{
|
|
return GetRptJsonResult(0, 0, dbRptResult, tableName, false);
|
|
}
|
|
|
|
public static string GetRptJsonResult(int start, int limit, DBDataSetResult dbRptResult, string tableName, bool page,DatasetSort datasetsort=null,string filterstr="")
|
|
{
|
|
var json = string.Empty;
|
|
List<Dictionary<string, object>> jsonSetData = null;
|
|
if (dbRptResult.Success)
|
|
{
|
|
DataTable dtSet = dbRptResult.DataSet.Tables[tableName];
|
|
// dtSet.DefaultView.RowFilter = filterstr;
|
|
if ((datasetsort!=null) && (!string.IsNullOrEmpty(datasetsort.property)))
|
|
{
|
|
|
|
// dtSet.DefaultView.Sort = ""+datasetsort.prop+" "+datasetsort.dire+"";
|
|
// DataTable dtSet2 = dtSet.DefaultView.ToTable();
|
|
|
|
jsonSetData = DSWeb.TruckMng.Helper.JsonHelper.ToJson(dtSet);
|
|
}
|
|
else
|
|
{
|
|
// DataTable dtSet2 = dtSet.DefaultView.ToTable();
|
|
jsonSetData = DSWeb.TruckMng.Helper.JsonHelper.ToJson(dtSet);
|
|
}
|
|
IEnumerable<Dictionary<string, object>> listjson;
|
|
if (page)
|
|
{
|
|
listjson = jsonSetData.Skip(start).Take(limit);
|
|
}
|
|
else
|
|
{
|
|
listjson = jsonSetData.AsEnumerable();
|
|
}
|
|
|
|
json = JsonConvert.Serialize(new { success = dbRptResult.Success, message = dbRptResult.Message, totalCount = jsonSetData.Count, data = listjson.ToArray() });
|
|
}
|
|
else
|
|
{
|
|
jsonSetData = new List<Dictionary<string, object>>();
|
|
|
|
json = JsonConvert.Serialize(new { success = dbRptResult.Success, message = dbRptResult.Message, totalCount = jsonSetData.Count, data = jsonSetData.ToArray() });
|
|
}
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
public static string GetRptJsonResult(int start, int limit, DataSet dbRptResult, bool page, DatasetSort datasetsort = null, string filterstr = "")
|
|
{
|
|
var json = string.Empty;
|
|
List<Dictionary<string, object>> jsonSetData = null;
|
|
if (dbRptResult!=null)
|
|
{
|
|
DataTable dtSet = dbRptResult.Tables[0];
|
|
jsonSetData = DSWeb.TruckMng.Helper.JsonHelper.ToJson(dtSet);
|
|
IEnumerable<Dictionary<string, object>> listjson;
|
|
if (page)
|
|
{
|
|
listjson = jsonSetData.Skip(start).Take(limit);
|
|
}
|
|
else
|
|
{
|
|
listjson = jsonSetData.AsEnumerable();
|
|
}
|
|
json = JsonConvert.Serialize(new { success = true, message = "操作成功!", totalCount = jsonSetData.Count, data = listjson.ToArray() });
|
|
}
|
|
else
|
|
{
|
|
jsonSetData = new List<Dictionary<string, object>>();
|
|
|
|
json = JsonConvert.Serialize(new { success = false, message = "操作失败!", totalCount = jsonSetData.Count, data = jsonSetData.ToArray() });
|
|
}
|
|
|
|
return json;
|
|
}
|
|
|
|
static public object JsonGetValue(string jsondata, string jsonname)
|
|
{
|
|
JavaScriptSerializer serializer = new JavaScriptSerializer();
|
|
Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(jsondata);
|
|
object value;
|
|
if (!json.TryGetValue(jsonname, out value))
|
|
{
|
|
throw new Exception("数据中不存在此值!");
|
|
}
|
|
return value;
|
|
}
|
|
}
|
|
} |