Esempio n. 1
0
        /// <summary>
        /// 动态聚组查询获取数据
        /// </summary>
        /// <param name="baseRule"></param>
        /// <param name="setting"></param>
        /// <param name="parInfos"></param>
        /// <param name="parValues"></param>
        /// <returns></returns>
        public System.Data.DataSet GetDynamicGroupQueryData(MB.Util.Model.DynamicGroupSetting setting, QueryParameterInfo[] parInfos, params object[] parValues)
        {
            MB.Orm.Mapping.QueryParameterMappings queryMappings = null;
            if (!string.IsNullOrEmpty(setting.EntityInfos.MainEntity.Alias))
            {
                queryMappings = new Orm.Mapping.QueryParameterMappings(setting.EntityInfos.MainEntity.Alias);
            }
            else
            {
                queryMappings = new Orm.Mapping.QueryParameterMappings(setting.EntityInfos.MainEntity.Name);
            }

            string   sqlFilter = MB.Orm.DbSql.SqlShareHelper.Instance.QueryParametersToSqlString(queryMappings, parInfos);
            Database db        = MB.Orm.Persistence.DatabaseHelper.CreateDatabase();

            MB.Orm.Persistence.PersistenceManagerHelper persitence = MB.Orm.Persistence.PersistenceManagerHelper.NewInstance;
            var       sql   = MB.Orm.DbSql.DynamicGroupBuilder.DynamicGroupBuilderFactory.CreateQueryBuilder(setting).BuildDynamicQuery(sqlFilter);
            DbCommand dbCmd = persitence.GetSqlStringCommand(db, sql);


            DataSet ds = null;

            try
            {
                MB.Util.TraceEx.Write("正在执行:" + MB.Orm.Persistence.DbCommandExecuteTrack.Instance.CommandToTrackMessage(db, dbCmd));

                ds = new DatabaseExecuteHelper(_QueryBehavior).ExecuteDataSet(db, dbCmd);
            }
            catch (Exception ex)
            {
                throw new MB.RuleBase.Exceptions.DatabaseExecuteException("GetDynamicGroupQueryData 出错!", ex);
            }
            return(ds);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据数据类型和过滤条件返回需要的数据。
        /// </summary>
        /// <param name="baseRule">指定操作的业务类。</param>
        /// <param name="dataInDocType">指定的数据类型。</param>
        /// <param name="whereFilters">过滤条件</param>
        /// <param name="otherParamValues">其它附加的过滤条件</param>
        /// <returns>满足条件的DataSet 类型数据</returns>
        public System.Data.DataSet GetObjectAsDataSet(IBaseQueryRule baseRule, object dataInDocType, QueryParameterInfo[] parInfos, params object[] parValues)
        {
            ObjectDataMappingAttribute mappingAtt = AttributeConfigHelper.Instance.GetObjectDataMappingAttribute(dataInDocType);

            if (mappingAtt == null)
            {
                throw new MB.RuleBase.Exceptions.RequireConfigDataMappingException(dataInDocType);
            }

            string sqlName = string.IsNullOrEmpty(mappingAtt.XmlCfgSelectSqlName) ? MB.Orm.Mapping.Xml.XmlSqlMappingInfo.SQL_SELECT_OBJECT : mappingAtt.XmlCfgSelectSqlName;

            MB.Orm.Mapping.QueryParameterMappings queryMappings = baseRule.QueryParamMapping;
            if (queryMappings == null)
            {
                queryMappings = MB.Orm.Mapping.Xml.SqlConfigHelper.Instance.GetSqlQueryParamMappings(mappingAtt.MappingXmlFileName, sqlName);
            }

            string sqlFilter = MB.Orm.DbSql.SqlShareHelper.Instance.QueryParametersToSqlString(queryMappings, parInfos);

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

            ArrayList paramValues = new ArrayList();

            if (parValues != null && parValues.Length > 0)
            {
                foreach (object v in parValues)
                {
                    paramValues.Add(v);
                }
            }
            paramValues.Add(sqlFilter);
            System.Data.Common.DbCommand[] cmds = MB.Orm.Persistence.PersistenceManagerHelper.NewInstance.CreateDbCommandByXml(db,
                                                                                                                               mappingAtt.MappingXmlFileName, sqlName, paramValues.ToArray());

            if (cmds.Length != 1)
            {
                throw new MB.RuleBase.Exceptions.SelectSqlXmlConfigException(mappingAtt.MappingXmlFileName, sqlName);
            }

            System.Data.Common.DbCommand cmd = cmds[0];

            DataSet ds = null;

            try {
                MB.Util.TraceEx.Write("正在执行:" + MB.Orm.Persistence.DbCommandExecuteTrack.Instance.CommandToTrackMessage(db, cmd));

                ds = new DatabaseExecuteHelper(_QueryBehavior).ExecuteDataSet(db, cmd);
            }
            catch (Exception ex) {
                throw new MB.RuleBase.Exceptions.DatabaseExecuteException("GetObjectAsDataSet 出错!", ex);
            }
            return(ds);
        }
Esempio n. 3
0
        /// <summary>
        /// 根据指定的 XML 和 SQL 名称获取参数的Mapping 配置信息。
        /// </summary>
        /// <param name="xmlFileName"></param>
        /// <param name="sqlName"></param>
        /// <returns></returns>
        public MB.Orm.Mapping.QueryParameterMappings GetSqlQueryParamMappings(string xmlFileName, string sqlName)
        {
            System.Xml.XmlNode sqlNode = getSqlNode(xmlFileName, sqlName);
            if (sqlNode == null || sqlNode.ChildNodes.Count == 0)
            {
                TraceEx.Write("在XML 文件:" + xmlFileName + " 中获取相应SQL 语句:" + sqlName + "出错,请检查资源文件或者对应SQL 语句是否存在!");
                return(null);
            }
            MB.Orm.Mapping.QueryParameterMappings mappings = null;
            foreach (System.Xml.XmlNode paramMappingNode in sqlNode.ChildNodes)
            {
                if (paramMappingNode.NodeType != System.Xml.XmlNodeType.Element)
                {
                    continue;
                }
                if (string.Compare(paramMappingNode.Name, XML_PARAM_MAPPINGS, true) != 0)
                {
                    continue;
                }

                mappings = new QueryParameterMappings();
                if (paramMappingNode.Attributes["DefaultTableAlias"] != null)
                {
                    mappings.DefaultTableAlias = paramMappingNode.Attributes["DefaultTableAlias"].Value;
                }

                foreach (System.Xml.XmlNode node in paramMappingNode.ChildNodes)
                {
                    if (node.NodeType != System.Xml.XmlNodeType.Element)
                    {
                        continue;
                    }
                    if (string.Compare(node.Name, "Mapping", true) != 0)
                    {
                        continue;
                    }
                    if (node.Attributes["Name"] == null || node.Attributes["DbFieldName"] == null)
                    {
                        throw new MB.Util.APPException(string.Format("XML配置文件{0},配置QueryParamMappings 是可能没有配置 Name 或者 DbFieldName!", xmlFileName));
                    }

                    mappings.Add(new QueryParameterMappingInfo(node.Attributes["Name"].Value, node.Attributes["DbFieldName"].Value));
                }
                break;
            }
            return(mappings);
        }
Esempio n. 4
0
        /// <summary>
        /// 根据指定类型获取满足条件的实体对象。
        /// </summary>
        /// <typeparam name="T">从MB.Orm.Common.BaseModel 中继承的数据对象类型。</typeparam>
        /// <param name="baseRule">获取实体对象集合的业务类。</param>
        /// <param name="dataInDocType">在业务类中的数据类型。</param>
        /// <param name="filter">过滤条件。</param>
        /// <returns>指定类型的集合类。</returns>
        public List <T> GetObjects <T>(IBaseQueryRule baseRule, object dataInDocType, QueryParameterInfo[] parInfos, params object[] parValues)
        {
            ObjectDataMappingAttribute mappingAtt = AttributeConfigHelper.Instance.GetObjectDataMappingAttribute(dataInDocType);

            if (mappingAtt == null)
            {
                throw new MB.RuleBase.Exceptions.RequireConfigDataMappingException(dataInDocType);
            }

            string sqlName = string.IsNullOrEmpty(mappingAtt.XmlCfgSelectSqlName) ? MB.Orm.Mapping.Xml.XmlSqlMappingInfo.SQL_SELECT_OBJECT : mappingAtt.XmlCfgSelectSqlName;

            MB.Orm.Mapping.QueryParameterMappings queryMappings = baseRule.QueryParamMapping;
            if (queryMappings == null)
            {
                queryMappings = MB.Orm.Mapping.Xml.SqlConfigHelper.Instance.GetSqlQueryParamMappings(mappingAtt.MappingXmlFileName, sqlName);
            }

            string sqlFilter  = MB.Orm.DbSql.SqlShareHelper.Instance.QueryParametersToSqlString(queryMappings, parInfos);
            Type   entityType = typeof(T);

            if (string.Compare(entityType.FullName, "System.Object", true) == 0)
            {
                if (mappingAtt.EntityType == null)
                {
                    throw new MB.Util.APPException("业务类:" + baseRule.GetType().FullName + " 中的:" +
                                                   dataInDocType.GetType() + " 的数据值:" + dataInDocType.ToString() +
                                                   " 在配置ObjectDataMapping时需要配置 EntityType", MB.Util.APPMessageType.SysErrInfo);
                }
                entityType = mappingAtt.EntityType;
            }

            List <object> pars = new List <object>();

            if (parValues != null && parValues.Length > 0)
            {
                foreach (object p in parValues)
                {
                    pars.Add(p);
                }
            }
            pars.Add(sqlFilter);
            //以后需要增加是否通过XML 配置还是根据实体自动生成。
            return(new DatabaseExcuteByXmlHelper(_QueryBehavior).GetObjectsByXml <T>(entityType, mappingAtt.MappingXmlFileName, sqlName, pars.ToArray()));
        }