using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing;

namespace vmsnet.HMI
{
    [TypeConverterAttribute(typeof(ExpandableObjectConverter)),Serializable()]
    public partial class CGROUP
    {
        private int idx;
        private int widx;
        private String title;
        private int row;
        private int column;
        private int rspan;
        private int cspan;
        private int rowcount;
        private int columncount;
        private String matrix;
        private RectangleF rect;
        private Font cellfont;
        private Color cellfontcolor;
        public String maxcellname = "#999";
        public String maxcellvalue = "00.000";
        public String maxcellalam = "↑0↓0";
        private String _alamtype;

        
        public CITEM[] itemarray;

        private RectangleF[] cellgroup;
        private Single cellgroup_width;
        private Single cellgroup_height;
        public Single _cell_title_width;
        public Single _cell_value_width;
        public Single _cell_alam_width;
        public short _null_itemseq;
        public Single _null_valueL;
        public Single _null_valueR;
        private Single _null_offset;    //옵셋

        public RectangleF Rect_Title;
        public RectangleF Rect_Header;
        public RectangleF Rect_body;

        private Single alamh;   //상위알람
        private Single alaml;   //하위알람
        private Single aalamh;   //상위알람
        //private Single aalaml;   //하위알람
        //public Single nbhh;
        public Single nbh;
        //public Single nbll;
        public Single nbl;

        public Boolean _pre_nbalam_h=false;
        public Boolean _pre_nbalam_l=false;
        public Boolean _nbalam_h = false;
        public Boolean _nbalam_l = false;
        
        public Single _amp;         //KAVALUE
        public String _ampidx;      //KAINDEX
        public String _ampunit;     //KAINDEX
        public short _ampdecpos;    //KAINDEX

        public Single _maxvolt;
        public Single _avgvolt;
        public Single _minvolt;
        public Single _sumvolt;     //전체합계
        public Single _sumvolt1;     //분주된SUm
        public Single _sumvoltA;    //전체합계(A)
        public Single _sumvoltB;    //전체합계(B)


        public short _alamcount=0;
        public short _alamcountlb = 0;

        public CITEM _maxitem = null;
        public CITEM _minitem = null;
        public CITEM _maxitemp = null;
        public CITEM _minitemp = null;

        public Boolean Showinfo=false;
        
        public delegate void OnChangeDataHandler();
        public event OnChangeDataHandler OnChangeData;
        
        public int _unusedcount = 0; //미사용채널수
        public int _errorcount = 0; //에러난채널수
        public int _disccount = 0; //에러난채널수


        public CGROUP()
        {
            _sumvolt = 0;
            _sumvolt1 = 0;
            _sumvoltA = 0;
            _sumvoltB = 0;
            _maxvolt = 0;
            _minvolt = 0;
            _avgvolt = 0;
            _errorcount = 0;
            _disccount = 0;
            idx = 0;
            widx = 0;
            row = 0;
            column = 0;
            columncount = 2;
            rowcount = 15;
            rspan = 1;
            cspan = 1;
            matrix = "15x2";
            title = "TINDEVIL";
            rect = new RectangleF(0, 0, 0, 0);
            cellfont = new Font("나눔고딕", 10, FontStyle.Bold);
            cellfontcolor = Color.Black;
            cellgroup = new RectangleF[1];
            Items = new CITEM[0];
        }

