基本信息
源码名称:基于C#的WinForm打印程序附带源代码
源码大小:0.74M
文件格式:.zip
开发语言:C#
更新时间:2020-11-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormsPrint
{
public partial class FormPrint : Form
{
string no;
public FormPrint(string no)
{
this.no = no;
InitializeComponent();
}
private void FormPrint_Load(object sender, EventArgs e)
{
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", GetList()));
//显示报表
this.reportViewer1.RefreshReport();
}
/// <summary>
/// 获取打印的数据源
/// </summary>
/// <returns></returns>
private List<Student> GetList()
{
string selectSql = "select * from Student ";
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" System.Windows.Forms.Application.StartupPath.ToString().Replace("bin\\Debug", "DB\\Student.accdb");
if (!string.IsNullOrEmpty(no))
{
selectSql = "where StudentNo='" no "'";
}
OleDbConnection con = new OleDbConnection(connStr);
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter(selectSql, con);
DataTable table = new DataTable();
da.Fill(table);
con.Close();
List<Student> list = new List<Student>();
Student stu = null;
foreach (DataRow row in table.Rows)
{
stu = new Student();
if (row.Table.Columns.Contains("StudentNo") && row["StudentNo"] != null && row["StudentNo"].ToString() != "")
{
stu.StudentNo = row["StudentNo"].ToString();
}
if (row.Table.Columns.Contains("StudentName") && row["StudentName"] != null && row["StudentName"].ToString() != "")
{
stu.StudentName = row["StudentName"].ToString();
}
if (row.Table.Columns.Contains("StudentAge") && row["StudentAge"] != null && row["StudentAge"].ToString() != "")
{
stu.StudentAge = Convert.ToInt32(row["StudentAge"]);
}
if (row.Table.Columns.Contains("StudentContent") && row["StudentContent"] != null && row["StudentContent"].ToString() != "")
{
stu.StudentContent = row["StudentContent"].ToString();
}
list.Add(stu);
}
return list;
}
}
}