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;
using System.Reflection;
using System.Reflection.Emit;

namespace RezerveBeliteHavaPeimaCS
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("مقادیر فیلدها نمی توانند خالی باشند");
            }
            else
            {
                FirstClass dbCheck = new FirstClass();
                DataTable dtChek = new DataTable();

                dtChek = dbCheck.dbOut("SELECT     TOP 100 PERCENT UserName, Password FROM userInfo WHERE     (Password = '" + textBox2.Text.Trim() + "' AND UserName = '" + textBox1.Text.Trim() + "') ORDER BY UserName");
                if (dtChek.Rows.Count <= 0)
                {
                    MessageBox.Show("نام کاربری و کلمه عبور اشتباه وارد شده اند");
                }
                else
                {
                    this.Visible = false;
                    frmMdi frm = new frmMdi();
                    frm.Show();
                }
            }
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            string path = Application.StartupPath.ToString() + "\\";
            //MessageBox.Show(path);
            try
            {
                SqlConnection con = new SqlConnection(Properties.Settings.Default.RezerveBelitTotal_DataConnectionString.ToString());
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "sp_attach_db @dbname = N'" + "RezerveBelitTotal" + "', @filename1 = N'" + path + "RezerveBelitTotal_Data.MDF" + "', @filename2 = N'" + path + "RezerveBelitTotal_Log.LDF" + "'";
                cmd.CommandType = CommandType.Text;
                con.Open();
                cmd.Connection = con;
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch 
            { 
                
            }
        }
    }
}