using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class LoginPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] != null)
        {
            Response.Redirect("Default.aspx?ID=" + DateTime.Now.Ticks.ToString());
        }
    }

    protected void Btn_Login_Click(object sender, EventArgs e)
    {
        UDF_GetLogin(Txt_UserName.Text.Trim() , Txt_Password.Text.Trim());
        //Response.Write(Session["UserTypeID"].ToString());
    }

    private void UDF_GetLogin(String Str_UserName , String Str_Password)
    {
        Class_LoginUsers Cls_Login = new Class_LoginUsers(Str_UserName.Trim() , Str_Password.Trim());
        Cls_Login.UDF_CheckUserValidation();
        if (Cls_Login.Is_LogedIn != true)
        {
            Lbl_Message.Visible = true;
            UDF_SaveLogs("Login Failed.");
            Lbl_Message.Text = "نام کاربری و یا کلمه عبور اشتباه می باشد.";
        }
        else
        {
            Session.Add("UserName", Txt_UserName.Text.Trim());
            Session.Add("NameSname" , Cls_Login.Str_NameSname);
            UDF_SaveLogs("Login Succeded.");
            Response.Redirect("Default.aspx?ID=" + DateTime.Now.Ticks.ToString());
        }
    }

    private void UDF_SaveLogs(String Str_LogDescription)
    {
        Class_LogRegister Cls_SaveLog = new Class_LogRegister(Str_LogDescription, Request.Url.ToString());
        Cls_SaveLog.UDF_SaveLogs();
    }

}
