private string GetMultiOrgnNameValues(string orgIdStrings)
        {
            List <string> list   = new List <string>();
            string        result = string.Empty;

            if (orgIdStrings.Trim().Length > 0)
            {
                IQueryService         service = Kingdee.BOS.Contracts.ServiceFactory.GetService <IQueryService>(base.Context);
                QueryBuilderParemeter para    = new QueryBuilderParemeter
                {
                    FormId              = "ORG_Organizations",
                    SelectItems         = SelectorItemInfo.CreateItems("FNAME"),
                    FilterClauseWihtKey = string.Format(" FORGID IN ({0}) AND FLOCALEID={1}", orgIdStrings, base.Context.UserLocale.LCID)
                };
                DynamicObjectCollection dynamicObjectCollection = service.GetDynamicObjectCollection(base.Context, para, null);
                foreach (DynamicObject current in dynamicObjectCollection)
                {
                    list.Add(current["FNAME"].ToString());
                }
                if (list.Count > 0)
                {
                    result = string.Join(",", list.ToArray());
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        private QueryBuilderParemeter GetQBPara(CheckPara para, string formKey)
        {
            FormMetadata          formMetadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formKey);
            QueryBuilderParemeter qbPara       = new QueryBuilderParemeter();

            qbPara.FormId = formKey;
            if (formKey == "STK_TransferDirect")
            {
                qbPara.FilterClauseWihtKey = string.Format(" FJNUnitEnzymes <> {0} And FSTOCKORGID ={1} And {2} = {3} And {4}={5} And {6} = '{7}' ",
                                                           para.unitEnzymes, para.orgId, matFldKey, para.matId, "FAuxPropId", para.auxPropId, "FLot.FNumber", para.lotNumber);
            }
            else
            {
                qbPara.FilterClauseWihtKey = string.Format(" FJNUnitEnzymes <> {0} And {1} ={2} And {3} = {4} And {5}={6} And {7} = '{8}' ",
                                                           para.unitEnzymes, formMetadata.BusinessInfo.MainOrgField.FieldName, para.orgId, matFldKey, para.matId, "FAuxPropId", para.auxPropId, "FLot.FNumber", para.lotNumber);
            }

            if (para.currFormKey.EqualsIgnoreCase(formKey))
            {
                qbPara.FilterClauseWihtKey += string.Format(" And {0} <> {1} ", para.currEnFldName, para.currentEntryId);
            }

            qbPara.SelectItems = SelectorItemInfo.CreateItems("FBillNo,FMaterialId.FNumber as FMatNumber,FMaterialId.FName as FMatName,FJNUnitEnzymes");

            return(qbPara);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据编码获取客户信息
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fNumber"></param>
        /// <returns></returns>
        private K3CustomerInfo GetCustomerByNo(Context ctx, string fNumber)
        {
            if (GetCustomerByNo(fNumber) != null)
            {
                return(GetCustomerByNo(fNumber));
            }

            QueryBuilderParemeter para = new QueryBuilderParemeter();

            para.FormId      = "BD_Customer";
            para.SelectItems = SelectorItemInfo.CreateItems("FCreateOrgId,FUseOrgId,FNumber,FShortName,FName,FCOUNTRY,FAddress,FZIP,FTEL,FSELLER,FSALDEPTID,FCustTypeId,FTRADINGCURRID,FTaxType,FTaxRate,FPriority,FIsTrade,F_HS_CustomerRegisteredMail,F_HS_Grade,F_HS_SpecialDemand,F_HS_TaxNum,FPRICELISTID,F_HS_CustomerPurchaseMail");

            if (!string.IsNullOrEmpty(fNumber))
            {
                para.FilterClauseWihtKey = " FNumber ='" + fNumber + "' and  FUseOrgId = 1";
                var k3Data = Kingdee.BOS.App.ServiceHelper.GetService <IQueryService>().GetDynamicObjectCollection(ctx, para);

                if (k3Data != null && k3Data.Count > 0)
                {
                    List <K3CustomerInfo> custs = BuildSynObjByCollection(ctx, k3Data);

                    if (custs != null && custs.Count > 0)
                    {
                        return(custs[0]);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 来源单获取日期
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="billData"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        public DynamicObjectCollection GetBillDataEntryDate(Kingdee.BOS.Context ctx,
                                                            DynamicObject billData,
                                                            JNQTYRatePara para)
        {
            var formKey   = billData["FBILLFORMID"].ToString();
            var lotFldKey = billData["FLOTFIELDKEY"].ToString();
            var billId    = billData["FBILLID"].ToString();
            var matFldKey = "FMaterialId";
            var lotid     = billData["flotid"].ToString();
            var matid     = billData["FMaterialId"].ToString();
            QueryBuilderParemeter qbPara = new QueryBuilderParemeter();

            qbPara.FormId = formKey;
            qbPara.FilterClauseWihtKey = string.Format(" fid ={0} And {1} ={2} And {3}.FNumber ='{4}' And FAuxPropId={5} ",
                                                       billId, lotFldKey, lotid, matFldKey, para.MaterialNumber, para.AuxPropId);
            qbPara.SelectItems = SelectorItemInfo.CreateItems("FPRODUCEDATE,FEXPIRYDATE");
            DynamicObjectCollection datas = null;

            try
            {
                datas = Kingdee.BOS.ServiceHelper.QueryServiceHelper.GetDynamicObjectCollection(ctx, qbPara);
            }
            catch (Exception ex)
            {
                return(datas);
            }
            return(datas);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 输入货主分类(组织、供应商、客户),获取货主数据
        /// </summary>

        /// <returns>返回服务结果。</returns>
        public ServiceResult ExecuteService(string formid)
        {
            var result = new ServiceResult <List <JSONObject> >();
            var ctx    = this.KDContext.Session.AppContext;

            // 检查上下文对象
            if (this.IsContextExpired(result))
            {
                return(result);
            }


            //获取相关信息
            try
            {
                //TODO:通过平台动态引擎获取数据
                var metadata       = FormMetaDataCache.GetCachedFormMetaData(ctx, "BAH_BD_Owner");
                var businessInfo   = metadata.BusinessInfo;
                var queryParameter = new QueryBuilderParemeter();
                queryParameter.FormId               = businessInfo.GetForm().Id;
                queryParameter.SelectItems          = SelectorItemInfo.CreateItems("FID,FNUMBER,FName");
                queryParameter.FilterClauseWihtKey  = "FDOCUMENTSTATUS = 'C' and FFORBIDSTATUS = 'A' and FFormId LIKE '%" + formid + "%' ";
                queryParameter.OrderByClauseWihtKey = "FNUMBER";
                var dataObjectCollection = QueryServiceHelper.GetDynamicObjectCollection(ctx, queryParameter);


                //queryParameter.FilterClauseWihtKey = "FDOCUMENTSTATUS = @FDOCUMENTSTATUS";
                //queryParameter.SqlParams.Add(new SqlParam("@FDOCUMENTSTATUS", KDDbType.String, "C"));
                //queryParameter.FilterClauseWihtKey = "FFORBIDSTATUS = @FFORBIDSTATUS";
                //queryParameter.SqlParams.Add(new SqlParam("@FFORBIDSTATUS", KDDbType.String, "A"));
                //var dataObjectCollection = BusinessDataServiceHelper.Load(ctx, businessInfo.GetDynamicObjectType(), queryParameter);
                JSONObject        Finaldata   = new JSONObject();
                List <JSONObject> return_data = new List <JSONObject>();
                foreach (DynamicObject dataObject in dataObjectCollection)
                {
                    JSONObject data = new JSONObject();
                    data.Add("FID", dataObject["FId"].ToString());
                    data.Add("FNUMBER", dataObject["FNumber"].ToString());
                    data.Add("FName", dataObject["FName"].ToString());
                    return_data.Add(data);
                }
                Finaldata.Add("Owner", return_data);
                //返回数据
                result.Code    = (int)ResultCode.Success;
                result.Data    = return_data;
                result.Message = "成功返回数据!";
            }
            catch (Exception ex)
            {
                result.Code    = (int)ResultCode.Fail;
                result.Message = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// queryservice取数方案,通过业务对象来获取数据,推荐使用
        /// </summary>
        /// <returns></returns>
        public DynamicObjectCollection GetQueryDatas()
        {
            QueryBuilderParemeter paramCatalog = new QueryBuilderParemeter()
            {
                FormId = "",                                                    //取数的业务对象
                FilterClauseWihtKey = "",                                       //过滤条件,通过业务对象的字段Key拼装过滤条件
                SelectItems         = SelectorItemInfo.CreateItems("", "", ""), //要筛选的字段【业务对象的字段Key】,可以多个,如果要取主键,使用主键名
            };

            DynamicObjectCollection dyDatas = Kingdee.BOS.ServiceHelper.QueryServiceHelper.GetDynamicObjectCollection(this.Context, paramCatalog);

            return(dyDatas);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// queryservice取数方案,通过业务对象来获取数据,推荐使用
        /// </summary>
        /// <returns></returns>
        public DynamicObjectCollection GetQueryDatas(string filter)
        {
            QueryBuilderParemeter paramCatalog = new QueryBuilderParemeter()
            {
                FormId = this.View.GetFormId(),                                                          //取数的业务对象
                FilterClauseWihtKey = filter,                                                            //过滤条件,通过业务对象的字段Key拼装过滤条件
                SelectItems         = SelectorItemInfo.CreateItems("FID", "FBILLNO", "FDOCUMENTSTATUS"), //要筛选的字段【业务对象的字段Key】,可以多个,如果要取主键,使用主键名
            };

            DynamicObjectCollection dyDatas = QueryServiceHelper.GetDynamicObjectCollection(this.Context, paramCatalog);

            return(dyDatas);
        }
Ejemplo n.º 8
0
        private string BillNo(string id, string listName, string selectColumn, string idColumn)
        {
            string result = string.Empty;

            if (id.Trim().Length > 0)
            {
                IQueryService         service = ServiceFactory.GetService <IQueryService>(base.Context);
                QueryBuilderParemeter para    = new QueryBuilderParemeter
                {
                    FormId              = listName,
                    SelectItems         = SelectorItemInfo.CreateItems(string.Format("{0},FID", selectColumn)),
                    FilterClauseWihtKey = string.Format(" FID = {0} ", id)
                };
                DynamicObjectCollection dynamicObjectCollection = service.GetDynamicObjectCollection(base.Context, para, null);
                result = dynamicObjectCollection[0][selectColumn].ToString();
            }
            return(result);
        }
Ejemplo n.º 9
0
        public void GetDefualtOrgNumber()
        {
            QueryBuilderParemeter para = new QueryBuilderParemeter();

            para.FormId               = "ORG_Organizations";
            para.SelectItems          = SelectorItemInfo.CreateItems("FNumber,FName");
            para.OrderByClauseWihtKey = "FOrgID";

            var k3Data = Kingdee.BOS.App.ServiceHelper.GetService <IQueryService>().GetDynamicObjectCollection(this.K3CloudContext, para);

            if (k3Data == null || k3Data.Count == 0)
            {
                DefaultOrgNumber = "100";
                return;
            }

            DefaultOrgNumber = k3Data[0]["FNumber"].ToString();
        }
Ejemplo n.º 10
0
        private string BillNo(string id)
        {
            string result = string.Empty;

            if (id.Trim().Length > 0)
            {
                IQueryService         service = ServiceFactory.GetService <IQueryService>(base.Context);
                QueryBuilderParemeter para    = new QueryBuilderParemeter
                {
                    FormId              = "SAL_SaleOrder",
                    SelectItems         = SelectorItemInfo.CreateItems("FBILLNO,FID"),
                    FilterClauseWihtKey = string.Format(" FID = {0} ", id)
                };
                DynamicObjectCollection dynamicObjectCollection = service.GetDynamicObjectCollection(base.Context, para, null);
                result = dynamicObjectCollection[0]["FBILLNO"].ToString();
            }
            return(result);
        }
        /// <summary>
        /// 获取所有勾选行单据编号
        /// </summary>
        /// <returns></returns>
        private DynamicObjectCollection CZ_GetSelectedRowsBillNo()
        {
            string filter = "FID in (";

            string[] fids = CZ_GetSelectedRowsFID();
            foreach (var fid in fids)
            {
                filter += fid + ",";
            }
            filter = filter.TrimEnd(',') + ")";
            QueryBuilderParemeter param = new QueryBuilderParemeter()
            {
                FormId = this.View.GetFormId(),
                FilterClauseWihtKey = filter,
                SelectItems         = SelectorItemInfo.CreateItems("FBILLNO"),
            };

            return(QueryServiceHelper.GetDynamicObjectCollection(this.Context, param));
        }
        public override AbsSynchroDataInfo BuildSynchroData(Context ctx, string fNumber, AbsSynchroDataInfo data = null)
        {
            QueryBuilderParemeter para = new QueryBuilderParemeter();

            para.FormId      = "BD_Customer";
            para.SelectItems = SelectorItemInfo.CreateItems("FCreateOrgId,FUseOrgId,FNumber,FShortName,FName,FCOUNTRY,FAddress,FZIP,FTEL,FSELLER,FSALDEPTID,FCustTypeId,FTRADINGCURRID,FPriority,FIsTrade,F_HS_CustomerRegisteredMail");

            if (!string.IsNullOrEmpty(fNumber))
            {
                para.FilterClauseWihtKey = " FNumber ='" + fNumber + "' and  FUseOrgId = 1";
                var k3Data = Kingdee.BOS.App.ServiceHelper.GetService <IQueryService>().GetDynamicObjectCollection(ctx, para);

                if (k3Data != null && k3Data.Count > 0)
                {
                    List <K3CustomerInfo> custs = BuildSynObjByCollection(ctx, k3Data);
                    return(custs[0]);
                }
            }
            return(null);
        }
        private QueryBuilderParemeter GetQBPara(CheckPara para, string formKey, string tableName, string entryFormKey)
        {
            FormMetadata          formMetadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formKey);
            QueryBuilderParemeter qbPara       = new QueryBuilderParemeter();

            qbPara.FormId = formKey;
            qbPara.FilterClauseWihtKey = string.Format(" FJNUnitEnzymes <> {0} And {1} ={2} And {3} = {4} And {5}={6} And {7} = '{8}' ",
                                                       para.unitEnzymes, formMetadata.BusinessInfo.MainOrgField.FieldName, para.orgId, matFldKey, para.matId, "FAuxPropId", para.auxPropId, "FLOT_TEXT", para.lotNumber);
            if (para.currFormKey.EqualsIgnoreCase(formKey))
            {
                qbPara.FilterClauseWihtKey += string.Format(" And {2}_{0} <> {1} ", para.currEnFldName, para.currentEntryId, entryFormKey);
            }
            if (para.tableName == tableName)
            {
                qbPara.FilterClauseWihtKey += string.Format(" And FID not in ({0})", para.linkId);
            }
            qbPara.SelectItems = SelectorItemInfo.CreateItems("FBillNo,FMaterialId.FNumber as FMatNumber,FMaterialId.FName as FMatName,FJNUnitEnzymes");

            return(qbPara);
        }
Ejemplo n.º 14
0
        public static DynamicObjectCollection QueryData(Context ctx, string formId, string strSelect, string strFilter)
        {
            DynamicObjectCollection objects;
            QueryBuilderParemeter   paremeter2 = new QueryBuilderParemeter {
                FormId              = formId,
                SelectItems         = SelectorItemInfo.CreateItems(strSelect),
                FilterClauseWihtKey = strFilter
            };
            QueryBuilderParemeter para    = paremeter2;
            IQueryService         service = Kingdee.BOS.Contracts.ServiceFactory.GetService <IQueryService>(ctx);

            try
            {
                objects = service.GetDynamicObjectCollection(ctx, para, null);
            }
            finally
            {
                Kingdee.BOS.Contracts.ServiceFactory.CloseService(service);
            }
            return(objects);
        }
Ejemplo n.º 15
0
        public static string GetSchemeId(Context ctx, string filterSchemeFormId)
        {
            QueryBuilderParemeter paremeter2 = new QueryBuilderParemeter {
                FormId      = "BOS_FilterScheme",
                SelectItems = SelectorItemInfo.CreateItems("FSCHEMEID")
            };
            QueryBuilderParemeter para = paremeter2;

            para.FilterClauseWihtKey = string.Format("FFormID=@FFormID and FIsDefault='1' and FUserId = -1", new object[0]);
            List <SqlParam> paramList = new List <SqlParam> {
                new SqlParam("@FFormID", 0x10, filterSchemeFormId)
            };
            DynamicObjectCollection objects = QueryServiceHelper.GetDynamicObjectCollection(ctx, para, paramList);
            string str = string.Empty;

            if ((objects != null) && (objects.Count != 0))
            {
                return(objects[0]["FSCHEMEID"].ToString());
            }
            return(str);
        }
Ejemplo n.º 16
0
        /*
         *  触发时机:
         *  主菜单单击时触发
         *
         *  应用场景:
         *  通常动态表单在设计时主菜单都会配置平台内置提供的服务,有时有些用户可能需要在调用平台内置功能前进行权限验证、数据检查等等,用户也可以在该事件中通过添加e.Cancel=true取消平台内置功能,完全自定义处理逻辑.
         *
         *  案例演示:
         *  添加菜单按钮,点击后保存当前单据
         *  点击复制按钮时,已禁用的记录禁止复制
         *  添加菜单按钮,弹出消息框显示所有仓库的名称
         */
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            switch (e.BarItemKey)
            {
            //添加菜单按钮,点击后保存当前单据
            case "tbSaveTest":
                var result = BusinessDataServiceHelper.Save(this.Context, this.View.BillBusinessInfo, this.Model.DataObject);
                if (result.IsSuccess)
                {
                    this.View.ShowMessage("单据保存成功!");
                    this.Model.DataChanged = false;
                }
                return;

            //点击复制按钮时,已禁用的记录禁止复制
            case "tbCopy":
                var fieldValue = this.Model.GetValue("FForbidStatus");
                if (fieldValue != null && fieldValue.ToString() == "B")
                {
                    this.View.ShowMessage("当前数据已被禁用,禁止复制!");
                    e.Cancel = true;
                }
                return;

            //弹出消息框显示所有仓库的名称
            case "tbQueryStock":
                var selectItems       = SelectorItemInfo.CreateItems("FName");
                var dyList            = BusinessDataServiceHelper.Load(this.View.Context, "BD_STOCK", selectItems, null);
                var warehouseNameList = new List <string>();
                foreach (var dy in dyList)
                {
                    warehouseNameList.Add(dy["Name"].ToString());
                }
                this.View.ShowMessage("仓库名称:" + string.Join(",", warehouseNameList));
                return;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 来源单获取单位酶活
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="billData"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        private decimal GetBillDataEntryRate(Kingdee.BOS.Context ctx,
                                             DynamicObject billData,
                                             JNQTYRatePara para)
        {
            var formKey   = billData["FBILLFORMID"].ToString();
            var lotFldKey = billData["FLOTFIELDKEY"].ToString();
            var billId    = billData["FBILLID"].ToString();
            var matFldKey = "FMaterialId";
            var lotid     = billData["flotid"].ToString();
            var matid     = billData["FMaterialId"].ToString();

            QueryBuilderParemeter qbPara = new QueryBuilderParemeter();

            qbPara.FormId = formKey;
            qbPara.FilterClauseWihtKey = string.Format(" fid ={0} And {1} ={2} And {3}.FNumber ='{4}' And FAuxPropId={5} ",
                                                       billId, lotFldKey, lotid, matFldKey, para.MaterialNumber, para.AuxPropId);
            //放到批号主档里过滤
            //if (para.OrgId > 0)
            //{
            //    qbPara.FilterClauseWihtKey +=string.Format ( " And {0}={1} ", GetOrgFldKey( ctx,formKey),para.OrgId );
            //}
            qbPara.SelectItems = SelectorItemInfo.CreateItems("FJNUnitEnzymes");
            try
            {
                DynamicObjectCollection datas = Kingdee.BOS.ServiceHelper.QueryServiceHelper.GetDynamicObjectCollection(ctx, qbPara);
                if (datas != null && datas.Count > 0)
                {
                    return(Convert.ToDecimal(datas[0]["FJNUnitEnzymes"]));
                }
            }
            catch (Exception ex)
            {
                return(0);
            }

            return(0);
        }
        /// <summary>
        /// 是否取消同步操作
        /// </summary>
        /// <param name="srcData"></param>
        /// <returns></returns>
        public override bool IsCancelSynchro(AbsSynchroDataInfo srcData)
        {
            K3CustomerInfo cust = srcData as K3CustomerInfo;

            if (SynSuccList != default(List <string>))
            {
                if (SynSuccList.Count > 0)
                {
                    foreach (var item in SynSuccList)
                    {
                        if (item.CompareTo(cust.FNumber) == 0)
                        {
                            return(false);
                        }
                    }
                }
            }
            QueryBuilderParemeter para = new QueryBuilderParemeter();

            para.FormId      = this.FormKey;
            para.SelectItems = SelectorItemInfo.CreateItems("FNumber");
            if (cust != null)
            {
                para.FilterClauseWihtKey = " FNumber='" + cust.FNumber + "' ";
            }


            var k3Data = Kingdee.BOS.App.ServiceHelper.GetService <IQueryService>().GetDynamicObjectCollection(this.K3CloudContext, para);

            if (k3Data == null || k3Data.Count == 0)
            {
                return(false);
            }

            return(true);
        }
        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            //(列表中批量审核场景下)取出所有数据包
            var queryService = ServiceHelper.GetService <IQueryService>();
            var viewService  = ServiceHelper.GetService <IViewService>();
            var dataEntites  = e.SelectedRows
                               .Select(data => data.DataEntity)
                               .ToArray();

            if (!dataEntites.Any())
            {
                return;
            }

            //取出所有的MasterId
            var    OrgIds       = dataEntites.Select(data => data.PkId <int>()).ToArray();
            string targetFormId = "BAH_BD_Organization";

            //找到对应普华物料的主键
            QueryBuilderParemeter para = new QueryBuilderParemeter();

            para.FormId              = targetFormId;
            para.SelectItems         = SelectorItemInfo.CreateItems("FID", "FMIRRORID");
            para.FilterClauseWihtKey = "FMirrorId in (Select FID From TABLE(fn_StrSplit(@OrgIds,',',1)))";
            para.SqlParams.Add(new SqlParam("@OrgIds", KDDbType.udt_inttable, OrgIds));
            var ids       = queryService.GetDynamicObjectCollection(this.Context, para).Select(data => data.Property <object>("FID")).ToArray();
            var mirrorids = queryService.GetDynamicObjectCollection(this.Context, para).Select(data => data.Property <int>("FMIRRORID")).ToArray();

            //用得到的主键去获取普华物料数据包
            var targetMetadata    = FormMetaDataCache.GetCachedFormMetaData(this.Context, targetFormId);
            var targetBillView    = targetMetadata.CreateBillView(this.Context);
            var targetBillService = targetBillView.AsDynamicFormViewService();
            var targetDataObjects = viewService.LoadFromCache(this.Context, ids, targetMetadata.BusinessInfo.GetDynamicObjectType()).ToList();

            //如果两边的数据包可以被关联,那么直接对应修改。
            dataEntites.Join(targetDataObjects,
                             left => left.PkId <int>(),
                             right => right.FieldProperty <DynamicObject>(targetMetadata.BusinessInfo.GetField("FMirrorId")).PkId <int>(),
                             (left, right) =>
            {
                targetBillView.Edit(right);
                targetBillService.UpdateValue("FNumber", -1, left.BDNumber());
                targetBillService.UpdateValue("FName", -1, new LocaleValue(left.BDName(this.Context)));
                return(right);
            }).ToArray();

            //如果数据包没有关联,则新增
            var unmatchDataEntities = dataEntites.Where(data => (mirrorids.Contains(data.PkId <int>()) == false))
                                      .ToArray();
            var addDataObjects = new List <DynamicObject>();

            foreach (var data in unmatchDataEntities)
            {
                targetBillView.AddNew();
                targetBillService.UpdateValue("FNumber", -1, data.BDNumber());
                targetBillService.UpdateValue("FName", -1, new LocaleValue(data.BDName(this.Context)));
                targetBillService.SetItemValueByID("FMirrorId", data.PkId <int>(), -1);
                addDataObjects.Add(targetBillView.Model.DataObject);
            }
            //合并待操作数据
            targetDataObjects.AddRange(addDataObjects);
            if (targetDataObjects.Any())
            {
                targetDataObjects.DoNothing(this.Context, targetMetadata.BusinessInfo, "Upload").Adaptive(op => this.OperationResult.MergeResult(op));
            }

            base.AfterExecuteOperationTransaction(e);
        }
        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);

            //TODO:
            //0.泛亚场景,当Id和MasterId相同时,才触发同步事件。
            //1.准备物料的数据包,e.DataEntities,取物料MasterId。
            //2.用MasterId关联查询普华智造里物料MirrorId,通过这个步骤知道,哪些需要修改(调用Save方法),哪些需要新增(调用Draft方法)。
            //3.需要修改的,直接关联同步修改。
            //4.需要新增的,通过表单代理直接创建新数据包。
            //5.统一调用上传操作。

            //(列表中批量审核场景下)取出所有数据包
            var queryService = ServiceHelper.GetService <IQueryService>();
            var viewService  = ServiceHelper.GetService <IViewService>();
            var dataEntites  = e.SelectedRows
                               .Select(data => data.DataEntity)
                               .Where(data => data.FieldProperty <bool>(this.BusinessInfo.GetField("FPHMXEnablePHManagement")))
                               .Where(data => data.PkId <int>() == data.MasterId <int>())
                               .ToArray();

            if (!dataEntites.Any())
            {
                return;
            }

            //取出所有的MasterId
            var    masterIds    = dataEntites.Select(data => data.PkId <int>()).ToArray();
            string targetFormId = PIBDFormPrimaryKey.Instance.Material();

            //找到对应普华物料的主键
            QueryBuilderParemeter para = new QueryBuilderParemeter();

            para.FormId              = targetFormId;
            para.SelectItems         = SelectorItemInfo.CreateItems("FID", "FMIRRORID");
            para.FilterClauseWihtKey = "FMirrorId in (Select FID From TABLE(fn_StrSplit(@MasterIds,',',1)))";
            para.SqlParams.Add(new SqlParam("@MasterIds", KDDbType.udt_inttable, masterIds));
            var ids       = queryService.GetDynamicObjectCollection(this.Context, para).Select(data => data.Property <object>("FID")).ToArray();
            var mirrorids = queryService.GetDynamicObjectCollection(this.Context, para).Select(data => data.Property <int>("FMIRRORID")).ToArray();

            //用得到的主键去获取普华物料数据包
            var targetMetadata     = FormMetaDataCache.GetCachedFormMetaData(this.Context, targetFormId);
            var targetBusinessInfo = targetMetadata.BusinessInfo;
            var targetBillView     = targetMetadata.CreateBillView(this.Context);
            var targetBillService  = targetBillView.AsDynamicFormViewService();
            var targetDataObjects  = viewService.LoadFromCache(this.Context, ids, targetBusinessInfo.GetDynamicObjectType()).ToList();

            //如果两边的数据包可以被关联,那么直接对应修改。
            dataEntites.Join(targetDataObjects,
                             left => left.MasterId <int>(),
                             right => right.FieldProperty <DynamicObject>(targetMetadata.BusinessInfo.GetField("FMirrorId")).MasterId <int>(),
                             (left, right) =>
            {
                targetBillView.Edit(right);
                targetBillService.UpdateValue("FNumber", -1, left.BDNumber());
                targetBillService.UpdateValue("FName", -1, new LocaleValue(left.BDName(this.Context)));
                targetBillService.UpdateValue("FSpecification", -1, new LocaleValue(left.FieldProperty <LocaleValue>(this.BusinessInfo.GetField("FSpecification")).Value(this.Context)));

                //基本
                left.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity"))
                .Adaptive(sub =>
                {
                    this.BusinessInfo.GetField("FBaseUnitId").AsType <BaseDataField>()
                    .Adaptive(field =>
                    {
                        if (!sub.FieldProperty <DynamicObject>(field).FieldRefProperty <bool>(field, "FPHMXEA") ||
                            left.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <decimal>(this.BusinessInfo.GetField("FPHMXStdCty")) > 0M)
                        {
                            targetBillService.UpdateValue("FEnableCapacity", -1, true);
                            targetBillService.UpdateValue("FCapacityUnit", -1, new LocaleValue(sub.FieldProperty <DynamicObject>(field).BDName(this.Context)));
                            targetBillService.UpdateValue("FCapacityScale", -1, sub.FieldProperty <DynamicObject>(field).FieldRefProperty <int>(field, "FPrecision"));
                        }                            //end if
                    });
                });

                //库存
                var pkgId = left.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <DynamicObject>(this.BusinessInfo.GetField("FPHMXPkgId")).PkId <string>();
                if (!pkgId.IsNullOrEmptyOrWhiteSpace())
                {
                    var entries = targetBillView.Model.GetEntityDataObject(targetBusinessInfo.GetEntity("FPackageEntry"));
                    if (entries.Any(entry => entry.FieldProperty <DynamicObject>(targetBusinessInfo.GetField("FEntryPackageId")).PkId <string>().EqualsIgnoreCase(pkgId)) == false)
                    {
                        targetBillView.Model.InsertEntryRow("FPackageEntry", 0);
                        targetBillService.SetItemValueByID("FEntryPackageId", pkgId, 0);
                    }                    //end if

                    //设置标准容量。
                    entries.Where(entry => targetBillView.Model.GetValue("FEnableCapacity").ToType <bool>() && entry.FieldProperty <DynamicObject>(targetBusinessInfo.GetField("FEntryPackageId")).PkId <string>().EqualsIgnoreCase(pkgId))
                    .FirstOrDefault()
                    .Adaptive(pkg =>
                    {
                        if (pkg != null)
                        {
                            var index = entries.IndexOf(pkg);
                            targetBillService.UpdateValue("FStdCty", index, left.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <decimal>(this.BusinessInfo.GetField("FPHMXStdCty")));
                        }                           //end if
                    });

                    //设置默认包装。
                    targetBillService.SetItemValueByID("FPackageId", pkgId, -1);
                }                    //end if

                //设置有效期。
                if (targetBillView.Model.GetValue("FEnableExpiry").ToType <bool>())
                {
                    targetBillService.UpdateValue("FExpPeriod", -1, left.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <int>(this.BusinessInfo.GetField("FExpPeriod")));
                    targetBillService.UpdateValue("FExpUnit", -1, left.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <string>(this.BusinessInfo.GetField("FExpUnit")));
                }                    //end if
                return(right);
            }).ToArray();

            //如果数据包没有关联,则新增
            var unmatchDataEntities = dataEntites.Where(data => (mirrorids.Contains(data.MasterId <int>()) == false))
                                      .ToArray();

            foreach (var data in unmatchDataEntities)
            {
                targetBillView.AddNew();
                targetBillService.UpdateValue("FNumber", -1, data.BDNumber());
                targetBillService.UpdateValue("FName", -1, new LocaleValue(data.BDName(this.Context)));
                targetBillService.UpdateValue("FSpecification", -1, new LocaleValue(data.FieldProperty <LocaleValue>(this.BusinessInfo.GetField("FSpecification")).Value(this.Context)));

                //基本
                data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity"))
                .Adaptive(sub =>
                {
                    this.BusinessInfo.GetField("FBaseUnitId").AsType <BaseDataField>()
                    .Adaptive(field =>
                    {
                        if (!sub.FieldProperty <DynamicObject>(field).FieldRefProperty <bool>(field, "FPHMXEA"))
                        {
                            targetBillService.UpdateValue("FEnableCapacity", -1, true);
                            targetBillService.UpdateValue("FCapacityUnit", -1, new LocaleValue(sub.FieldProperty <DynamicObject>(field).BDName(this.Context)));
                            targetBillService.UpdateValue("FCapacityScale", -1, sub.FieldProperty <DynamicObject>(field).FieldRefProperty <int>(field, "FPrecision"));
                        }        //end if
                    });
                });

                //库存
                data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1"))
                .Adaptive(sub =>
                {
                    //设置分录包装。
                    var pkgId = sub.FieldProperty <DynamicObject>(this.BusinessInfo.GetField("FPHMXPkgId")).PkId <string>();
                    if (targetBusinessInfo.GetEntity("FPackageEntry").DefaultRows < 1)
                    {
                        targetBillView.Model.InsertEntryRow("FPackageEntry", 0);
                    }
                    targetBillService.SetItemValueByID("FEntryPackageId", pkgId, 0);

                    if (targetBillView.Model.GetValue("FEnableCapacity").ToType <bool>())
                    {
                        targetBillService.UpdateValue("FStdCty", 0, sub.FieldProperty <decimal>(this.BusinessInfo.GetField("FPHMXStdCty")));
                    }    //end if

                    //设置默认包装。
                    targetBillService.SetItemValueByID("FPackageId", pkgId, -1);
                });
                targetBillService.UpdateValue("FEnableLot", -1, data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <bool>(this.BusinessInfo.GetField("FIsBatchManage")));
                targetBillService.UpdateValue("FEnableExpiry", -1, data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <bool>(this.BusinessInfo.GetField("FIsKFPeriod")));
                targetBillService.UpdateValue("FExpPeriod", -1, data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <int>(this.BusinessInfo.GetField("FExpPeriod")));
                targetBillService.UpdateValue("FExpUnit", -1, data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <string>(this.BusinessInfo.GetField("FExpUnit")));
                targetBillService.UpdateValue("FLotExpiryUnique", -1, data.SubHeadProperty(this.BusinessInfo.GetEntity("SubHeadEntity1")).FieldProperty <bool>(this.BusinessInfo.GetField("FIsExpParToFlot")));
                targetBillService.SetItemValueByID("FMirrorId", data.PkId <int>(), -1);
                targetDataObjects.Add(targetBillView.Model.DataObject);
            }//end foreach

            //统一调用上传操作。
            if (targetDataObjects.Any())
            {
                var op = targetDataObjects.DoNothing(this.Context, targetBusinessInfo, "Upload");
                this.OperationResult.MergeResult(op);
            } //end if
        }     //end method