BOM 分配问题
527次浏览
编辑于2016年05月27日 10:09:03
插件开发,手动新增BOM,生成的BOM,在进行分配后,当BOM新增物料,同步更新下级BOM时,BOM子项明细的FMASTERID为0,导致后续删除,修改子项物料不能同步更新,有知道怎么回事的吗?(SQL SERVER数据库好使,ORACLE数据库不好使)。以下是手动生成BOM的代码,请大神帮忙看看是怎么回事?
DynamicObjectCollection mxEntryCol = (DynamicObjectCollection)xsddInfo["SaleOrderEntry"]; //销售订单明细分录
DynamicObjectCollection bomEntryCol = (DynamicObjectCollection)xsddInfo["SaleOrderHTBOM"]; //销售订单BOM分录
for (int i = 0; i < mxEntryCol.Count; i++)
{
StringBuilder bomChildIdSQL = new StringBuilder(); //子项物料的Id
DynamicObject mxEntryInfo = mxEntryCol[i];
//创建【物料清单】formmetadata
ISetStatusService setBillStatus = Kingdee.BOS.App.ServiceHelper.GetService();
IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService();
FormMetadata zxMeta = metaService.Load(this.Context, "ENG_BOM") as FormMetadata; //物料清单
BusinessInfo info = zxMeta.BusinessInfo;
IViewService ivs = ServiceHelper.GetService();
//判断如果BOM明细中有订单明细物料则为订单明细物料生成物料清单
bool cBomFlag = false;
for (int j = 0; j < bomEntryCol.Count; j++)
{
DynamicObject bomEntryInfo = bomEntryCol[j]; //bom明细分录的信息
DynamicObject bomEntryMaterial = (DynamicObject)bomEntryInfo["F_ld_gm"];
DynamicObject bomChildEntryMaterial = (DynamicObject)bomEntryInfo["F_ld_bjmx"];
//订单合同明细物料
DynamicObject mxMaInfo = (DynamicObject)mxEntryInfo["MaterialId"];
if (bomEntryMaterial["ID"].ToString().Equals(mxMaInfo["Id"].ToString())) {
//modify by wangyingjie 2016-3-3 begin
bomChildIdSQL.Append(",");
bomChildIdSQL.Append("'").Append(bomChildEntryMaterial["Id"].ToString()).Append("'");//bom分录的部件明细 拼接串
//modify by wangyingjie 2016-3-3 end
cBomFlag = true;
}
}
if (cBomFlag == true) {
DynamicObject htObj = (DynamicObject)xsddInfo["F_ld_hthxx"];//合同号
DynamicObject mxEntryMaInfo = (DynamicObject)mxEntryInfo["MaterialId"];//父项物料
if (htObj == null)
{
throw new KDBusinessException("zx-001", "请维护合同号信息!");
}
//BOM版本号
String bomNumber = mxEntryMaInfo["Number"].ToString() + "_" + htObj["Number"].ToString() + "_" + xsddInfo["BillNo"].ToString();
//再此进行判断系统是是否存在此【物料】的BOM,如存在通过BOM版本号获得对象进行修改,如不存在 进行新建
string bomId = isHaveBOMID(bomNumber);
if (!bomId.Equals(""))
{ //系统中存在此版本号的BOM,则进行BOM数据创建
DynamicObject czBOMObject = BusinessDataServiceHelper.LoadSingle(this.Context, bomId, info.GetDynamicObjectType());
//删除【此版本号】下bom不是此物料串的数据
deleteBOMChild(info,bomId, bomChildIdSQL.ToString());
//修改【此版本号】下bom子项物料的数量
updateANDinsertBOMChild(info, bomId, bomEntryCol);
}else{ // 系统中不存在此版本号的BOM,则进行BOM数据创建
DynamicObject bomObject = new DynamicObject(info.GetDynamicObjectType()); //物料清单BOM
//DynamicObjectCollection zxEntitys = new DynamicObjectCollection(info.GetEntryEntity("FEntity").DynamicObjectType); //分录集合
DynamicObjectCollection bomEntitys = bomObject["TreeEntity"] as DynamicObjectCollection;
bomEntitys.Clear();
//父项物料
BaseDataField wlInfo = info.GetField("FMATERIALID") as BaseDataField;
wlInfo.RefIDDynamicProperty.SetValue(bomObject, mxEntryMaInfo["Id"]); //物料Id
var wlObjs = ivs.LoadFromCache(this.Context, new object[] { mxEntryMaInfo["Id"] }, wlInfo.RefFormDynamicObjectType);
if (wlObjs.Count() > 0)
wlInfo.DynamicProperty.SetValue(bomObject, wlObjs[0]);
//父项物料单位
DynamicObject mxEntryUnitInfo = (DynamicObject)mxEntryInfo["UnitId"];
BaseDataField wldwInfo = info.GetField("FUNITID") as BaseDataField;
wldwInfo.RefIDDynamicProperty.SetValue(bomObject, mxEntryUnitInfo["Id"]); //单位Id
var wldwObjs = ivs.LoadFromCache(this.Context, new object[] { mxEntryUnitInfo["Id"] }, wldwInfo.RefFormDynamicObjectType);
if (wldwObjs.Count() > 0)
wldwInfo.DynamicProperty.SetValue(bomObject, wldwObjs[0]);
//父项物料基本单位
DynamicObject mxUnitInfo = (DynamicObject)mxEntryInfo["BaseUnitId"];
BaseDataField wlUnitInfo = info.GetField("FBaseUnitId") as BaseDataField;
wlUnitInfo.RefIDDynamicProperty.SetValue(bomObject, mxUnitInfo["Id"]); //单位Id
var wlUnitObjs = ivs.LoadFromCache(this.Context, new object[] { mxUnitInfo["Id"] }, wlUnitInfo.RefFormDynamicObjectType);
if (wlUnitObjs.Count() > 0)
wlUnitInfo.DynamicProperty.SetValue(bomObject, wlUnitObjs[0]);
//成品率需大于零
bomObject["YIELDRATE"] = 100;
//创建组织
//string zzid = getAdminId("100");//原默认集团下 2016-3-11 变更为取当前组织
string zzid = Convert.ToString(this.Context.CurrentOrganizationInfo.ID);
if (!zzid.Equals("") && zzid != null)
{
BaseDataField cjzzInfo = info.GetField("FCreateOrgId") as BaseDataField;
cjzzInfo.RefIDDynamicProperty.SetValue(bomObject, zzid);
var cjzzObjs = ivs.LoadFromCache(this.Context, new object[] { zzid }, cjzzInfo.RefFormDynamicObjectType);
if (cjzzObjs.Count() > 0)
cjzzInfo.DynamicProperty.SetValue(bomObject, cjzzObjs[0]);
//使用组织
BaseDataField syzzInfo = info.GetField("FUseOrgId") as BaseDataField;
syzzInfo.RefIDDynamicProperty.SetValue(bomObject, zzid);
var syzzObjs = ivs.LoadFromCache(this.Context, new object[] { zzid }, syzzInfo.RefFormDynamicObjectType);
if (syzzObjs.Count() > 0)
syzzInfo.DynamicProperty.SetValue(bomObject, syzzObjs[0]);
}
//单据类型
string billid = getBillTypeId();
if (!billid.Equals("") && billid != null)
{
BaseDataField djlxInfo = info.GetField("FBILLTYPE") as BaseDataField;
djlxInfo.RefIDDynamicProperty.SetValue(bomObject, billid);
var djlxObjs = ivs.LoadFromCache(this.Context, new object[] { billid }, djlxInfo.RefFormDynamicObjectType);
if (djlxObjs.Count() > 0)
djlxInfo.DynamicProperty.SetValue(bomObject, djlxObjs[0]);
}
//批量
bomObject["Qty"] = 1;
//基本单位批量
bomObject["BaseQty"] = 1;
//BOM分类
bomObject["BOMCATEGORY"] = 1; //默认值
//BOM用途
bomObject["BOMUSE"] = 99; //默认值
//禁用状态
bomObject["ForbidStatus"] = "A"; //禁用状态
//BOM版本号
bomObject["Number"] = bomNumber;
//***创建BOM明细分录***
for (int j = 0; j < bomEntryCol.Count; j++)
{
DynamicObject bomEntryInfo = bomEntryCol[j]; //bom明细分录的信息
//if(bomEntryInfo["F_ld_gm"]!=null){
DynamicObject bomEntryMaterial = (DynamicObject)bomEntryInfo["F_ld_gm"];
if (bomEntryMaterial["ID"].ToString().Equals(mxEntryMaInfo["Id"].ToString()))
{ //当bom清单分录中的柜名 与 明细中的物料相等时 添加物料清单的子项物料
// ---- 分割线 begin ----
DynamicObject entry = new DynamicObject(bomEntitys.DynamicCollectionItemPropertyType);
//序号
entry["Seq"] = j + 1;
//项次
entry["ReplaceGroup"] = j;
//工序
entry["OPERID"] = 10;
//是否发损耗
entry["FISGETSCRAP"] = 1;
//变更类型
entry["ChangeType"] = 1;
//变更时间
entry["ChangeTime"] = DateTime.Now;
//rowid
entry["RowId"] = System.Guid.NewGuid().ToString();
//RowExpandType
entry["RowExpandType"] = 0;
//子项明细物料
BaseDataField zxwlInfo = info.GetField("FMATERIALIDCHILD") as BaseDataField;
zxwlInfo.RefIDDynamicProperty.SetValue(entry, ((DynamicObject)bomEntryInfo["F_ld_bjmx"])["Id"]); //物料Id
var zxwlObjs = ivs.LoadFromCache(this.Context, new object[] { ((DynamicObject)bomEntryInfo["F_ld_bjmx"])["Id"] }, zxwlInfo.RefFormDynamicObjectType);
if (zxwlObjs.Count() > 0)
zxwlInfo.DynamicProperty.SetValue(entry, zxwlObjs[0]);
//子项类型 枚举
entry["MATERIALTYPE"] = 1; //默认值
//子项物料单位 UnitId
FormMetadata bomEntryMeta = metaService.Load(this.Context, "BD_MATERIAL") as FormMetadata; //物料
BusinessInfo bomInfo = bomEntryMeta.BusinessInfo;
DynamicObject bomMaterial = BusinessDataServiceHelper.LoadSingle(this.Context, ((DynamicObject)bomEntryInfo["F_ld_bjmx"])["Id"], bomInfo.GetDynamicObjectType());
DynamicObjectCollection baseMaterial = (DynamicObjectCollection)bomMaterial["MaterialBase"];
DynamicObject unitInfo = (DynamicObject)baseMaterial[0]["BaseUnitId"];
BaseDataField zxwldwInfo = info.GetField("FCHILDUNITID") as BaseDataField;
zxwldwInfo.RefIDDynamicProperty.SetValue(entry, unitInfo["Id"]); //Id
var zxwldwObjs = ivs.LoadFromCache(this.Context, new object[] { unitInfo["Id"] }, zxwldwInfo.RefFormDynamicObjectType);
if (zxwldwObjs.Count() > 0)
zxwldwInfo.DynamicProperty.SetValue(entry, zxwldwObjs[0]);
BaseDataField zxwldwBaseInfo = info.GetField("FChildBaseUnitID") as BaseDataField;
zxwldwBaseInfo.RefIDDynamicProperty.SetValue(entry, unitInfo["Id"]); //Id
var zxwldwBaseObjs = ivs.LoadFromCache(this.Context, new object[] { unitInfo["Id"] }, zxwldwBaseInfo.RefFormDynamicObjectType);
if (zxwldwBaseObjs.Count() > 0)
zxwldwBaseInfo.DynamicProperty.SetValue(entry, zxwldwObjs[0]);
//货主类型
entry["OWNERTYPEID"] = "BD_OwnerOrg";
//用量类型 枚举
entry["DOSAGETYPE"] = 2;
//用量份子、分母
entry["NUMERATOR"] = bomEntryInfo["F_ld_BOMQty"];
entry["DENOMINATOR"] = 1;
//基本单位分子、分母
entry["BaseNumerator"] = bomEntryInfo["F_ld_BOMQty"];
entry["BaseDenominator"] = 1;
//生效日期、失效日期
entry["EFFECTDATE"] = DateTime.Now; //生效日期
entry["EXPIREDATE"] = DateTime.Parse("9999-12-31"); //失效日期
//发料方式
entry["ISSUETYPE"] = 1;
//时间单位
entry["FTIMEUNIT"] = 1;
//面价
entry["F_ld_mj"] = bomEntryInfo["F_ld_mj"];
//单价
entry["F_ld_dj"] = bomEntryInfo["F_ld_BOMPrice"];
//金额
entry["F_ld_je"] = Convert.ToDecimal(bomEntryInfo["F_ld_BOMPrice"].ToString()) * Convert.ToDecimal(bomEntryInfo["F_ld_BOMQty"].ToString());
//含税单价
entry["F_ld_hsdj"] = bomEntryInfo["F_ld_bompricehs"];
//含税金额
entry["F_ld_hsje"] = Convert.ToDecimal(bomEntryInfo["F_ld_bompricehs"].ToString()) * Convert.ToDecimal(bomEntryInfo["F_ld_BOMQty"].ToString());
//是否质保关键件
entry["F_ld_sfzbggj"] = bomEntryInfo["F_ld_bomzbgjj"];
bomEntitys.Add(entry);
// ---- 分割线 end ----
} // if mxEntryMaterial == bomEntryMaterial end
//}//if bomMaterial end
} // for bomEntry end
//获取主键服务,为分录设置主键
Kingdee.BOS.Contracts.IDBService service = Kingdee.BOS.App.ServiceHelper.GetService();
long[] maxFIDs = service.GetSequenceInt64(this.Context, "T_ENG_BOM", 1).ToArray();
int n = 0;
bomObject[0] = maxFIDs[0];
if (bomEntitys.Count() > 0)
{
long[] maxFlIds = service.GetSequenceInt64(this.Context, "T_ENG_BOMCHILD", bomEntitys.Count()).ToArray();
foreach (DynamicObject flObj in bomEntitys)
{
flObj[0] = maxFlIds[n++];
}
}
ISaveService iSaveService = ServiceHelper.GetService();
DynamicObject[] objResults = new DynamicObject[] { bomObject };
IOperationResult result = iSaveService.Save(this.Context, info, objResults);
if ((result.ValidationErrors != null && result.ValidationErrors.Count > 0)) //|| (result.OperateResult != null && result.OperateResult.Count > 0)
{
result.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
string sp = "\r\n";
errorMessage.Append("生成BOM明细失败").Append(sp);
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in result.ValidationErrors.ToArray())
{
errorMessage.Append(error.Message).Append(sp);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
//throw new Exception("生成BOM明细失败!");
}
//获取单据状态转换服务
ISetStatusService setStatusService = Kingdee.BOS.App.ServiceHelper.GetService();
List> lstKeyValuePairs = new List>();
KeyValuePair
DynamicObjectCollection mxEntryCol = (DynamicObjectCollection)xsddInfo["SaleOrderEntry"]; //销售订单明细分录
DynamicObjectCollection bomEntryCol = (DynamicObjectCollection)xsddInfo["SaleOrderHTBOM"]; //销售订单BOM分录
for (int i = 0; i < mxEntryCol.Count; i++)
{
StringBuilder bomChildIdSQL = new StringBuilder(); //子项物料的Id
DynamicObject mxEntryInfo = mxEntryCol[i];
//创建【物料清单】formmetadata
ISetStatusService setBillStatus = Kingdee.BOS.App.ServiceHelper.GetService
IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService
FormMetadata zxMeta = metaService.Load(this.Context, "ENG_BOM") as FormMetadata; //物料清单
BusinessInfo info = zxMeta.BusinessInfo;
IViewService ivs = ServiceHelper.GetService
//判断如果BOM明细中有订单明细物料则为订单明细物料生成物料清单
bool cBomFlag = false;
for (int j = 0; j < bomEntryCol.Count; j++)
{
DynamicObject bomEntryInfo = bomEntryCol[j]; //bom明细分录的信息
DynamicObject bomEntryMaterial = (DynamicObject)bomEntryInfo["F_ld_gm"];
DynamicObject bomChildEntryMaterial = (DynamicObject)bomEntryInfo["F_ld_bjmx"];
//订单合同明细物料
DynamicObject mxMaInfo = (DynamicObject)mxEntryInfo["MaterialId"];
if (bomEntryMaterial["ID"].ToString().Equals(mxMaInfo["Id"].ToString())) {
//modify by wangyingjie 2016-3-3 begin
bomChildIdSQL.Append(",");
bomChildIdSQL.Append("'").Append(bomChildEntryMaterial["Id"].ToString()).Append("'");//bom分录的部件明细 拼接串
//modify by wangyingjie 2016-3-3 end
cBomFlag = true;
}
}
if (cBomFlag == true) {
DynamicObject htObj = (DynamicObject)xsddInfo["F_ld_hthxx"];//合同号
DynamicObject mxEntryMaInfo = (DynamicObject)mxEntryInfo["MaterialId"];//父项物料
if (htObj == null)
{
throw new KDBusinessException("zx-001", "请维护合同号信息!");
}
//BOM版本号
String bomNumber = mxEntryMaInfo["Number"].ToString() + "_" + htObj["Number"].ToString() + "_" + xsddInfo["BillNo"].ToString();
//再此进行判断系统是是否存在此【物料】的BOM,如存在通过BOM版本号获得对象进行修改,如不存在 进行新建
string bomId = isHaveBOMID(bomNumber);
if (!bomId.Equals(""))
{ //系统中存在此版本号的BOM,则进行BOM数据创建
DynamicObject czBOMObject = BusinessDataServiceHelper.LoadSingle(this.Context, bomId, info.GetDynamicObjectType());
//删除【此版本号】下bom不是此物料串的数据
deleteBOMChild(info,bomId, bomChildIdSQL.ToString());
//修改【此版本号】下bom子项物料的数量
updateANDinsertBOMChild(info, bomId, bomEntryCol);
}else{ // 系统中不存在此版本号的BOM,则进行BOM数据创建
DynamicObject bomObject = new DynamicObject(info.GetDynamicObjectType()); //物料清单BOM
//DynamicObjectCollection zxEntitys = new DynamicObjectCollection(info.GetEntryEntity("FEntity").DynamicObjectType); //分录集合
DynamicObjectCollection bomEntitys = bomObject["TreeEntity"] as DynamicObjectCollection;
bomEntitys.Clear();
//父项物料
BaseDataField wlInfo = info.GetField("FMATERIALID") as BaseDataField;
wlInfo.RefIDDynamicProperty.SetValue(bomObject, mxEntryMaInfo["Id"]); //物料Id
var wlObjs = ivs.LoadFromCache(this.Context, new object[] { mxEntryMaInfo["Id"] }, wlInfo.RefFormDynamicObjectType);
if (wlObjs.Count() > 0)
wlInfo.DynamicProperty.SetValue(bomObject, wlObjs[0]);
//父项物料单位
DynamicObject mxEntryUnitInfo = (DynamicObject)mxEntryInfo["UnitId"];
BaseDataField wldwInfo = info.GetField("FUNITID") as BaseDataField;
wldwInfo.RefIDDynamicProperty.SetValue(bomObject, mxEntryUnitInfo["Id"]); //单位Id
var wldwObjs = ivs.LoadFromCache(this.Context, new object[] { mxEntryUnitInfo["Id"] }, wldwInfo.RefFormDynamicObjectType);
if (wldwObjs.Count() > 0)
wldwInfo.DynamicProperty.SetValue(bomObject, wldwObjs[0]);
//父项物料基本单位
DynamicObject mxUnitInfo = (DynamicObject)mxEntryInfo["BaseUnitId"];
BaseDataField wlUnitInfo = info.GetField("FBaseUnitId") as BaseDataField;
wlUnitInfo.RefIDDynamicProperty.SetValue(bomObject, mxUnitInfo["Id"]); //单位Id
var wlUnitObjs = ivs.LoadFromCache(this.Context, new object[] { mxUnitInfo["Id"] }, wlUnitInfo.RefFormDynamicObjectType);
if (wlUnitObjs.Count() > 0)
wlUnitInfo.DynamicProperty.SetValue(bomObject, wlUnitObjs[0]);
//成品率需大于零
bomObject["YIELDRATE"] = 100;
//创建组织
//string zzid = getAdminId("100");//原默认集团下 2016-3-11 变更为取当前组织
string zzid = Convert.ToString(this.Context.CurrentOrganizationInfo.ID);
if (!zzid.Equals("") && zzid != null)
{
BaseDataField cjzzInfo = info.GetField("FCreateOrgId") as BaseDataField;
cjzzInfo.RefIDDynamicProperty.SetValue(bomObject, zzid);
var cjzzObjs = ivs.LoadFromCache(this.Context, new object[] { zzid }, cjzzInfo.RefFormDynamicObjectType);
if (cjzzObjs.Count() > 0)
cjzzInfo.DynamicProperty.SetValue(bomObject, cjzzObjs[0]);
//使用组织
BaseDataField syzzInfo = info.GetField("FUseOrgId") as BaseDataField;
syzzInfo.RefIDDynamicProperty.SetValue(bomObject, zzid);
var syzzObjs = ivs.LoadFromCache(this.Context, new object[] { zzid }, syzzInfo.RefFormDynamicObjectType);
if (syzzObjs.Count() > 0)
syzzInfo.DynamicProperty.SetValue(bomObject, syzzObjs[0]);
}
//单据类型
string billid = getBillTypeId();
if (!billid.Equals("") && billid != null)
{
BaseDataField djlxInfo = info.GetField("FBILLTYPE") as BaseDataField;
djlxInfo.RefIDDynamicProperty.SetValue(bomObject, billid);
var djlxObjs = ivs.LoadFromCache(this.Context, new object[] { billid }, djlxInfo.RefFormDynamicObjectType);
if (djlxObjs.Count() > 0)
djlxInfo.DynamicProperty.SetValue(bomObject, djlxObjs[0]);
}
//批量
bomObject["Qty"] = 1;
//基本单位批量
bomObject["BaseQty"] = 1;
//BOM分类
bomObject["BOMCATEGORY"] = 1; //默认值
//BOM用途
bomObject["BOMUSE"] = 99; //默认值
//禁用状态
bomObject["ForbidStatus"] = "A"; //禁用状态
//BOM版本号
bomObject["Number"] = bomNumber;
//***创建BOM明细分录***
for (int j = 0; j < bomEntryCol.Count; j++)
{
DynamicObject bomEntryInfo = bomEntryCol[j]; //bom明细分录的信息
//if(bomEntryInfo["F_ld_gm"]!=null){
DynamicObject bomEntryMaterial = (DynamicObject)bomEntryInfo["F_ld_gm"];
if (bomEntryMaterial["ID"].ToString().Equals(mxEntryMaInfo["Id"].ToString()))
{ //当bom清单分录中的柜名 与 明细中的物料相等时 添加物料清单的子项物料
// ---- 分割线 begin ----
DynamicObject entry = new DynamicObject(bomEntitys.DynamicCollectionItemPropertyType);
//序号
entry["Seq"] = j + 1;
//项次
entry["ReplaceGroup"] = j;
//工序
entry["OPERID"] = 10;
//是否发损耗
entry["FISGETSCRAP"] = 1;
//变更类型
entry["ChangeType"] = 1;
//变更时间
entry["ChangeTime"] = DateTime.Now;
//rowid
entry["RowId"] = System.Guid.NewGuid().ToString();
//RowExpandType
entry["RowExpandType"] = 0;
//子项明细物料
BaseDataField zxwlInfo = info.GetField("FMATERIALIDCHILD") as BaseDataField;
zxwlInfo.RefIDDynamicProperty.SetValue(entry, ((DynamicObject)bomEntryInfo["F_ld_bjmx"])["Id"]); //物料Id
var zxwlObjs = ivs.LoadFromCache(this.Context, new object[] { ((DynamicObject)bomEntryInfo["F_ld_bjmx"])["Id"] }, zxwlInfo.RefFormDynamicObjectType);
if (zxwlObjs.Count() > 0)
zxwlInfo.DynamicProperty.SetValue(entry, zxwlObjs[0]);
//子项类型 枚举
entry["MATERIALTYPE"] = 1; //默认值
//子项物料单位 UnitId
FormMetadata bomEntryMeta = metaService.Load(this.Context, "BD_MATERIAL") as FormMetadata; //物料
BusinessInfo bomInfo = bomEntryMeta.BusinessInfo;
DynamicObject bomMaterial = BusinessDataServiceHelper.LoadSingle(this.Context, ((DynamicObject)bomEntryInfo["F_ld_bjmx"])["Id"], bomInfo.GetDynamicObjectType());
DynamicObjectCollection baseMaterial = (DynamicObjectCollection)bomMaterial["MaterialBase"];
DynamicObject unitInfo = (DynamicObject)baseMaterial[0]["BaseUnitId"];
BaseDataField zxwldwInfo = info.GetField("FCHILDUNITID") as BaseDataField;
zxwldwInfo.RefIDDynamicProperty.SetValue(entry, unitInfo["Id"]); //Id
var zxwldwObjs = ivs.LoadFromCache(this.Context, new object[] { unitInfo["Id"] }, zxwldwInfo.RefFormDynamicObjectType);
if (zxwldwObjs.Count() > 0)
zxwldwInfo.DynamicProperty.SetValue(entry, zxwldwObjs[0]);
BaseDataField zxwldwBaseInfo = info.GetField("FChildBaseUnitID") as BaseDataField;
zxwldwBaseInfo.RefIDDynamicProperty.SetValue(entry, unitInfo["Id"]); //Id
var zxwldwBaseObjs = ivs.LoadFromCache(this.Context, new object[] { unitInfo["Id"] }, zxwldwBaseInfo.RefFormDynamicObjectType);
if (zxwldwBaseObjs.Count() > 0)
zxwldwBaseInfo.DynamicProperty.SetValue(entry, zxwldwObjs[0]);
//货主类型
entry["OWNERTYPEID"] = "BD_OwnerOrg";
//用量类型 枚举
entry["DOSAGETYPE"] = 2;
//用量份子、分母
entry["NUMERATOR"] = bomEntryInfo["F_ld_BOMQty"];
entry["DENOMINATOR"] = 1;
//基本单位分子、分母
entry["BaseNumerator"] = bomEntryInfo["F_ld_BOMQty"];
entry["BaseDenominator"] = 1;
//生效日期、失效日期
entry["EFFECTDATE"] = DateTime.Now; //生效日期
entry["EXPIREDATE"] = DateTime.Parse("9999-12-31"); //失效日期
//发料方式
entry["ISSUETYPE"] = 1;
//时间单位
entry["FTIMEUNIT"] = 1;
//面价
entry["F_ld_mj"] = bomEntryInfo["F_ld_mj"];
//单价
entry["F_ld_dj"] = bomEntryInfo["F_ld_BOMPrice"];
//金额
entry["F_ld_je"] = Convert.ToDecimal(bomEntryInfo["F_ld_BOMPrice"].ToString()) * Convert.ToDecimal(bomEntryInfo["F_ld_BOMQty"].ToString());
//含税单价
entry["F_ld_hsdj"] = bomEntryInfo["F_ld_bompricehs"];
//含税金额
entry["F_ld_hsje"] = Convert.ToDecimal(bomEntryInfo["F_ld_bompricehs"].ToString()) * Convert.ToDecimal(bomEntryInfo["F_ld_BOMQty"].ToString());
//是否质保关键件
entry["F_ld_sfzbggj"] = bomEntryInfo["F_ld_bomzbgjj"];
bomEntitys.Add(entry);
// ---- 分割线 end ----
} // if mxEntryMaterial == bomEntryMaterial end
//}//if bomMaterial end
} // for bomEntry end
//获取主键服务,为分录设置主键
Kingdee.BOS.Contracts.IDBService service = Kingdee.BOS.App.ServiceHelper.GetService
long[] maxFIDs = service.GetSequenceInt64(this.Context, "T_ENG_BOM", 1).ToArray();
int n = 0;
bomObject[0] = maxFIDs[0];
if (bomEntitys.Count() > 0)
{
long[] maxFlIds = service.GetSequenceInt64(this.Context, "T_ENG_BOMCHILD", bomEntitys.Count()).ToArray();
foreach (DynamicObject flObj in bomEntitys)
{
flObj[0] = maxFlIds[n++];
}
}
ISaveService iSaveService = ServiceHelper.GetService
DynamicObject[] objResults = new DynamicObject[] { bomObject };
IOperationResult result = iSaveService.Save(this.Context, info, objResults);
if ((result.ValidationErrors != null && result.ValidationErrors.Count > 0)) //|| (result.OperateResult != null && result.OperateResult.Count > 0)
{
result.IsSuccess = false;
StringBuilder errorMessage = new StringBuilder();
string sp = "\r\n";
errorMessage.Append("生成BOM明细失败").Append(sp);
foreach (Kingdee.BOS.Core.Validation.ValidationErrorInfo error in result.ValidationErrors.ToArray())
{
errorMessage.Append(error.Message).Append(sp);
}
throw new KDBusinessException("zx-001", errorMessage.ToString());
//throw new Exception("生成BOM明细失败!");
}
//获取单据状态转换服务
ISetStatusService setStatusService = Kingdee.BOS.App.ServiceHelper.GetService
List
KeyValuePair
推荐阅读