Exemplo n.º 1
0
        /// <summary>
        /// 根据指定的表字段及字段的值来填充数据集
        /// </summary>
        /// <param name="field">字段</param>
        /// <param name="value">对应的字段的值</param>
        public void SelectWithParam(string field, object value)
        {
            TkDebug.AssertArgumentNullOrEmpty(field, "field", this);
            TkDebug.AssertArgumentNull(value, "value", this);

            Select(SqlParamBuilder.CreateEqualSql(Context, GetFieldInfo(field), value));
        }
Exemplo n.º 2
0
        private IParamBuilder CreateItemParamBuilder(string value, bool isEqual, int index = 0)
        {
            IParamBuilder[] builders = new IParamBuilder[fFields.Length];

            for (int i = 0; i < fFields.Length; ++i)
            {
                if (isEqual)
                {
                    builders[i] = SqlParamBuilder.CreateEqualSql(Context, fFields[i], value);
                }
                else
                {
                    if (index == 0)
                    {
                        builders[i] = LikeParamBuilder.CreateLikeSql(Context, fFields[i], value);
                    }
                    else
                    {
                        builders[i] = LikeParamBuilder.CreateLikeSql(Context, fFields[i],
                                                                     fFields[i].FieldName + index, value);
                    }
                }
            }
            return(SqlParamBuilder.CreateParamBuilderWithOr(builders));
        }
Exemplo n.º 3
0
 public override IParamBuilder GetCondition(IFieldInfo field, string fieldValue)
 {
     if (IsEqual)
     {
         return(SqlParamBuilder.CreateParamBuilderWithOr(
                    SqlParamBuilder.CreateEqualSql(Context, fField1, fieldValue),
                    SqlParamBuilder.CreateEqualSql(Context, fField2, fieldValue)));
     }
     else
     {
         if (WordSplit)
         {
             string[]             values = fieldValue.Split(' ');
             List <IParamBuilder> items  = new List <IParamBuilder>(values.Length);
             int index = 0;
             foreach (var value in values)
             {
                 string newValue = value.Trim();
                 if (!string.IsNullOrEmpty(newValue))
                 {
                     ++index;
                     IParamBuilder builder = GetLikeParamBuilder(newValue, index);
                     items.Add(builder);
                 }
             }
             return(ParamBuilder.CreateParamBuilder(items));
         }
         else
         {
             return(GetLikeParamBuilder(fieldValue));
         }
     }
 }
Exemplo n.º 4
0
        internal static string GetLayer(TableResolver resolver, DbTreeDefinition tree, string parentId)
        {
            TkDbContext   context    = resolver.Context;
            IFieldInfo    layerField = resolver.GetFieldInfo(tree.LayerField);
            IParamBuilder fixBuilder = resolver.CreateFixCondition();
            string        execRootId = tree.ExecuteRootId;

            if (execRootId == parentId)
            {
                string subStringSql = context.ContextConfig.GetFunction("SubString",
                                                                        layerField.FieldName, 1, 3);
                string sql = string.Format(ObjectUtil.SysCulture,
                                           "SELECT MAX({0}) FROM {1}", subStringSql, resolver.TableName);
                string value = (fixBuilder == null ? DbUtil.ExecuteScalar(sql, context)
                    : DbUtil.ExecuteScalar(sql, context, fixBuilder)).ToString();
                if (string.IsNullOrEmpty(value))
                {
                    return("000");
                }
                else
                {
                    return(AddLayer(value));
                }
            }
            else
            {
                try
                {
                    string sql = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}",
                                               layerField.FieldName, resolver.TableName);
                    IParamBuilder builder = ParamBuilder.CreateParamBuilder(fixBuilder,
                                                                            SqlParamBuilder.CreateEqualSql(context, resolver.GetFieldInfo(tree.IdField), parentId));
                    string topLayer     = DbUtil.ExecuteScalar(sql, context, builder).ToString();
                    string subStringSql = context.ContextConfig.GetFunction("SubString",
                                                                            layerField.FieldName, topLayer.Length + 1, 3);

                    builder = CreateLayerParamBuilder(context, layerField, topLayer);
                    builder = SqlParamBuilder.CreateParamBuilder(fixBuilder, builder);
                    sql     = string.Format(ObjectUtil.SysCulture, "SELECT MAX({0}) FROM {1}",
                                            subStringSql, resolver.TableName);
                    string value = DbUtil.ExecuteScalar(sql, context, builder).ToString().Trim();
                    if (string.IsNullOrEmpty(value))
                    {
                        DataRow parentRow = resolver.SelectRowWithParam(tree.IdField, parentId);
                        parentRow[tree.LeafField] = 0;
                        resolver.SetCommands(AdapterCommand.Update);
                        return(topLayer + "000");
                    }
                    else
                    {
                        return(topLayer + AddLayer(value.Substring(value.Length - 3)));
                    }
                }
                catch
                {
                    return(string.Empty);
                }
            }
        }
