private IParamBuilder InternalCreateLikeSql(TkDbContext context, IFieldInfo fieldName, string likeValue, string exceptValue) { string fieldName1 = fieldName.FieldName + "1"; string fieldName2 = fieldName.FieldName + "2"; fSql = string.Format(ObjectUtil.SysCulture, "{0} LIKE {1} AND {0} <> {2}", context.EscapeName(fieldName.FieldName), context.GetSqlParamName(fieldName1), context.GetSqlParamName(fieldName2)); fParams.Add(fieldName1, fieldName.DataType, likeValue); fParams.Add(fieldName2, fieldName.DataType, exceptValue); return(this); }
private void SetDataSet(object userId) { fDataSet = new DataSet { Locale = CultureInfo.CurrentCulture }; TkDbContext context = DbContextUtil.CreateDefault(); using (context) { IParamBuilder builder = SqlParamBuilder.CreateEqualSql(context, "USER_ID", TkDataType.String, userId); fAdmin = DbUtil.ExecuteScalar("SELECT USER_ADMIN FROM UR_USERS", context, builder).ToString() == "1"; SqlSelector selector = new SqlSelector(context, fDataSet); using (selector) { string userIdName = context.GetSqlParamName("USER_ID"); string sql = string.Format(ObjectUtil.SysCulture, FUNC_SQL, userIdName, context.ContextConfig.GetFunction("LENGTH", "FN_TREE_LAYER")); selector.Select("SYS_FUNCTION", sql, builder.Parameters); Dictionary <int, FunctionItem> idFunctions = new Dictionary <int, FunctionItem>(); DataTable table = fDataSet.Tables["SYS_FUNCTION"]; foreach (DataRow row in table.Rows) { FunctionItem item = new FunctionItem(row); if (item.IsLeaf) { try { idFunctions.Add(item.Id, item); fFunctions.Add(item.Key, item); } catch { } } } sql = string.Format(ObjectUtil.SysCulture, SUB_FUNC_SQL, userIdName); selector.Select("SYS_SUB_FUNC", sql, builder.Parameters); table = fDataSet.Tables["SYS_SUB_FUNC"]; var group = from item in table.AsEnumerable() group item by item.Field <int>("FnId"); foreach (var groupItem in group) { FunctionItem item; if (idFunctions.TryGetValue(groupItem.Key, out item)) { item.AddSubFunctions(groupItem); } } } } }