一、说明
1. web层写法,既在表单插件,列表插件中适应
2. app层写法,既在操作插件,转换插件,反写插件,账表插件中适应
3. 相关变量说明
var bInfo= this.View.BillBusinessInfo; //web层写法 ,业务元数据信息
bInfo= this.BusinessInfo; //app层写法
var form = bInfo.GetForm(); //form表单
var pkFiledName = form.PkFieldName; //单据主健字段名
var billNoKey = businessInfo.GetBillNoField().Key; //单据编号key
var entryEntity = businessInfo.GetEntity("FEntity"); //单据体
var entryPKName = string.Concat(entryEntity.Key, "_", entryEntity.EntryPkFieldName); //单据体主健字段名
var fMaterialId = "FMaterial"; //物料字段key
var strfilter = "1=1"; //过滤条件
var strOrder = billNoKey; //排序
4. 需要引用的组件
Kingdee.BOS.dll(所有插件)
Kingdee.BOS.Core.dll (所有插件)
Kingdee.BOS.Contract.dll(所有插件)
Kingdee.BOS.App.dll (所有插件)
Kingdee.BOS.ServiceHelper.dll (Web层插件)
Kingdee.BOS.App.Core.dll (APP层插件)
二、查询不带有实体结构的数据包代码
1. 直接通过Sql查询数据
1. sql脚本
var sql = @"select t0.FID,t0.FBillNo,t1.FEntryId from t_sal_order t0 inner join t_sal_orderEntry t1 on t0.FID = t1.FID ";
2. 或者通过下面的方式可以生成sql
List<SelectorItemInfo> lstSelectItm = new List<SelectorItemInfo>();
lstSelectItm.Add(new SelectorItemInfo(pkFiledKey));
lstSelectItm.Add(new SelectorItemInfo(billNoKey));
lstSelectItm.Add(new SelectorItemInfo(entryPKName));
lstSelectItm.Add(new SelectorItemInfo(fMaterialId));
lstSelectItm.Add(new SelectorRefItemInfo("FMaterial.FNumber"));
DynamicSqlBuilder sqlbd = new DynamicSqlBuilder(this.Context, bInfo.GetQueryInfo(), strfilter, strOrder, lstSelectItm);
sql = sqlbd.BuildSqlForQuery();
//web层写法
var dynObjs = ListDataServiceHelper.GetData(this.Context, sql);
var dynObjs = DBServiceHelper.ExecuteDynamicObject(this.Context,sql)
//app层写法
IListDataServices service = ServiceFactory.GetService<IListDataServices>(this.Context);
dynObjs = service.GetData(this.Context, sql);
//web层和app层都可以
var dynObjs1 = DBUtils.ExecuteDynamicObject(this.Context, sql);
2. 通过查询参数
var queryParam = new QueryBuilderParemeter();
queryParam.FormId = form.Id;
queryParam1.FilterClauseWihtKey = strfilter ;
queryParam.SelectItems.Add(new SelectorItemInfo(pkFiledKey));
queryParam.SelectItems.Add(new SelectorItemInfo(billNoKey));
queryParam.SelectItems.Add(new SelectorItemInfo(entryPKName));
queryParam.SelectItems.Add(new SelectorItemInfo(fMaterialId));
queryParam.SelectItems.Add(new SelectorRefItemInfo("FMaterial.FNumber"));
//web层写法
var dynObjs2 = QueryServiceHelper.GetDynamicObjectCollection(this.Context, queryParam);
//app层写法
IQueryService queryService = ServiceFactory.GetService<IQueryService>(this.Context); 、
dynObjs2 = queryService.GetDynamicObjectCollection(this.Context, queryParam);
三、 查询带有实体结构的数据包
1. 通过formId和参数,得到部分数据包
var lstSelectItem = new List<SelectorItemInfo>();
lstSelectItem.Add(new SelectorItemInfo(pkFiledKey));
lstSelectItem.Add(new SelectorItemInfo(billNoKey));
lstSelectItem.Add(new SelectorItemInfo(entryPKName));
lstSelectItem.Add(new SelectorItemInfo(fMaterialId));
OQLFilter filter = OQLFilter.CreateHeadEntityFilter(strfilter);
//web层写法
var dynObjs3 = BusinessDataServiceHelper.Load(this.Context, form.Id, lstSelectItem, filter);
//app层写法
IViewService vservice = ServiceFactory.GetViewService(this.Context);
dynObjs3 = vservice.Load(this.Context, form.Id, lstSelectItem, filter);
2. 得到整个完整数据包
var queryParam1 = new QueryBuilderParemeter();
queryParam1.FormId = form.Id;
queryParam1.FilterClauseWihtKey = strfilter ;
var dynType = bInfo.GetDynamicObjectType();
//web层写法
var dynObjs4 = BusinessDataServiceHelper.Load(this.Context, dynType, queryParam1);
或者
BusinessDataServiceHelper.LoadSingle(this.Context, pk, bInfo.GetDynamicObjectType());
//app层写法
IViewService vservice1 = ServiceFactory.GetViewService(this.Context);
dynObjs4 = vservice1.Load(this.Context, dynType, queryParam1);
3. 得到部分数据包
var lstFieldKey = new List<string>() { fMaterialId, billNoKey, entryPKName, fMaterialId };
var subBusinessInfo = bInfo.GetSubBusinessInfo(lstFieldKey);
var subDynType = subBusinessInfo.GetDynamicObjectType();
//web层写法
var dynObjs5 = BusinessDataServiceHelper.Load(this.Context, subDynType, queryParam1);
//app层写法
IViewService vservice2 = ServiceFactory.GetViewService(this.Context);
dynObjs5 = vservice2.Load(this.Context, subDynType, queryParam1);
4. 查询基础资料数据包
var baseDataField = bInfo.GetField(fMaterialId ) as BaseDataField;
var queryParam = new QueryBuilderParemeter();
queryParam.FormId = baseDataField.LookUpObject.FormId;
queryParam.FilterClauseWihtKey = string.Format("{0} in ({1})",baseDataField.LookUpObject.PKFieldName,
string.Join(",", pkIds));
var baseObjs = BusinessDataServiceHelper.LoadFromCache(this.Context,
baseDataField.RefFormDynamicObjectType, queryParam);
四、过滤条件推荐写法:
根据内码做过滤,一般需要判断内码数量,一个时使用等号, 50个之内使用in, 50个之外使用临时表:
var pkIds = lstPkValues.Distinct().ToArray(); //首先去除重复 string filter = string.Empty; if (pkIds.Length == 1) { filter = string.Format("{0} = {1} ", pkFieldName, pkIds[0]); queryParam.FilterClauseWihtKey =filter ; } else if (pkIds.Length <= 50) { filter= string.Format("{0} in ({1}) ", pkFieldName, string.Join(",", pkIds)); queryParam.FilterClauseWihtKey =filter ; } else { // 这得到的是一个临时表,可以当表来使用。 var cardSql = StringUtils.GetSqlWithCardinality(arrPkValues.Length, "@PKValue", 1, false); ExtJoinTableDescription joinTable = new ExtJoinTableDescription() { TableName = cardSql, TableNameAs = "sp", FieldName = "FId", ScourceKey = pkFieldName, JoinFirst = true }; queryParam.ExtJoinTables.Add(joinTable); var sqlParm = new SqlParam("@PKValue", pkType, paramValue); queryParam.SqlParams.Add(sqlParm); }
其他:
得到数据相关信息代码
PerformanceContext pctx = PerformanceContext.Create();
var dataService = new K3DataCenterService();
var dataCenterInfo = dataService.GetConnectionString(pctx, this.Context.DBId);
数据包结构参考帖:https://vip.kingdee.com/article/45021