Exemplo n.º 5
0
        private static IParamBuilder CreateLayerParamBuilder(TkDbContext context,
                                                             IFieldInfo layer, string topLayer)
        {
            string        fieldName = layer.FieldName;
            IParamBuilder builder   = SqlParamBuilder.CreateParamBuilder(
                SqlParamBuilder.CreateSingleSql(context, layer, "!=", fieldName + "0", topLayer),
                SqlParamBuilder.CreateSingleSql(context, layer, "LIKE", fieldName + "1", topLayer + "%"));

            return(builder);
        }
Exemplo n.º 6
0
 public override IParamBuilder GetCondition(IFieldInfo field, string fieldValue)
 {
     if (IsEqual)
     {
         return(SqlParamBuilder.CreateEqualSql(Context, field, fieldValue));
     }
     else
     {
         return(SqlParamBuilder.CreateSingleSql(Context, field, "LIKE", fieldValue + "%"));
     }
 }
Exemplo n.º 7
0
 public override IParamBuilder GetCondition(IFieldInfo fieldName, string fieldValue)
 {
     try
     {
         DateTime date = DateTime.Parse(fieldValue, ObjectUtil.SysCulture);
         return(SqlParamBuilder.CreateSingleSql(Context, fieldName, "<", fieldName.FieldName + "END", date.AddDays(1)));
     }
     catch
     {
         return(SqlParamBuilder.NoResult);
     }
 }
Exemplo n.º 8
0
        internal static void SortTree(TableResolver resolver, DbTreeDefinition tree,
                                      string id, TreeNodeMoveDirection direct)
        {
            TkDebug.AssertArgumentNull(resolver, "resolver", null);
            TkDebug.AssertArgumentNull(tree, "tree", null);
            TkDebug.AssertArgumentNullOrEmpty(id, "id", null);

            IParamBuilder fixBuilder = resolver.CreateFixCondition();
            IParamBuilder builder    = ParamBuilder.CreateParamBuilder(fixBuilder,
                                                                       SqlParamBuilder.CreateEqualSql(resolver.Context, resolver.GetFieldInfo(tree.IdField), id));

            IFieldInfo layerField = resolver.GetFieldInfo(tree.LayerField);
            string     sql        = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}",
                                                  layerField.FieldName, resolver.TableName);
            string layer       = DbUtil.ExecuteScalar(sql, resolver.Context, builder).ToString();
            string parentLayer = layer.Substring(0, layer.Length - 3);

            resolver.SetCommands(AdapterCommand.Update);
            builder = SqlParamBuilder.CreateSingleSql(resolver.Context, layerField, "LIKE", parentLayer + "___");
            resolver.Select(builder, "ORDER BY " + layerField.FieldName);
            if (resolver.HostTable == null || resolver.HostTable.Rows.Count == 0)
            {
                return;
            }

            int rowNum = GetRowNum(resolver.HostTable, tree.IdField, id);

            if (rowNum == -1)
            {
                return;
            }
            //根据移动方向,执行不同操作
            switch (direct)
            {
            case TreeNodeMoveDirection.Up:
                if (rowNum == 0)    //已经最前,不能向上移动
                {
                    return;
                }
                SwapLayer(resolver, tree, rowNum, rowNum - 1);
                break;

            case TreeNodeMoveDirection.Down:
                if (rowNum == resolver.HostTable.Rows.Count - 1)    //已经最后,不能向下移动
                {
                    return;
                }
                SwapLayer(resolver, tree, rowNum, rowNum + 1);
                break;
            }
        }
