using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Mesnac.Controls.Base;
using System.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart;
using System.Windows.Forms;

namespace Mesnac.Controls.Default
{
    [ToolboxBitmap(typeof(TChart), "Images.TChart.bmp")]//暂用曲线图片!!!
    public partial class MCTeeChartBar : Steema.TeeChart.TChart,IBaseControl
    {
        #region 字段定义

        private bool _isEventValid = true;      //保存事件有效性
        private Dictionary<double, string> _data = null; //故障原因

        #endregion

        #region 构造方法

        public MCTeeChartBar()
        {
            InitializeComponent();
            this.InitMethod();
        }

        public MCTeeChartBar(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
            this.InitMethod();
        }

        #endregion

        #region 属性定义
        
        public Dictionary<double, string> DataValue
        {
            get
            {
                return _data;
            }
            set
            {
                _data = value;
            }
        }

        #endregion

        #region 方法定义

        /// <summary>
        /// 初始化方法
        /// </summary>
        public void InitMethod()
        {
            this.Series.Clear();
            this.Chart.Series.Add(new Steema.TeeChart.Styles.Bar());//柱状图显示

            this.Chart.Header.Text = "停机分析图表";
            this.Chart.Panel.Shadow.Visible = false;
            this.Chart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
            this.Chart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;

            this.Chart.Axes.Bottom.Title.Text = "故障原因";  //设置X轴标题
            this.Chart.Axes.Left.Title.Text = "故障占比";//设置Y轴标题

            this.Chart.Series.Add(new Steema.TeeChart.Styles.Bar());

            //this.Chart.Series.SeriesMarks.Visible = true;

            this.Legend.Alignment = LegendAlignments.Right;
            this.Legend.Visible = true;
            this.Chart.Legend.Shadow.Visible = false;
            this.Chart.Legend.Visible = false;

            setData();
        }

        public void setData()
        {
            if (DataValue != null)
            {
                foreach (KeyValuePair<double, string> dv in DataValue)
                {
                    this.Chart.Series[0].Add(Convert.ToDouble(dv.Key), dv.Value.ToString());
                    this.Chart.Series[0].Marks.Style = MarksStyles.PercentTotal;
                }
            }
        }

        #endregion

        #region 接口成员实现


        public string MCKey
        {
            get;
            set;
        }

        public object MCValue
        {
            get;
            set;
        }

        public bool IsDbControl
        {
            get;
            set;
        }

        public IBaseControl MCRoot
        {
            get;
            set;
        }

        public string MCDataSourceID
        {
            get;
            set;
        }

        public MCDataSource MCDataSource
        {
            get;
            set;
        }

        public string InitDataSource
        {
            get;
            set;
        }

        public string ActionDataSource
        {
            get;
            set;
        }

        public object BindDataSource
        {
            get;
            set;
        }

        public DbOptionTypes DbOptionType
        {
            get;
            set;
        }

        public bool MCVisible
        {
            get;
            set;
        }

        public bool MCEnabled
        {
            get;
            set;
        }

        public bool IsValid
        {
            get;
            set;
        }

        public bool IsEventValid
        {
            get { return this._isEventValid; }
            set { this._isEventValid = value; }
        }

        #endregion
    }
}