public static IBillView CreateView(Context ctx, String targetFormId, out IBillViewService billViewService)
{
FormMetadata meta = MetaDataServiceHelper.Load(ctx, targetFormId) as FormMetadata;
BusinessInfo info = meta.BusinessInfo;
IResourceServiceProvider formServiceProvider = meta.BusinessInfo.GetForm().GetFormServiceProvider(true);
billViewService = formServiceProvider.GetService(typeof(IDynamicFormView)) as IBillViewService;
Form form = meta.BusinessInfo.GetForm();
BillOpenParameter billOpenParameter = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);
billOpenParameter = new BillOpenParameter(form.Id, string.Empty);
billOpenParameter.Context = ctx;
billOpenParameter.ServiceName = form.FormServiceName;
billOpenParameter.PageId = Guid.NewGuid().ToString();
billOpenParameter.FormMetaData = meta;
billOpenParameter.LayoutId = meta.GetLayoutInfo().Id;
billOpenParameter.Status = OperationStatus.ADDNEW;
billOpenParameter.PkValue = null;
billOpenParameter.CreateFrom = CreateFrom.Default;
billOpenParameter.ParentId = 0;
billOpenParameter.GroupId = "";
billOpenParameter.DefaultBillTypeId = null;
billOpenParameter.DefaultBusinessFlowId = null;
//设置参数,主业务组织修改时,不提示,直接创建新单
billOpenParameter.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
List<AbstractDynamicFormPlugIn> value = form.CreateFormPlugIns();
billOpenParameter.SetCustomParameter(FormConst.PlugIns, value);
//初始化视图
((IDynamicFormViewService)billViewService).Initialize(billOpenParameter, formServiceProvider);
//表单视图
IBillView bill_view = (IBillView)billViewService;
//创建新的模型数据
bill_view.CreateNewModelData();
//主动触发插件的OnLoad事件
DynamicFormViewPlugInProxy proxy = bill_view.GetService<DynamicFormViewPlugInProxy>();
proxy.FireOnLoad();
return bill_view;
}
/* 使用时如下 */
private void CreatePrdMo(JArray bills)
{
for (int q = 0; q < bills.Count; q++)
{
JObject bill = bills[q] as JObject;
IBillViewService billViewService;
IBillView bill_view = CreateView(this.Context, "PRD_MO", out billViewService);
bill_view.Model.SetItemValueByID("FPrdOrgId", bill["FPrdOrgId"].ToString(), 0);
bill_view.Model.SetItemValueByID("FEnTrustOrgId", this.Context.CurrentOrganizationInfo.ID.ToString(), 0);
bill_view.Model.SetItemValueByNumber("FBillType", "SCDD06_SYS", 0);
JArray Entries = bill["Entries"] as JArray;
for (int i = 0; i < Entries.Count; i++)
{
JObject entryObj = Entries[i] as JObject;
bill_view.Model.InsertEntryRow("FEntity", i);
// 物料
bill_view.Model.SetItemValueByNumber("FMaterialId", Convert.ToString(entryObj["FMaterialId"]), i);
// 辅助属性
// 等级
if (entryObj["FF100010"] != null && !Convert.ToString(entryObj["FF100010"]).Trim().Equals(""))
{
bill_view.Model.SetValue("$$FAuxPropId__FF100010", Convert.ToString(entryObj["FF100010"]), i);
}
// 花色
if (entryObj["FF100012"] != null && !Convert.ToString(entryObj["FF100012"]).Trim().Equals(""))
{
bill_view.Model.SetValue("$$FAuxPropId__FF100012", Convert.ToString(entryObj["FF100012"]), i);
}
bill_view.Model.SetValue("FQty", entryObj["FQty"].ToString(), i);
}
IOperationResult save_result = bill_view.Model.Draft();
this.OperationResult.MergeResult(save_result);
}
}