Exemplo n.º 1
0
        /// <summary>
        /// 判断该业务对象对应的键值是否已经进行了提交处理。
        /// 区别于CheckHasSubmit 最主要的部分是增加和是否审核通过的判断。
        /// </summary>
        /// <param name="dbCmd"></param>
        /// <param name="busObj"></param>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public bool CheckParentHasSubmit(Database db, MB.RuleBase.IFace.IBaseRule baseRule, object mainEntity)
        {
            RuleSettingAttribute ruleSettAtt = MB.RuleBase.Atts.AttributeConfigHelper.Instance.GetRuleSettingAtt(baseRule);

            //如果用户没有配置那么表示不需要上级引用的约束控制
            if (ruleSettAtt == null || ruleSettAtt.BaseDataType == null)
            {
                return(true);
            }
            //providerAtt.BaseDataType
            ParentProviderAttribute providerAtt = MB.RuleBase.Atts.AttributeConfigHelper.Instance.GetParentProviderAttByType(ruleSettAtt.BaseDataType);

            if (providerAtt == null || providerAtt.ProviderTableName == null || providerAtt.ProviderTableName.Length == 0)
            {
                return(true);
            }
            if (!MB.Util.MyReflection.Instance.CheckObjectExistsProperty(mainEntity, providerAtt.ForeingKeyField))
            {
                throw new MB.Util.APPException(string.Format("在检查引用上级对象时 属性{0}在对象{1}中不存在。请检查配置信息!", providerAtt.ForeingKeyField, mainEntity.GetType().FullName), MB.Util.APPMessageType.DisplayToUser);
            }

            object refrenceKeyValue = MB.Util.MyReflection.Instance.InvokePropertyForGet(mainEntity, providerAtt.ForeingKeyField);

            return(CheckParentHasSubmit(db, providerAtt.ProviderTableName, providerAtt.ProviderKeyName, refrenceKeyValue.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 提交指定的业务处理数据。
        /// </summary>
        /// <param name="baseRule"></param>
        /// <param name="mainEntity"></param>
        /// <returns></returns>
        public int ObjectSubmit(MB.RuleBase.IFace.IBaseRule baseRule, object mainEntity)
        {
            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);
            string sql      = string.Format("UPDATE  {0} SET {1} = '1',{2} = SYSTIMESTAMP WHERE {3} = '{4}' ", mappingInfo.MapTable, ENTITY_DOC_STATE, ENTITY_LAST_MODIFIED_DATE, keyName, keyValue.ToString());

            Database db = MB.Orm.Persistence.DatabaseHelper.CreateDatabase();

            //在提交之前先检查服务器日期
            MB.Orm.Persistence.EntityDistributedHelper.NewInstance.CheckEntityCanSave(mainEntity);

            DbCommand cmd = db.GetSqlStringCommand(sql);

            _DbExexuteHelper.ExecuteNonQuery(db, cmd);

            return(1);
        }
Exemplo n.º 3
0
        /// <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);
        }