Пример #1
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;
            }
        }
Пример #2
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);
     }
 }
Пример #4
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);
        }
Пример #5
0
        public void FillDetailTable(TableResolver masterResolver, TableResolver detailResolver)
        {
            TkDebug.AssertNotNull(masterResolver, "masterResolver", this);
            TkDebug.AssertNotNull(detailResolver, "detailResolver", this);

            if ((fType & RelationType.OnlyFill) != RelationType.OnlyFill)
            {
                return;
            }
            DataTable table = masterResolver.HostTable;

            TkDebug.AssertNotNull(table, string.Format(ObjectUtil.SysCulture, "主表{0}不存在",
                                                       masterResolver.TableName), this);

            foreach (DataRow row in table.Rows)
            {
                string filterSql = FilterSql == null ? string.Empty
                    : Expression.Execute(FilterSql, masterResolver.Source);
                if (Top == 0)
                {
                    if (fDetailFields.Length == 1)
                    {
                        if (fManyToMany == null)
                        {
                            detailResolver.SelectWithParam(filterSql, OrderBy,
                                                           fDetailFields[0], row[fMasterFields[0]]);
                        }
                        else
                        {
                            IParamBuilder container = GetDetailParamBuilder(detailResolver, row, filterSql);

                            detailResolver.Select(container, OrderBy);
                        }
                    }
                    else
                    {
                        if (fManyToMany == null)
                        {
                            object[] masterValues = new object[fMasterFields.Length];
                            for (int i = 0; i < fMasterFields.Length; ++i)
                            {
                                masterValues[i] = row[fMasterFields[i]];
                            }
                            detailResolver.SelectWithParams(filterSql, OrderBy, fDetailFields, masterValues);
                        }
                        else
                        {
                            ThrowErrorManyToManyMode();
                        }
                    }
                }
                else
                {
                    if (fManyToMany == null)
                    {
                        object[]      values  = (from item in fMasterFields select row[item]).ToArray();
                        IParamBuilder builder = detailResolver.CreateParamBuilder(filterSql, fDetailFields, values);
                        detailResolver.SelectTopRows(Top, builder, OrderBy);
                    }
                    else
                    {
                        if (fDetailFields.Length == 1)
                        {
                            IParamBuilder container = GetDetailParamBuilder(detailResolver, row, filterSql);

                            detailResolver.SelectTopRows(Top, container, OrderBy);
                        }
                        else
                        {
                            ThrowErrorManyToManyMode();
                        }
                    }
                }
            }
            detailResolver.AddVirtualFields();
        }