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

namespace Mesnac.Controls.Feeding
{
    /// <summary>
    /// 胶料重量偏差值标签
    /// </summary>
    [ToolboxBitmap(typeof(System.Windows.Forms.Label))]
    public partial class RecipPlyFact : Label
    {
        public RecipPlyFact()
        {
            InitializeComponent();
        }


        private string _finishStatusName;
        private OnOffStatuses _finishStatus;
        private string _dataName;
        private DataTable _data;
        private DataTable _cloneData;
        private string _currentRecipPlyName1;
        private int _currentRecipPly1;
        private string _currentRecipPlyName2;
        private int _currentRecipPly2;
        private string _currentRecipPlyName3;
        private int _currentRecipPly3;
        private string _currentRecipPlyName4;
        private int _currentRecipPly4;
        private string _currentRecipPlyName5;
        private int _currentRecipPly5;
        private string _currentRecipPlyName6;
        private int _currentRecipPly6;
        private string _currentRecipPlyName7;
        private int _currentRecipPly7;
        private string _currentRecipPlyName8;
        private int _currentRecipPly8;
        private string _currentRecipPlyName9;
        private int _currentRecipPly9;
        private string _currentRecipPlyName10;
        private int _currentRecipPly10;
        private string _currentRecipPlyName11;
        private int _currentRecipPly11;
        private string _currentRecipPlyName12;
        private int _currentRecipPly12;
        private string _currentRecipPlyName13;
        private int _currentRecipPly13;
        private string _currentRecipPlyName14;
        private int _currentRecipPly14;
        private string _currentRecipPlyName15;
        private int _currentRecipPly15;
        private string _plyCurrentValueName1;
        private double _plyCurrentValue1; //胶料实际值
        private string _plyCurrentValueName2;
        private double _plyCurrentValue2;
        private string _plyCurrentValueName3;
        private double _plyCurrentValue3;
        private string _plyCurrentValueName4;
        private double _plyCurrentValue4;
        private string _plyCurrentValueName5;
        private double _plyCurrentValue5;
        private string _plyCurrentValueName6;
        private double _plyCurrentValue6;
        private string _plyCurrentValueName7;
        private double _plyCurrentValue7;
        private string _plyCurrentValueName8;
        private double _plyCurrentValue8;
        private string _plyCurrentValueName9;
        private double _plyCurrentValue9;
        private string _plyCurrentValueName10;
        private double _plyCurrentValue10;
        private string _plyCurrentValueName11;
        private double _plyCurrentValue11;
        private string _plyCurrentValueName12;
        private double _plyCurrentValue12;
        private string _plyCurrentValueName13;
        private double _plyCurrentValue13;
        private string _plyCurrentValueName14;
        private double _plyCurrentValue14;
        private string _plyCurrentValueName15;
        private double _plyCurrentValue15;


