Webapi快速构建Json
通过金蝶内置api帮助类快速构建Json,实现保存单据等操作
```
//保存
private void button1_Click(object sender, EventArgs e)
{
//登录结果类型等于1,代表登录成功
if (LogIn() == 1)
{
// 获取保存Json
var saveStr = BuildUploadObj();
// 转成JObject
var saveObj = JObject.Parse(saveStr);
// 获取Model
var modelObj = saveObj["Model"];
// 设值
modelObj["FNumber"] = "testNumber";
modelObj["FName"] = "testName";
var client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
var loginResult = client.ValidateLogin("123456", "Administrator", "888888", 2052);
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
if (resultType == 1)
{
client.Save("BD_MATERIAL", saveObj.ToString());
}
}
else
{
this.textBox2.Text = "登录失败";
}
}
// 获取Json的方法类
private static string BuildUploadObj()
{
// SaveDesigner为保存操作的设计组件,其他操作请查询T_MDL_FormOperationType 表格
var designerClass = "Kingdee.BOS.Bill.OperationService.SaveDesign,Kingdee.BOS.Business.Bill";
var designType = TypesContainer.GetOrRegister(designerClass);
var designer = Activator.CreateInstance(designType) as OperationWebServiceDesigner;
designer.OperationId = "Save";
designer.IsWebApi = true;
var meta = FormMetaDataCache.GetCachedFormMetaData(new Context(), "BD_MATERIAL");
var model = designer.CreateServiceModel(new Context(), meta, null) as FormServiceModel;
// WebApiParamHelper 为内部封装WebApi帮助类,没有对外发布,需要用发射调用获取JSON
var webApiHelperClass =
"Kingdee.BOS.Business.PlugIn.DynamicService.WebApiParamHelper,Kingdee.BOS.Business.PlugIn";
var webApiHelperType = TypesContainer.GetOrRegister(webApiHelperClass);
var webApiHelper = Activator.CreateInstance(webApiHelperType);
var getJsonData = webApiHelperType.GetMethod("GetJSONData", new Type[] { typeof(DTOType), typeof(Boolean) });
return getJsonData?.Invoke(webApiHelper, new object[] { model?.RequestDTOType, true }).GetString();
}
请问Type为空是为什么
Webapi快速构建Json
通过金蝶内置api帮助类快速构建Json,实现保存单据等操作``` //保存 private void button1_Click(object ...
点击下载文档
本文2024-09-16 17:15:48发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14569.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章