using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace emlakOtomasyonu
{
    public partial class frmKullaniciGirisi : Form
    {
        public frmKullaniciGirisi()
        {
            InitializeComponent();
        }

        sinif sinif = new sinif();

        private void fmrKullaniciGirisi_Load(object sender, EventArgs e)
        {
            try
            {
                if (sinif.baglanti.State == ConnectionState.Closed)
                    sinif.baglanti.Open();
                if (sinif.dataTableDoldur("kullanici").Rows.Count == 0)
                {
                    frmKullaniciKayit frmKullaniciKayit = new frmKullaniciKayit();
                    frmKullaniciKayit.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnGiris_Click(object sender, EventArgs e)
        {
            try
            {
                string sorgu = "select kullaniciAdi, sifre from kullanici where kullaniciAdi = '" + txtKullaniciAdi.Text + "' and sifre = '" + txtSifre.Text + "'";
                sinif.komut = new OleDbCommand(sorgu, sinif.baglanti);
                OleDbDataReader dr = sinif.komut.ExecuteReader();
                if (dr.Read())
                {
                    this.Hide();
                    frmAna frmAna = new frmAna();
                    frmAna.Show();
                }
                else
                    MessageBox.Show("Kullanıcı adınızı veya şifrenizi yanlış girdiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void lblSifremiUnuttum_Click(object sender, EventArgs e)
        {
            frmSifremiUnuttum frmSifremiUnuttum = new frmSifremiUnuttum();
            frmSifremiUnuttum.ShowDialog();
        }

        private void txtKullaniciAdi_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsLetter(e.KeyChar) && e.KeyChar != (char)Keys.Back && !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }
    }
}
