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;

namespace vmsnet
{
  
    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 string bugreport { get; set; }

    

        public string databasefolder { get; set; }
    

     
        
        public int threadlimit { 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; }
      

        ////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 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 (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";

            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.Parent.FullName;
            }
            else return databasefolder;
        }


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

}
