Exemple #1
0
        public override async Task Build()
        {
            RptRootInst inst = _part.Inst;

            if (string.IsNullOrEmpty(Tbl))
            {
                return;
            }

            // 使用时再加载
            var rptData = await inst.Info.GetData(Tbl);

            if (rptData == null)
            {
                return;
            }

            RptMatrixInst matrixInst = new RptMatrixInst(this);

            matrixInst.RptData = rptData;
            ReBuildData(matrixInst.RptData.Data);
            inst.Body.AddChild(matrixInst);
            if (!HideRowHeader && !HideColHeader)
            {
                RptTextInst corner = new RptTextInst(Corner.Item);
                matrixInst.CornerInst = corner;
            }
            //列头
            BuildHeader(rptData, ColHeader, matrixInst);
            //行头
            BuildHeader(rptData, RowHeader, matrixInst);
            //数据
            foreach (RptMtxHeaderInst rowHeaderInst in matrixInst.RowHeaderInsts)
            {
                foreach (RptMtxHeaderInst colHeaderInst in matrixInst.ColHeaderInsts)
                {
                    RptText cell = GetCellByRowCol(rowHeaderInst.MtxRowsRow, colHeaderInst.MtxRowsCol);
                    if (cell != null)
                    {
                        RptTextInst txtInst = new RptTextInst(cell);
                        Dictionary <string, string> filter = new Dictionary <string, string>();
                        foreach (string key in rowHeaderInst.Filter.Keys)
                        {
                            filter.Add(key, rowHeaderInst.Filter[key]);
                        }
                        foreach (string key in colHeaderInst.Filter.Keys)
                        {
                            filter.Add(key, colHeaderInst.Filter[key]);
                        }
                        txtInst.Filter = filter;
                        matrixInst.AddCell(txtInst);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 创建小计
 /// </summary>
 /// <param name="totals"></param>
 /// <param name="p_header"></param>
 /// <param name="p_matInst"></param>
 /// <param name="p_curRow"></param>
 /// <param name="p_data"></param>
 /// <param name="p_loc"></param>
 void CreateTotalInst(List <RptMtxSubtotal> totals, RptMtxHeader p_header, RptMatrixInst p_matInst, Row p_curRow, RptData p_data, TotalLocation p_loc)
 {
     foreach (RptMtxSubtotal total in totals)
     {
         if (total.TotalLoc == p_loc)
         {
             if (total.SubTotals.Count > 0)
             {
                 CreateTotalInst(total.SubTotals, p_header, p_matInst, p_curRow, p_data, p_loc);
             }
             else
             {
                 RptMtxHeaderInst totalInst = new RptMtxHeaderInst(p_header);
                 for (int j = 0; j < p_header.Levels.IndexOf(total.Level); j++)
                 {
                     RptMtxLevel nLevel = p_header.Levels[j];
                     nLevel.Item.ColSpan = 1;
                     nLevel.Item.RowSpan = 1;
                     RptTextInst txtlevel = new RptTextInst(nLevel.Item);
                     totalInst.TxtInsts.Add(txtlevel);
                     totalInst.Filter.Add(nLevel.Field, p_curRow.Str(nLevel.Field));
                 }
                 RptItemBase parent = total.Parent;
                 while (parent is RptMtxSubtotal)
                 {
                     RptTextInst parTotal = new RptTextInst((parent as RptMtxSubtotal).Item);
                     totalInst.TxtInsts.Add(parTotal);
                     parent = parent.Parent;
                 }
                 RptTextInst txtTotal = new RptTextInst(total.Item);
                 totalInst.TxtInsts.Add(txtTotal);
                 totalInst.RptData         = p_data;
                 totalInst.RptData.Current = p_curRow.Index;
                 totalInst.Index           = p_curRow.Index;
                 if (p_header is RptMtxColHeader)
                 {
                     totalInst.MtxRowsCol = total.Col;
                     p_matInst.AddColHeader(totalInst);
                 }
                 else
                 {
                     totalInst.MtxRowsRow = total.Row;
                     p_matInst.AddRowHeader(totalInst);
                 }
             }
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// 创建标题
 /// </summary>
 /// <param name="p_titles"></param>
 /// <param name="p_header"></param>
 /// <param name="p_matInst"></param>
 /// <param name="p_curRow"></param>
 /// <param name="p_data"></param>
 void CreateSubTiltelInst(List <RptMtxSubtitle> p_titles, RptMtxHeader p_header, RptMatrixInst p_matInst, Row p_curRow, RptData p_data)
 {
     foreach (RptMtxSubtitle title in p_titles)
     {
         if (title.SubTitles.Count > 0)
         {
             CreateSubTiltelInst(title.SubTitles, p_header, p_matInst, p_curRow, p_data);
         }
         else
         {
             RptMtxHeaderInst titleInst = new RptMtxHeaderInst(p_header);
             for (int j = 0; j <= p_header.Levels.IndexOf(title.Level); j++)
             {
                 RptMtxLevel nLevel = p_header.Levels[j];
                 nLevel.Item.ColSpan = 1;
                 nLevel.Item.RowSpan = 1;
                 RptTextInst txtlevel = new RptTextInst(nLevel.Item);
                 titleInst.TxtInsts.Add(txtlevel);
                 titleInst.Filter.Add(nLevel.Field, p_curRow.Str(nLevel.Field));
             }
             RptItemBase parent = title.Parent;
             while (parent is RptMtxSubtotal)
             {
                 RptTextInst parTotal = new RptTextInst((parent as RptMtxSubtotal).Item);
                 titleInst.TxtInsts.Add(parTotal);
                 parent = parent.Parent;
             }
             RptTextInst txtTotal = new RptTextInst(title.Item);
             titleInst.TxtInsts.Add(txtTotal);
             titleInst.RptData         = p_data;
             titleInst.RptData.Current = p_curRow.Index;
             titleInst.Index           = p_curRow.Index;
             if (p_header is RptMtxColHeader)
             {
                 titleInst.MtxRowsCol = title.Col;
                 p_matInst.AddColHeader(titleInst);
             }
             else
             {
                 titleInst.MtxRowsRow = title.Row;
                 p_matInst.AddRowHeader(titleInst);
             }
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// 构造行头或列头
        /// </summary>
        /// <param name="p_rptData"></param>
        /// <param name="p_header"></param>
        /// <param name="p_matInst"></param>
        void BuildHeader(RptData p_rptData, RptMtxHeader p_header, RptMatrixInst p_matInst)
        {
            List <string> colNames      = p_header.GetFieldNames();
            List <Row>    allHeaderData = SelectDistinctDataRows(p_rptData.Data, colNames);
            Row           preRow        = null;

            for (int i = 0; i < allHeaderData.Count; i++)
            {
                Row curRow = allHeaderData[i];
                if (preRow == null || !string.IsNullOrEmpty(CompareTwoRows(preRow, curRow, colNames)))
                {
                    //前面小计
                    foreach (RptMtxLevel level in p_header.Levels)
                    {
                        if (level.SubTotals.Count <= 0)
                        {
                            continue;
                        }
                        RptMtxLevel beforLevel = null;
                        if (p_header.Levels.IndexOf(level) - 1 >= 0)
                        {
                            beforLevel = p_header.Levels[p_header.Levels.IndexOf(level) - 1];
                        }
                        //第一行(列) 或者 前一行(列)层值与当前行层值不同 创建小计
                        if (preRow == null || (beforLevel != null && preRow.Str(beforLevel.Field) != curRow.Str(beforLevel.Field)))
                        {
                            CreateTotalInst(level.SubTotals, p_header, p_matInst, curRow, p_rptData, TotalLocation.Before);
                        }
                    }

                    //数据
                    RptMtxHeaderInst headerInst = new RptMtxHeaderInst(p_header);
                    foreach (RptMtxLevel level in p_header.Levels)
                    {
                        if (level.SubTitles.Count > 0)
                        {
                            CreateSubTiltelInst(level.SubTitles, p_header, p_matInst, curRow, p_rptData);
                        }
                        else
                        {
                            //手动置1,因为输出头的时候按一行或一列输出,不需要控件合并
                            level.Item.ColSpan = 1;
                            level.Item.RowSpan = 1;
                            RptTextInst txtlevel = new RptTextInst(level.Item);
                            headerInst.TxtInsts.Add(txtlevel);
                        }
                    }
                    if (headerInst.TxtInsts.Count > 0)
                    {
                        headerInst.RptData = p_rptData;
                        headerInst.Index   = curRow.Index;
                        if (p_header is RptMtxColHeader)
                        {
                            headerInst.MtxRowsCol = p_header.Levels[p_header.Levels.Count - 1].Col;
                            p_matInst.AddColHeader(headerInst);
                        }
                        else
                        {
                            headerInst.MtxRowsRow = p_header.Levels[p_header.Levels.Count - 1].Row;
                            p_matInst.AddRowHeader(headerInst);
                        }
                        //生成条件
                        foreach (string name in colNames)
                        {
                            headerInst.Filter.Add(name, curRow.Str(name));
                        }
                    }

                    //后面小计
                    for (int k = p_header.Levels.Count - 1; k >= 0; k--)
                    {
                        RptMtxLevel level = p_header.Levels[k];
                        if (level.SubTotals.Count <= 0)
                        {
                            continue;
                        }
                        RptMtxLevel beforLevel = null;
                        if (p_header.Levels.IndexOf(level) - 1 >= 0)
                        {
                            beforLevel = p_header.Levels[p_header.Levels.IndexOf(level) - 1];
                        }
                        Row nextRow = null;
                        if (i < allHeaderData.Count - 1)
                        {
                            nextRow = allHeaderData[i + 1];
                        }
                        //最后一行(列) 或者 下一行(列)层值与当前行层值不同 创建小计
                        if (nextRow == null || (beforLevel != null && curRow.Str(beforLevel.Field) != nextRow.Str(beforLevel.Field)))
                        {
                            foreach (RptMtxSubtotal total in level.SubTotals)
                            {
                                CreateTotalInst(level.SubTotals, p_header, p_matInst, curRow, p_rptData, TotalLocation.After);
                            }
                        }
                    }
                }
                preRow = curRow;
            }
        }