- 积分
- 0
- 在线时间
- 47 小时
- 主题
- 2
- 注册时间
- 2014-4-14
- 帖子
- 34
- 最后登录
- 2019-6-20
- 帖子
- 34
- 软币
- 421
- 在线时间
- 47 小时
- 注册时间
- 2014-4-14
|
[size=14.44444465637207px]C# 运用DEVEXPRESS XtraReport 制作报表,
[size=14.44444465637207px]FORM 窗体中放置3个TEXTBOX.TEXT 一个BUTTON(打印)
[size=14.44444465637207px]button 下代码为:
[size=14.44444465637207px]private void button1_Click(object sender, EventArgs e)
[size=14.44444465637207px] {
[size=14.44444465637207px] string cnStr = System.Configuration.ConfigurationSettings.AppSettings["Connstr"];
[size=14.44444465637207px] SqlConnection cn = new SqlConnection(cnStr);
[size=14.44444465637207px] string Sql = "SELECT scandata.gch,gcda.gcm,tdh,bh,cast(sl as int)as sl, COUNT(stationName) AS zysl,barcode1, cc ,ys, bzl,zc, stationName FROM dbo.ScanData left join gcda on scandata.gch=gcda.gch where 1=1";
[size=14.44444465637207px] if (textBox1.Text != "")
[size=14.44444465637207px] {
[size=14.44444465637207px] Sql = Sql + " and scandata.gch='" + textBox1.Text + "'";
[size=14.44444465637207px] }
[size=14.44444465637207px] if (textBox2.Text != "")
[size=14.44444465637207px] {
[size=14.44444465637207px] Sql = Sql + " and tdh='" + textBox2.Text + "'";
[size=14.44444465637207px] }
[size=14.44444465637207px] if (textBox3.Text != "")
[size=14.44444465637207px] {
[size=14.44444465637207px] Sql = Sql + " and bh='" + textBox3.Text + "'";
[size=14.44444465637207px] }
[size=14.44444465637207px] Sql = Sql + " GROUP BY barcode1,stationName, sl, zc, bzl, cl, ys, cc, scandata.gch,scandata.dh,gcda.gcm,tdh, bh order by bh ";
[size=14.44444465637207px] DataSet ds = new DataSet();
[size=14.44444465637207px] SqlCommand sqlcmd = new SqlCommand(Sql, cn);
[size=14.44444465637207px] SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
[size=14.44444465637207px] da.Fill(ds, "scandata");
[size=14.44444465637207px] XtraReport1 report = new XtraReport1(ds);
[size=14.44444465637207px] if (ds.Tables[0].Rows.Count != 0)
[size=14.44444465637207px] {
[size=14.44444465637207px]
[size=14.44444465637207px] report.DataSource = ds.Tables[0];
[size=14.44444465637207px] report.ShowPreview();
[size=14.44444465637207px]
[size=14.44444465637207px] }
[size=14.44444465637207px] }
[size=14.44444465637207px]xtraReport1 代码为:
[size=14.44444465637207px]public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
[size=14.44444465637207px] {
[size=14.44444465637207px] public XtraReport1(DataSet ds)
[size=14.44444465637207px] {
[size=14.44444465637207px] InitializeComponent();
[size=14.44444465637207px] SetDataBind(ds);
[size=14.44444465637207px] }
[size=14.44444465637207px] private void SetDataBind(DataSet ds)//绑定数据源
[size=14.44444465637207px] {
[size=14.44444465637207px] DataSource = ds;
[size=14.44444465637207px] this.xrTableCell1.DataBindings.Add("Text", DataSource, "gch");
[size=14.44444465637207px] this.xrTableCell2.DataBindings.Add("Text", DataSource, "tdh");
[size=14.44444465637207px] this.xrTableCell3.DataBindings.Add("Text", DataSource, "sl");
[size=14.44444465637207px] }
[size=14.44444465637207px]
[size=14.44444465637207px] private DataSet GetTempDataSet()
[size=14.44444465637207px] {
[size=14.44444465637207px] DataSet ds = new DataSet();
[size=14.44444465637207px] string cnStr = System.Configuration.ConfigurationSettings.AppSettings["Connstr"];
[size=14.44444465637207px] SqlConnection cn = new SqlConnection(cnStr);
[size=14.44444465637207px] string Sql = "SELECT scandata.gch,gcda.gcm,tdh,bh,cast(sl as int)as sl, COUNT(stationName) AS zysl,barcode1, cc ,ys, bzl,zc, stationName FROM dbo.ScanData left join gcda on scandata.gch=gcda.gch GROUP BY barcode1,stationName, sl, zc, bzl, cl, ys, cc, scandata.gch,scandata.dh,gcda.gcm,tdh, bh order by bh";
[size=14.44444465637207px]
[size=14.44444465637207px] SqlCommand sqlcmd = new SqlCommand(Sql, cn);
[size=14.44444465637207px] SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
[size=14.44444465637207px] da.Fill(ds, "scandata");
[size=14.44444465637207px] return ds;
[size=14.44444465637207px] }
[size=14.44444465637207px] }
[size=14.44444465637207px]可是查询的结果只有 一行数据,
[size=14.44444465637207px]为什么?
[size=14.44444465637207px]什么构造函数,我不是懂
[size=14.44444465637207px]麻烦高手指点,我只想做个依据条件打印的单据 ,做了两天,实在没法,特来询问,谢谢 !
|
|