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

namespace WindowsApplication2
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlDataReader MyRead;
            sqlDataAdapter1.SelectCommand.Parameters.Clear();
            sqlDataAdapter1.SelectCommand.CommandText = "SELECT seller.* FROM seller WHERE nameSeller = @name AND familySeller = @password";
            sqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@name", textBox1.Text);
            sqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@password", textBox2.Text);
            sqlConnection1.Open();
            MyRead = sqlDataAdapter1.SelectCommand.ExecuteReader();
            if (MyRead.Read())
            {
                sqlConnection1.Close();
                this.Close();
            }
            else
            {
                textBox1.Text = "";
                textBox2.Text = "";
                sqlConnection1.Close();
            }
        }

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

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

        private void Form2_Load(object sender, EventArgs e)
        {

        }

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

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text=="") && (textBox2.Text==""))
            {
                MMDClassLibrary.MMessageBox box = new MMDClassLibrary.MMessageBox();
                box.ShowAlertMessage("لطفا نام کاربری و رمز عبور خود را وارد کنید ");
            }
            else
            {
            SqlDataReader MyRead;
            sqlDataAdapter1.SelectCommand.Parameters.Clear();
            sqlDataAdapter1.SelectCommand.CommandText = "SELECT seller.* FROM seller WHERE nameSeller = @name AND familySeller = @password";
            sqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@name", textBox1.Text);
            sqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@password", textBox2.Text);
            sqlConnection1.Open();
            MyRead = sqlDataAdapter1.SelectCommand.ExecuteReader();
            if (MyRead.Read())
            {
                sqlConnection1.Close();
                this.Close();
            }
            else
            {
                //MMDClassLibrary.MMessageBox box2 = new MMDClassLibrary.MMessageBox();
                //box2.ShowAlertMessage("نام کاربری و یا رمز عبور را اشتباه وارد کرده اید.دوباره سعی کنید ");
                erorr ef = new erorr();
                ef.ShowDialog();
                textBox1.Text = "";
                textBox2.Text = "";
                sqlConnection1.Close();
            }
        }
    }

        private void pictureBox3_MouseEnter(object sender, EventArgs e)
        {
            label3.Visible = true;
        }

        private void pictureBox3_MouseLeave(object sender, EventArgs e)
        {
            label3.Visible = false;
        }

        private void pictureBox2_MouseEnter(object sender, EventArgs e)
        {
            label4.Visible = true;
        }

        private void pictureBox2_MouseLeave(object sender, EventArgs e)
        {
            label4.Visible = false;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if ((textBox1.Text == "") && (textBox2.Text == ""))
            {
                MMDClassLibrary.MMessageBox box = new MMDClassLibrary.MMessageBox();
                box.ShowAlertMessage("لطفا نام کاربری و رمز عبور خود را وارد کنید ");
            }
            else
            {
                SqlDataReader MyRead;
                sqlDataAdapter1.SelectCommand.Parameters.Clear();
                sqlDataAdapter1.SelectCommand.CommandText = "SELECT seller.* FROM seller WHERE nameSeller = @name AND familySeller = @password";
                sqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@name", textBox1.Text);
                sqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@password", textBox2.Text);
                sqlConnection1.Open();
                MyRead = sqlDataAdapter1.SelectCommand.ExecuteReader();
                if (MyRead.Read())
                {
                    sqlConnection1.Close();
                    this.Close();
                }
                else
                {
                    //MMDClassLibrary.MMessageBox box2 = new MMDClassLibrary.MMessageBox();
                    //box2.ShowAlertMessage("نام کاربری و یا رمز عبور را اشتباه وارد کرده اید.دوباره سعی کنید ");
                    erorr ef = new erorr();
                    ef.ShowDialog();
                    textBox1.Text = "";
                    textBox2.Text = "";
                    sqlConnection1.Close();
                }
            }
        }

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

        private void button1_MouseEnter(object sender, EventArgs e)
        {
            label3.Visible = true;
        }

        private void button1_MouseLeave(object sender, EventArgs e)
        {
            label3.Visible = false;
        }
 
    }
}