protected void btnLogin_Click(object sender, ImageClickEventArgs e)
{
if((txtusername.Text!="") & (txtpassword.Text!=""))
{
if (checkUser(SessionConfig.Current.UserType, txtusername.Text.Trim(), txtpassword.Text.Trim()) == 1)
{
if (!objCon.isUserHasSessionId("SessionID", "tblLoginUser", "LoginUserID", SessionConfig.Current.UserLoginID))
{
UpdateSession(txtusername.Text.Trim());
Response.Redirect("~/AdminDashboard.aspx?UserType=" + userType.ToString(),false);
}
else
{
Message - You have already logged in
}
}
else
{
txtusername.Text = "";
txtpassword.Text = "";
txtusername.Focus();
//Message- User name or password wrong
}
}
}
public int checkUser (string userName,string userPwd)
{
int resQry = 0;
try
{
string qryGetuserId = "select count(*) from tblloginuser where LoginUserName='" + userName + "' and LoginUserPassword='" + userPwd + "' and userTypeId=" + userTypeId + "";
resQry = objCon.GetQryResult(qryGetuserId, "tblloginuser");
return resQry;
}
catch (Exception ex)
{
return 0;
}
}
public void UpdateSession(string userName)
{
try
{
string qry = string.Format("UPDATE tblloginuser set SessionID='{0}'where username='" + userName + "'",objLib.GetSessionId(userName));
SqlDataAdapter ada = new SqlDataAdapter(qry, connectionstring);
DataSet ds = new DataSet();
ada.Fill(ds, tableName);
}
catch (Exception ex)
{
}
}
//Get master table unique id
public Int32 GetQryResult(string qryInput, string tableName)
{
try
{
SqlDataAdapter ada = new SqlDataAdapter(qryInput, connectionstring);
DataSet ds = new DataSet();
ada.Fill(ds, tableName);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0][0].ToString() != "")
{
return Convert.ToInt32(ds.Tables[0].Rows[0][0]);
}
else
{
return 0;
}
}
else
return 0;
}
catch (Exception ex)
{
throw ex;
}
}