【金蝶二开,获取系统单据并赋值可调用值更新实体服务规则】
// 获取元数据集合,可以对数据进行修改,新增等操作
var materailMetadata = ServiceHelper.GetService<Kingdee.BOS.Contracts.IMetaDataService>().Load(Context, "PUR_PAT") as FormMetadata;
// 获取业务元素据
var materailBiz = materailMetadata.BusinessInfo;
// 定义一个DynamicObject包为量体单动态实体定义
DynamicObject dynObj = new DynamicObject(materailMetadata.BusinessInfo.GetDynamicObjectType());
// 设置单据体
var entityInvPty = materailBiz.GetEntity("FPUR_PATENTRY");
var entityInvPtyData = dynObj[entityInvPty.EntryName] as DynamicObjectCollection;
dynObj["Name"] = "CS101";
dynObj["Date"] = dateOnlyString;
dynObj["PurchaseOrgId_Id"] = e.DataEntitys[0]["PurchaseOrgId_Id"];
dynObj["UseORGId_Id"] = e.DataEntitys[0]["PurchaseOrgId_Id"];
dynObj["EffectiveDate"] = dateOnlyString;
dynObj["CreatorId_Id"] = e.DataEntitys[0]["ApproverId_Id"];
dynObj["EffectiveUserId_Id"] = e.DataEntitys[0]["ApproverId_Id"];
dynObj["CreateDate"] = dateOnlyString;
dynObj["PaReason_Id"] = "7590e08cf9064cdfbfe7e3a7fb0741e2";
// 本方法可以直接加载基础资料,辅助资料等数据
DBServiceHelper.LoadReferenceObject(Context,new[{dynObj},materailMetadata.BusinessInfo.GetDynamicObjectType(), true);
MoView.Model.DataObject = dynObj;
// 遍历单据体
int k = 0;
foreach (var it in pair.Value)
{
// 获取匹配数据
var thdj = a1.Where(t => Convert.ToString(t["FMATERIALID"]).Equals(Convert.ToString(it["FMATERIALID"]))).Distinct().ToList();
var entityInvPtyRow = new DynamicObject(entityInvPty.DynamicObjectType);
entityInvPtyRow["MaterialId_Id"] = Convert.ToInt32(it["FMATERIALID"]);
entityInvPtyRow["PriceListId_Id"] = Convert.ToString(it["FID"]);
entityInvPtyRow["SupplierId_Id"] = Convert.ToInt32(it["FSUPPLIERID"]);
entityInvPtyRow["UnitID_Id"] = Convert.ToInt32(it["FUNITID"]);
entityInvPtyRow["AdjustRange"] = 1;
DBServiceHelper.LoadReferenceObject(Context, new[] { entityInvPtyRow }, entityInvPty.DynamicObjectType, true);
// 在元数据中调用实体服务规则和值更新
MoView.RuleContainer.RaiseDataChanged("FMaterialId", dynObj, new BOSActionExecuteContext(MoView));
MoView.InvokeFieldUpdateService("FMaterialId", k);
MoView.RuleContainer.RaiseDataChanged("FPriceListId", dynObj, new BOSActionExecuteContext(MoView));
MoView.InvokeFieldUpdateService("FPriceListId", k);
MoView.RuleContainer.RaiseDataChanged("FSupplierId", dynObj, new BOSActionExecuteContext(MoView));
MoView.InvokeFieldUpdateService("FSupplierId", k);
entityInvPtyData.Add(entityInvPtyRow);
entityInvPtyData[k]["Seq"] = k;
entityInvPtyData[k]["IsIncludedTax"] = false;
entityInvPtyData[k]["FIsPriceExcludeTax"] = true;
entityInvPtyData[k]["BeforePrice"] = Convert.ToDouble(it["FPRICE"]);
entityInvPtyData[k]["AfterPrice"] = Convert.ToDouble(thdj[0]["F_YDL_DJ"]);
//entityInvPtyData[k]["BeforePriceCoefficient"] = 1;
//entityInvPtyData[k]["AfterPriceCoefficient"] = 1;
var sx = (Convert.ToDecimal(1) + (privateKey / 100)) * Convert.ToDecimal(thdj[0]["F_YDL_DJ"]);
var xx = (Convert.ToDecimal(1) - (privateKey / 100)) * Convert.ToDecimal(thdj[0]["F_YDL_DJ"]);
entityInvPtyData[k]["EffectiveDate"] = dateOnlyString;
entityInvPtyData[k]["ExpiryDate"] = endDate;
entityInvPtyData[k]["SrcEntryID"] = Convert.ToInt32(it["FENTRYID"]);
MoView.RuleContainer.RaiseDataChanged("FBeforePrice", dynObj, new BOSActionExecuteContext(MoView));
MoView.InvokeFieldUpdateService("FBeforePrice", k);
MoView.RuleContainer.RaiseDataChanged("FAfterPrice", dynObj, new BOSActionExecuteContext(MoView));
MoView.InvokeFieldUpdateService("FAfterPrice", k);
entityInvPtyData[k]["UpPrice"] = sx;
entityInvPtyData[k]["DownPrice"] = xx;
k++;
}
// 通过系统方法直接调用保存服务
var saveResult = BusinessDataServiceHelper.Save(Context, MoView.BillBusinessInfo, new[] { dynObj }, OperateOption.Create(), "Save");
}
// 如果是直接加载还需要手写两个方法
/// <summary>
/// 创建单据视图
/// </summary>
/// <param name="ctx"></param>
/// <param name="metaData"></param>
/// <returns></returns>
public IDynamicFormView CreateView(string formId)
{
FormMetadata metadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formId);
var OpenParameter = CreateOpenParameter(metadata);
var Provider = metadata.BusinessInfo.GetForm().GetFormServiceProvider(true);
string importViewClass = "Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web";
Type type = Type.GetType(importViewClass);
IDynamicFormView view = (IDynamicFormView)Activator.CreateInstance(type);
((IDynamicFormViewService)view).Initialize(OpenParameter, Provider);
return view;
}
/// <summary>
/// 创建输入参数
/// </summary>
/// <param name="ctx"></param>
/// <param name="metaData"></param>
/// <returns></returns>
private BillOpenParameter CreateOpenParameter(FormMetadata metaData)
{
Form form = metaData.BusinessInfo.GetForm();
BillOpenParameter openPara = new BillOpenParameter(form.Id, metaData.GetLayoutInfo().Id);
openPara = new BillOpenParameter(form.Id, string.Empty);
openPara.Context = this.Context;
openPara.ServiceName = form.FormServiceName;
openPara.PageId = Guid.NewGuid().ToString();
// 单据
openPara.FormMetaData = metaData;
openPara.LayoutId = metaData.GetLayoutInfo().Id;
// 操作相关参数
openPara.Status = OperationStatus.ADDNEW;
openPara.PkValue = null;
openPara.CreateFrom = CreateFrom.Default;
openPara.ParentId = 0;
openPara.GroupId = "";
openPara.DefaultBillTypeId = null;
openPara.DefaultBusinessFlowId = null;
// 修改主业务组织无须用户确认
openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
// 插件
List<AbstractDynamicFormPlugIn> plugins = form.CreateFormPlugIns();
openPara.SetCustomParameter(FormConst.PlugIns, plugins);
return openPara;
}
【金蝶二开,获取系统单据并赋值可调用值更新实体服务规则】
本文2024-09-16 17:10:05发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-13958.html