        [System.ComponentModel.Browsable(false)]
        public Single Sumvolt
        {
            get { return _sumvolt; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Sumvolt1
        {
            get { return _sumvolt1; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single SumvoltA
        {
            get { return _sumvoltA; }
        }
        [System.ComponentModel.Browsable(false)]
        public Single SumvoltB
        {
            get { return _sumvoltB; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Maxvolt
        {
            get { return _maxvolt; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Minvolt
        {
            get { return _minvolt; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Avgvolt
        {
            get { return _avgvolt; }
        }

        //[System.ComponentModel.Browsable(false)]
        //public Single AmpKA
        //{
        //    get { return _ampka; }
        //}
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),Browsable(false), Category("알람"), Description("그룹에 지정된 알람형태입니다. Manual 과 Auto 가 있으며 변경을 하시려면 알람설정(alam Setup)을 이용하세요.")]
        public String AlarmType
        {
            get { return  _alamtype; }
            set { _alamtype = value; }
           
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false), Category("알람수동"), Description("그룹에 지정되는 상위알람값입니다. 셀의 알람설정이 그룹으로 지정되었다면 이 값이 사용됩니다.")]
        public Single HIGH
        {
            get { return alamh; }
            set { alamh = value;
            if (OnChangeData != null) OnChangeData();
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false), Category("알람수동"), Description("그룹에 지정되는 하위알람값입니다. 셀의 알람설정이 그룹으로 지정되었다면 이 값이 사용됩니다.")]
        public Single LOW
        {
            get { return alaml; }
            set { alaml = value;
            if (OnChangeData != null) OnChangeData(); 
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false), Category("알람자동"), Description("그룹에 지정되는 상위알람값입니다. 셀의 알람설정이 그룹으로 지정되었다면 이 값이 사용됩니다.")]
        public Single UP
        {
            get { return aalamh; }
            set
            {
                aalamh = value;
                if (OnChangeData != null) OnChangeData(); 
            }
        }

        //[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false), Category("알람자동"), Description("그룹에 지정되는 하위알람값입니다. 셀의 알람설정이 그룹으로 지정되었다면 이 값이 사용됩니다.")]
        //public Single DOWN
        //{
        //    get { return aalaml; }
        //    set
        //    {
        //        aalaml = value;
        //        try { OnChangeData(); }
        //        catch { }
        //    }
        //}


        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),Browsable(false), Category("일반"), Description("Null Balance 보정값입니다.")]
        public Single NullBalanceOffset
        {
            get { return this._null_offset; }
            set { this._null_offset = value;
            if (OnChangeData != null) OnChangeData(); 
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false), Category("일반"), Description("Null Balance 기준 아이템번호입니다.")]
        public short NullBalanceSeq
        {
            get { return this._null_itemseq; }
            set
            {
                this._null_itemseq = value;
                if (OnChangeData != null) OnChangeData(); 
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("셀표시 글꼴의 색상입니다."),Browsable(false)]
        public Color 셀글꼴색상
        {
            get { return this.cellfontcolor; }
            set { this.cellfontcolor = value;
            if (OnChangeData != null) OnChangeData(); 
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("셀표시 글꼴입니다.")]
        public Font 셀글꼴
        {
            get { return this.cellfont; }
            set { this.cellfont = value;
            if (OnChangeData != null) OnChangeData(); 
            }
        }

        [System.ComponentModel.Browsable(false)]
        public RectangleF[] CellGroup
        {
            get { return this.cellgroup; }
            set { this.cellgroup = value; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single CellGroup_Height
        {
            get { return cellgroup_height; }
            set { cellgroup_height = value; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single CellGroup_Width
        {
            get { return cellgroup_width; }
            set { cellgroup_width = value; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Cell_Title_Width
        {
            get { return _cell_title_width; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Cell_Value_Width
        {
            get { return _cell_value_width; }
        }

        [System.ComponentModel.Browsable(false)]
        public Single Cell_Alam_Width
        {
            get { return _cell_alam_width; }
        }

        [System.ComponentModel.Browsable(false)]
        public int ColumnCount
        {
            get { return columncount; }
        }

        [System.ComponentModel.Browsable(false)]
        public int RowCount
        {
            get { return rowcount; }
        }

        /// <summary>
        /// 내부아이템
        /// </summary>
        [System.ComponentModel.Browsable(false)]
        public CITEM[] Items
        {
            get { return itemarray; }
            set { itemarray = value; }
        }

        /// <summary>
        /// 이그룹의 전체 영역
        /// </summary>
        [System.ComponentModel.Browsable(false)]
        public RectangleF R
        {
            get { return rect; }
            set { rect = value; }

        }

        /// <summary>
        /// 그룹의일련번호
        /// </summary>
        [System.ComponentModel.Browsable(false)]
        public int IDX
        {
            get { return idx; }
            set { idx = value; }
        }

        /// <summary>
        /// ROWSPAN
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("이 그룹이 표시되는데 사용되는 줄병합 갯수입니다.(기본값:1)"), System.ComponentModel.Browsable(false)]
        public int 줄병합
        {
            get { return rspan; }
            set { rspan = value; }
        }

        /// <summary>
        /// COLUMNSPAN
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("이 그룹이 표시되는데 사용되는 열병합 갯수입니다.(기본값:1)"), System.ComponentModel.Browsable(false)]
        public int 열병합
        {
            get { return cspan; }
            set { cspan = value; }
        }

        /// <summary>
        /// WINDOW IDX
        /// </summary>
        [System.ComponentModel.Browsable(false)]
        public int WIDX
        {
            get { return widx; }
            set { widx = value; }
        }

        /// <summary>
        /// LOCATION COLUmN
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("이 그룹이 표시되는데 사용되는 열의 위치값입니다."), System.ComponentModel.Browsable(false)]
        public int 열번호
        {
            get { return this.column; }
            set { column = value; }
        }

        /// <summary>
        /// LOCATION ROW
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("이 그룹이 표시되는데 사용되는 줄의 위치값입니다."), System.ComponentModel.Browsable(false)]
        public int 줄번호
        {
            get { return this.row; }
            set { row = value; }
        }

        /// <summary>
        /// MATRIX ARRAY
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("이 그룹이 표시되는 아이템의 배열을 표시합니다. 20x2 일경우 총 40개의 셀이 배치됩니다."), System.ComponentModel.Browsable(false)]
        public String 아이템배열
        {
            get { return this.matrix; }
            set
            {
                matrix = value;
                matrix = matrix.Replace("*", "x").Replace("X", "x").Replace("/", "x").Replace("-", "x");
                rowcount = int.Parse(matrix.Split(new char[] { 'x' })[0]);
                columncount = int.Parse(matrix.Split(new char[] { 'x' })[1]);
                cellgroup = new RectangleF[columncount];                
                itemarray = new CITEM[(rowcount * columncount) - 1];
            }
        }

        /// <summary>
        /// THIS NAME
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("일반"), Description("이 그룹의 이름입니다.")]
        public String 이름
        {
            get { return this.title; }
            set { title = value;
            if (OnChangeData != null) OnChangeData(); 
            }
        }
    }
}
