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 SMSActivation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int _hour;
        int _minute;
        int _second;

        string _code = string.Empty;
        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            _code=rnd.Next(1000,9999).ToString();

            PARSGREEN.API_SendSMS.SendSMS send = new PARSGREEN.API_SendSMS.SendSMS();
            int successCount = 0;
            string[] returnStr = null;
            int retStatus = send.SendGroupSMS("", "", new string[] { txtMobile.Text }, _code, false, string.Empty, ref successCount, ref returnStr);

            lblMobile.Visible = false;
            txtMobile.Visible = false;
            button1.Visible = false;

            lblCode.Visible = true;
            lblRemainingTime.Visible = true;
            button2.Visible = true;
            lblRem.Visible = true;
            txtCode.Visible = true;

            _hour = 00;
            _minute = 03;
            _second = 00;

            lblRemainingTime.ForeColor = Color.Black;

            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (_minute == 0 && _hour == 0 && _second == 0)
            {
                timer1.Enabled = false;
                lblCode.Visible = false;
                lblRemainingTime.Visible = false;
                button2.Visible = false;
                lblRem.Visible = false;
                txtCode.Visible = false;

                lblMobile.Visible = true;
                txtMobile.Visible = true;
                button1.Visible = true;
            }
            else
            {
                if (_second < 1)
                {
                    _second = 59;
                    if (_minute == 0)
                    {
                        _minute = 59;
                        if (_hour != 0)
                            _hour -= 1;
                    }
                    else
                    {
                        _minute -= 1;
                    }
                }
                else
                    _second -= 1;

                lblRemainingTime.Text = _hour <= 9 ? "0" + _hour.ToString() + ":" : _hour.ToString() + ":";
                lblRemainingTime.Text += _minute <= 9 ? "0" + _minute.ToString() + ":" : _minute.ToString() + ":";
                lblRemainingTime.Text += _second <= 9 ? "0" + _second.ToString() : _second.ToString();

                if (_minute == 0 && _hour == 0 && _second < 60)
                    lblRemainingTime.ForeColor = Color.Red;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (_code == txtCode.Text)
            {
                panel1.Visible = false;
                timer1.Enabled = false;
            }
                
            else
                txtCode.Text = string.Empty;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
    }
}
