Ejemplo n.º 1
0
        /// <summary>
        /// ���ݼ�������
        /// </summary>
        /// <param name="values">����</param>
        /// <param name="index">FieldItem������</param>
        /// <returns>����</returns>
        private List<List<PdfDesc>> GetFieldList(object[] values, int datasourceIndex, ListContentType contentType)
        {
            List<List<PdfDesc>> list = new List<List<PdfDesc>>();
            List<PdfDesc> row = new List<PdfDesc>();
            DataSourceItem fieldItem = Report.FieldItems[datasourceIndex];
            bool allowAdd = false;
            multiRow = 1;

            for (int i = 0; i < fieldItem.Fields.Count; i++)
            {
                FieldItem field = fieldItem.Fields[i];
                if (i > 0 && field.NewLine)
                {
                    multiRow++;
                    #region Add row to list

                    if (contentType == ListContentType.GroupTotal || contentType == ListContentType.Total)
                    {
                        foreach (PdfDesc item in row)
                        {
                            allowAdd = item.Value != String.Empty;
                            if (allowAdd)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        allowAdd = true;
                    }

                    if (allowAdd)
                    {
                        list.Add(row);
                    }
                    #endregion
                    row = new List<PdfDesc>();
                    for (int j = 0; j < field.NewLinePostion - 1; j++)
                    {
                        PdfDesc pdfDesc = new PdfDesc();
                        pdfDesc.Value = String.Empty;
                        pdfDesc.LeftLine = false;
                        pdfDesc.RightLine = Report.Format.ColumnInsideGridLine;
                        pdfDesc.TopLine = false;
                        pdfDesc.BottomLine = false;
                        pdfDesc.Width = field.Width;
                        pdfDesc.FieldNum = datasourceIndex;
                        pdfDesc.IsCaption = contentType == ListContentType.Caption;
                        row.Add(pdfDesc);
                    }
                }

                PdfDesc pdfValue = new PdfDesc();
                pdfValue.Value = values[i].ToString();
                pdfValue.Cells = field.Cells;
                pdfValue.FieldNum = datasourceIndex;
                pdfValue.IsCaption = contentType == ListContentType.Caption;
                if (contentType == ListContentType.Caption)
                {
                    pdfValue.HAlign = field.CaptionAlignment;
                }
                else
                {
                    pdfValue.HAlign = field.ColumnAlignment;
                }
                pdfValue.LeftLine = false;

                switch (contentType)
                {
                    case ListContentType.GroupTotal:
                    case ListContentType.Total:
                        pdfValue.RightLine = false;
                        break;
                    case ListContentType.Field:
                    case ListContentType.Caption:
                        pdfValue.RightLine = Report.Format.ColumnInsideGridLine;
                        break;
                }

                if (i == 0 || multiRow == 1 || contentType == ListContentType.GroupTotal || contentType == ListContentType.Total)
                {
                    pdfValue.TopLine = Report.Format.RowGridLine;
                }
                pdfValue.BottomLine = false;
                pdfValue.Width = field.Width;
                row.Add(pdfValue);
            }

            allowAdd = false;
            if (contentType == ListContentType.GroupTotal || contentType == ListContentType.Total)
            {
                foreach (PdfDesc item in row)
                {
                    allowAdd = item.Value != String.Empty;
                    if (allowAdd)
                    {
                        break;
                    }
                }
            }
            else
            {
                allowAdd = true;
            }

            if (allowAdd)
            {
                list.Add(row);
            }

            if (contentType == ListContentType.Field || contentType == ListContentType.Caption)
            {
                if (multiRow > 1)
                {
                    int maxColumnCount = 0;
                    int tempCount = 0;
                    List<int> allLength = new List<int>();
                    foreach (List<PdfDesc> crow in list)
                    {
                        foreach (PdfDesc pdfDesc in crow)
                        {
                            tempCount += pdfDesc.Cells;
                        }

                        if (tempCount > maxColumnCount)
                        {
                            maxColumnCount = tempCount;
                        }

                        allLength.Add(tempCount);

                        tempCount = 0;
                    }

                    foreach (List<PdfDesc> crow in list)
                    {
                        int restCount = maxColumnCount - allLength[list.IndexOf(crow)];
                        for (int i = 0; i < restCount; i++)
                        {
                            if (row[0].GroupGap == DataSourceItem.GroupGapType.None)
                            {
                                PdfDesc pdfDesc = new PdfDesc();
                                pdfDesc.Value = String.Empty;
                                pdfDesc.LeftLine = false;
                                pdfDesc.RightLine = report.Format.ColumnInsideGridLine;

                                pdfDesc.TopLine = report.Format.RowGridLine && list.IndexOf(crow) == 0;
                                pdfDesc.BottomLine = false;
                                pdfDesc.FieldNum = datasourceIndex;
                                pdfDesc.IsCaption = contentType == ListContentType.Caption;
                                crow.Add(pdfDesc);
                            }
                        }
                    }
                }
            }

            return list;
        }
Ejemplo n.º 2
0
        private List<List<PdfDesc>> ExportField(List<List<int>> allStartIndex)
        {
            List<List<PdfDesc>> allList = new List<List<PdfDesc>>();
            int currentRowCount = 0;

            try
            {
                for (int i = 0; i < Report.FieldItems.Count; i++)
                {
                    DataSourceItem fieldItem = Report.FieldItems[i];
                    List<string> groupColumns = new List<string>();
                    DataTable table = GroupBy(i, groupColumns);//��Table��������

                    if (table.Rows.Count > this.ProgressCount)
                    {
                        this.ProgressCount = table.Rows.Count;
                    }

                    currentRowCount = 0;

                    int startIndex = 0;
                    int count = 0;

                    if (allStartIndex[i].Count > Report.CurrentPageIndex - 1)
                    {
                        if (table.Rows.Count > 0 && allStartIndex[i].Count > Report.CurrentPageIndex - 1)
                        {
                            startIndex = allStartIndex[i][Report.CurrentPageIndex - 1];
                        }
                    }

                    if (allStartIndex[i].Count == 1 && Report.CurrentPageIndex == 1)
                    {
                        count = table.Rows.Count;
                    }
                    else if (allStartIndex[i].Count >= Report.CurrentPageIndex)
                    {
                        if (allStartIndex[i].Count == Report.CurrentPageIndex)
                        {
                            count = table.Rows.Count - allStartIndex[i][Report.CurrentPageIndex - 1];
                        }
                        else
                        {
                            count = Report.CurrentPageIndex < Report.PageCount ? allStartIndex[i][Report.CurrentPageIndex] - allStartIndex[i][Report.CurrentPageIndex - 1] : table.Rows.Count - allStartIndex[i][Report.CurrentPageIndex - 1];
                        }
                    }

                    if (count != 0)
                    {
                        if (fieldItem.CaptionStyle == DataSourceItem.CaptionStyleType.ColumnHeader)
                        {
                            List<List<PdfDesc>> captionList = CreateFieldCaption(i);
                            allList.AddRange(captionList);
                        }
                    }

                    if (count != 0)
                    {
                        for (int j = startIndex; j < table.Rows.Count; j++)
                        {
                            bool groupEmpty = groupColumns.Count > 0 && j > startIndex && !GroupBreak(table.Rows[j - 1], table.Rows[j], groupColumns);//Group�ظ������ϲ���ʾ
                            object[] dataValues = new object[fieldItem.Fields.Count];
                            for (int k = 0; k < dataValues.Length; k++)
                            {
                                FieldItem field = fieldItem.Fields[k];
                                string caption = fieldItem.CaptionStyle == DataSourceItem.CaptionStyleType.RowHeader ? field.Caption : string.Empty;
                                if (field.SuppressIfDuplicated && groupEmpty && groupColumns.Contains(field.ColumnName))
                                {
                                    dataValues[k] = string.Empty;
                                }
                                else
                                {
                                    dataValues[k] = GetFormatedValue(field.Format, caption, " ", table.Rows[j][field.ColumnName]);
                                }
                            }
                            List<List<PdfDesc>> dataList = GetFieldList(dataValues, i, ListContentType.Field);
                            allList.AddRange(dataList);

                            currentRowCount++;

                            if (groupColumns.Count > 0 && (j == table.Rows.Count - 1 || GroupBreak(table.Rows[j], table.Rows[j + 1], groupColumns)))
                            {
                                //�����
                                if (fieldItem.GroupTotal)
                                {
                                    object[] groupValues = new object[fieldItem.Fields.Count];
                                    bool grouptotal = false;
                                    for (int k = 0; k < groupValues.Length; k++)
                                    {
                                        FieldItem field = fieldItem.Fields[k];
                                        if (field.Sum != FieldItem.SumType.None)
                                        {
                                            groupValues[k] = GetFormatedValue(field.Format, field.GroupTotalCaption
                                        , GroupTotal(field.ColumnName, field.Sum, table, table.Rows[j], groupColumns));
                                            grouptotal = true;
                                        }
                                        else
                                        {
                                            groupValues[k] = string.Empty;
                                        }
                                    }
                                    groupFilter = null;//����GroupFilter
                                    if (grouptotal)
                                    {
                                        List<List<PdfDesc>> groupList = GetFieldList(groupValues, i, ListContentType.GroupTotal);
                                        allList.AddRange(groupList);
                                    }
                                }

                                switch (fieldItem.GroupGap)
                                {
                                    case DataSourceItem.GroupGapType.None:
                                        break;
                                    case DataSourceItem.GroupGapType.EmptyRow:
                                    case DataSourceItem.GroupGapType.SingleLine:
                                    case DataSourceItem.GroupGapType.DoubleLine:
                                        if (j != table.Rows.Count - 1)//���һ�鲻��
                                        {
                                            List<List<PdfDesc>> emptyList = new List<List<PdfDesc>>();
                                            List<PdfDesc> emptyString = new List<PdfDesc>();
                                            PdfDesc pdfDesc = new PdfDesc();
                                            pdfDesc.Value = String.Empty;
                                            pdfDesc.LeftLine = false;
                                            pdfDesc.RightLine = false;
                                            pdfDesc.TopLine = Report.Format.RowGridLine;
                                            pdfDesc.BottomLine = false;
                                            pdfDesc.GroupGap = fieldItem.GroupGap;
                                            pdfDesc.FieldNum = i;
                                            emptyString.Add(pdfDesc);
                                            emptyList.Add(emptyString);
                                            allList.AddRange(emptyList);
                                        }
                                        break;
                                    case DataSourceItem.GroupGapType.Page:
                                        break;
                                }
                            }

                            if (currentRowCount >= count)
                            {
                                if (!ExportByHeight)
                                {
                                    pdf.WriteFields(allList, Report.FieldFont, multiRow);
                                    allList.Clear();
                                }
                                break;
                            }

                            processInfoCollection[i] = j + 1;

                            this.ProgressInfo = processInfoCollection[i];
                        }

                        if (Report.CurrentPageIndex == allStartIndex[i].Count)
                        {
                            //����
                            bool total = false;
                            object[] totalValues = new object[fieldItem.Fields.Count];
                            for (int j = 0; j < totalValues.Length; j++)
                            {
                                FieldItem field = fieldItem.Fields[j];
                                if (field.Sum != FieldItem.SumType.None)
                                {
                                    totalValues[j] = GetFormatedValue(field.Format, field.TotalCaption, GroupTotal(field.ColumnName, field.Sum, table, null, groupColumns));
                                    total = true;
                                }
                                else
                                {
                                    totalValues[j] = string.Empty;
                                }
                            }
                            if (total)
                            {
                                List<List<PdfDesc>> totalList = GetFieldList(totalValues, i, ListContentType.Total);

                                allList.AddRange(totalList);

                                if (!ExportByHeight)
                                {
                                    pdf.WriteFields(totalList, Report.FieldFont, multiRow);
                                    allList.Clear();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowException(ex);
            }

            return allList;
        }