本帖最后由 zhulilong 于 2022-3-24 22:17 编辑
编写服务端命令,需要直接获取表数据,但是调用this.DataAccess.GetTableData时会出错。以下是测试数据和代码,返回的都是: {"ID":"出错了!!!"}
using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using GrapeCity.Forguncy.ServerApi;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PicDataJson
{
[Icon("pack://application:,,,/PicDataJson;component/Resources/Icon.png")]
public class PicDataJson : Command, ICommandExecutableInServerSide, IServerCommandParamGenerator
{
public override string ToString()
{
return "JSON数据处理";
}
[DisplayName("返回结果至变量")]
[Description("返回的结果是一个JSON对象。")]
public string ReturnParam { get; set; }
public IEnumerable<GenerateParam> GetGenerateParams()
{
yield return new GenerateNormalParam()
{
ParamName = ReturnParam
};
}
public ExecuteResult Execute(IServerCommandExecuteContext dataContext)
{
Dictionary<string, object> data;
try
{
TableData tableData= new TableData();
data = tableData.GetData("ID","1");
dataContext.Parameters[ReturnParam] = data;
}
catch (Exception ex) { dataContext.Parameters[ReturnParam] = ex.Message; }
return new ExecuteResult();
}
}
public class TableData : ForguncyApi
{
public Dictionary<string, object> GetData(string id, string val)
{
var valuepair = new ColumnValuePair()
{
ColumnName = id,
Value = val
};
Dictionary<string, object> data = new Dictionary<string, object>();
try
{
data = this.DataAccess.GetTableData("表格", valuepair);
}
catch
{
data.Add("ID", "出错了!!!");
}
return data;
}
}
|