Exemplo n.º 9
0
        public void SelectWithKeys(params object[] values)
        {
            TkDebug.AssertEnumerableArgumentNull(values, "values", this);
            TkDebug.Assert(KeyCount == values.Length, string.Format(ObjectUtil.SysCulture,
                                                                    "参数values的个数和表的主键字段个数不匹配,主键的个数为{0},而values的个数为{1}",
                                                                    KeyCount, values.Length), this);

            IParamBuilder[] builders = new IParamBuilder[KeyCount];
            for (int i = 0; i < KeyCount; ++i)
            {
                builders[i] = SqlParamBuilder.CreateEqualSql(Context, fKeyFieldArray[i], values[i]);
            }
            Select(ParamBuilder.CreateParamBuilder(builders));
        }
Exemplo n.º 10
0
        public void SelectWithParam(string filterSql, string orderBy, string field, object value)
        {
            TkDebug.AssertArgumentNullOrEmpty(field, "field", this);
            TkDebug.AssertArgumentNull(value, "value", this);

            IParamBuilder builder = SqlParamBuilder.CreateEqualSql(Context, GetFieldInfo(field), value);

            if (!string.IsNullOrEmpty(filterSql))
            {
                builder = ParamBuilder.CreateParamBuilder(builder, ParamBuilder.CreateSql(filterSql));
            }

            Select(builder, orderBy);
        }
Exemplo n.º 11
0
        private IEnumerable <ITreeNode> SelectChildNode(string parentId, int level)
        {
            string        value     = fProvider.GetSqlLikeValue(fDefinition, level, parentId);
            IFieldInfo    fieldInfo = fSelector.GetFieldInfo(fDefinition.IdField);
            IParamBuilder builder   = SqlParamBuilder.CreateSingleSql(fSelector.Context,
                                                                      fieldInfo, "LIKE", value);

            if (!string.IsNullOrEmpty(parentId))
            {
                builder = SqlParamBuilder.CreateParamBuilder(builder,
                                                             SqlParamBuilder.CreateSingleSql(fSelector.Context, fieldInfo,
                                                                                             "<>", fDefinition.IdField + 1, parentId));
            }
            return(TreeUtil.SelectData(fSelector, this, () => fSelector.Select(builder), null).ToArray());
        }
