using System.Collections.Generic;
using System;
using System.Drawing;
using System.Diagnostics;
using System.Data;
using System.Collections;
using System.Windows.Forms;
using AR;
using System.Windows.Media;
using System.ComponentModel;

namespace vmsnet
{
    public class CTrendSetting : AR.Setting
    {
        [Browsable(false)]
        public DateTime graph_time_start { get; set; }
        [Browsable(false)]
        public DateTime graph_time_end { get; set; }



        [Category("Y-Axis"), DisplayName("Y축 표시영역(시작)"), Description("Y축 그래프의 시작범위 입니다(voltage)")]
        public float graph_y_start { get; set; }
        [Category("Y-Axis"), DisplayName("Y축 표시영역(종료)"), Description("Y축 그래프의 종료범위 입니다(voltage)")]

        public float graph_y_end { get; set; }
        [Category("X-Axis"), DisplayName("X축 바닥영역 최소 크기"), Description("X축 바닥 글자 영역의 최소 크기 입니다. 글자가 가려지는 경우 이값을 늘려주세요")]

        public float graph_bottom_minsize { get; set; }
        [Category("Y-Axis"), DisplayName("Y축영역 자동설정"), Description("Y축 영역을 자동으로 설정합니다. 입력된 값에 따라서 자동으로 변경 됩니다")]
        public bool y_scale_auto { get; set; }



        [Browsable(false)]
        public string tv_selectgroup0 { get; set; }
        [Browsable(false)]

        public string tv_selectgroup { get; set; }
        public override void AfterLoad()
        {
            if ((graph_y_end < graph_y_start) || (graph_y_start == 0f && graph_y_end == 0f))
                y_scale_auto = true;

            if (graph_time_end.Year == 1982 || graph_time_start.Year == 1982)
            {
                graph_time_end = DateTime.Now;
                graph_time_start = graph_time_end.AddDays(-7);
            }

            if (graph_bottom_minsize < 1) graph_bottom_minsize = 45;


        }
        public override void AfterSave()
        {

        }
    }
    public class CDesignSetting : AR.Setting
    {
        public string font_nb { get; set; }
        public string font_cellname { get; set; }
        public string font_cellvalue { get; set; }
        public string font_summary { get; set; }
        public string font_celltitle { get; set; }
        public string font_alarmvalue { get; set; }

        public string font_kaValue { get; set; }
        public string font_kaUnit { get; set; }
        public override void AfterLoad()
        {
            if (font_nb.isEmpty()) font_nb = "Tahoma,35,1";
            if (font_cellname.isEmpty()) font_cellname = "Tahoma,7,1";
            if (font_cellvalue.isEmpty()) font_cellvalue = "Tahoma,8,1";
            if (font_summary.isEmpty()) font_summary = "Tahoma,10,1";
            if (font_celltitle.isEmpty()) font_celltitle = "Tahoma,8,1";
            if (font_alarmvalue.isEmpty()) font_alarmvalue = "Tahoma,7,1";
            if (font_kaValue.isEmpty()) font_kaValue = "Arial,40,1";
            if (font_kaUnit.isEmpty()) font_kaUnit = "Arial,10,1";
        }
        public override void AfterSave()
        {

        }
    }
    
    public class CSetting : AR.Setting
    {
        public int Startup_DelayTime_Alam { get; set; }
        public int Startup_DelayTime_Save { get; set; }

        public int MaxChCount { get; set; }

        public bool EnableKA { get; set; }
        public bool alamplc { get; set; }
        public string plc_port { get; set; }
      
        public int plc_addr { get; set; }
        public string bugreport { get; set; }

        public int viewSize { get; set; }
        public int datadiv { get; set; }
        public bool nullbalnce { get; set; }
        public bool Sumab { get; set; }

        public string databasefolder { get; set; }
        public bool binarysave { get; set; }
        public bool synctime { get; set; }
        //Public Property ascii As Boolean
        //public bool autorun { get; set; } ////Monitor Auto Run
        public bool lsb { get; set; }

        /// <summary>
        /// 서브윈도우가 open/close 될때 설정 됨
        /// </summary>
        public bool opensubwindow { get; set; }
        public short trashper { get; set; } ////자동삭제용량단위
        public short saveterm { get; set; }
        public bool seconddata { get; set; }
        public bool thirddata { get; set; }
        public bool getdata4 { get; set; }
        public bool sound { get; set; }


        public string dbtype { get; set; }
        public string sangho { get; set; }
        public int threadlimit { get; set; }
        public string tel { get; set; }
        public int graph_time_day { get; set; }
        public int graph_time_hour { get; set; }
        public int graph_time_min { get; set; }
        public int graph_line_width { get; set; }
        public int graph_starty { get; set; }
        public int graph_endy { get; set; }

        public string win1pos { get; set; }
        public string win2pos { get; set; }


