using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class LoginPage : System.Web.UI.Page
{
   protected void tnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            Lsc_EVotingDataContext db = new Lsc_EVotingDataContext();
            tblUser User = db.tblUsers.SingleOrDefault  (n => n.UsersName == Txt_UserName.Text.Trim() && n.UsersPwa == Txt_Pass.Text.Trim());
            if (User == null )
            {
                System.Web.HttpContext.Current.Session.Add("IsLogIn", "false");
                Lbl_Meesege.Visible = true;
                Lbl_Meesege.Text = "شما ثبت نام نکرده اید!";
            }
            else
            {
                Lbl_Meesege.Visible = false;
                System.Web.HttpContext.Current.Session.Add("UserTypeID", User.UserTypeID);
                System.Web.HttpContext.Current.Session.Add("IsLogIn", "true");
                System.Web.HttpContext.Current.Session.Add("UserName", Txt_UserName.Text.Trim());
                Lbl_Meesege.Visible = true;
                Response.Redirect("Default.aspx");
            }
        }
        catch
        {
            System.Web.HttpContext.Current.Session.Add("IsLogIn", "false");
            Lbl_Meesege.Visible = true;
        }
    }
}