using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

using C1.Win.FlexReport;
using C1.Win.C1Ribbon;

namespace ControlExplorer.FlexReport
{
    public partial class CommonReports : C1DemoForm
    {
        C1FlexReport report;
        RibbonComboBox comboReports;
        XmlDocument doc;

        public CommonReports()
        {
            InitializeComponent();
            c1Zoom1.Target = null;

            var selReportLabel = new C1.Win.C1Ribbon.RibbonButton();
            c1FlexViewer1.Ribbon.QatItemsHolder.Add(selReportLabel);
            c1FlexViewer1.Ribbon.Qat.ItemLinks.Add(selReportLabel);
            selReportLabel.Text = "Select Report:";
            selReportLabel.Click += selReportLabel_Click;

            comboReports = new RibbonComboBox();
            comboReports.GripHandleVisible = true;
            comboReports.TextAreaWidth = 170;
            comboReports.MaxDropDownItems = 12;
            comboReports.DropDownStyle = RibbonComboBoxStyle.DropDownList;
            comboReports.SelectedIndexChanged += comboReports_SelectedIndexChanged;

            var coll = comboReports.Items;
            coll.Add(new RibbonButton("01: Alternating Background"));
            coll.Add(new RibbonButton("02: Custom Paper Size"));
            coll.Add(new RibbonButton("03: Unbound Images"));
            coll.Add(new RibbonButton("04: Bound Images"));
            coll.Add(new RibbonButton("05: Watermark"));
            coll.Add(new RibbonButton("06: CanGrow CanShrink"));
            coll.Add(new RibbonButton("07: Force Page Breaks"));
            coll.Add(new RibbonButton("08: Global Constant"));
            coll.Add(new RibbonButton("09: Dynamic Page Header"));
            coll.Add(new RibbonButton("10: Gutter"));
            coll.Add(new RibbonButton("11: Charts"));
            coll.Add(new RibbonButton("12: Custom Fields"));
            coll.Add(new RibbonButton("13: Subtotals and other Aggregates"));
            coll.Add(new RibbonButton("14: Page Headers in Subreports"));
            coll.Add(new RibbonButton("15: Subreport"));
            coll.Add(new RibbonButton("16: Retrieve Values from Subreports"));
            coll.Add(new RibbonButton("17: Conditional Formatting"));
            coll.Add(new RibbonButton("18: Running Sums"));
            coll.Add(new RibbonButton("19: Continued Headers"));
            coll.Add(new RibbonButton("20: Sorting"));
            coll.Add(new RibbonButton("21: Cross-tab Reports"));
            coll.Add(new RibbonButton("22: Suppress or Force Zeros"));
            coll.Add(new RibbonButton("23: Mail Merge"));
            coll.Add(new RibbonButton("24: Report Parameters"));

            c1FlexViewer1.Ribbon.QatItemsHolder.Add(comboReports);
            c1FlexViewer1.Ribbon.Qat.ItemLinks.Add(comboReports);

            report = new C1FlexReport();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (report != null)
                {
                    c1FlexViewer1.DocumentSource = null;
                    report.Dispose();
                    report = null;
                }
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        private void CommonReports_Load(object sender, EventArgs e)
        {
            doc = new XmlDocument();
            doc.LoadXml(ControlExplorer.Properties.Resources.CommonReports);
            comboReports.SelectedIndex = 0;
        }

        private void LoadReport(string reportName)
        {
            // load C1FlexReport with selected report
            report.Load(doc, reportName);

            // assign report to the flex viewer control
            c1FlexViewer1.DocumentSource = report;
        }

        void selReportLabel_Click(object sender, EventArgs e)
        {
            foreach (RibbonItem item in c1FlexViewer1.Ribbon.Qat.Items)
            {
                RibbonComboBox rbc = item as RibbonComboBox;
                if (rbc == comboReports)
                {
                    rbc.DroppedDown = true;
                    break;
                }
            }
        }

        void comboReports_SelectedIndexChanged(object sender, EventArgs e)
        {
            RibbonButton item = comboReports.SelectedItem;
            if (item != null)
            {
                LoadReport(item.Text);
            }
        }
    }
}
