C#空间

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTab;
using DevExpress.XtraPrinting.Control;
using DevExpress.XtraReports.UI;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private List<XtraTabPage> tabpage = new List<XtraTabPage>();
        private List<PrintControl> printcon = new List<PrintControl>();
        private List<XtraReport> report = new List<XtraReport>();
        private string path = string.Empty;
        private void Form1_Load(object sender, EventArgs e)
        {
            path = AppDomain.CurrentDomain.BaseDirectory;
            // TODO: 这行代码将数据加载到表“dataSet1.Orders1”中。您可以根据需要移动或删除它。
            this.orders1TableAdapter.Fill(this.dataSet1.Orders1);
            // TODO: 这行代码将数据加载到表“dataSet1.Orders”中。您可以根据需要移动或删除它。
            this.ordersTableAdapter.Fill(this.dataSet1.Orders);

            dataSet1.Tables["DataTable1"].Rows.Add("page0", "Orders", "XtraReport.repx");
            dataSet1.Tables["DataTable1"].Rows.Add("page1", "Orders1", "XtraReport2.repx");
            dataSet1.Tables["DataTable1"].Rows.Add("page2", "Orders", "XtraReport.repx");
            dataSet1.Tables["DataTable1"].Rows.Add("page3", "Orders1", "XtraReport2.repx");
            dataSet1.Tables["DataTable1"].Rows.Add("page4", "Orders1", "XtraReport2.repx");
            foreach (DataRow dr in dataSet1.Tables["DataTable1"].Rows)
            {

                XtraTabPage page = new XtraTabPage();
                XtraReport2 xrepot = new XtraReport2();
                string pa = path + "\\" + dr["DataColumn3"].ToString();
                xrepot.LoadLayout(pa);
                xrepot.Name = dr["DataColumn1"].ToString();
                page.Name = dr["DataColumn1"].ToString();
                page.Text = dr["DataColumn1"].ToString();
                page.TabPageWidth = 100;
                PrintControl print = new PrintControl();
                print.Name = dr["DataColumn1"].ToString();
                print.Dock = System.Windows.Forms.DockStyle.Fill;
                print.PrintingSystem = xrepot.PrintingSystem;       
                xrepot.DataSource = dataSet1.Tables[dr["DataColumn2"].ToString()];
                xrepot.CreateDocument();
                report.Add(xrepot);
                printcon.Add(print);
                page.Controls.Add(print);
                tabpage.Add(page);
                xtraTabControl1.TabPages.Add(page);
            }

            //dataSet1.Tables["DataTable1"].Rows.Add("page0", "Orders");
        }

        private void xtraTabControl1_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            string selpage = xtraTabControl1.SelectedTabPage.Text.ToString();
            foreach (XtraReport rp in report)
            {
                if (rp.Name == selpage)
                {
                    /*
                    string dc = string.Empty;
                    foreach (DataRow r in dataSet1.Tables["DataTable1"].Rows)
                    {
                        if (r["DataColumn1"].ToString() == selpage)
                            dc = r["DataColumn2"].ToString();
                    }
                    rp.DataSource = dataSet1.Tables[dc];*/
                    rp.CreateDocument();

                }
            }
            foreach (PrintControl prc in printcon)
            {
                if (prc.Name == selpage)
                    printBarManager1.PrintControl = prc;
            }
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            dataSet1.Tables["Orders1"].Rows.Clear();
            dataSet1.Tables["Orders"].Rows.Clear();
            /*
            foreach (XtraReport rp2 in report)
            {
                rp2.CreateDocument();
            }*/
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.orders1TableAdapter.Fill(this.dataSet1.Orders1);
            // TODO: 这行代码将数据加载到表“dataSet1.Orders”中。您可以根据需要移动或删除它。
            this.ordersTableAdapter.Fill(this.dataSet1.Orders);
        }
    }
}

posted on 2010-09-22 22:49  小海洋  阅读(3884)  评论(5编辑  收藏  举报