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 university
{
    public partial class ramz : Form
    {
        
        public ramz()
        {
            InitializeComponent();
        }
        String StrConn;
        String StrQ;
            
       
           private void textBox1_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            char ch;
            ch = e.KeyChar;
            if (ch == '\r')
                textBox2.Focus();
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            char ch;
            ch = e.KeyChar;
            if (ch == '\r')
                button1.Focus();
        }
        private void ramz_Activated(object sender, EventArgs e)
        {
            textBox1.Focus();
        }
       

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

            SqlConnection myConn;
            SqlCommand myComm;
            SqlDataReader myDR;

            try
            {

                StrConn = "SERVER=.;DATABASE=university;Integrated Security=True";
                StrQ = "SELECT * FROM [ubur] WHERE (([kalame] = @kalame) AND ([Password] = @Password))";
                myConn = new SqlConnection(StrConn);
                myComm = new SqlCommand();
                myComm.Connection = myConn;
                myComm.CommandType = CommandType.Text;
                myComm.CommandText = StrQ;
                myComm.Parameters.Add("kalame", SqlDbType.NVarChar, 100).Value = this.textBox1.Text;
                myComm.Parameters.Add("Password", SqlDbType.NChar, 100).Value = this.textBox2.Text;
                myConn.Open();
                myDR = myComm.ExecuteReader();

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

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

        

        


      
    }
}

