操作服务插件创建单据原创
金蝶云社区-牛哇牛哇
牛哇牛哇
6人赞赏了该文章 126次浏览 未经作者许可,禁止转载编辑于2024年11月04日 15:29:34

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);


    }

}

图标赞 6
6人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!