コード例 #1
0
        /// <summary>
        /// 操作已经完成,事务未提交时触发:同步删除下游单据数据
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            // 本单主键为字符串类型,略过
            if (this.BusinessInfo.GetForm().PkFieldType == EnumPkFieldType.STRING)
            {
                return;
            }

            // 把单据数据包,展开为按实体Key为标识存储的数据字典
            ExtendedDataEntitySet dataEntitySet = new ExtendedDataEntitySet();

            dataEntitySet.Parse(e.DataEntitys, this.BusinessInfo);

            // 对各单据体进行循环,分别扫描下游单据,逐单删除
            foreach (var entity in this.BusinessInfo.Entrys)
            {
                // 判断此实体,是否需要扫描下游单据
                if (this.IgnoreEntity(entity))
                {
                    continue;
                }

                // 取实体数据集合
                ExtendedDataEntity[] rows = dataEntitySet.FindByEntityKey(entity.Key);
                if (rows == null)
                {
                    // 容错
                    continue;
                }

                // 取实体的业务流程数据
                HashSet <long> entityIds = new HashSet <long>();
                foreach (var row in rows)
                {
                    long entityId = Convert.ToInt64(row.DataEntity[0]);
                    entityIds.Add(entityId);
                }
                BusinessFlowInstanceCollection bfInstances = this.LoadBFInstance(entity.Key, entityIds);
                if (bfInstances == null || bfInstances.Count == 0)
                {
                    // 无关联的业务流程实例,略过
                    continue;
                }

                // 从业务流程实例中,分析出本单据体的下游单据内码:按目标单据体分好组
                Dictionary <string, HashSet <long> > dctTargetEntityIds = this.GetTargetEntityIds(
                    entity, entityIds, bfInstances);

                // 对各种下游单据进行循环,逐个删除
                foreach (var targetBill in dctTargetEntityIds)
                {
                    IOperationResult deleteResult = this.DeleteTargetBill(targetBill.Key, targetBill.Value);
                    if (CheckOpResult(deleteResult) == false)
                    {
                        // 删除失败,无需继续,退出
                        return;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 操作执行后逻辑处理
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.EndOperationTransactionArgs e)
        {
            var         billGroups   = e.DataEntitys.GroupBy(o => Convert.ToString(o["BillTypeId_Id"]));
            List <long> lstNewMtrlId = new List <long>();
            List <long> lstNewBomId  = new List <long>();

            foreach (var billGroup in billGroups)
            {
                var billTypeParaObj = AppServiceContext.GetService <ISysProfileService>().LoadBillTypeParameter(this.Context, this.BusinessInfo.GetForm().Id, billGroup.Key);
                if (billTypeParaObj == null)
                {
                    continue;
                }

                bool bSupportNoMtrlQuote = Convert.ToBoolean(billTypeParaObj["F_JN_NoMtrlIdQuotation"]);

                if (bSupportNoMtrlQuote)
                {
                    ExtendedDataEntitySet dataEntitySet = new ExtendedDataEntitySet();
                    dataEntitySet.Parse(billGroup.ToArray(), this.BusinessInfo);

                    var quoteEntryRows = dataEntitySet.FindByEntityKey("FQUOTATIONENTRY")
                                         .Where(o => !o["F_JN_ProductName"].IsEmptyPrimaryKey())
                                         .ToArray();
                    if (quoteEntryRows.Any() == false)
                    {
                        continue;
                    }

                    lstNewMtrlId.AddRange(quoteEntryRows.Select(o => (long)o["MaterialId_Id"])
                                          .Distinct()
                                          .Where(o => o > 0));
                    lstNewBomId.AddRange(quoteEntryRows.Select(o => (long)o["BomId_Id"])
                                         .Distinct()
                                         .Where(o => o > 0));
                }
            }

            //反禁用关联的物料及物料清单
            OperateOption mtrlOption = OperateOption.Create();

            mtrlOption.SetVariableValue("IsList", true);
            FormMetadata mtrlMetadata = AppServiceContext.MetadataService.Load(this.Context, "BD_MATERIAL") as FormMetadata;
            var          mtrlOpRet    = AppServiceContext.SetStatusService.SetBillStatus(this.Context, mtrlMetadata.BusinessInfo,
                                                                                         lstNewMtrlId.Select(o => new KeyValuePair <object, object>(o, null)).ToList(),
                                                                                         null, "Enable", mtrlOption);

            this.OperationResult.MergeResult(mtrlOpRet);

            OperateOption bomOption = OperateOption.Create();

            bomOption.SetVariableValue("IsList", true);
            FormMetadata bomMetadata = AppServiceContext.MetadataService.Load(this.Context, "ENG_BOM") as FormMetadata;
            var          bomOpRet    = AppServiceContext.SetStatusService.SetBillStatus(this.Context, bomMetadata.BusinessInfo,
                                                                                        lstNewBomId.Select(o => new KeyValuePair <object, object>(o, null)).ToList(),
                                                                                        null, "Enable", bomOption);

            this.OperationResult.MergeResult(bomOpRet);
        }
コード例 #3
0
        public void AutomationInvalid(Context ctx)
        {
            DateTime Date = new DateTime();

            Date = DateTime.Now;
            string sql = string.Format(@"select * from T_SAL_QUOTATION t1 inner join T_SAL_QUOTATIONENTRY t2 on t1.FID=t2.FID 
                                         where datediff(day,FMODIFYDATE,'{0}')>=10 and FDOCUMENTSTATUS <>'C'", Date);
            //未审核超过十天的数据
            DynamicObjectCollection obj = DBUtils.ExecuteDynamicObject(ctx, sql, null, null, CommandType.Text, null);

            if (obj.Count <= 0)
            {
                return;
            }
            List <int> list = new List <int>();
            int        id   = 0;

            foreach (DynamicObject item in obj)
            {
                //单据类型为定价单
                if (Convert.ToString(item["FBILLTYPEID"]) == "dde3ab8a6b714e9fa7039d065a169f92")
                {
                    continue;
                }
                id = Convert.ToInt32(item["fid"]);
                list.Add(id);
            }
            string Sql = string.Format("update T_SAL_QUOTATION set FINVALIDSTATUS='B' where fid in ({0})", string.Join(",", list.ToArray()));

            DBUtils.Execute(ctx, Sql);

            FormMetadata metaData     = (FormMetadata)AppServiceContext.MetadataService.Load(ctx, "SAL_QUOTATION", true);
            var          Buinfo       = metaData.BusinessInfo;
            var          billGroups   = obj.GroupBy(o => Convert.ToString(o["FBillTypeId"]));
            List <int>   lstNewMtrlId = new List <int>();
            List <int>   lstNewBomId  = new List <int>();

            foreach (var billGroup in billGroups)
            {
                var billTypeParaObj = AppServiceContext.GetService <ISysProfileService>().LoadBillTypeParameter(ctx, "SAL_QUOTATION", billGroup.Key);
                if (billTypeParaObj == null)
                {
                    continue;
                }

                bool bSupportNoMtrlQuote = Convert.ToBoolean(billTypeParaObj["F_JN_NoMtrlIdQuotation"]);

                if (bSupportNoMtrlQuote)
                {
                    ExtendedDataEntitySet dataEntitySet = new ExtendedDataEntitySet();
                    dataEntitySet.Parse(billGroup.ToArray(), Buinfo);
                    var quoteEntryRows = dataEntitySet.FindByEntityKey("FBillHead");
                    var Entryobj       = quoteEntryRows.Where(o => !o["F_JN_ProductName"].IsEmptyPrimaryKey()).ToArray();
                    if (Entryobj.Any() == false)
                    {
                        continue;
                    }

                    lstNewMtrlId.AddRange(Entryobj.Select(o => (int)o["FMATERIALID"])
                                          .Distinct()
                                          .Where(o => o > 0));
                    lstNewBomId.AddRange(Entryobj.Select(o => (int)o["FBOMID"])
                                         .Distinct()
                                         .Where(o => o > 0));
                }
            }
            //禁用关联的物料及物料清单
            if (lstNewMtrlId.Count > 0)
            {
                OperateOption mtrlOption = OperateOption.Create();
                mtrlOption.SetVariableValue("IsList", true);
                FormMetadata mtrlMetadata = AppServiceContext.MetadataService.Load(ctx, "BD_MATERIAL") as FormMetadata;
                var          mtrlOpRet    = AppServiceContext.SetStatusService.SetBillStatus(ctx, mtrlMetadata.BusinessInfo,
                                                                                             lstNewMtrlId.Select(o => new KeyValuePair <object, object>(o, null)).ToList(),
                                                                                             null, "Forbid", mtrlOption);
            }
            if (lstNewBomId.Count > 0)
            {
                OperateOption bomOption = OperateOption.Create();
                bomOption.SetVariableValue("IsList", true);
                FormMetadata bomMetadata = AppServiceContext.MetadataService.Load(ctx, "ENG_BOM") as FormMetadata;
                var          bomOpRet    = AppServiceContext.SetStatusService.SetBillStatus(ctx, bomMetadata.BusinessInfo,
                                                                                            lstNewBomId.Select(o => new KeyValuePair <object, object>(o, null)).ToList(),
                                                                                            null, "Forbid", bomOption);
            }
        }