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.OleDb;

namespace TelBook
{
    public partial class fmlogin : Form
    {
        public fmlogin()
        {
            InitializeComponent();
        }
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|DATA.ACCDB;JET OLEDB:DATABASE PASSWORD=●●●●●●●●●●●●;");

        private void fmlogin_Load(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string d;
                OleDbDataAdapter adap;
                DataSet ds = new DataSet();
                d = "select * from users";
                adap = new OleDbDataAdapter(d, con);
                adap.Fill(ds, "users");
                comboBox1.DataSource = ds.Tables["users"];
                comboBox1.DisplayMember = "usern1";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
               Main main = new Main();
                string se = "Select * from users where usern1='" + comboBox1.Text + "' AND pass1= '" + txpass.Text + "'";
                OleDbCommand dbc = new OleDbCommand(se, con);
                OleDbDataReader dr = dbc.ExecuteReader();
                if (dr.Read())
                {
                    this.Hide();
                    main.lp1.Text = comboBox1.Text;
                    main.ShowDialog(); this.Close();
                }
                else
                    MessageBox.Show("نام کاربری با رمز عبور مطابقت ندارد","Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                txpass.ResetText();
            }
            catch(Exception ex)
            {

                MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void txpass_Enter(object sender, EventArgs e)
        {

        }

        private void txpass_KeyPress(object sender, KeyPressEventArgs e)
        {
           
        }

        private void txpass_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyData==Keys.Enter)
            {
                button1_Click(0, null);
            }
        }

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