

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ChuPiao.Common.HD
{


    //系统配置文件读取
    public class IniConfig
    {

        private static IniConfig instance = new IniConfig();

        public static IniConfig Instance
        {
            get
            {
                return instance;
            }
        }
        private string INIPATH = HD.StartupPath + "\\configs\\Config.ini";
        public const string SELECTION = "DEFAULT";

        //是否是1064版本
        private string new1064 = "0";

        //按键 键与键的间隔
        private int keyInterval = GConfig.KEY_DELAY_IN_KEY ? 300:800;

        //和键与键的间隔 随机上浮值
        private int keyRandomFloat = 100;

        //票与票的间隔
        private int ticketInterval = 1000;

        //票与票随机上浮值
        private int ticketRandomFloat = 1000;


        



        public int getRandomKeyInterval() {
            return keyInterval + new Random().Next(keyRandomFloat);
        }


        public int getRandomTicketInterval()
        {
            return ticketInterval + new Random().Next(ticketRandomFloat);
        }



        public int KeyRandomFloat {
            get { return keyRandomFloat; }
            set { keyRandomFloat = value; }
        }



        public int TicketInterval
        {
            get { return ticketInterval; }
            set { ticketInterval = value; }
        }

  

        public int TicketRandomFloat
        {
            get { return ticketRandomFloat; }
            set { ticketRandomFloat = value; }
        }


        public int KeyInterval
        {
            get { return keyInterval; }
            set { keyInterval = value; }
        }

        //是否是1064版本
        public bool isNew1064
        {
            get { return "1".Equals(new1064); }
        }

        private IniConfig()
        {
            new1064 = HD.Ini_ReadP(SELECTION, "停止出票出纸", new1064, INIPATH);
            keyInterval = HD.Ini_ReadPInt(SELECTION, "键的间隔_ms", keyInterval, INIPATH);
            keyRandomFloat = HD.Ini_ReadPInt(SELECTION, "键随机上浮值_ms", keyRandomFloat, INIPATH);

            ticketInterval = HD.Ini_ReadPInt(SELECTION, "票的间隔_ms", ticketInterval, INIPATH);
            ticketRandomFloat = HD.Ini_ReadPInt(SELECTION, "票随机上浮值_ms", ticketRandomFloat, INIPATH);
        }


        public void saveKeyIntervalConfig()
        {
            HD.Ini_Write(SELECTION, "键的间隔_ms", keyInterval, INIPATH);
            HD.Ini_Write(SELECTION, "键随机上浮值_ms", keyRandomFloat, INIPATH);

            HD.Ini_Write(SELECTION, "票的间隔_ms", ticketInterval, INIPATH);
            HD.Ini_Write(SELECTION, "票随机上浮值_ms", ticketRandomFloat, INIPATH);
        }



    }
}
