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

namespace WareHouse
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("مقادیر فیلدها نمی توانند خالی باشند");
            }
            else
            {
                FirstClass dbCheck = new FirstClass();
                DataTable dtChek = new DataTable();

                dtChek = dbCheck.dbOut("SELECT     TOP 100 PERCENT UserName, Password FROM userInfo WHERE     (Password = '" + textBox2.Text.Trim() + "' AND UserName = '" + textBox1.Text.Trim() + "') ORDER BY UserName");
                if (dtChek.Rows.Count <= 0)
                {
                    MessageBox.Show("نام کاربری و کلمه عبور اشتباه وارد شده اند");
                }
                else
                {
                    GlobalClass.GlobalVar = textBox1.Text.Trim();
                    textBox1.Text = "";
                    textBox2.Text = "";
                    dtChek.Clear();
                    this.Visible = false;
                    frmMain frm = new frmMain();
                    frm.Show();
                }
            }
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            textBox1.RightToLeft = RightToLeft.No;
            textBox2.RightToLeft = RightToLeft.No;
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.CreateSpecificCulture("en"));
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                if (int.Parse(e.KeyValue.ToString()) == 13)
                {
                    button1.PerformClick();
                }
            }
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                if (int.Parse(e.KeyValue.ToString()) == 13)
                {
                    button1.PerformClick();
                }
            }
        }
    }
}