        /// <summary>
        /// 数据源
        /// </summary>
        public DataTable Data
        {
            get { return _data; }
            set
            {
                _data = value;
                this._cloneData = _data;
                if (this._cloneData == null || this._cloneData.TableName != this._data.TableName)
                {
                    this.InitData(false);
                }
            }
        }  
        /// <summary>
        /// 数据源动画属性
        /// </summary>
        public string DataName
        {
            get { return _dataName; }
            set { _dataName = value; }
        }
        /// <summary>
        /// 一车结束标志动画属性
        /// </summary>
        public string FinishStatusName
        {
            get { return _finishStatusName; }
            set { _finishStatusName = value; }
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData(bool isclear)
        {
            try
            {
                if (isclear)
                {
                    if (this._cloneData == null || this._cloneData.TableName != this._data.TableName)
                    {
                        if (this._cloneData != null)
                        {
                            this._cloneData.Dispose();
                        }
                        this._cloneData = null;
                    }
                }
                if ((this._cloneData == null && this._data != null && this._data.Rows.Count > 0) || (this._cloneData != null && this._data != null && this._cloneData.TableName != this._data.TableName))
                {
                    this._cloneData = this._data.Copy();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        /// <summary>
        /// 一车结束标志
        /// </summary>
        public OnOffStatuses FinishStatus
        {
            get { return _finishStatus; }
            set
            {
                if ((int)value > 1)
                {
                    this._finishStatus = OnOffStatuses.On;
                }
                else if ((int)value < 0)
                {
                    this._finishStatus = OnOffStatuses.Off;
                }
                else
                {
                    this._finishStatus = value;
                }
                //如果一车标志结束,则重新绑定数据源
                if (this._finishStatus == OnOffStatuses.On)
                {
                    this.InitData(true);
                }
            }
        }

        #region 称量的第几种胶料动画属性

        /// <summary>
        /// 称量的第一种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName1
        {
            get { return _currentRecipPlyName1; }
            set { _currentRecipPlyName1 = value; }
        }
        /// <summary>
        /// 称量的第二种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName2
        {
            get { return _currentRecipPlyName2; }
            set { _currentRecipPlyName2 = value; }
        }
        /// <summary>
        /// 称量的第三种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName3
        {
            get { return _currentRecipPlyName3; }
            set { _currentRecipPlyName3 = value; }
        }
        /// <summary>
        /// 称量的第四种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName4
        {
            get { return _currentRecipPlyName4; }
            set { _currentRecipPlyName4 = value; }
        }
        /// <summary>
        /// 称量的第五种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName5
        {
            get { return _currentRecipPlyName5; }
            set { _currentRecipPlyName5 = value; }
        }
        /// <summary>
        /// 称量的第六种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName6
        {
            get { return _currentRecipPlyName6; }
            set { _currentRecipPlyName6 = value; }
        }
        /// <summary>
        /// 称量的第七种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName7
        {
            get { return _currentRecipPlyName7; }
            set { _currentRecipPlyName7 = value; }
        }
        /// <summary>
        /// 称量的第八种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName8
        {
            get { return this._currentRecipPlyName8; }
            set { this._currentRecipPlyName8 = value; }
        }
        /// <summary>
        /// 称量的第九种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName9
        {
            get { return this._currentRecipPlyName9; }
            set { this._currentRecipPlyName9 = value; }
        }
        /// <summary>
        /// 称量的第十种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName10
        {
            get { return this._currentRecipPlyName10; }
            set { this._currentRecipPlyName10 = value; }
        }
        /// <summary>
        /// 称量的第十一种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName11
        {
            get { return this._currentRecipPlyName11; }
            set { this._currentRecipPlyName11 = value; }
        }
        /// <summary>
        /// 称量的第十二种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName12
        {
            get { return this._currentRecipPlyName12; }
            set { this._currentRecipPlyName12 = value;}
        }
        /// <summary>
        /// 称量的第十三种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName13
        {
            get { return this._currentRecipPlyName13; }
            set { this._currentRecipPlyName13 = value; }
        }
        /// <summary>
        /// 称量的第十四种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName14
        {
            get { return this._currentRecipPlyName14; }
            set { this._currentRecipPlyName14 = value; }
        }
        /// <summary>
        /// 称量的第十五种胶料动画属性
        /// </summary>
        public string CurrentRecipPlyName15
        {
            get { return this._currentRecipPlyName15; }
            set { this._currentRecipPlyName15 = value; }
        }

        #endregion

        #region 胶料实际值动画属性
        /// <summary>
        /// 称量的第一种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName1
        {
            get { return this._plyCurrentValueName1; }
            set { this._plyCurrentValueName1 = value; }
        }
        /// <summary>
        /// 称量的第二种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName2
        {
            get { return _plyCurrentValueName2; }
            set { this._plyCurrentValueName2 = value; }
        }
        /// <summary>
        /// 称量的第三种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName3
        {
            get { return this._plyCurrentValueName3; }
            set { this._plyCurrentValueName3 = value; }
        }
        /// <summary>
        /// 称量的第四种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName4
        {
            get { return this._plyCurrentValueName4; }
            set { this._plyCurrentValueName4 = value; }
        }
        /// <summary>
        /// 称量的第五种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName5
        {
            get { return this._plyCurrentValueName5; }
            set { this._plyCurrentValueName5 = value; }
        }
        /// <summary>
        /// 称量的第六种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName6
        {
            get { return this._plyCurrentValueName6; }
            set { this._plyCurrentValueName6 = value; }
        }
        /// <summary>
        /// 称量的第七种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName7
        {
            get { return this._plyCurrentValueName7; }
            set { this._plyCurrentValueName7 = value; }
        }
        /// <summary>
        /// 称量的第八种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName8
        {
            get { return this._plyCurrentValueName8; }
            set { this._plyCurrentValueName8 = value; }
        }
        /// <summary>
        /// 称量的第九种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName9
        {
            get { return this._plyCurrentValueName9; }
            set { this._plyCurrentValueName9 = value; }
        }
        /// <summary>
        /// 称量的第十种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName10
        {
            get { return this._plyCurrentValueName10; }
            set { this._plyCurrentValueName10 = value; }
        }
        /// <summary>
        /// 称量的第十一种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName11
        {
            get { return this._plyCurrentValueName11; }
            set { this._plyCurrentValueName11 = value; }
        }
        /// <summary>
        /// 称量的第十二种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName12
        {
            get { return this._plyCurrentValueName12; }
            set { this._plyCurrentValueName12 = value; }
        }
        /// <summary>
        /// 称量的第十三种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName13
        {
            get { return this._plyCurrentValueName13; }
            set { this._plyCurrentValueName13 = value; }
        }
        /// <summary>
        /// 称量的第十四种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName14
        {
            get { return this._plyCurrentValueName14; }
            set { this._plyCurrentValueName14 = value; }
        }
        /// <summary>
        /// 称量的第十五种胶料实际值动画属性
        /// </summary>
        public string PlyCurrentValueName15
        {
            get { return this._plyCurrentValueName15; }
            set { this._plyCurrentValueName15 = value; }
        }

        #endregion


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

            InitializeComponent();
        }
        #region 判断当前称量的胶料
        /// <summary>
        /// 称量的第一种胶料
        /// </summary>
        public int CurrentRecipPly1
        {
            get { return _currentRecipPly1; }
            set
            {
                _currentRecipPly1 = value;
            }
        }
        /// <summary>
        /// 称量的第二种胶料
        /// </summary>
        public int CurrentRecipPly2
        {
            get { return _currentRecipPly2; }
            set
            {
                _currentRecipPly2 = value;
            }
        }
        /// <summary>
        /// 称量的第三种胶料
        /// </summary>
        public int CurrentRecipPly3
        {
            get { return _currentRecipPly3; }
            set
            {
                _currentRecipPly3 = value;
            }
        }
        /// <summary>
        /// 称量的第四种胶料
        /// </summary>
        public int CurrentRecipPly4
        {
            get { return _currentRecipPly4; }
            set
            {
                _currentRecipPly4 = value;
            }
        }
        /// <summary>
        /// 称量的第五种胶料
        /// </summary>
        public int CurrentRecipPly5
        {
            get { return _currentRecipPly5; }
            set
            {
                _currentRecipPly5 = value;
            }
        }
        /// <summary>
        /// 称量的第六种胶料
        /// </summary>
        public int CurrentRecipPly6
        {
            get { return _currentRecipPly6; }
            set
            {
                _currentRecipPly6 = value;
            }
        }
        /// <summary>
        /// 称量的第七种胶料
        /// </summary>
        public int CurrentRecipPly7
        {
            get { return _currentRecipPly7; }
            set
            {
                _currentRecipPly7 = value;
            }
        }
        /// <summary>
        /// 称量的第八种胶料
        /// </summary>
        public int CurrentRecipPly8
        {
            get { return this._currentRecipPly8; }
            set 
            {
                this._currentRecipPly8 = value;
            }
        }
        /// <summary>
        /// 称量的第九种胶料
        /// </summary>
        public int CurrentRecipPly9
        {
            get { return this._currentRecipPly9; }
            set
            {
                this._currentRecipPly9 = value;
            }
        }
        /// <summary>
        /// 称量的第十种胶料
        /// </summary>
        public int CurrentRecipPly10
        {
            get { return this._currentRecipPly10; }
            set
            {
                this._currentRecipPly10 = value;
            }
        }
        /// <summary>
        /// 称量的第十一种胶料
        /// </summary>
        public int CurrentRecipPly11
        {
            get { return this._currentRecipPly11; }
            set
            {
                this._currentRecipPly11 = value;
            }
        }
        /// <summary>
        /// 称量的第十二种胶料
        /// </summary>
        public int CurrentRecipPly12
        {
            get { return this._currentRecipPly12; }
            set
            {
                this._currentRecipPly12 = value;
            }
        }
        /// <summary>
        /// 称量的第十三种胶料
        /// </summary>
        public int CurrentRecipPly13
        {
            get { return this._currentRecipPly13; }
            set 
            {
                this._currentRecipPly13 = value;
            }
        }
        /// <summary>
        /// 称量的第十四种胶料
        /// </summary>
        public int CurrentRecipPly14
        {
            get { return this._currentRecipPly14; }
            set
            {
                this._currentRecipPly14 = value;
            }
        }
        /// <summary>
        /// 称量的第十五种胶料
        /// </summary>
        public int CurrentRecipPly15
        {
            get { return this._currentRecipPly15; }
            set
            {
                this._currentRecipPly15 = value;
            }
        }

        #endregion

        #region 胶料实际值属性
        /// <summary>
        /// 第一种胶料实际值
        /// </summary>
        public double PlyCurrentValue1
        {
            get { return _plyCurrentValue1; }
            set
            {
                _plyCurrentValue1 = value;
                this.RefreshCurrentValue(1, value);
            }
        }
        /// <summary>
        /// 第二种胶料实际值
        /// </summary>
        public double PlyCurrentValue2
        {
            get { return this._plyCurrentValue2; }
            set
            {
                this._plyCurrentValue2 = value;
                this.RefreshCurrentValue(2, value);
            }
        }
        /// <summary>
        /// 第三种胶料实际值
        /// </summary>
        public double PlyCurrentValue3
        {
            get { return this._plyCurrentValue3; }
            set
            {
                this._plyCurrentValue3 = value;
                this.RefreshCurrentValue(3, value);
            }
        }
        /// <summary>
        /// 第四种胶料实际值
        /// </summary>
        public double PlyCurrentValue4
        {
            get { return this._plyCurrentValue4; }
            set
            {
                this._plyCurrentValue4 = value;
                this.RefreshCurrentValue(4, value);
            }
        }
        /// <summary>
        /// 第五种胶料实际值
        /// </summary>
        public double PlyCurrentValue5
        {
            get { return this._plyCurrentValue5; }
            set
            {
                this._plyCurrentValue5 = value;
                this.RefreshCurrentValue(5, value);
            }
        }
        /// <summary>
        /// 第六种胶料实际值
        /// </summary>
        public double PlyCurrentValue6
        {
            get { return this._plyCurrentValue6; }
            set
            {
                this._plyCurrentValue6 = value;
                this.RefreshCurrentValue(6, value);
            }
        }
        /// <summary>
        /// 第七种胶料实际值
        /// </summary>
        public double PlyCurrentValue7
        {
            get { return this._plyCurrentValue7; }
            set
            {
                this._plyCurrentValue7 = value;
                this.RefreshCurrentValue(7, value);
            }
        }
        /// <summary>
        /// 第八种胶料实际值
        /// </summary>
        public double PlyCurrentValue8
        {
            get { return this._plyCurrentValue8; }
            set
            {
                this._plyCurrentValue8 = value;
                this.RefreshCurrentValue(8, value);
            }
        }
        /// <summary>
        /// 第九种胶料实际值
        /// </summary>
        public double PlyCurrentValue9
        {
            get { return this._plyCurrentValue9; }
            set
            {
                this._plyCurrentValue9 = value;
                this.RefreshCurrentValue(9, value);
            }
        }
        /// <summary>
        /// 第十种胶料实际值
        /// </summary>
        public double PlyCurrentValue10
        {
            get { return this._plyCurrentValue10; }
            set
            {
                this._plyCurrentValue10 = value;
                this.RefreshCurrentValue(10, value);
            }
        }
        /// <summary>
        /// 第十一种胶料实际值
        /// </summary>
        public double PlyCurrentValue11
        {
            get { return this._plyCurrentValue11; }
            set
            {
                this._plyCurrentValue11 = value;
                this.RefreshCurrentValue(11, value);
            }
        }
        /// <summary>
        /// 第十二种胶料实际值
        /// </summary>
        public double PlyCurrentValue12
        {
            get { return this._plyCurrentValue12; }
            set
            {
                this._plyCurrentValue12 = value;
                this.RefreshCurrentValue(12, value);
            }
        }
        /// <summary>
        /// 第十三种胶料实际值
        /// </summary>
        public double PlyCurrentValue13
        {
            get { return this._plyCurrentValue13; }
            set
            {
                this._plyCurrentValue13 = value;
                this.RefreshCurrentValue(13, value);
            }
        }
        /// <summary>
        /// 第十四种胶料实际值
        /// </summary>
        public double PlyCurrentValue14
        {
            get { return this._plyCurrentValue14; }
            set
            {
                this._plyCurrentValue14 = value;
                this.RefreshCurrentValue(14, value);
            }
        }
        /// <summary>
        /// 第十五种胶料实际值
        /// </summary>
        public double PlyCurrentValue15
        {
            get { return this._plyCurrentValue15; }
            set
            {
                this._plyCurrentValue15 = value;
                this.RefreshCurrentValue(15, value);
            }
        }

        #endregion

        #region 辅助方法

        private void RefreshCurrentValue(int step, double values)
        {
            if (this._currentRecipPly15 == 1 && step == 15)
            {
                getValues(15, values);
            }
            if (this._currentRecipPly14 == 1 && step == 14)
            {
                getValues(14, values);
            }
            if (this._currentRecipPly13 == 1 && step == 13)
            {
                getValues(13, values);
            }
            if (this._currentRecipPly12 == 1 && step == 12)
            {
                getValues(12, values);
            }
            if (this._currentRecipPly11 == 1 && step == 11)
            {
                getValues(11, values);
            }
            if (this._currentRecipPly10 == 1 && step == 10)
            {
                getValues(10, values);
            }
            if (this._currentRecipPly9 == 1 && step == 9)
            {
                getValues(9, values);
            }
            if (this._currentRecipPly8 == 1 && step == 8)
            {
                getValues(8, values);
            }
            if (this._currentRecipPly7 == 1 && step == 7)
            {
                getValues(7, values);
            }
            if (this._currentRecipPly6 == 1 && step == 6)
            {
                getValues(6, values);
            }
            if (this._currentRecipPly5 == 1 && step == 5)
            {
                getValues(5, values);
            }
            if (this._currentRecipPly4 == 1 && step == 4)
            {
                getValues(4, values);
            }
            if (this._currentRecipPly3 == 1 && step == 3)
            {
                getValues(3, values);
            }
            if (this._currentRecipPly2 == 1 && step==2)
            {
                getValues(2, values);
            }
            if (this._currentRecipPly1 == 1 && step == 1)
            {
                getValues(1, values);
            }
        }

        private void getValues(int step,double values)
        {
            if (this._cloneData != null)
            {
                if (this._cloneData.Columns.Contains("序号") && this._cloneData.Columns.Contains("设定"))
                {
                    for (int i = 0; i < this._cloneData.Rows.Count; i++)
                    {
                        if (step == int.Parse(this._cloneData.Rows[i]["序号"].ToString()))
                        {
                            this.Text =  Convert.ToDecimal((values - double.Parse(this._cloneData.Rows[i]["设定"].ToString())).ToString()).ToString("f2");
                        }
                    }
                }
            }
        }

        #endregion
    }
}