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 DevComponents.DotNetBar;
using System.Data.SqlClient;
namespace amlak_keshavarzi
{
    public partial class login : DevComponents.DotNetBar.Metro.MetroForm
    {
        public login()
        {
            InitializeComponent();
        }

        static SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\keshavarzi.mdf;Integrated Security=True");
        SqlDataAdapter da = new SqlDataAdapter("",con);
        DataSet ds = new DataSet();

        private void clear()
        {
            txt_username.Clear();
            txt_password.Clear();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
           
           string s = "select password from login where username='"+txt_username.Text+"'and password='"+txt_password.Text+"'";
           SqlDataAdapter da = new SqlDataAdapter(s, con);
           da.Fill(ds, "t1");
           if (ds.Tables["t1"].Rows.Count > 0)
           {
               this.Hide();
               main m = new main();
               m.Show();
           }

           else
           {
               MessageBox.Show("نام کاربری یا رمز عبور اشتباه است","خطا");
               clear();
               txt_username.Focus();
           }
           
          
           
        }

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

        private void btn_login_KeyPress(object sender, KeyPressEventArgs e)
        {
            btn_login_Click(sender,e);
        }

        private void btn_cancel_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)27)
                this.Close();
        }
       



    }
}