        public int tvr_selectgroup0 { get; set; }
        public int tvr_selectgroup { get; set; }
        public int cell_voltindex { get; set; }
        public int cell_timeindex { get; set; }

        ////150319
        public int maintv_xgap { get; set; } ////개별전해조보기에서 X 축 표시간격
        public float maintv_ygap { get; set; } ////개별전해조보기에서 Y 축 표시간격
        public int maintv_xterm { get; set; } ////개별전해조보기에서 X 축 표시범위
        public int maintv_winsize { get; set; } ////개별전해조보기의 창 크기

        public int meas_pri1 { get; set; } ////1번째 수집명령의 시작값
        public int meas_pri2 { get; set; } ////1번째 수집명령의 종료값
        public int meas_sec1 { get; set; } ////2번째 수집명령의 시작값
        public int meas_sec2 { get; set; } ////2번째 수집명령의 종료값
        public int meas_3rd1 { get; set; } ////2번째 수집명령의 시작값
        public int meas_3rd2 { get; set; } ////2번째 수집명령의 종료값
        public int meas_4th1 { get; set; } ////2번째 수집명령의 시작값
        public int meas_4th2 { get; set; } ////2번째 수집명령의 종료값

        public string grp0chlist { get; set; }
        public string grp1chlist { get; set; }
        public string grp2chlist { get; set; }
        public string grp3chlist { get; set; }
        public string grp4chlist { get; set; }
        public string grp5chlist { get; set; }
        public string grp6chlist { get; set; }
        public string grp7chlist { get; set; }
        public string grp8chlist { get; set; }
        public string grp9chlist { get; set; }

        public string indicator_port { get; set; }
        public int indicator_baud { get; set; }
        public int indicator_slaveno { get; set; }



        public CSetting()
        {
            bugreport = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bugreport");
        }

        public override void AfterLoad()
        {
            ////버그리포트 폴더가 없다면 생성한다.
            if (bugreport.isEmpty() == false && System.IO.Directory.Exists(bugreport) == false)
                System.IO.Directory.CreateDirectory(bugreport);

            //시작지연시간
            if (Startup_DelayTime_Alam < 1) Startup_DelayTime_Alam = 10;
            if (Startup_DelayTime_Save < 1) Startup_DelayTime_Save = 5;

            if (indicator_baud == 0) indicator_baud = 9600;
            if (threadlimit < 500) threadlimit = 500;

            if (MaxChCount < 1) MaxChCount = 10;
            if (meas_pri1 == 0 && meas_pri2 == 0)
            {
                //0번유닛 1번채널 부터~1번유닛 60번채널
                meas_pri1 = 001;
                meas_pri2 = 160;
            }
            if (meas_sec1 == 0 && meas_sec2 == 0)
            {
                //2번유닛 1번채널 부터~3번유닛 60번채널
                meas_sec1 = 201;
                meas_sec2 = 360;
            }

            if (meas_3rd1 == 0 && meas_3rd1 == 0)
            {
                //4번유닛 1번채널 부터~5번유닛 60번채널
                meas_3rd1 = 401;
                meas_3rd1 = 560;
            }

            if (meas_4th1 == 0 && meas_4th2 == 0)
            {
                //4번유닛 1번채널 부터~5번유닛 60번채널
                meas_4th1 = 601;
                meas_4th2 = 560;
            }

            //if (viewSize.IsNumeric() == false) viewSize = "300";   //240622

            ////트렌드뷰용 데이터정보
            if (maintv_xgap == 0) maintv_xgap = 300;
            if (maintv_xterm == 0) maintv_xterm = 3600;
            if (maintv_ygap == 0) maintv_ygap = 0.5f;
            if (maintv_winsize == 0) maintv_winsize = 50;

            ////일반설정
            if (tvr_selectgroup0 == 0) tvr_selectgroup0 = 0;
            if (tvr_selectgroup == 0) tvr_selectgroup = 0;

            ////그래프설정
            if (win1pos.isEmpty()) win1pos = "10,10";
            if (win2pos.isEmpty()) win2pos = "10,10";

            if (viewSize < 1) viewSize = 300;
            if (graph_time_day < 1) viewSize = 0;
            if (graph_time_hour < 1) viewSize = 0;
            if (graph_time_min < 1) viewSize = 45;
            if (graph_endy < 1) viewSize = 5;

            try
            {
                ////백업한다.
                System.IO.File.Copy("setting.xml", "setting~.xml", true);
            }
            catch { }
        }

        public string GetDatabasePath()
        {
            if (databasefolder.isEmpty())
            {
                //트렌드와 알람은 상위폴더를 반환해야한다
                var di = new System.IO.DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
                return di.FullName;
            }
            else return databasefolder;
        }


        public override void AfterSave()
        {
            //throw new NotImplementedException();
        }
    }

}
