protected virtual TabConditionCount DoTabCountAction(IInputData input) { TabConditionCount result = new TabConditionCount(); if (TabSheets != null && TabSheets.Count > 0) { ParamBuilderContainer condition = CreateListCondition(input); string sql = string.Format(ObjectUtil.SysCulture, "SELECT COUNT(*) FROM {0}", GetTableName(Context)); string queryCon = input.QueryString[CONDITION_HEADER_NAME]; if (!string.IsNullOrEmpty(queryCon)) { queryCon = Uri.UnescapeDataString(queryCon); QueryCondition queryCondition = QueryCondition.FromEncodeString(queryCon); condition.Add(queryCondition.Builder); } foreach (var tabItem in TabSheets) { IParamBuilder builder = condition.IsEmpty ? tabItem.ParamBuilder : ParamBuilder.CreateParamBuilder(condition, tabItem.ParamBuilder); int count = DbUtil.ExecuteScalar(sql, Context, builder).Value <int>(); result.Add(tabItem.Id, count); } } return(result); }
/// <summary> /// 计算Sequence的下一个值 /// </summary> /// <param name="name">Sequence的名称</param> /// <param name="connection">数据库连接</param> /// <returns>该Sequence的下一个数值</returns> public static string Execute(string name, IDbConnection connection) { TkDebug.AssertArgumentNullOrEmpty(name, "name", null); TkDebug.AssertArgumentNull(connection, "connection", null); try { return(ExecuteSequence(name, connection)); } catch (Exception ex) { string sql = string.Format(ObjectUtil.SysCulture, "SELECT COUNT(*) FROM USER_SEQUENCES WHERE SEQUENCE_NAME = 'S_{0}'", name); int count = int.Parse(DbUtil.ExecuteScalar(sql, connection).ToString(), ObjectUtil.SysCulture); if (count == 0) { sql = string.Format(ObjectUtil.SysCulture, "CREATE SEQUENCE S_{0}", name); DbUtil.ExecuteNonQuery(sql, connection); return(ExecuteSequence(name, connection)); } else { TkDebug.ThrowToolkitException( string.Format(ObjectUtil.SysCulture, "系统中存在S_{0}的Sequence,却无法取值,请检查数据库方面的原因", name), ex, null); return(null); } } }
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); } } }
private static string ExecuteSequence(string name, IDbConnection connection) { string sql = string.Format(ObjectUtil.SysCulture, "SELECT S_{0}.nextval FROM dual", name); object value = DbUtil.ExecuteScalar(sql, connection); return(value.ToString()); }
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; } }
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; }
private CountInfo CreatePageInfo(IInputData input, int pageNumber, int pageSize, ParamBuilderContainer condition) { CountInfo pageInfo; int totalCount = input.QueryString["TotalCount"].Value <int>(); if (totalCount <= 0 || input.IsPost) { int count = DbUtil.ExecuteScalar("SELECT COUNT(*) FROM " + GetTableName(Context), Context, condition).Value <int>(); pageInfo = new CountInfo(count, pageNumber, pageSize); } else { pageInfo = new CountInfo(totalCount, input.QueryString["TotalPage"].Value <int>(), pageNumber, pageSize); } return(pageInfo); }
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 static string Execute(string name, TkDbContext context) { object value; string sqlRead = string.Format(ObjectUtil.SysCulture, "SELECT ID_VALUE FROM ID_CODEID WHERE ID_NAME = '{0}'", name); string sqlUpdate = string.Format(ObjectUtil.SysCulture, "UPDATE ID_CODEID SET ID_VALUE = ID_VALUE + 1 WHERE ID_NAME = '{0}'", name); string sqlInsert = string.Format(ObjectUtil.SysCulture, "INSERT INTO ID_CODEID (ID_NAME, ID_VALUE) VALUES ('{0}', 1)", name); value = DbUtil.ExecuteScalar(sqlRead, context); if (value == DBNull.Value) { DbUtil.ExecuteNonQuery(sqlInsert, context); value = 0; } else { DbUtil.ExecuteNonQuery(sqlUpdate, context); } int num = int.Parse(value.ToString(), ObjectUtil.SysCulture) + 1; return(num.ToString(ObjectUtil.SysCulture)); }