我有SAP Crystal Reports for Microsoft Visual Studio版本13.0.14.1720。我試圖在C#Windows窗體應用程序中顯示報告。該報告現在失敗,出現ArgumentOutOfRangeException。棧跟蹤如下:顯示帶顯示字符串屬性的Crystal報表ArgumentOutOfRangeException
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at CrystalDecisions.Shared.PageRender.draw_FieldObjectInstance(FieldObjectInstance fieldObject, Graphics g)
at CrystalDecisions.Shared.PageRender.draw_ReportObjectInstance(ReportObjectInstance instance, Graphics g, Rectangle clipRect)
at CrystalDecisions.Shared.PageRender.draw_SectionInstance(SectionInstance section, Graphics g, Rectangle clipRect)
at CrystalDecisions.Shared.PageRender.Render(PageObject page, Graphics g, Graphics device_g)
at CrystalDecisions.Windows.Forms.PageControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at CrystalDecisions.Windows.Forms.PageControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我在Visual Studio 2015中運行此並停止執行的錯誤。錯誤發生在此字段上:
Field name: #SiteError2
ObjectName: SiteError11
Size: 120x221
OffsetInSection: 5528x0
SectionKind: GroupFooter
Section: GroupFooterSection2
查看報告定義,此字段位於組頁腳上。該字段抓取錯誤總數的最大值。運行總數評估每條記錄並重新設置組的變化。
如果至少有1個錯誤,該字段應該顯示一個星號。否則,它是空白的。因此,顯示字符串具有下式:
iif(CurrentFieldValue > 0, "*", "")
如果更改顯示字符串式的定義中使用以外的任何「」,如果值是< = 0,則沒有錯誤。例如,下面顯示字符串,則不會發生該錯誤:
iif(CurrentFieldValue > 0, "*", "N")
顯示字符串是一樣的,在同一組頁腳上其它列進行運行總其它列。實際上,組頁腳中有幾個與此相同的字段。
我嘗試從頭開始刪除並重新創建該字段。發生同樣的錯誤。
我試着更改「將數據庫NULL值轉換爲默認值」和「將其他NULL值轉換爲默認值」的報告選項,但仍然出現錯誤。
我也嘗試將報告格式從舊版本升級到最新版本。
報告欄定義如下。組頭上的字段正在計算下面的_Error列的最大值。這些列被定義爲整數。
<xs:element name="DRSiteAnalystSummary_Column_1_Error" type="xs:int" minOccurs="0" />
<xs:element name="DRSiteAnalystSummary_Column_2_Error" type="xs:int" minOccurs="0" />
<xs:element name="DRSiteAnalystSummary_Column_3_Error" type="xs:int" minOccurs="0" />
我在GAC中的CrystalDecisions.Shared.dll上運行JetBrains dotPeek。反編譯PageRender.draw_FieldObjectInstance方法,我看到一些數組索引引用。這一個對我來說很突出:
private void draw_FieldObjectInstance(FieldObjectInstance fieldObject, Graphics g)
{
...
if (fieldObject.IsFieldNumeric)
{
fieldObjectInstance = (NumericFieldObjectInstance) fieldObject;
num7 = (int) g.MeasureString(fieldObjectInstance.PrefixReserve, font, this.m_layout, stringFormat).Width;
SizeF sizeF2 = g.MeasureString(fieldObjectInstance.SuffixReserve, font, this.m_layout, stringFormat);
num8 = (int) sizeF2.Width;
sizeF2 = g.MeasureString(fieldObjectInstance.FixedLeftReserve, font, this.m_layout, stringFormat);
num9 = (int) sizeF2.Width;
sizeF1 = g.MeasureString(fieldObjectInstance.FixedRightReserve, font, this.m_layout, stringFormat);
num10 = (int) sizeF1.Width;
if (!fieldObjectInstance.AllowClipping)
{
sizeF1 = g.MeasureString((string) fieldObject.TextLines[0], font, this.m_layout, stringFormat);
if ((int) sizeF1.Width + num7 + num8 + num9 + num10 > width)
{
flag2 = true;
alignment = Alignment.LeftAlign;
int num11 = width;
sizeF1 = g.MeasureString('#'.ToString(), font, this.m_layout, stringFormat);
int num12 = (int) sizeF1.Width;
int count = num11/num12;
**fieldObject.TextLines[0] = (object) new string('#', count);**
}
}
}
上面的代碼似乎假設有一個文本行。在發生錯誤時,TextLines屬性的長度爲0. IsFieldNumeric爲true,fieldObjectInstance.AllowClipping爲false,因此它看起來像此代碼將運行並失敗。