login form user status problem
here is the coding of my form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.OleDb;
namespace Project
{
public partial class frmlogin : Form
{
int UserId;
int UserStatus;
string UserName;
string UserRole;
string Password;
string ConfirmPassword;
public frmlogin()
{
InitializeComponent();
}
private void frmlogin_Load(object sender, EventArgs e)
{
}
private void btnlogin_Click(object sender, EventArgs e)
{
try
{
ConnectionClass l_ConnectionClass = new ConnectionClass();
DataSet l_UserDataSet = l_ConnectionClass.FetchDataInDataSet("select * from tbluserlogin where userName = '"+txtusername.Text.ToLower().Trim()+"' and userPwd = '"+txtpwd.Text.Trim()+"'");
if (l_UserDataSet.Tables[0].Rows.Count > 0)
{
PublicVariables.CheckLoginFlag = true;
PublicVariables.OSUserID = Convert.ToInt16(l_UserDataSet.Tables[0].Rows[0]["userId"]);
PublicVariables.UserRole = l_UserDataSet.Tables[0].Rows[0]["userRole"].ToString();
Close();
}
else
{
MessageBox.Show("Login Failed !!!!", "Error", MessageBoxButtons.OK);
PublicVariables.CheckLoginFlag = false;
txtusername.Text = "";
txtpwd.Text = "";
txtusername.Focus();
}
}
catch (Exception Ex)
{
MessageBox.Show("Connection Failed. Plz Check your Network Cable Connection", "Error", MessageBoxButtons.OK);
}
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
and for this i have made a connectionclass.cs form for the connection. in that only i have define publicvariables.
public sealed class PublicVariables
{
public static Boolean CheckLoginFlag = false;
public static short OSUserID = 0;
public static string UserRole = "";
}
now i have to set the user status in this form. like when user will login the userstatus column in the table will be updated to 1 in that user name row. and when the user will log out from the MDI form Logout or Exit strip the user status will be 0. plz help.
Replies
Know the answer? Post it — somebody with the same question will find it here.