Exemplo n.º 12
0
        internal static void MoveTree(TableResolver resolver, DbTreeDefinition tree, string sourceId, string destId)
        {
            TkDebug.AssertArgumentNull(resolver, "resolver", null);
            TkDebug.AssertArgumentNull(tree, "tree", null);
            TkDebug.AssertArgumentNullOrEmpty(sourceId, "sourceId", null);
            TkDebug.AssertArgumentNullOrEmpty(destId, "destId", null);

            IFieldInfo layerField = resolver.GetFieldInfo(tree.LayerField);
            string     sql        = string.Format(ObjectUtil.SysCulture, "SELECT {0} FROM {1}",
                                                  layerField.FieldName, resolver.TableName);
            IParamBuilder builder = ParamBuilder.CreateParamBuilder(resolver.CreateFixCondition(),
                                                                    SqlParamBuilder.CreateEqualSql(resolver.Context, resolver.GetFieldInfo(tree.IdField), destId));
            string  destLayer = DbUtil.ExecuteScalar(sql, resolver.Context, builder).ToString();
            DataRow srcRow    = resolver.SelectRowWithParam(tree.IdField, sourceId);

            if (destId == srcRow[tree.ParentIdField].ToString())
            {
                //throw new InvalidMoveException();
            }

            string oldLayer = srcRow[tree.LayerField].ToString();

            if (destLayer.StartsWith(oldLayer, StringComparison.Ordinal))
            {
                //throw new InvalidMoveException();
            }

            resolver.SetCommands(AdapterCommand.Update);

            string newLayer = GetLayer(resolver, tree, destId);

            srcRow[tree.LayerField] = newLayer;

            DataTable table        = resolver.HostTable;
            int       currentCount = table.Rows.Count;

            builder = CreateLayerParamBuilder(resolver.Context, layerField, oldLayer);
            resolver.Select(builder);
            for (int i = currentCount; i < table.Rows.Count; ++i)
            {
                DataRow row = table.Rows[i];
                row[tree.LayerField] = row[tree.LayerField].ToString().Replace(
                    oldLayer, newLayer);
            }

            SetParentLeaf(resolver, tree, srcRow[tree.ParentIdField].ToString());
            srcRow[tree.ParentIdField] = destId;
        }
Exemplo n.º 13
0
        internal static IParamBuilder GetLevelBuilder(TableSelector selector,
                                                      LevelTreeDefinition treeDef, int level, string value, ILevelProvider provider)
        {
            IParamBuilder[] builders = new IParamBuilder[level + 1];
            IFieldInfo      idField  = selector.GetFieldInfo(treeDef.IdField);

            for (int i = 0; i <= level; ++i)
            {
                string likeValue = provider.GetSqlLikeValue(treeDef, i, value);
                builders[i] = SqlParamBuilder.CreateSingleSql(selector.Context, idField, "LIKE",
                                                              treeDef.IdField + i, likeValue);
            }
            IParamBuilder builder = SqlParamBuilder.CreateParamBuilderWithOr(builders);

            return(builder);
        }
 protected override void FillUpdateTables(TableResolver resolver, IInputData input)
 {
     if (SupportData)
     {
         var fieldInfo            = resolver.GetFieldInfo(ParentKey);
         ListDataRightEventArgs e = new ListDataRightEventArgs(Context,
                                                               BaseGlobalVariable.Current.UserInfo, resolver);
         var builder = DataRight.GetListSql(e);
         builder = ParamBuilder.CreateParamBuilder(
             SqlParamBuilder.CreateEqualSql(Context, fieldInfo, fParentKey), builder);
         resolver.Select(builder);
     }
     else
     {
         resolver.SelectWithParam(ParentKey, fParentKey);
     }
 }
Exemplo n.º 15
0
        public RegNameList <ListTabSheet> CreateTabSheet(IDbDataSource dataSource,
                                                         IFieldInfoIndexer indexer)
        {
            if (TabSheets != null)
            {
                RegNameList <ListTabSheet> result = new RegNameList <ListTabSheet>();
                foreach (var item in TabSheets)
                {
                    string sql = item.Condition == null ? null :
                                 Expression.Execute(item.Condition, dataSource);
                    IParamBuilder builder = string.IsNullOrEmpty(sql) ? null :
                                            SqlParamBuilder.CreateSql(sql);
                    result.Add(new ListTabSheet(item.Id,
                                                item.Caption.ToString(ObjectUtil.SysCulture), builder));
                }
                return(result);
            }
            if (CodeTabSheet != null)
            {
                RegNameList <ListTabSheet> result = new RegNameList <ListTabSheet>();
                if (CodeTabSheet.NeedAllTab)
                {
                    result.Add(new ListTabSheet("_All", "全部", null));
                }
                CodeTable table = PlugInFactoryManager.CreateInstance <CodeTable>(
                    CodeTablePlugInFactory.REG_NAME, CodeTabSheet.CodeRegName);
                YJC.Toolkit.Decoder.CodeTableContainer data = new YJC.Toolkit.Decoder.CodeTableContainer();
                table.Fill(data, dataSource.Context);

                var        tableData = data[CodeTabSheet.CodeRegName];
                IFieldInfo info      = indexer[CodeTabSheet.NickName];
                TkDebug.AssertNotNull(info, "", this);
                foreach (var item in tableData)
                {
                    IParamBuilder builder  = SqlParamBuilder.CreateEqualSql(dataSource.Context, info, item.Value);
                    var           tabSheet = new ListTabSheet(item.Value, item.Name, builder);
                    result.Add(tabSheet);
                }
                return(result);
            }

            return(null);
        }
