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;
using _UseFull;
using System.Data.SqlClient;
using System.IO;

public partial class pg_Login : System.Web.UI.Page
{
    //333333333333333333333333333333333333
    SqlConnection con;
    SqlCommand cmd;
    //333333333333333333333333333333333333
    protected void Page_Load(object sender, EventArgs e)
    {
        Label lblTitle = (Label)this.Master.FindControl("lblTitle");
        lblTitle.Text = "ورود به سایت";
        C_myClass.MenueItemsCreate(User, panelMenues);
    }
    
    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        try
        {
            string fullName = "", gender = "";
            int iden = 0;
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            cmd = con.CreateCommand();
            string userName = Login1.UserName;
            if (Roles.IsUserInRole(userName, "manager"))
            {
                gender = C_Usefull.FindStringWithStringShart(con, cmd, "t_Managers", "gender", "userName", userName);
                fullName = C_Usefull.FindStringWithStringShart(con, cmd, "t_Managers", "fullName", "userName", userName);
                iden = C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Managers", "managerId", "userName", userName);
            }
            else if (Roles.IsUserInRole(userName, "admin"))
            {
                gender = C_Usefull.FindStringWithStringShart(con, cmd, "t_Admins", "gender", "userName", userName);
                fullName = C_Usefull.FindStringWithStringShart(con, cmd, "t_Admins", "fullName", "userName", userName);
                iden = C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Admins", "adminId", "userName", userName);
            }
            else if (Roles.IsUserInRole(userName, "student"))
            {
                gender = C_Usefull.FindStringWithStringShart(con, cmd, "t_Students", "gender", "userName", userName);
                fullName = C_Usefull.FindStringWithStringShart(con, cmd, "t_Students", "fullName", "userName", userName);
                iden = C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Students", "studentId", "userName", userName);
            }
            else if (Roles.IsUserInRole(userName, "teacher"))
            {
                gender = C_Usefull.FindStringWithStringShart(con, cmd, "t_Teachers", "gender", "userName", userName);
                fullName = C_Usefull.FindStringWithStringShart(con, cmd, "t_Teachers", "fullName", "userName", userName);
                iden = C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Teachers", "teacherId", "userName", userName);
            }
            else if (Roles.IsUserInRole(userName, "user"))
            {
                gender = C_Usefull.FindStringWithStringShart(con, cmd, "t_Users", "gender", "userName", userName);
                fullName = C_Usefull.FindStringWithStringShart(con, cmd, "t_Users", "fullName", "userName", userName);
                iden = C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Users", "userId", "userName", userName);
            }
            Session["fullName"] = fullName;
            Session["gender"] = gender;
            Session["iden"] = iden;
            OnlineActiveUsers.OnlineUsersInstance.OnlineUsers.SetUserOnline(userName);
        }
        catch(Exception ex)
        {
        }
    }
}
