Exemplo n.º 1
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.º 2
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.º 3
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.º 4
0
        public void Switch(TableResolver resolver, DataRow row)
        {
            TkDebug.AssertArgumentNull(resolver, "resolver", null);
            TkDebug.AssertArgumentNull(row, "row", null);

            object value = row[NickName];

            row.BeginEdit();
            try
            {
                if (value == DBNull.Value)
                {
                    switch (NullValueProcess)
                    {
                    case SwitchNullProcessMethod.OpenValue:
                        row[NickName] = OpenValue;
                        break;

                    case SwitchNullProcessMethod.ThrowException:
                        throw new WebPostException(ErrorMessage);
                    }
                }
                else if (value.ToString() == OpenValue)
                {
                    row[NickName] = CloseValue;
                }
                else
                {
                    row[NickName] = OpenValue;
                }
                if (UpdateTrackField)
                {
                    resolver.UpdateTrackField(UpdateKind.Update, row);
                }
            }
            finally
            {
                row.EndEdit();
            }
            resolver.SetCommands(AdapterCommand.Update);
            resolver.UpdateDatabase();
        }
Exemplo n.º 5
0
        internal static void DeleteTree(TableResolver resolver, DbTreeDefinition tree, string id, IInputData inputData)
        {
            TkDebug.AssertArgumentNull(resolver, "resolver", null);
            TkDebug.AssertArgumentNull(tree, "tree", null);
            TkDebug.AssertArgumentNullOrEmpty(id, "id", null);

            DataRow row = null;

            if (resolver.HostTable != null)
            {
                row = resolver.HostTable.Select(string.Format(ObjectUtil.SysCulture, "{0} = '{1}'",
                                                              tree.IdField, id))[0];
            }
            else
            {
                row = resolver.SelectRowWithParam(tree.IdField, id);
            }

            resolver.SetCommands(AdapterCommand.Update | AdapterCommand.Delete);

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

            IFieldInfo    layerField = resolver.GetFieldInfo(tree.LayerField);
            IParamBuilder builder    = CreateLayerParamBuilder(resolver.Context, layerField,
                                                               row[tree.LayerField].ToString());

            resolver.Select(builder);
            for (int i = currentCount; i < table.Rows.Count; ++i)
            {
                DataRow delRow = table.Rows[i];
                resolver.DeleteRow(delRow, UpdateKind.Delete, null, inputData);
            }

            SetParentLeaf(resolver, tree, row[tree.ParentIdField].ToString());
            resolver.DeleteRow(row, UpdateKind.Delete, null, inputData);
        }