Exemplo n.º 16
0
        internal static void SetParentLeaf(TableResolver resolver, DbTreeDefinition fields, string parentId)
        {
            //DataTable table = resolver.HostTable;
            string sql = string.Format(ObjectUtil.SysCulture,
                                       "SELECT COUNT(*) FROM {0}", resolver.TableName);
            IParamBuilder builder = SqlParamBuilder.CreateEqualSql(
                resolver.Context, resolver.GetFieldInfo(fields.ParentIdField), parentId);

            builder = SqlParamBuilder.CreateParamBuilder(resolver.CreateFixCondition(), builder);
            int count = DbUtil.ExecuteScalar(sql, resolver.Context, builder).Value <int>();

            if (count == 1)
            {
                DataRow row = resolver.TrySelectRowWithParam(fields.IdField, parentId);
                if (row != null)
                {
                    row[fields.LeafField] = 1;
                }
            }
        }
Exemplo n.º 17
0
        public IParamBuilder CreateParamBuilder(string filterSql, string[] fields, params object[] values)
        {
            TkDebug.AssertEnumerableArgumentNullOrEmpty(fields, "fields", this);
            TkDebug.AssertEnumerableArgumentNull(values, "values", this);
            TkDebug.Assert(fields.Length == values.Length, string.Format(ObjectUtil.SysCulture,
                                                                         "参数fields和values的个数不匹配,fields的个数为{0},而values的个数为{1}",
                                                                         fields.Length, values.Length), this);

            List <IParamBuilder> list = new List <IParamBuilder>(fields.Length + 1);

            for (int i = 0; i < fields.Length; i++)
            {
                IParamBuilder builder = SqlParamBuilder.CreateEqualSql(Context,
                                                                       GetFieldInfo(fields[i]), values[i]);
                list.Add(builder);
            }
            if (!string.IsNullOrEmpty(filterSql))
            {
                list.Add(ParamBuilder.CreateSql(filterSql));
            }

            return(ParamBuilder.CreateParamBuilder(list));
        }
Exemplo n.º 18
0
        internal static IParamBuilder GetValueBuilder(TableSelector selector,
                                                      DbTreeDefinition treeDef, int topLevel, NormalDataRowTreeNode node)
        {
            string layer = node.Layer;
            int    len   = layer.Length / 3;

            if (len < topLevel)
            {
                return(null);
            }

            IParamBuilder[] builders = new IParamBuilder[len - topLevel + 1];
            for (int i = 0; i < builders.Length; i++)
            {
                int    subLength = (topLevel + i - 1) * 3;
                string likeValue = layer.Substring(0, subLength).PadRight(subLength + 3, '_');
                string paramName = treeDef.LayerField + i.ToString(ObjectUtil.SysCulture);
                builders[i] = SqlParamBuilder.CreateSingleSql(selector.Context,
                                                              selector.GetFieldInfo(treeDef.LayerField), "LIKE", paramName, likeValue);
            }
            IParamBuilder builder = SqlParamBuilder.CreateParamBuilderWithOr(builders);

            return(builder);
        }
