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 System.Data.SqlClient;

namespace Ajans
{
    public partial class Form1 : Form
    {
        String StrConn;
        String StrQ;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StrQ = "";

            SqlConnection myConn;
            SqlCommand myComm;
            SqlDataReader myDR;
          
            try
            {

                StrConn = "Data Source=.;Initial Catalog=Havapeyma;Integrated Security=True";
                StrQ = "SELECT * FROM [Admin] WHERE (([UserName] = @UserName) AND ([Password] = @Pass))";
                myConn = new SqlConnection(StrConn);
                myComm = new SqlCommand();
                myComm.Connection = myConn;
                myComm.CommandType = CommandType.Text;
                myComm.CommandText = StrQ;
                myComm.Parameters.Add("UserName", SqlDbType.NVarChar, 50).Value = this.textBox1.Text;
                myComm.Parameters.Add("Pass", SqlDbType.NVarChar, 50).Value = this.textBox2.Text;
                myConn.Open();
                myDR = myComm.ExecuteReader();

                if (myDR.Read())
                {
                    Form2 F2 = new Form2();
                    F2.ShowDialog();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("نام کاربری یا کلمه عبور صحیح نمی باشد","خطا");
                    textBox1.Text = ""; textBox2.Text = ""; textBox1.Focus();
                }
                myConn.Close();
            }
            catch (Exception) { }
        }

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