예제 #1
0
        private Dictionary <string, object> ProcessDynamicParams(SqlParams sqlParams, ref string reportsql, ref string prepareSql, ref string totalSql)
        {
            var parameters = new Dictionary <string, object>();
            var elements   = XmlConfig.Elements("Dynamic");

            if (XmlConfig.Attribute("BaseType") != null)
            {
                var baseConfig = AllReportConfig.Elements("Rep").FirstOrDefault(q => q.Attribute("key").Value == XmlConfig.Attribute("BaseType").Value);
                if (baseConfig != null)
                {
                    foreach (var item in baseConfig.Elements("Dynamic"))
                    {
                        var property = elements.FirstOrDefault(p => p.Attribute("property").Value == item.Attribute("property").Value);
                        if (property != null)
                        {
                            property.Add(item.Elements());
                        }
                    }
                }
            }

            foreach (var itemEle in elements)
            {
                Dictionary <string, object> dataRes;
                List <ReportWhereEntity>    list = FillReportWhereEntity(itemEle);
                string dynamicStr = GetDynamicStr(list, sqlParams.Where, out dataRes);
                string dyProperty = itemEle.Attribute("property").Value;

                if (!string.IsNullOrEmpty(reportsql))
                {
                    reportsql = reportsql.Replace(dyProperty, dynamicStr);
                }
                //if (!string.IsNullOrEmpty(footerSql))
                //    footerSql = footerSql.Replace(dyProperty, dynamicStr);
                if (!string.IsNullOrEmpty(prepareSql))
                {
                    prepareSql = prepareSql.Replace(dyProperty, dynamicStr);
                }
                if (!string.IsNullOrEmpty(totalSql))
                {
                    totalSql = totalSql.Replace(dyProperty, dynamicStr);
                }

                if (dataRes != null)
                {
                    foreach (var item in dataRes)
                    {
                        if (parameters.All(p => p.Key != item.Key.ToLower()))
                        {
                            parameters.Add(item.Key.ToLower(), item.Value);
                        }
                    }
                }
            }

            foreach (var item in sqlParams.Where)
            {
                if (parameters.All(p => p.Key != item.Key.ToLower()))
                {
                    parameters.Add(item.Key.ToLower(), item.Value);
                }
            }
            return(parameters);
        }