using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Project
{
    public enum eFormList
    {
        없음 = 0,
        NR구매관리,
        프로젝트관리,
        업무일지,
        재고관리,
        재고현황,
        근태입력,
        품목입고,
    }
    public enum eToolPosition
    {
        Left = 0,
        Right,
        Top,
        Bottom,
        Hide,
    }
    public class Setting : arUtil.Setting
    {
        #region "log"

        [Browsable(false)]
        public Boolean Log_IO { get; set; }

        #endregion

        [DisplayName("업무일지8시간초과입력불가"), Description("업무일지 근무시간 란에 8시간을 초과 입력 할 수 없게 합니다")]
        public Boolean Disable8HourOver { get; set; }

        //[DisplayName("원달러환율")]
        //public double wondoller { get; set; }
        [Description("시작 화면")]
        public eFormList startForm { get; set; }

        [Description("중복으로 창을 열수 있습니다")]
        public Boolean DupWindow { get; set; }

        [Description("Password for Setting")]
        [Browsable(false)]
        public string Password_Setup { get; set; }

        [Description("Password for UserSetting")]
        [Browsable(false)]
        public string Password_User { get; set; }

        [Description("Display Language"), DisplayName("Language")]
        public string Language { get; set; }

        [Description("Full Screen Window")]
        public Boolean FullScreen { get; set; }

        public string SharedDataPath { get; set; }

        [Category("구매"), DisplayName("오류항목표시")]
        public Boolean Showbuyerror { get; set; }

        [DisplayName("업무일지 미리보기 창 숨김")]
        public Boolean NotShowJobreportPRewView { get; set; }

        [Category("Barcode"), DisplayName("Port Name")]
        public string Barcode { get; set; }

   

        [Browsable(false)]
        public string lastid { get; set; }
        [Browsable(false)]
        public string lastdpt { get; set; }
        [Browsable(false)]
        public string lastgcode { get; set; }
        public int CamIndex { get; set; }

        [DisplayName("Tool Bar")]
        public eToolPosition HideToolbar { get; set; }



        public Setting() : this(Util.CurrentPath + "setting.xml") { }




        public Setting(string file)
        {
            this.filename = file;
            var fi = new System.IO.FileInfo(this.filename);
            if (fi.Directory.Exists == false) fi.Directory.Create();
            if (fi.Exists == false)
            {
                this.Load();
                this.Save();
            }
        }

        public override void AfterLoad()
        {
            if (Language.isEmpty()) Language = "Kor";
            if (Password_Setup.isEmpty()) Password_Setup = "0000";
            if (Password_User.isEmpty()) Password_User = "9999";

            var str_toolbar = Xml.get_Data("enum", "HideToolbar", "0");
            this.HideToolbar = (eToolPosition)int.Parse(str_toolbar);

            //시작폼가져오기
            var 시작품 = Xml.get_Data("startForm");
            var list = Enum.GetNames(typeof(eFormList));
            int idx = -1;
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] == 시작품)
                {
                    idx = i;
                }
            }
            if (idx == -1) this.startForm = eFormList.업무일지;
            else this.startForm = (eFormList)idx;

        }
        public override void AfterSave()
        {
            Xml.set_Data("enum", "HideToolbar", ((int)HideToolbar).ToString());
            Xml.Save();
        }
    }

    public class UserSetting : arUtil.Setting
    {
        public UserSetting() : this(Util.CurrentPath + "UserSet.xml") { }
        public UserSetting(string file)
        {
            this.filename = file;
            var fi = new System.IO.FileInfo(this.filename);
            if (fi.Directory.Exists == false) fi.Directory.Create();
            if (fi.Exists == false)
            {
                this.Load();
                this.Save();
            }
        }
        public override void AfterLoad()
        {
            //throw new NotImplementedException();
        }
        public override void AfterSave()
        {
            //throw new NotImplementedException();
        }
    }

}
