using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AzmoonGir
{
    public partial class FrmTime : Form
    {
        public FrmTime()
        {
            InitializeComponent();
        }

        private void FrmTime_Load(object sender, EventArgs e)
        {
            try
            {
                txttime.Text = Properties.Settings.Default.Qtime.ToString();
            }
            catch
            {
                txttime.Text = "25";
                Properties.Settings.Default.Qtime = Convert.ToInt32(txttime.Text.Trim());
                Properties.Settings.Default.Save();
            }


        }
        
        private void btnsave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txttime.Text))
            {
                errorProvider1.SetError(txttime, "زمان را وارد کنید");
            }

            else if (Convert.ToInt32(txttime.Text) < 5)
            {
                errorProvider1.SetError(txttime, "زمان پاسخگویی به سوالات نمی تواند کمتر از 5 ثانیه باشد");
            }
            else
            {
                Properties.Settings.Default.Qtime = Convert.ToInt32(txttime.Text.Trim());
                Properties.Settings.Default.Save();
                this.Close();
            }
        }

        private void txttime_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Convert.ToInt16(e.KeyChar) <= 57 & Convert.ToInt16(e.KeyChar) >= 48 || Convert.ToInt16(e.KeyChar) == 8)
            {
            }
            else
            {
                e.KeyChar = Convert.ToChar(Keys.None);
            }
        } 
    }
}
