using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WSDDBBrowser.Core;

namespace WSDDBBrowser
{
    /// <summary>
    /// PgChartView.xaml 的交互逻辑
    /// </summary>
    public partial class PgChartView : Page, IDisposable
    {
        public PgChartView()
        {
            InitializeComponent();
        }

        public void Dispose()
        {
            foreach (var item in items)
                item.Dispose();
        }
        List<PgItemChartView> items = new List<PgItemChartView>();
        public void Init()
        {
            if (DBViewerModel.Instance.CurrProcess.HasSBData)
            {
                {
                    PgMonitorChartConfig config = new PgMonitorChartConfig();
                    config.Init();

                    Frame f = new Frame();
                    f.Content = config;

                    TabItem tabItem = new TabItem()
                    {
                        Header = "温度监控配置",
                        Content = f
                    };
                    tabControl.Items.Add(tabItem);
                }
                {
                    PgMonitorChartView view = new PgMonitorChartView();
                    view.Init();
                    
                    TabItem tabItem = new TabItem()
                    {
                        Header = "温度趋势图",
                        Content = view
                    };
                    tabControl.Items.Add(tabItem);
                }
            }
            if (DBViewerModel.Instance.CurrProcess.HasTGData)
            {
                {
                    PgChartConfig config = new PgChartConfig();
                    config.Init();

                    Frame f = new Frame();
                    f.Content = config;

                    TabItem tabItem = new TabItem()
                    {
                        Header = "厚度测量配置",
                        Content = f
                    };
                    tabControl.Items.Add(tabItem);
                }
                foreach (var scanDataItem in DBViewerModel.Instance.ScanDataItems)
                {
                    PgItemChartView pgItemChartView = new PgItemChartView();
                    pgItemChartView.Init(scanDataItem);
                    items.Add(pgItemChartView);

                    TabItem tabItem = new TabItem()
                    {
                        Header = scanDataItem.DeviceName,
                        Content = pgItemChartView
                    };

                    tabControl.Items.Add(tabItem);
                }
            }
        }

        private void ButtonBack_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.GoBack();
            this.NavigationService.RemoveBackEntry();
            this.KeepAlive = false;
            this.Dispose();
        }

        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {

        }
    }
}
