using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinformLocateDataSource.Reports;

namespace WinformLocateDataSource
{
    public partial class Winfrom动态数据源 : Form
    {
        public Winfrom动态数据源()
        {
            InitializeComponent();
            GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"Reports\RDL报表.rdlx"));
            rpt.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(locatedate);
            this.viewer1.LoadDocument(rpt.Document);
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel1.LinkVisited = true;
            Process.Start("IExplore", "http://www.gcpowertools.com.cn/products/redirect.aspx?r=77");
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel2.LinkVisited = true;
            Process.Start("IExplore", "https://demo.grapecity.com.cn/activereports/aspnet/controlexplorer/");
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel4.LinkVisited = true;
            Process.Start("IExplore", "https://www.grapecity.com.cn/blogs/categories/activereports");
        }

        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel5.LinkVisited = true;
            Process.Start("IExplore", "https://gcdn.grapecity.com.cn/forum.php?mod=forumdisplay&fid=152");
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel3.LinkVisited = true;
            Process.Start("IExplore", "https://www.grapecity.com.cn/developer/activereports");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedIndex.ToString() == "0")
            {
                GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"Reports\RDL报表.rdlx"));
                rpt.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(locatedate);
                this.viewer1.LoadDocument(rpt.Document);
            }
            if (this.comboBox1.SelectedIndex.ToString() == "1")
            {
                GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"Reports\页面报表.rdlx"));
                rpt.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(locatedate);
                this.viewer1.LoadDocument(rpt.Document);
            }
            if (this.comboBox1.SelectedIndex.ToString() == "2")
            {
                GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();
                System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(@"Reports\区域报表.rpx");
                sectionReport.LoadLayout(xtr);
                sectionReport.DataSource = GetDataSource();
                xtr.Close();
                viewer1.LoadDocument(sectionReport);
            }
            if (this.comboBox1.SelectedIndex.ToString() == "3")
            {
                SectionReport1 rpt = new SectionReport1();
                rpt.DataSource = GetDataSource();
                viewer1.LoadDocument(rpt);
            }
        }
        private void locatedate(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
        {
            if (args.DataSourceName == "DataSource1")
            {
                if (args.DataSetName == "DataSet1")
                {
                    args.Data = returndata();
                }
            }
        }
        private DataTable returndata()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("产品编号");
            dt.Columns.Add("产品名称");
            dt.Columns.Add("单价");
            dt.Columns.Add("库存量");
            dt.Columns.Add("产地");
            dt.Rows.Add("A001", "苹果", 10, 300, "中国");
            dt.Rows.Add("A002", "葡萄", 20, 200, "中国");
            dt.Rows.Add("A003", "香蕉", 30, 400, "中国");
            dt.Rows.Add("A004", "甘蔗", 10, 300, "中国");
            dt.Rows.Add("A005", "荔枝", 20, 200, "中国");
            dt.Rows.Add("A006", "芒果", 30, 400, "中国");
            dt.Rows.Add("A007", "猕猴桃", 110, 300, "中国");
            dt.Rows.Add("A008", "柠檬", 210, 200, "中国");
            dt.Rows.Add("A009", "栗子", 320, 400, "中国");
            dt.Rows.Add("A010", "火龙果", 100, 300, "中国");
            dt.Rows.Add("A011", "青芒", 250, 200, "中国");
            dt.Rows.Add("A012", "巴旦木", 320, 200, "中国");
            dt.Rows.Add("A013", "土豆", 380, 400, "中国");
            dt.Rows.Add("A014", "苹果", 110, 300, "中国");
            dt.Rows.Add("A015", "葡萄", 420, 200, "中国");
            dt.Rows.Add("A016", "香蕉", 530, 400, "中国");
            dt.Rows.Add("A017", "土豆", 380, 400, "中国");
            dt.Rows.Add("A018", "苹果", 110, 300, "中国");
            dt.Rows.Add("A019", "葡萄", 420, 200, "中国");
            dt.Rows.Add("A020", "香蕉", 530, 400, "中国");
            dt.Rows.Add("A021", "苹果", 10, 300, "中国");
            dt.Rows.Add("A022", "葡萄", 20, 200, "中国");
            dt.Rows.Add("A023", "香蕉", 30, 400, "中国");
            dt.Rows.Add("A024", "甘蔗", 10, 300, "中国");
            dt.Rows.Add("A025", "荔枝", 20, 200, "中国");
            dt.Rows.Add("A026", "芒果", 30, 400, "中国");
            return dt;
        }
        private DataTable GetDataSource()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("产品编号");
            dt.Columns.Add("产品名称");
            dt.Columns.Add("单价");
            dt.Columns.Add("库存量");
            dt.Rows.Add("A10002", "苹果", 10, 150);
            dt.Rows.Add("A15681", "香蕉", 230, 350);
            dt.Rows.Add("A15481", "菠萝", 220, 250);
            dt.Rows.Add("A10002", "苹果", 250, 350);
            dt.Rows.Add("A15681", "香蕉", 120, 750);
            dt.Rows.Add("A12681", "菠萝", 320, 550);
            dt.Rows.Add("A10002", "苹果", 520, 560);
            dt.Rows.Add("A15681", "香蕉", 620, 250);
            dt.Rows.Add("A15081", "菠萝", 720, 510);
            dt.Rows.Add("A10002", "苹果", 320, 500);
            dt.Rows.Add("A15681", "香蕉", 290, 950);
            dt.Rows.Add("A15681", "菠萝", 720, 650);
            dt.Rows.Add("A11202", "苹果", 520, 350);
            dt.Rows.Add("A15681", "香蕉", 620, 950);
            dt.Rows.Add("A15681", "菠萝", 820, 550);
            dt.Rows.Add("A10002", "苹果", 20, 650);
            dt.Rows.Add("A15781", "香蕉", 20, 350);
            dt.Rows.Add("A15081", "菠萝", 20, 509);
            dt.Rows.Add("A10102", "苹果", 200, 505);
            dt.Rows.Add("A15611", "香蕉", 290, 580);
            dt.Rows.Add("A15481", "菠萝", 209, 501);
            return dt;
        }

        private void Winfrom动态数据源_Load(object sender, EventArgs e)
        {

        }
    }
}
