/// <summary> /// 构造函数。 /// </summary> /// <param name="ownSetting">表和键值用逗号分开,多个不同对象引用用分号分开. 如:OrderDoc,UID;Material,ID</param> public NextOwnAttribute(string ownTableName, string ownFieldName, string description) { _OwnTableName = ownTableName; _OwnFieldName = ownFieldName; _OwnDescription = description; _RestrictOption = LinkRestrictOption.CancelSubmit; }
/// <summary> /// 构造函数... /// </summary> /// <param name="cfgXmlSqlName">判断该对象是否被引用在XML中配置的SQL语句名称。</param> /// <param name="description"></param> public NextOwnAttribute(string cfgXmlSqlName, string description) { _CfgXmlSqlName = cfgXmlSqlName; _OwnDescription = description; _RestrictOption = LinkRestrictOption.CancelSubmit; }
/// <summary> /// 检查当前对象是否已被其它对象引用。 /// </summary> /// <param name="db"></param> /// <param name="baseRule"></param> /// <param name="mainEntity"></param> /// <param name="restrictOption"></param> /// <returns></returns> public bool ObjectOwnerless(Database db, MB.RuleBase.IFace.IBaseRule baseRule, object mainEntity, LinkRestrictOption restrictOption) { if (restrictOption == LinkRestrictOption.CancelSubmit) { if (!CheckExistsDocState(mainEntity)) { return(true); } var docState = GetEntityDocState(mainEntity); if (docState == DocState.Progress) { return(true); } } RuleSettingAttribute ruleSettAtt = MB.RuleBase.Atts.AttributeConfigHelper.Instance.GetRuleSettingAtt(baseRule); //如果用户没有配置那么表示不需要上级引用的约束控制 if (ruleSettAtt == null || ruleSettAtt.BaseDataType == null) { return(true); } NextOwnAttribute[] atts = MB.RuleBase.Atts.AttributeConfigHelper.Instance.GetNextOwnAttByType(ruleSettAtt.BaseDataType); if (atts == null || atts.Length == 0) { return(true); } List <DbCommand> cmds = new List <DbCommand>(); string objDescription = string.Empty; MB.Orm.Mapping.ModelMappingInfo mappingInfo = null; string keyName = MB.Orm.Mapping.AttMappingManager.Instance.GetPrimaryKey(mainEntity, ref mappingInfo); object keyValue = MB.Util.MyReflection.Instance.InvokePropertyForGet(mainEntity, keyName); foreach (NextOwnAttribute att in atts) { //只有配置成 阻止撤消提交的,才进行这样的处理 if (att.RestrictOption != restrictOption) { continue; } if (string.IsNullOrEmpty(att.CfgXmlSqlName)) { string sql = string.Format("SELECT 1 FROM {0} WHERE {1}='{2}'", att.OwnTableName, att.OwnFieldName, keyValue.ToString()); if (!string.IsNullOrEmpty(att.OwnFilter)) { sql += string.Format(att.OwnFilter, keyValue.ToString()); } DbCommand tempCmd = db.GetSqlStringCommand(sql); cmds.Add(tempCmd); } else { System.Data.Common.DbCommand[] tempCmds = MB.Orm.Persistence.PersistenceManagerHelper.NewInstance.CreateDbCommandByXml(db, mappingInfo.XmlConfigFileName, att.CfgXmlSqlName, keyValue); if (tempCmds.Length != 1) { throw new MB.RuleBase.Exceptions.SelectSqlXmlConfigException(mappingInfo.XmlConfigFileName, att.CfgXmlSqlName); } cmds.AddRange(tempCmds); } if (objDescription.Length == 0) { objDescription = "<<" + att.OwnDescription + ">>"; } else { objDescription += "或 <<" + att.OwnDescription + ">>"; } } foreach (DbCommand dbCmd in cmds) { object val = _DbExexuteHelper.ExecuteScalar(db, dbCmd); if (val != null && val != System.DBNull.Value) { throw new MB.Util.APPException(string.Format("由于该对象已生成{0},不能再进行重做。", objDescription), MB.Util.APPMessageType.DisplayToUser); } } return(true); }