public override bool Validate(ValidateContext context) { DocStruct docStruct = context.ValidateObject as DocStruct; BOMStruct bOMStruct = context.ValidateList as BOMStruct; if (docStruct != null && bOMStruct != null) { List <string> list = new List <string>(); if (docStruct.IsConfigPart && !docStruct.ContainsKey(_.DELETE_CONFIG) && ValidateCreoConfig.IsZuBiao(docStruct) &&//不是族表实例的时候。判断不了实例的添加与删除 !comp_arr.Contains(docStruct.FileName)) //每一个文件只比较一次 { comp_arr.Add(docStruct.FileName); var Configs = docStruct.GetString(ZuBiaoNames).Trim().Split(';'); Configs = Configs.Concat(new string[] { GetFileWithoutExt(docStruct.FileName) }).ToArray(); foreach (DocConfig cfg in from p in this.docconfigManager.GetStandardPartsConfigByDVerId(docStruct.RealityVerId) where !string.IsNullOrEmpty(p.ConfigName) select p) { if (!Configs.Any((string p) => BOMHelp.IsEquals(p, cfg.ConfigName, true))) { if (docStruct.IsBorrow || BOMHelp.Contains(docStruct.OperateType, EntityOperateType.NotCheckOut)) { string msg = string.Format("{0}:不允许修改文档族表实例", docStruct.IsBorrow ? "借用" : "未检出"); this.DealDocStruct(docStruct, delegate(DocStruct p) { p.SetDocStateL(false, "red", msg); }); return(false); } if (!list.Contains(cfg.ConfigID)) { list.Add(cfg.ConfigID); } } } if (list.Count > 0) { docStruct.WriteValue(_.DELETE_CONFIG, string.Join(",", list.ToArray())); } } if (context.CurIndex == bOMStruct.Count && !this.ValidateConfigUse(bOMStruct)) { return(false); } } return(true); }
/// <summary> /// 验证族实例 /// </summary> /// <param name="sourcedoc"></param> /// <param name="context"></param> /// <param name="std"></param> /// <param name="GetRelations"></param> /// <returns></returns> static bool ValidateConfigParts(DocStruct sourcedoc, ValidateContext context, DocConfig std, Func <ChildStruct, IList> GetRelations) { if (std != null) { sourcedoc.ConfigId = std.ConfigID; if (!string.IsNullOrEmpty(std.MatVerId)) { sourcedoc.MaterialVerId = std.MatVerId; } BOMHelp.Write(context.CurScopeProperty, "__STD_OLD_MaterialVerId", std.MatVerId); foreach (var current in sourcedoc.ParentRelation.Where(p => p.ParentNode != null)) { DocStruct parent = current.ParentNode; IEnumerable <ObjectRelation> source = GetRelations(current).Cast <ObjectRelation>(); if (!source.Any <ObjectRelation>()) { if (!ValidatorHelp.CheckPCRelation(current)) { bool result = false; return(result); } sourcedoc.IsBorrow = true; current.RelationOperateType = RelationOperateType.AddRelation; } else { if (parent.IsBorrow) { sourcedoc.IsBorrow = true; } else { ObjectRelation objectRelation = source.FirstOrDefault((ObjectRelation p) => (string.IsNullOrEmpty(p.ParentConfigID) || p.ParentConfigID == parent.ConfigId) && BOMHelp.IsEquals(p.ConfigID, std.ConfigID)); if (objectRelation != null) { current.RelationId = objectRelation.RelationId; bool flag = current.Count == current.HiddenCount; if (objectRelation.IsHidden != flag || !BOMHelp.Contains(parent.OperateType, EntityOperateType.NotCheckOut)) { current.RelationOperateType = RelationOperateType.ModifyRelation; } } else { current.RelationOperateType = RelationOperateType.AddRelation; } } } } } else if (!ValidateCreoConfig.IsZuBiao(sourcedoc)) //没有到如果该配置 同时不是族表实例 { foreach (var item in sourcedoc.ParentRelation.Where(p => p.ParentNode != null)) { if (!ValidatorHelp.CheckPCRelation(item)) { return(false); } } } return(true); }