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

namespace projectcsharp
{
    public partial class frm_login : Form
    {
        public frm_login()
        {
            InitializeComponent();
        }
        public SqlConnection con = new SqlConnection("server=(local);database=resturan;Integrated Security=True");
       
        private void btn_open_Click(object sender, EventArgs e)
        {
            SqlDataAdapter da = new SqlDataAdapter("select  username_ ,pass,limit  from tbl_users where username_= '" + txt_username.Text + "' and  pass ='" + txt_pas.Text + "' ", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            try
            {
                if ((txt_username.Text == dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString()) && (txt_pas.Text == dataGridView1[1, dataGridView1.CurrentRow.Index].Value.ToString()))
                {
                    if (dataGridView1[2, dataGridView1.CurrentRow.Index].Value.ToString() == "True")
                    {
                        Class1.limit = true;
                    }
                    Class1.login = true;
                    this.Close();
                }
            }
            catch
            {
                MessageBox.Show("نام کاربری یا رمز اشتباه است", "پیغام", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }

        }
        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void txt_username_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
                btn_open_Click(sender, e);
        }
        private void txt_pas_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
                btn_open_Click(sender, e);
        }

        private void frm_login_Load(object sender, EventArgs e)
        {

        }


    }
}
