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;
using FarsiMsgBox;

namespace ajans
{
    public partial class form_login : Form
    {

        DataView objdv;

        public form_login()
        {
            InitializeComponent();
        }

        private void txtuser_TextChanged(object sender, EventArgs e)
        {
            lbluser.Text = "";
            lblpass.Text = "";
        }

        private void txtpass_TextChanged(object sender, EventArgs e)
        {
            lbluser.Text = "";
            lblpass.Text = "";
        }

        private void login_Click(object sender, EventArgs e)
        {
            login Login = new login();
            objdv = new DataView(Login.SelectAccountLogin().Tables["login"]);
            lbluser.DataBindings.Clear();
            lbluser.DataBindings.Add("text", objdv, "user_name");
            lblpass.DataBindings.Clear();
            lblpass.DataBindings.Add("text", objdv, "password");
            if (lbluser.Text != txtuser.Text || lblpass.Text != txtpass.Text) FarsiMessage.ShowMessageBox("نام کاربری یا رمز عبور اشتباه می باشد.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
            else
            {
                this.Hide();
                form_splash frmSplash = new form_splash();
                frmSplash.Show();
            }
        }

        private void exit_Click(object sender, EventArgs e)
        {
            this.Opacity = 1;
            for (int i = 100; i > 1; i--)
            {
                this.Opacity -= 0.01;
                Application.DoEvents();
            }
            Application.Exit();
        }

        private void txtuser_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                login Login = new login();
                objdv = new DataView(Login.SelectAccount(txtuser.Text, txtpass.Text).Tables["login"]);
                lbluser.DataBindings.Clear();
                lbluser.DataBindings.Add("text", objdv, "user_name");
                lblpass.DataBindings.Clear();
                lblpass.DataBindings.Add("text", objdv, "password");
                if (lbluser.Text != txtuser.Text || lblpass.Text != txtpass.Text) FarsiMessage.ShowMessageBox("نام کاربری یا رمز عبور اشتباه می باشد.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
                else
                {
                    form_splash frmSplash = new form_splash();
                    frmSplash.Show();
                    this.Hide();
                }
            }
        }

        private void txtpass_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                login Login = new login();
                objdv = new DataView(Login.SelectAccount(txtuser.Text, txtpass.Text).Tables["login"]);
                lbluser.DataBindings.Clear();
                lbluser.DataBindings.Add("text", objdv, "user_name");
                lblpass.DataBindings.Clear();
                lblpass.DataBindings.Add("text", objdv, "password");
                if (lbluser.Text != txtuser.Text || lblpass.Text != txtpass.Text) FarsiMessage.ShowMessageBox("نام کاربری یا رمز عبور اشتباه می باشد.", "پیغام", ShowButton.تائید_تنها, MsgIcon.Information_1);
                else
                {
                    form_splash frmSplash = new form_splash();
                    frmSplash.Show();
                    this.Hide();
                }
            }
        }

        private void form_login_Load(object sender, EventArgs e)
        {

        }

    }
}