Exemplo n.º 19
0
 public override IParamBuilder GetCondition(IFieldInfo fieldName, string fieldValue)
 {
     return(SqlParamBuilder.CreateSingleSql(Context, fieldName, ">=", fieldName.FieldName, fieldValue));
 }
Exemplo n.º 20
0
        public IParamBuilder CreateDetailParamBuilder(TableResolver masterResolver,
                                                      TableResolver detailResolver, IInputData input)
        {
            TkDebug.AssertNotNull(masterResolver, "masterResolver", this);
            TkDebug.AssertNotNull(detailResolver, "detailResolver", this);
            TkDebug.AssertNotNull(input, "input", this);

            string[] keyArray = Array.ConvertAll(masterResolver.GetKeyFieldArray(),
                                                 field => field.NickName);
            if (ObjectUtil.ArrayEqual(keyArray, fMasterFields))
            {
                if (fDetailFields.Length == 1)
                {
                    if (fManyToMany == null)
                    {
                        return(SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                              detailResolver.GetFieldInfo(fDetailFields[0]),
                                                              input.QueryString[fMasterFields[0]]));
                    }
                    else
                    {
                        return(GetManyToManyParamBuilder(detailResolver,
                                                         input.QueryString[fMasterFields[0]]));
                    }
                }
                else
                {
                    if (fManyToMany == null)
                    {
                        IParamBuilder[] builders = new IParamBuilder[fDetailFields.Length];
                        for (int i = 0; i < fDetailFields.Length; ++i)
                        {
                            builders[i] = SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                                         detailResolver.GetFieldInfo(fDetailFields[i]),
                                                                         input.QueryString[fMasterFields[i]]);
                        }

                        return(ParamBuilder.CreateParamBuilder(builders));
                    }
                    else
                    {
                        return(ThrowErrorManyToManyMode());
                    }
                }
            }
            else
            {
                DataRow row = masterResolver.Query(input.QueryString);
                if (fDetailFields.Length == 1)
                {
                    if (fManyToMany == null)
                    {
                        return(SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                              detailResolver.GetFieldInfo(fDetailFields[0]), row[fMasterFields[0]]));
                    }
                    else
                    {
                        return(GetManyToManyParamBuilder(detailResolver, row[fMasterFields[0]]));
                    }
                }
                else
                {
                    if (fManyToMany == null)
                    {
                        IParamBuilder[] builders = new IParamBuilder[fDetailFields.Length];
                        for (int i = 0; i < fDetailFields.Length; ++i)
                        {
                            builders[i] = SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                                         detailResolver.GetFieldInfo(fDetailFields[i]),
                                                                         row[fMasterFields[i]]);
                        }

                        return(ParamBuilder.CreateParamBuilder(builders));
                    }
                    else
                    {
                        return(ThrowErrorManyToManyMode());
                    }
                }
            }
        }
Exemplo n.º 21
0
 public override IParamBuilder GetCondition(IFieldInfo field, string fieldValue)
 {
     return(SqlParamBuilder.CreateEqualSql(Context, field, fieldValue));
 }
Exemplo n.º 22
0
        public override IParamBuilder GetCondition(IFieldInfo field, string fieldValue)
        {
            string likeValue = string.Format(ObjectUtil.SysCulture, "%\"{0}\"%", fieldValue);

            return(SqlParamBuilder.CreateSingleSql(Context, field, "LIKE", likeValue));
        }
Exemplo n.º 23
0
 private IParamBuilder GetLikeParamBuilder(string value, int index = 0)
 {
     return(SqlParamBuilder.CreateParamBuilderWithOr(
                LikeParamBuilder.CreateLikeSql(Context, fField1, fField1.FieldName + index, value),
                LikeParamBuilder.CreateLikeSql(Context, fField2, fField2.FieldName + index, value)));
 }