FastReport报表添加到vs2017,vs2015,vs2010中,
可以在vs中设计FastReport报表。点击按钮,弹出FastReport设计,还有打印。
可以在vs中设计FastReport报表。点击按钮,弹出FastReport设计,还有打印。
解决方案 »
- C#里面有没有像hibernate一类的对象持久化、ORmapping框架?
- 请教 datagridview
- 大哥大姐看看吧!——菜鸟问题
- 多线程的锁定
- 代码看不懂怎么办
- 高手请进,百分送!
- c# 里用table读取excel数据后 为什么显示不了excel里第一行的数据呀 先谢谢了
- 怎样用List<T>的remove?
- 请教ShellExcute调用WinRar不能正常解压的问题
- 求FarPoint Spread 1.0 Windows Form组件或者其他好的相关组件
- C# restSharp cookie 登录
- VS2017,怎么设置成这样:关闭启动web调试后自动打开的浏览器不退出调试
using FastReport;
using FastReport.Format;
using FastReport.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace FastReportDesign
{
public partial class FrmDesign : Form
{
private readonly HouseholdEnterBusiness householdEnterBusiness = new HouseholdEnterBusiness();
public FrmDesign()
{
InitializeComponent();
} private void BtnDesign_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txtReportPath.Text))
{
MessageBox.Show("请选择报告模板");
return;
}
Report report = new Report();
report.Load(txtReportPath.Text);
Hashtable para = new Hashtable();
if (!string.IsNullOrEmpty(txtSql1.Text.Trim()))
{
report.RegisterData(GetDataTableBySql(txtSql1.Text), "Data1");
}
if (!string.IsNullOrEmpty(txtSql2.Text.Trim()))
{
report.RegisterData(GetDataTableBySql(txtSql2.Text), "Data2");
}
if (!string.IsNullOrEmpty(txtSql3.Text.Trim()))
{
report.RegisterData(GetDataTableBySql(txtSql3.Text), "Data3");
}
if (!string.IsNullOrEmpty(txtSql4.Text.Trim()))
{
report.RegisterData(GetDataTableBySql(txtSql4.Text), "Data4");
}
if (!string.IsNullOrEmpty(txtSql5.Text.Trim()))
{
report.RegisterData(GetDataTableBySql(txtSql5.Text), "Data5");
}
//report.GetDataSource("Data1").Enabled = true;
report.Design(); } public DataTable GetDataTableBySql(string sql)
{
DataTable dt = new DataTable();
try
{
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dt);
cmd.Dispose();
}
connection.Close();
connection.Dispose();
}
}
catch
{ }
return dt;
} private void btnSelectReportPath_Click(object sender, EventArgs e)
{
if (openFileInfo.ShowDialog() == DialogResult.OK)
{
txtReportPath.Text = openFileInfo.FileName;
}
} private void btnGetSql_Click(object sender, EventArgs e)
{
if (!System.IO.File.Exists(txtReportPath.Text))
{
MessageBox.Show("请选择报告模板");
return;
}
Report report = new Report();
report.Load(txtReportPath.Text);
if (report.GetParameter("Sql1") != null)
{
txtSql1.Text = report.GetParameter("Sql1").Description.ToString();
}
if (report.GetParameter("Sql2") != null)
{
txtSql2.Text = report.GetParameter("Sql2").Description.ToString();
}
if (report.GetParameter("Sql3") != null)
{
txtSql3.Text = report.GetParameter("Sql3").Description.ToString();
}
if (report.GetParameter("Sql4") != null)
{
txtSql4.Text = report.GetParameter("Sql4").Description.ToString();
}
if (report.GetParameter("Sql5") != null)
{
txtSql5.Text = report.GetParameter("Sql5").Description.ToString();
}
} private void FrmDesign_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
}
}
{
partial class FrmDesign
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnGetSql = new System.Windows.Forms.Button();
this.BtnDesign = new System.Windows.Forms.Button();
this.lblReportPath = new System.Windows.Forms.Label();
this.btnSelectReportPath = new System.Windows.Forms.Button();
this.txtReportPath = new System.Windows.Forms.TextBox();
this.openFileInfo = new System.Windows.Forms.OpenFileDialog();
this.label1 = new System.Windows.Forms.Label();
this.txtSql1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtSql2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtSql3 = new System.Windows.Forms.TextBox();
this.txtSql4 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txtSql5 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnGetSql
//
this.btnGetSql.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnGetSql.Location = new System.Drawing.Point(680, 336);
this.btnGetSql.Name = "btnGetSql";
this.btnGetSql.Size = new System.Drawing.Size(104, 23);
this.btnGetSql.TabIndex = 0;
this.btnGetSql.Text = "获取Sql";
this.btnGetSql.UseVisualStyleBackColor = true;
this.btnGetSql.Click += new System.EventHandler(this.btnGetSql_Click);
//
// BtnDesign
//
this.BtnDesign.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.BtnDesign.Location = new System.Drawing.Point(599, 336);
this.BtnDesign.Name = "BtnDesign";
this.BtnDesign.Size = new System.Drawing.Size(75, 23);
this.BtnDesign.TabIndex = 0;
this.BtnDesign.Text = "设计";
this.BtnDesign.UseVisualStyleBackColor = true;
this.BtnDesign.Click += new System.EventHandler(this.BtnDesign_Click);
//
// lblReportPath
//
this.lblReportPath.AutoSize = true;
this.lblReportPath.Location = new System.Drawing.Point(22, 13);
this.lblReportPath.Name = "lblReportPath";
this.lblReportPath.Size = new System.Drawing.Size(112, 15);
this.lblReportPath.TabIndex = 1;
this.lblReportPath.Text = "报告模板路径:";
//
// btnSelectReportPath
//
this.btnSelectReportPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSelectReportPath.Location = new System.Drawing.Point(680, 13);
this.btnSelectReportPath.Name = "btnSelectReportPath";
this.btnSelectReportPath.Size = new System.Drawing.Size(112, 23);
this.btnSelectReportPath.TabIndex = 2;
this.btnSelectReportPath.Text = "选择模板";
this.btnSelectReportPath.UseVisualStyleBackColor = true;
this.btnSelectReportPath.Click += new System.EventHandler(this.btnSelectReportPath_Click);
//
// txtReportPath
//
this.txtReportPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtReportPath.Location = new System.Drawing.Point(140, 10);
this.txtReportPath.Name = "txtReportPath";
this.txtReportPath.ReadOnly = true;
this.txtReportPath.Size = new System.Drawing.Size(534, 25);
this.txtReportPath.TabIndex = 3;
//
// openFileInfo
//
this.openFileInfo.DefaultExt = "frx";
this.openFileInfo.FileName = "选择模板文件";
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(80, 53);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 15);
this.label1.TabIndex = 1;
this.label1.Text = "Sql1:";
//
// txtSql1
//
this.txtSql1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtSql1.Location = new System.Drawing.Point(140, 50);
this.txtSql1.Multiline = true;
this.txtSql1.Name = "txtSql1";
this.txtSql1.Size = new System.Drawing.Size(652, 49);
this.txtSql1.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(80, 108);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 15);
this.label2.TabIndex = 1;
this.label2.Text = "Sql2:";
//
// txtSql2
//
this.txtSql2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtSql2.Location = new System.Drawing.Point(140, 105);
this.txtSql2.Multiline = true;
this.txtSql2.Name = "txtSql2";
this.txtSql2.Size = new System.Drawing.Size(652, 49);
this.txtSql2.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(80, 163);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 15);
this.label3.TabIndex = 1;
this.label3.Text = "Sql3:";
//
// txtSql3
//
this.txtSql3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtSql3.Location = new System.Drawing.Point(140, 160);
this.txtSql3.Multiline = true;
this.txtSql3.Name = "txtSql3";
this.txtSql3.Size = new System.Drawing.Size(652, 49);
this.txtSql3.TabIndex = 3;
//
// txtSql4
//
this.txtSql4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtSql4.Location = new System.Drawing.Point(140, 215);
this.txtSql4.Multiline = true;
this.txtSql4.Name = "txtSql4";
this.txtSql4.Size = new System.Drawing.Size(652, 49);
this.txtSql4.TabIndex = 3;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(80, 215);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(54, 15);
this.label4.TabIndex = 1;
this.label4.Text = "Sql4:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(80, 270);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(54, 15);
this.label5.TabIndex = 1;
this.label5.Text = "Sql5:";
//
// txtSql5
//
this.txtSql5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtSql5.Location = new System.Drawing.Point(140, 270);
this.txtSql5.Multiline = true;
this.txtSql5.Name = "txtSql5";
this.txtSql5.Size = new System.Drawing.Size(652, 49);
this.txtSql5.TabIndex = 3;
//
// FrmDesign
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(796, 371);
this.Controls.Add(this.txtSql5);
this.Controls.Add(this.txtSql4);
this.Controls.Add(this.txtSql3);
this.Controls.Add(this.txtSql2);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtSql1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtReportPath);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnSelectReportPath);
this.Controls.Add(this.label1);
this.Controls.Add(this.lblReportPath);
this.Controls.Add(this.BtnDesign);
this.Controls.Add(this.btnGetSql);
this.Name = "FrmDesign";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "报表设计器";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmDesign_FormClosed);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Button btnGetSql;
private System.Windows.Forms.Button BtnDesign;
private System.Windows.Forms.Label lblReportPath;
private System.Windows.Forms.Button btnSelectReportPath;
private System.Windows.Forms.TextBox txtReportPath;
private System.Windows.Forms.OpenFileDialog openFileInfo;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtSql1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtSql2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtSql3;
private System.Windows.Forms.TextBox txtSql4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtSql5;
}
}