Ejemplo n.º 1
0
        public static string GetFormatValue(DDProvider ddProvider, DataView dvData, string columnName, object value)
        {
            string formatValue = String.Empty;
            object ddValue = null;

            ddValue = ddProvider.GetDDValue(columnName, DDInfo.EditMask);
            if (ddValue != null && ddValue.ToString() != String.Empty)
            {
                switch (dvData.Table.Columns[columnName].DataType.Name)
                {
                    case "Int16":
                        formatValue = Convert.ToInt16(value).ToString(ddValue.ToString());
                        break;
                    case "Int32":
                        formatValue = Convert.ToInt32(value).ToString(ddValue.ToString());
                        break;
                    case "Int64":
                        formatValue = Convert.ToInt64(value).ToString(ddValue.ToString());
                        break;
                    case "Double":
                        formatValue = Convert.ToDouble(value).ToString(ddValue.ToString());
                        break;
                    case "Decimal":
                        formatValue = Convert.ToDecimal(value).ToString(ddValue.ToString());
                        break;
                    case "UInt16":
                        formatValue = Convert.ToUInt16(value).ToString(ddValue.ToString());
                        break;
                    case "UInt32":
                        formatValue = Convert.ToUInt32(value).ToString(ddValue.ToString());
                        break;
                    case "UInt64":
                        formatValue = Convert.ToUInt64(value).ToString(ddValue.ToString());
                        break;

                    case "DateTime":
                        formatValue = Convert.ToDateTime(value).ToString(ddValue.ToString());
                        break;

                    case "String":
                    case "Boolean":
                        formatValue = value.ToString();
                        break;

                    default:
                        formatValue = value.ToString();
                        break;
                }
            }
            else
            {
                formatValue = value.ToString();
            }

            return formatValue;
        }
Ejemplo n.º 2
0
        public Table WriteItem(List<List<object>> lists, System.Drawing.Font sysFont)
        {
            #region Variable Definition
            //int tempCount = 0;
            int cellCount = 0;
            int maxColumnCount = -1;
            Font pdfFont = null;
            Table tb = null;
            Image image = null;
            string imagePath = String.Empty;
            float imageWidth = float.Epsilon;
            Cell cell = null;
            double height = 0.0;
            #endregion

            //try
            //{
                pdfFont = this.GetPdfFont(sysFont);

                //计算Table中最大的Column数。
                #region Old Function
                //foreach (List<object> list in lists)
                //{
                //    foreach (ReportItem item in list)
                //    {
                //        tempCount += item.Cells;
                //    }
                //    if (tempCount > maxColumnCount)
                //    {
                //        maxColumnCount = tempCount;
                //    }
                //    tempCount = 0;
                //}
                #endregion

                maxColumnCount = mPageWidth;

                if (lists.Count == 0)
                {
                    return tb;
                }

                tb = new Table(maxColumnCount, lists.Count);
                tb.Border = Rectangle.NO_BORDER;

                tb.Cellpadding = PdfSizeConfig.Cellpadding;
                //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比
                tb.Width = 100;
                tb.Alignment = Element.ALIGN_LEFT;

                foreach (List<object> list in lists)
                {
                    cellCount = 0;

                    height += GetHeight(list, sysFont);

                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].GetType().Name != "ReportImageItem")
                        {
                            if (((ReportItem)list[i]).Font == null)
                            {
                                pdfFont = this.GetPdfFont(sysFont);
                            }
                            else
                            {
                                pdfFont = this.GetPdfFont(((ReportItem)list[i]).Font);
                            }
                            string value = "";
                            string format = "";

                            if (string.IsNullOrEmpty(((ReportItem)list[i]).Format))
                            {
                                if (list[i] is ReportDataSourceItem)
                                {
                                    DDProvider ddProvider = new DDProvider(report.HeaderDataSource, mDesignTime);
                                    string ddValue = ddProvider.GetDDValue(((ReportDataSourceItem)list[i]).ColumnName, DDInfo.FieldCaption).ToString();
                                    if (ddValue == "")
                                    {
                                        ddValue = ddProvider.GetDDValue(((ReportDataSourceItem)list[i]).ColumnName, DDInfo.FieldName).ToString();
                                    }
                                    format = ddValue + ":{0}";
                                }
                                else
                                {
                                    format = "{0}";
                                }
                            }
                            else
                            {
                                format = ((ReportItem)list[i]).Format;
                            }

                            value = string.IsNullOrEmpty(((ReportItem)list[i]).Format) ? string.Format(format, ((ReportItem)list[i]).Value) :
                                String.Format(format, ((ReportItem)list[i]).Value);

                            cell = new Cell(new Chunk(value, pdfFont));
                        }
                        else
                        {
                            #region Image Item
                            image = Image.GetInstance((System.Drawing.Image)((ReportItem)list[i]).Value, System.Drawing.Imaging.ImageFormat.Jpeg);

                            image.Alignment = this.GetPdfImageHAlign(((ReportItem)list[i]).ContentAlignment);

                            if (list.Count > 1)
                            {
                                imageWidth = (this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / (float)list.Count;
                                //imageWidth -= (float)16;
                                //image.ScaleAbsoluteWidth(imageWidth);
                            }
                            Chunk chuck = new Chunk(image, 0, 0, true);
                            cell = new Cell(chuck);
                            #endregion
                        }

                        cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用
                        cell.VerticalAlignment = Cell.ALIGN_MIDDLE;

                        cell.HorizontalAlignment = this.GetPdfHAlign(((ReportItem)list[i]).ContentAlignment);

                        if (((ReportItem)list[i]).Cells == 0)
                        {
                            if (tb.Columns - cellCount != 0)
                            {
                                cell.Colspan = tb.Columns - cellCount;
                            }
                        }
                        else
                        {
                            cell.Colspan = ((ReportItem)list[i]).Cells;
                        }
                        cell.Border = Rectangle.NO_BORDER;

                        if (((ReportItem)list[i]).Position == ReportItem.PositionAlign.Right && ((ReportItem)list[i]).Cells != 0)
                        {
                            if (maxColumnCount - cellCount - ((ReportItem)list[i]).Cells != 0)
                            {
                                Cell tempCell = new Cell();
                                tempCell.Colspan = maxColumnCount - cellCount - ((ReportItem)list[i]).Cells;
                                tempCell.Border = Rectangle.NO_BORDER;
                                tb.AddCell(tempCell);

                                cellCount = maxColumnCount - ((ReportItem)list[i]).Cells;
                            }
                        }

                        if (i == 0 && ((ReportItem)list[i]).Position != ReportItem.PositionAlign.Right)
                        {
                            tb.AddCell(cell, lists.IndexOf(list), i);
                        }
                        else
                        {
                            tb.AddCell(cell, lists.IndexOf(list), cellCount);
                        }

                        cellCount += ((ReportItem)list[i]).Cells;
                    }
                }

                if (ExportByHeight)
                {
                    if (HeaderTable == null && object.ReferenceEquals(sysFont, report.HeaderFont))
                    {
                        HeaderTable = tb;

                        if (HeaderHeight == 0.0)
                        {
                            HeaderHeight = height;
                        }

                    }
                    else if (FooterTable == null && object.ReferenceEquals(sysFont, report.FooterFont))
                    {
                        FooterTable = tb;

                        if (FooterHeight == 0.0)
                        {
                            FooterHeight = height;
                        }
                    }
                }
                else
                {
                    this.pdfDoc.Add(tb);
                }
            //}
            //catch (Exception ex)
            //{
            //    log.WriteExceptionInfo(ex);
            //    throw ex;
            //}

            return tb;
        }