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
        public static void GetInsertCommand(TableResolver resolver)
        {
            List <FieldInfoEventArgs> list = resolver.GetFieldInfo(UpdateKind.Insert);

            if (resolver.DataAdapter.InsertCommand == null)
            {
                resolver.DataAdapter.InsertCommand = resolver.Context.CreateCommand();
            }
            else
            {
                resolver.DataAdapter.InsertCommand.Parameters.Clear();
            }
            resolver.DataAdapter.InsertCommand.CommandText = CreateInsertSql(resolver, list);
            list = null;
        }
Exemplo n.º 4
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;
        }
 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.º 6
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.º 7
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);
        }
Exemplo n.º 8
0
 private IParamBuilder GetManyToManyParamBuilder(TableResolver detailResolver, object masterValue)
 {
     return(ParamBuilder.CreateSql(string.Format(ObjectUtil.SysCulture,
                                                 "{0} IN ({1})", detailResolver.GetFieldInfo(fDetailFields[0]).FieldName,
                                                 fManyToMany.GetSubSelectSql(masterValue))));
 }
Exemplo n.º 9
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());
                    }
                }
            }
        }