using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ChuPiao.Common.Utils;
using ChuPiao.AutoPrint.Services;

namespace ChuPiao.AutoPrint.Desktop.Dialogs
{
    public partial class DlgSetKeyInterval : Form
    {
        public DlgSetKeyInterval()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            int keyInterval = 200;
            if (radioButton1.Checked == true)
            {
                keyInterval = 0;
            }
            else if (radioButton2.Checked == true)
            {
                keyInterval = 50;
            }
            else if (radioButton3.Checked == true)
            {
                keyInterval = 100;
            }
            else if (radioButton4.Checked == true)
            {
                keyInterval = 150;
            }
            else if (radioButton5.Checked == true)
            {
                keyInterval = 200;
            }
            else
            {
                if (!Int32.TryParse(textBoxInput.Text.Trim(), out keyInterval))
                {
                    MessageService.ShowMessage("键码间隔请设置成整数值！");
                    return;
                }

            }

            LocalConfigUtil.KeyInterval = keyInterval;
            LocalConfigUtil.SaveConfig("KeyInterval", keyInterval.ToString());

            int ticketInterval;
            if (!Int32.TryParse(textBoxInput2.Text.Trim(), out ticketInterval))
            {
                MessageService.ShowMessage("票间隔请设置成整数值！");
                return;
            }
            LocalConfigUtil.TicketInterval = ticketInterval;
            LocalConfigUtil.SaveConfig("TicketInterval", ticketInterval.ToString());


            MessageService.ShowMessage("键码间隔【" + keyInterval.ToString() + "】，票间隔【" + ticketInterval.ToString() + "】，立即生效！");
            this.DialogResult = DialogResult.OK;
        }

        private void DlgSetKeyInterval_Load(object sender, EventArgs e)
        {
            if (LocalConfigUtil.KeyInterval == 0)
            {
                radioButton1.Checked = true;
            }
            else if (LocalConfigUtil.KeyInterval == 50)
            {
                radioButton2.Checked = true;
            }
            else if (LocalConfigUtil.KeyInterval == 100)
            {
                radioButton3.Checked = true;
            }
            else if (LocalConfigUtil.KeyInterval == 150)
            {
                radioButton4.Checked = true;
            }
            else if (LocalConfigUtil.KeyInterval == 200)
            {
                radioButton5.Checked = true;
            }
            else
            {
                radioButton6.Checked = true;
                this.textBoxInput.Text = LocalConfigUtil.KeyInterval.ToString();
            }

            this.textBoxInput2.Text = LocalConfigUtil.TicketInterval.ToString();
        }

    }
}