服务插件编写取值问题
金蝶云社区-云社区用户8YYY1234
云社区用户8YYY1234
0人赞赏了该文章 2,620次浏览 未经作者许可,禁止转载编辑于2015年01月13日 16:41:43

需求是:点击提交,执行2个sql :一个获取select,一个是update ,均已实现,还要对另一张表插入数据,就在这里出现问题了,
服务端,取值都是在e.DataEntitys,然后复写 public override void OnPreparePropertys(PreparePropertysEventArgs e){少什么加什么}//添加用标识,取值用属性

我的代码在 private void saveProuctCode(DynamicObject dyInfo, DynamicObject dyEntryInfo){}

出了问题,请帮忙指点一下。有点急。

附上代码:
[code]using System;
using System.Transactions;
using Kingdee.BOS;
using Kingdee.BOS.Util;
using Kingdee.BOS.App;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.BOS.ServiceHelper;
using DynamicObject = Kingdee.BOS.Orm.DataEntity.DynamicObject;

namespace Sdl.Sp.InStock.Submit.ServicePlugIn
{
public class GeneratePalletCodeService : AbstractOperationServicePlugIn
{
public override void BeginOperationTransaction(BeginOperationTransactionArgs e)
{
using (KDTransactionScope trans = new KDTransactionScope(TransactionScopeOption.Required))
{
foreach (var item in e.DataEntitys)
{
DynamicObject dyBillType = (DynamicObject)item["BillType"];
if (dyBillType["Number"].Equals("JDSCRK02_SYS"))
{
//生成码
string sqlPalletCode = string.Format(@"select top 1 T.PalletCode from (select FCount,MIN(FSerialNumber) as PalletCode FROM PalletCodeTable where FIsEnable = 0 group by FCount ) T");
DynamicObjectCollection dyCols = DBUtils.ExecuteDynamicObject(this.Context, sqlPalletCode);
if (dyCols != null && dyCols.Count > 0)
{
DynamicObject resultObject = dyCols[0];
item["FPALLETCODE"] = resultObject[0];// 赋值
string updateSqlCount = string.Format(@"UPDATE PalletCodeTable SET FIsEnable = 1, FCount = FCount + 1 where FSerialNumber = {0}", resultObject[0]);
DBUtils.Execute(this.Context, updateSqlCount);// 更新状态字段
}
}
DynamicObjectCollection dyEntityColl = item["Entity"] as DynamicObjectCollection;//获取分录数据
if (dyEntityColl != null && dyEntityColl.Count > 0)
{
foreach (DynamicObject dyEntryInfo in dyEntityColl)
{
var productCode = dyEntryInfo["FENTRYPRODUCTCODE"];
if (!productCode.IsNullOrEmpty())
{
saveProuctCode(item, dyEntryInfo);
}
}
}
base.BeginOperationTransaction(e);
trans.Complete();
}
}
}

private void saveProuctCode(DynamicObject dyInfo, DynamicObject dyEntryInfo)
{
FormMetadata meta = MetaDataServiceHelper.Load(this.Context, "fgd_PROCODETABLE") as FormMetadata;
BusinessInfo produceCodeInfo = meta.BusinessInfo;

DynamicObject dyProduceCodeInfo = new DynamicObject(produceCodeInfo.GetDynamicObjectType());
//produceCodeInfo.GetField("BILLID").DynamicProperty.SetValue(dyProduceCodeInfo, DBServiceHelper.GetSequenceInt32(this.Context, "FGD_PROCODETABLE", 1));
//produceCodeInfo.GetField("PRODUCTCODE").DynamicProperty.SetValue(dyProduceCodeInfo, produceCodeInfo.GetEntity("PALLETCODE"));//dyEntryInfo["PALLETCODE"]);
//produceCodeInfo.GetField("PALLETCODE").DynamicProperty.SetValue(dyProduceCodeInfo, dyInfo["PALLETCODE"]);
//produceCodeInfo.GetField("MATERIAL").DynamicProperty.SetValue(dyProduceCodeInfo, dyEntryInfo["MATERIAL"]);
//produceCodeInfo.GetField("WEIGHT").DynamicProperty.SetValue(dyProduceCodeInfo, dyEntryInfo["RealQty"]);
//produceCodeInfo.GetField("PRODUCTDATE").DynamicProperty.SetValue(dyProduceCodeInfo, dyEntryInfo["ProduceDate"]);
//produceCodeInfo.GetField("BILLNUMBER").DynamicProperty.SetValue(dyProduceCodeInfo, dyInfo["BillNo"]);
//produceCodeInfo.GetField("DESTINATION").DynamicProperty.SetValue(dyProduceCodeInfo, dyInfo["DESTINATION"]);
produceCodeInfo.GetField("FDATAISENABLE").DynamicProperty.SetValue(dyProduceCodeInfo, 1);
produceCodeInfo.GetField("FPALLETCODEISENABLE").DynamicProperty.SetValue(dyProduceCodeInfo, 1);
var stockOrg = produceCodeInfo.GetField("FSTORG") as BaseDataField;
if (stockOrg != null)
{
// stockOrg.RefIDDynamicProperty.SetValue(dyProduceCodeInfo, dyInfo["StockOrgId"]);
SetBaseDataFieldValue(this.Context, stockOrg, dyProduceCodeInfo, dyInfo["StockOrgId"]);
}
produceCodeInfo.GetField("FCreateDate").DynamicProperty.SetValue(dyProduceCodeInfo, DateTime.Now);
IOperationResult result = ServiceHelper.GetService().Save(this.Context, produceCodeInfo, new DynamicObject[] { dyProduceCodeInfo }, null, "Save");
}
///


/// 获取单据字段属性,类似eas上的selector
///

///
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
e.FieldKeys.Add("FBillNo");
e.FieldKeys.Add("FBillType");
e.FieldKeys.Add("FDESTINATION");
e.FieldKeys.Add("FPALLETCODE");
e.FieldKeys.Add("FStockOrgId");
e.FieldKeys.Add("FENTRYPRODUCTCODE");
e.FieldKeys.Add("FPALLETCODE");
e.FieldKeys.Add("FMATERIAL");
e.FieldKeys.Add("FRealQty");
e.FieldKeys.Add("FProduceDate");
base.OnPreparePropertys(e);
}

///


/// 给基础资料字段赋值
///

///
///
///
///
public static void SetBaseDataFieldValue(Context ctx, BaseDataField field, DynamicObject data, object value)
{
long lPKValue = 0;
Int64.TryParse(value.ToString(), out lPKValue);
if (value.ToString().Length > 1 || lPKValue > 0)
{
DynamicObject valueobj = LoadReferenceData(ctx, field.RefFormDynamicObjectType, (object)value);
field.DynamicProperty.SetValue(data, valueobj);
field.RefIDDynamicProperty.SetValue(data, value);
}
else
{
field.DynamicProperty.SetValue(data, null);
field.RefIDDynamicProperty.SetValue(data, 0);
}
}
///
/// 根据ORM模型、对象主键,获取对象的ORM数据包
///

/// ORM数据模型
/// 主键值
///
private static DynamicObject LoadReferenceData(Context ctx, DynamicObjectType dt, object pkValue)
{
if (pkValue.IsEmptyPrimaryKey())
{
return null;
}
Kingdee.BOS.Orm.OperateOption option = Kingdee.BOS.Orm.OperateOption.Create();
option.SetThrowExceptionWhenNotFind(false);
IViewService service = ServiceFactory.GetService(ctx);
return service.LoadSingle(ctx, pkValue, dt, option);
}
}
}[/code]
不知道这么写对不对?