[code] ///
/// 创建计划订单(周计划类型)单据
///
///
private void CreateWeeklyPlanBill(DynamicObjectCollection dyoCollection)
{
try
{
int k = 0;
int j = 0;
Kingdee.BOS.Core.Bill.IBillView billView = YEA.K3.MIS.APP.Core.CommonUtil.CreateBillView(this.Context,
YEA.K3.MIS.APP.Core.CommonUtil.GetFormMetadata(this.Context, "PLN_PLANORDER")); //计划订单
List
List
var targetBillMeta = MetaDataServiceHelper.Load(this.Context, "PLN_PLANORDER") as FormMetadata;
#region 构建数据包
for (var i = 0; i < dyoCollection.Count; i++)
{
if (dyoCollection[i]["FID"].ToString().Equals("0"))
{
k++; //创建
((IBillViewService) billView).LoadData();
billView.Model.DataObject = UpdateData(billView.Model.DataObject, dyoCollection[i],
billView.BusinessInfo);
saveObj.Add(billView.Model.DataObject);
}
else
{
j++; //更新
object[] obs = new object[1];
obs[0] = dyoCollection[i]["FID"];
DynamicObject obj =
BusinessDataServiceHelper.Load(this.Context, obs,
targetBillMeta.BusinessInfo.GetDynamicObjectType())[0];
UpdateData(obj, dyoCollection[i], billView.BusinessInfo);
updateObj.Add(obj);
}
}
#endregion
#region 保存
bool returnFlag = true;
StringBuilder sb = new StringBuilder();
using (
KDTransactionScope trans =
new KDTransactionScope(System.Transactions.TransactionScopeOption.Required))
{
if (saveObj.Count > 0)
{
//批量保存
IOperationResult result =
BusinessDataServiceHelper.Validate(this.Context, targetBillMeta.BusinessInfo,
new DynamicObject[] {billView.Model.DataObject}, "Save") as OperationResult;
//通过调用检验服务获取结果
if (!result.IsSuccess)
{
returnFlag = false;
int failCount = result.ValidationErrors.Count;
for (int p = 0; p < failCount; p++)
{
sb.AppendLine(result.ValidationErrors[p].Message + "\n");
}
}
IOperationResult saveResult = BusinessDataServiceHelper.Save(this.Context, billView.BusinessInfo,
saveObj.ToArray(),
Kingdee.BOS.Orm.OperateOption.Create(), "Save");
if (!saveResult.IsSuccess)
{
returnFlag = false;
int failCount = saveResult.ValidationErrors.Count;
for (int p = 0; p < failCount; p++)
{
sb.AppendLine(saveResult.ValidationErrors[p].Message + "\n");
}
}
}
if (updateObj.Count > 0)
{
//批量更新
IOperationResult result = BusinessDataServiceHelper.Save(this.Context,
targetBillMeta.BusinessInfo, updateObj.ToArray());
if (!result.IsSuccess)
{
returnFlag = false;
int failCount = result.ValidationErrors.Count;
for (int p = 0; p < failCount; p++)
{
sb.AppendLine(result.ValidationErrors[p].Message + "\n");
}
}
}
if (returnFlag)
{
trans.Complete();
}
else
{
this.View.ShowErrMessage(sb.ToString());
}
}
#endregion
base.View.ShowMessage("保存成功,本次新建【" + k + "】条数据,更新【" + j + "】条数据", MessageBoxType.Notice);
}
catch (Exception e)
{
base.View.ShowErrMessage("保存失败,失败原因:" + e.Message + "\n" + e.StackTrace);
}
}
#endregion
#region 单据数据赋值
///
/// 更新的单据赋值
///
///
///
///
///
private DynamicObject UpdateData(DynamicObject dyobj, DynamicObject data, BusinessInfo businessInfo)
{
dyobj["ID"] = data["FID"]; //fid
dyobj["FFORMID"] = "PLN_PLANORDER";
if (!data["fbillType"].IsNullOrEmptyOrWhiteSpace())
{
dyobj["FBillTypeID_ID"] = data["fbillType"]; // 周计划
dyobj["FBillTypeID"] = BusinessDataServiceHelper.LoadSingle(this.Context, data["fbillType"],(businessInfo.GetField("FBillTypeID") as BillTypeField).RefFormDynamicObjectType);
}
dyobj["DemandType"] = data["FDemandType"]; // 需求来源
dyobj["SaleOrderId"] = data["FSaleOrderId"]; // 需求单据内码
dyobj["SaleOrderEntryId"] = data["FSaleOrderEntryId"]; // 需求单据分录内码
dyobj["SaleOrderNo"] = data["FSaleOrderNo"]; // 需求单据编号
dyobj["SaleOrderEntrySeq"] = data["FSaleOrderEntrySeq"]; // 需求单据行号
dyobj["DataSource"] = data["FDataSource"]; //数据来源
dyobj["ReleaseType"] = data["FReleaseType"]; //投放类型
if (!data["FMaterialId"].ToString().Equals("0"))
{
dyobj["MaterialId_ID"] = data["FMaterialId"]; //物料编码
dyobj["MaterialId"] = BusinessDataServiceHelper.LoadSingle(this.Context, data["FMaterialId"],(businessInfo.GetField("FMaterialId") as BaseDataField).RefFormDynamicObjectType);
dyobj["SupplyMaterialId_ID"] = data["FMaterialId"]; //供应组织物料
dyobj["SupplyMaterialId"] = BusinessDataServiceHelper.LoadSingle(this.Context, data["FMaterialId"],(businessInfo.GetField("FMaterialId") as BaseDataField).RefFormDynamicObjectType);
}
if (!data["FBomId"].ToString().Equals("0"))
{
dyobj["BomId_ID"] = data["FBomId"]; //BOM版本
dyobj["BomId"] = BusinessDataServiceHelper.LoadSingle(this.Context, data["FBomId"],(businessInfo.GetField("FBomId") as BaseDataField).RefFormDynamicObjectType);
}
if (!data["FAuxPropId"].ToString().Equals("0"))
{
dyobj["AuxPropId_ID"] = data["FAuxPropId"]; //维度字段
dyobj["AuxPropId"] = BusinessDataServiceHelper.LoadSingle(this.Context, data["FAuxPropId"],(businessInfo.GetField("FAuxPropId") as RelatedFlexGroupField).RefFormDynamicObjectType);
}
if (!data["FUnitId"].ToString().Equals("0"))
{
dyobj["UnitId_ID"] = data["FUnitId"]; //单位
dyobj["UnitId"] = BusinessDataServiceHelper.LoadSingle(this.Context, data["FUnitId"],(businessInfo.GetField("FUnitId") as BaseDataField).RefFormDynamicObjectType);
}
dyobj["PlanFinishDate"] = data["FPlanFinishDate"]; //建议到货/完工日期
dyobj["PlanStartDate"] = data["FPlanStartDate"]; // 建议采购/生产日期
dyobj["FirmStartDate"] = data["FFirmStartDate"]; // 认采购/生产日期
dyobj["FirmFinishDate"] = data["FFirmFinishDate"]; //确认到货/完工日期
dyobj["DemandDate"] = data["FDemandDate"]; //需求日期
dyobj["SugQty"] = data["FSugQty"]; // 建议订单量
dyobj["FirmQty"] = data["FFirmQty"]; // 确认订单量
dyobj["OrderQty"] = data["FOrderQty"]; // 计划订单量
return dyobj;
}
[/code][password]123456[/password]