/// <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)); }
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)); } } }
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)); }
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); } } }
public override IParamBuilder GetCondition(IFieldInfo field, string fieldValue) { if (IsEqual) { return(SqlParamBuilder.CreateEqualSql(Context, field, fieldValue)); } else { return(SqlParamBuilder.CreateSingleSql(Context, field, "LIKE", fieldValue + "%")); } }
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; } }
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)); }
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); }
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; }
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); } }
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); }
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; } } }
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)); }
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()); } } } }
public override IParamBuilder GetCondition(IFieldInfo field, string fieldValue) { return(SqlParamBuilder.CreateEqualSql(Context, field, fieldValue)); }