1、创建项目,命名规范:开发商.K3.SCM.WebApi.ServicesStub
2、添加引用
using Kingdee.BOS.ServiceFacade.KDServiceFx; using Kingdee.BOS.WebApi.ServicesStub;
3、新建类,继承webapi业务抽象服务AbstractWebApiBusinessService。
/// <summary> /// 根据客户名称获取客户的售后信息 /// </summary> /// <param name="customer"></param> /// <returns></returns> public JsonObject GetAfterOrder(string customer) { bool isFail = false; string errorMsg = string.Empty; string returnJson = string.Empty; Context ctx = this.KDContext.Session.AppContext; if (ctx == null) { errorMsg = "接口上下文为空"; isFail = true; goto toReturn; } if (string.IsNullOrEmpty(customer)) { isFail = true; errorMsg = "异常:客户名称为空。"; goto toReturn; } string querySql = "数据库查询语句";
var result = DBUtils.ExecuteDynamicObject(ctx, querySql); if (result.Count > 0) { returnJson = JsonConvert.SerializeObject(result); } toReturn: JsonObject jo = new JsonObject() { IsError = isFail, Message = errorMsg, Value = returnJson }; return jo; }
--查询数据执行,需引用
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
使用工具类DBUtils可以对数据库进行操作。
DBUtils.Execute:执行更新SQL语句
DBUtils.ExecuteBatch:批量执行SQL语句
DBUtils.ExecuteDataSet:执行查询SQL,返回DataSet
DBUtils.ExecuteDynamicObject:执行查询SQL,返回DynamicObjectCollection
DBUtils.ExecuteStoreProcedure:执行存储过程
完美。
标签:WebApi,string,自定义,金蝶,BOS,SQL,using,DBUtils From: https://www.cnblogs.com/lanrenka/p/17680621.html