找传奇、传世资源到传世资源站!

基于C#的WinForm打印程序附带源代码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboard

using System;using System.Collections.Generic;using
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;
        }
    }
}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复