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 The_Contacts
{
    public partial class SecurityCode : Form
    {
        public SecurityCode()
        {
            InitializeComponent();
        }
        string Captcha;
        void RefreshCaptcha()
        {
            CaptchaImage.CaptchaImage C = new CaptchaImage.CaptchaImage(RandomNumber(), 100, 39);
            pictureBox2.Image = C.Image;
            Captcha = C.Text;
        }
        private void SecurityCode_Load(object sender, EventArgs e)
        {
            RefreshCaptcha();
        }
        System.Speech.Synthesis.SpeechSynthesizer Speech = new System.Speech.Synthesis.SpeechSynthesizer();
        public string RandomNumber()
        {
            Random rnd = new Random();
            return rnd.Next(10000, 99999).ToString();
        }
        void SpeekCaptcha()
        {
            Speech.Volume = 100;
            foreach (Char objChar in Captcha.ToCharArray())
            {
                Speech.Speak(objChar.ToString());
            }
            btnSpeek.Enabled = btnRetry.Enabled = true;
        }

        private void btnRetry_Click(object sender, EventArgs e)
        {
            RefreshCaptcha();
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtSecurityCode.Text == Captcha)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("کد امنیتی صحیح نیست.","خطا",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

        private void btnSpeek_Click(object sender, EventArgs e)
        {
            SpeekCaptcha();
        }
    }
}
