c#

位置:IT落伍者 >> c# >> 浏览文章

VC# .Net中使用Crystal Report(二)


发布日期:2024年03月29日
 
VC# .Net中使用Crystal Report(二)

双击button添加button_Click点击事件

private void button_Click(object sender SystemEventArgs e)

{

try

{

if(openFileDialogShowDialog()==DialogResultOK)

thiscrystalReportViewerReportSource = @openFileDialogFileName;

//加载水晶报表将报表文件绑定到CrystalReportView 控件;

}

catch(Exception error)

{

MessageBoxShow(errorToString()错误);

}

}

OK!按Ctrl+F运行吧

可以浏览你系统内现有的报表实例

\Program Files\Microsoft Visual Studio NET\Crystal Reports\Samples\Reports\Feature Examples\Chartrpt

using System;

using SystemDrawing;

using SystemCollections;

using SystemComponentModel;

using SystemWindowsForms;

using SystemData;

namespace WindowsApplication

{

/// <summary>

/// Form 的摘要说明

/// </summary>

public class Form : SystemWindowsFormsForm

{

private CrystalDecisionsWindowsFormsCrystalReportViewer crystalReportViewer;

private SystemWindowsFormsButton button;

private SystemWindowsFormsOpenFileDialog openFileDialog;

/// <summary>

/// 必需的设计器变量

/// </summary>

private SystemComponentModelContainer components = null;

public Form()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

//

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

//

}

/// <summary>

/// 清理所有正在使用的资源

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

componentsDispose();

}

}

baseDispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// 设计器支持所需的方法 不要使用代码编辑器修改

/// 此方法的内容

/// </summary>

private void InitializeComponent()

{

thiscrystalReportViewer = new

CrystalDecisionsWindowsFormsCrystalReportViewer();

thisbutton = new SystemWindowsFormsButton();

thisopenFileDialog = new SystemWindowsFormsOpenFileDialog();

thisSuspendLayout();

//

// crystalReportViewer

//

thiscrystalReportViewerActiveViewIndex = ;

thiscrystalReportViewerDock= SystemWindowsFormsDockStyleFill;

thiscrystalReportViewerDockPaddingBottom = ;

thiscrystalReportViewerDockPaddingLeft = ;

thiscrystalReportViewerDockPaddingRight = ;

thiscrystalReportViewerDockPaddingTop = ;

thiscrystalReportViewerName = crystalReportViewer;

thiscrystalReportViewerReportSource = null;

thiscrystalReportViewerSize = new SystemDrawingSize( );

thiscrystalReportViewerTabIndex = ;

//

// button

//

thisbuttonAnchor = SystemWindowsFormsAnchorStylesBottom;

thisbuttonLocation = new SystemDrawingPoint( );

thisbuttonName = button;

thisbuttonTabIndex = ;

thisbuttonText = 打开报表;

thisbuttonClick += new SystemEventHandler(thisbutton_Click);

//

// openFileDialog

//

thisopenFileDialogFilter = Crystal Report (*rpt)|*rpt|所有文件(**)|**;

thisopenFileDialogTitle = 打开水晶报表;

//

// Form

//

thisAutoScaleBaseSize = new SystemDrawingSize( );

thisClientSize = new SystemDrawingSize( );

thisControlsAddRange(new SystemWindowsFormsControl[] {

thisbutton

thiscrystalReportViewer});

thisName = Form;

thisStartPosition = SystemWindowsFormsFormStartPositionCenterScreen;

thisText = 水晶报表浏览器;

thisResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点

/// </summary>

[STAThread]

static void Main()

{

ApplicationRun(new Form());

}

private void button_Click(object sender SystemEventArgs e)

{

try

{

if(openFileDialogShowDialog()==DialogResultOK)

thiscrystalReportViewerReportSource = @openFileDialogFileName;

//加载水晶报表将资源报表绑定到水晶报表查看器

}

catch(Exception error)

{

MessageBoxShow(errorToString()错误); //处理异常错误

}

}

}

}

               

上一篇:Visual Basic.Net连各种数据库的几种方法

下一篇:C#高级编程: 数据库的绑定[2]