I have tried to manage user session, but the issue is I can not access other attributes in the database as they are not in the object.
(我已经尝试管理用户会话,但是问题是我无法访问数据库中的其他属性,因为它们不在对象中。)
Teacher t = new Teacher
{
t_email = textBox_Login_Email.Text,
t_password = textBox_Login_Pass.Text,
};
Other attributes are t_id and t_name.
(其他属性是t_id和t_name。)
I can only access these two using the following code (我只能使用以下代码访问这两个)
session.Instance.user.t_email
session.Instance.user.t_password
I need to get Teacher's id which is t_id from the database.
(我需要从数据库中获取老师的ID,即t_id。)
I am storing the object "t" in the session object using (我使用以下命令将对象“ t”存储在会话对象中)
session.Instance.user = t;
Below is the code for my session class and login class session.cs
(以下是我的会话类和登录类session.cs的代码)
public class session
{
#region Define as Singleton
private static session _Instance;
public static session Instance
{
get
{
if(_Instance == null)
{
_Instance = new session();
}
return (_Instance);
}
}
private session()
{
}
#endregion
public Teacher user { get; set; }
public bool isLoggedIn
{
get
{
if (user != null)
return true;
else return false;
}
}
}
login.cs
(login.cs)
namespace TestBoardAdmin
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void button_Login_Click(object sender, EventArgs e)
{
using (examEntities obj = new examEntities())
{
Teacher t = new Teacher
{
t_email = textBox_Login_Email.Text,
t_password = textBox_Login_Pass.Text,
};
//var x = obj.Teachers.Where(a => a.t_email == t.t_email).Select(a => new { a.t_id });
var y = obj.Teachers.Where(a => a.t_email == t.t_email && a.t_password == t.t_password);
if (y.Count() > 0)
{
MessageBox.Show("Logged In succesfully");
textBox_Login_Email.Clear();
textBox_Login_Pass.Clear();
//this.Close();
session.Instance.user = t;
Chose_Action chose_action = new Chose_Action();
chose_action.Show();
//return 1;
}
else
{
//ViewBag.SuccessMessage = "Wrong Email or Password";
//return 0;
MessageBox.Show("Email or Password Incorrect");
//textBox_Login_Email.Clear();
textBox_Login_Pass.Clear();
}
}
}
private void textBox_Login_Email_TextChanged(object sender, EventArgs e)
{
}
private void textBox_Login_Pass_TextChanged(object sender, EventArgs e)
{
}
}
}
I actually want to store the corresponding t_id in another table when the user adds in the database, the database will also add the id of the user who added something in the database.
(当用户在数据库中添加数据时,我实际上想将相应的t_id存储在另一个表中,该数据库还将添加在数据库中添加了内容的用户的ID。)
So, for that I want to get t_id of the corresponding user session. (因此,为此,我想获取相应用户会话的t_id。)
I have used ado.net and Linq in this project.
(我在该项目中使用了ado.net和Linq。)
ask by Kiran_t translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…