报表打印 谢谢
wrost 2006-07-06 03:32:27 我用条码枪扫描一个条码,然后从数据库取一条记录,然后生成一个报表。 怎么让报表生成好后,自动打印
谢谢
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using mima;
using System.IO.Ports;
namespace CrystalReportsApplication1
{
public partial class Form1 : Form
{
private string FlagComm;
RPPolo RPPolo1;
RPSantana RPSantana1;
public Form1()
{
InitializeComponent();
CryReportView.ReportSource = null;
RPPolo1 = new RPPolo();
RPSantana1 = new RPSantana();
FlagComm = "0";
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.Open();
Form1.CheckForIllegalCrossThreadCalls = false;
}
/// <summary>
/// 获得sql语句
/// </summary>
/// <param name="StrSqlWhere">扫描到的条码</param>
/// <returns></returns>
private string GetSql(string StrSqlWhere)
{
string StrSql,StrTableName;
StrTableName = string.Empty;
StrSql = string.Empty;
switch (comboBox1.SelectedIndex)
{
case 1: StrTableName = "Data_VW3SPKDA"; break;
case 2: StrTableName = "Data_VW4SPKDA"; break;
case 3: StrTableName = "Data_FOCD34DA"; break;
case 4: StrTableName = "Data_VWSGM18DA"; break;
}
StrSql = "select * from " + StrTableName + " where ModuleBC = '" + StrSqlWhere + "'";
return StrSql;
}
/// <summary>
/// 返回需要查询的表
/// </summary>
/// <returns></returns>
private string GetTable()
{
string StrTableName = string.Empty;
switch (comboBox1.SelectedIndex)
{
case 1: StrTableName = "Data_VW3SPKDA"; break;
case 2: StrTableName = "Data_VW4SPKDA"; break;
case 3: StrTableName = "Data_FOCD34DA"; break;
case 4: StrTableName = "Data_VWSGM18DA"; break;
}
return StrTableName;
}
/// <summary>
/// 打印报表,根据CheckBox决定是否要打印
/// </summary>
/// <param name="BC"></param>
private void Print(string BC)
{
mima.DataBase DB = new DataBase();
DataSet DS = new DataSet();
string StrSql,StrTableName;
//if (comboBox1.SelectedIndex == 0)
//{
// textBox1.Text = "before";
// return;
//}
////textBox1.Text = "after";
StrTableName = GetTable();
StrSql = GetSql(BC);
DS = DB.RunProc(StrSql, DS, StrTableName);
switch (comboBox1.SelectedIndex)
{
case 1:
{
RPSantana1.SetDataSource(DS);
CryReportView.ReportSource = RPSantana1;
}; break;
case 2:
{
RPPolo1.SetDataSource(DS);
CryReportView.ReportSource = RPPolo1;
}; break;
//case 3: StrTableName = Data_FOCD34DA; break;
//case 4: StrTableName = Data_VWSGM18DA; break;
}
//CryReportView.DataBindings();
}
private void BtnSearch_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 串口获取事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string str = serialPort1.ReadLine();
textBox1.Text = str.Replace("\r","");
if (str != "")
{
FlagComm = "1";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (FlagComm == "1")
{
FlagComm = "0";
Print(textBox1.Text);
}
}
}
}