Ejemplo n.º 1
0
        /// <summary>
        /// 整合表头信息
        /// </summary>
        /// <param name="noteType">贯穿信息(递归过程中国年保持不变)</param>
        /// <param name="rowCount">剩余的行数</param>
        /// <param name="nodes"></param>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        private List <TCell> GetHeaderCells(TextNoteType noteType, int rowCount, List <TNode> nodes, int rowIndex,
                                            int columnIndex)
        {
            List <TCell> cells         = new List <TCell>();
            View         currentView   = this.DrawView;
            Document     doc           = currentView.Document;
            int          currentColumn = columnIndex;
            int          currentRow    = rowIndex;

            for (int k = 0; k < nodes.Count; k++)
            {
                TNode currentNode = nodes[k];
                int   columnSpan  = currentNode.LeafCount;

                int rowUnit = rowCount / currentNode.Depth; //改树形分支剩余的行数
                int rowSpan = rowUnit;

                string        text   = currentNode.Name;
                var           leaves = currentNode.GetLeaves();
                ColumnSetting column = leaves[0].Tag as ColumnSetting;
                if (column != null)
                {
                    var data = new TextNoteData(currentView, XYZ.Zero, XYZ.BasisX, XYZ.BasisY,
                                                BaseDataSupply.ConvertToTextNodeAlgin(column.TextAlignment), text, noteType);
                    TextNote tn    = data.Create(currentView.Document);
                    TCell    tCell = null;
                    cells.Add(tCell = new TCell()
                    {
                        RowIndex    = currentRow,
                        ColumnIndex = currentColumn,
                        RowSpan     = rowSpan,
                        ColumnSpan  = columnSpan,
                        Value       = tn
                    });

                    //if (isAutoFit)
                    //{
                    double tempWidth = doc.ComputeTextNoteWidth(currentView, text, noteType).FromApi() * 0.7;
                    tCell.Tag = tempWidth;
                    //    columnsWidth[k] = columnsWidth[k].IsThanEq(tempWidth) ? columnsWidth[k] : tempWidth;
                    //}
                }

                if (!currentNode.IsLeaf)
                {
                    cells.AddRange(GetHeaderCells(noteType, rowCount - rowSpan, currentNode.Nodes, currentRow + rowSpan,
                                                  currentColumn));
                }
                currentColumn = currentColumn + columnSpan;
            }
            return(cells);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建表头
        /// </summary>
        /// <returns></returns>
        public Grid CreateHeaderEx()
        {
            if (this.m_TNodes == null)
            {
                throw new ArgumentNullException();
            }
            Grid       grid    = new Grid();
            List <int> depthes = new List <int>();


            #region 取所有叶子节点
            List <TNode> tempNodes = new List <TNode>(this.m_TNodes);
            for (int i = 0; i < tempNodes.Count; i++)
            {
                TNode node = tempNodes[i];
                if (node.IsLeaf)
                {
                    depthes.Add(node.Level);
                }
                else
                {
                    tempNodes.AddRange(node.Nodes);
                }
            }
            List <TNode> leaves = TNode.GetLeaves(this.m_TNodes);
            #endregion
            depthes = depthes.Distinct().ToList();
            int rowCount     = MathUtil.MinCommonMultiple(depthes);
            int columnCount  = this.m_TNodes.Sum(n => n.LeafCount);
            int rowExtend    = rowCount * 2 - 1;
            int columnExtend = columnCount * 2 - 1 + 2;//为了使最后列能拖动
            for (int i = 0; i < columnExtend; i++)
            {
                ColumnDefinition column = new ColumnDefinition();
                column.Width = new GridLength(1, GridUnitType.Star); //GetWidthEx(node, i == 0 ? -m_SplitBorder : -2 * m_SplitBorder);//
                grid.ColumnDefinitions.Add(column);


                if (i % 2 == 1)
                {
                    column.Width = GridLength.Auto;
                    //GridSplitter splitter = CreateVSplitter();
                    //Grid.SetColumn(splitter, i);
                    //Grid.SetRowSpan(splitter, rowExtend);
                    //grid.Children.Add(splitter);
                }
                else
                {
                    int leaveIndex = i / 2;
                    if (leaveIndex < leaves.Count)
                    {
                        DataGridColumn dataColumn = leaves[leaveIndex].Tag as DataGridColumn;
                        if (dataColumn != null)
                        {
                            column.Width = GetWidthEx(leaves[leaveIndex], i == 0 ? -m_SplitBorder : -2 * m_SplitBorder);
                            this.m_RelationColumns.Add(new Tuple <ColumnDefinition, DataGridColumn, double>(column, dataColumn, 2 * this.m_SplitBorder));
                            DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromProperty(ColumnDefinition.WidthProperty, typeof(ColumnDefinition));
                            //EventHandler handler = (sender, e) =>
                            //{
                            //    //dataColumn.Width = new DataGridLength(column.ActualWidth);
                            //};
                            descriptor.AddValueChanged(column, UpdateDataGridColumnsSize);
                        }
                    }
                }
            }
            for (int i = 0; i < rowExtend; i++)
            {
                RowDefinition rowdefinition = new RowDefinition();
                rowdefinition.Height = new GridLength(1, GridUnitType.Star);
                grid.RowDefinitions.Add(rowdefinition);

                if (i % 2 == 1)
                {
                    rowdefinition.Height = GridLength.Auto;
                    //GridSplitter splitter = CreateHSplitter();
                    //Grid.SetRow(splitter, i);

                    //Grid.SetColumnSpan(splitter, columnExtend);
                    //grid.Children.Add(splitter);
                }
            }


            CreateHeadeExr(grid, rowCount, 0, 0, this.m_TNodes);
            return(grid);
        }