Beispiel #1
0
        private static string AppendListSql(Pagination page, AdminCredential admin, DBDatabase db, string sql)
        {
            Sys_Entity entity = db.FirstOrDefault <Sys_Entity>(new Sql("SELECT * FROM Sys_Entity WHERE ID=" + page.eid));

            if (sql.IndexOf(entity.Name + ".ID") == -1)
            {
                sql = sql.Replace("SELECT", "SELECT " + entity.Name + ".ID AS " + entity.Name + "$ID,");
            }
            if (sql.IndexOf(entity.Name + ".Name") == -1)
            {
                sql = sql.Replace("SELECT", "SELECT " + entity.Name + ".Name AS " + entity.Name + "$Name,");
            }
            if (sql.IndexOf(entity.Name + ".OwnerID") == -1)
            {
                sql = sql.Replace("SELECT", "SELECT " + entity.Name + ".OwnerID AS " + entity.Name + "$OwnerID,");
            }
            //Where条件
            if (!string.IsNullOrEmpty(page.WhereSql))
            {
                if (sql.IndexOf("WHERE") != -1)
                {
                    sql += " AND ";
                }
                else
                {
                    sql += " WHERE ";
                }
                sql += page.WhereSql;
            }
            if (page.IsSearch)
            {
                page.Page = 1;
            }
            //关键字
            sql = AppendSqlForKeyWord(page.KeyWord, page.eid.Value, db, sql);
            //权限过滤
            if (entity.IsEnableDataAuthorize)
            {
                sql = AppendSqlForAuth(page, admin, sql, entity.Name);
            }
            //Tab
            if (page.pid.HasValue)
            {
                sql = AppendSqlForTab(page, db, sql, entity.Name);
            }
            //统计数据
            if (entity.IsEnableSumData)
            {
                CacheHelper.Single.TrySave($"{page.vid}-{admin.ID}-sumdata-sql", GetSumDataSql(entity.ID, db, sql));
            }
            //排序
            var orderSql = GetOrderSql(page, db, entity.Name);

            sql += orderSql;
            //表单分页
            CacheHelper.Single.TrySave($"{page.vid}-{admin.ID}-formpage-sql", GetFormPageSql(entity.Name, orderSql));
            CacheHelper.Single.TrySave($"{page.vid}-{admin.ID}-list-sql", sql);
            return(sql);
        }