I need to capture the logout time and login time. I can capture the login time already but I cannot capture the logout time. I would appreciate all the help that you had given me. Thank you.
This is the coding in the logout button:
protected void logoutButton_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
cmd.Parameters.AddWithValue("@MemberID", Session["MemberID"]);
Session.Abandon();
}
I also need to do in global.asax. And this is the coding:
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
connection.Open();
//retrieve the logid
string connectionString1 = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString1);
connection.Open();
//prepare sql statements
//string sql = "SELECT * from LoggedInUsers where emailaddress='" + emailaddress + "' And Password='" + password + "'";
//Response.Write(sql);
//command = new SqlCommand(sql, connection);
SqlDataAdapter da = new SqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
/* add value to Session */
Session["LogId"] = dt.Rows[0]["LogId"].ToString();
SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
cmd.Parameters.AddWithValue("@MemberID", MemberID);
//pass the session
int logid = (int)Session["MemberId"];
DateTime dateTime = DateTime.Now;
string s = dateTime.ToString();
//update record based on logid
SqlCommand cmd1 = new SqlCommand("UPDATE LoggedInUsers set LogoutTime = '" + s + "' Where MemberID = @MemberID");
//prepare sql statements
string sql1 = "UPDATE LoggedInUsers set LogoutTime= '" + s + "' where emailaddress=@EmailAddress";
//Response.Write(sql + "<br />");
why bother to capture log out time? imho, log out time has to be one of the most meaningless metrics ever.
let me explain:
(a) many end users simply forget to log out.
(b) a user who is about to log out at the end of her/his work day may first go to the washroom, chew the fat with co-workers, kill time in other ways, et cetera.
a better server side metric would be to log each activity and save the log for further analysis,
e.g.:
John Doe logged on at 09:23:16
" " selected accounting application at 09:23:57
" " posted sales transaction #622 at 09:25:02
" " posted sales transaction #658 at 09:29:22
" " posted sales transaction #789 at 09:45:07
et cetera
From the above, we can determine how much work John Doe has done
and compute averages and means; also we can determine whether
John Doe was not working on sales transactions for about 15 minutes
by examing #789 to determine whether it was a very large transaction
by counting its detail records or a very small sales transaction with only
a few details ... we can also compare John Doe's performance with
that of his peers. all of this without needing to know when John Doe logged out.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
You tell us ... what happens when you run your code in debug mode and step through it line by line?
Debugging your code is the best way imho to find out what is wrong with it ... debugging your code helps you understand it better.
i'm assuming that you do know how to use the debugger.
sorry, you've really not provided enough information ... for example, you have not even mentioned whether your code compiles clean.
also, even when code does compile clean, you should look at the compiler warning messages since sometimes warning messages may reveal potential problems that may not show up when testing.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Then you need to run the code in such a way that the breakpoint is triggered. Last time we had this conversation you didn't seem to know what that means. Is there anyone who is physically near you that could give you some assistance on the most basic aspects
of debugging? I tried to find some sites for your but none of them seemed to be sufficiently basic to cover what you need.
What do you think that logging out means? Is there something in your website which is a button that says 'Logout'? Before you get to sorting out your code (which is a mess) you need to work out what is going to cause it to run. What do you think 'Logging
out' means? Have you ever been to a web site were you 'Log out'? On that web site how did you log out?
unleashed-my...
Member
78 Points
57 Posts
logout time
Nov 17, 2011 01:03 AM|LINK
I need to capture the logout time and login time. I can capture the login time already but I cannot capture the logout time. I would appreciate all the help that you had given me. Thank you.
This is the coding in the logout button:
protected void logoutButton_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
cmd.Parameters.AddWithValue("@MemberID", Session["MemberID"]);
Session.Abandon();
}
I also need to do in global.asax. And this is the coding:
protected void Session_End(object sender, EventArgs e)
{
if (Session["MemberId"] != null)
{
UpdateLoggedInUsersLogoutTime(Convert.ToInt32(Session["MemberId"].ToString()));
}
//string emailaddress = (string)Session["emailaddress"];
}protected Boolean UpdateLoggedInUsersLogoutTime(int MemberID)
{
SqlConnection connection = null;
SqlCommand command = null;
Boolean successFlag = false;
try
{
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
connection.Open();
//retrieve the logid
string connectionString1 = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString1);
connection.Open();
//prepare sql statements
//string sql = "SELECT * from LoggedInUsers where emailaddress='" + emailaddress + "' And Password='" + password + "'";
//Response.Write(sql);
//command = new SqlCommand(sql, connection);
SqlDataAdapter da = new SqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
/* add value to Session */
Session["LogId"] = dt.Rows[0]["LogId"].ToString();
SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
cmd.Parameters.AddWithValue("@MemberID", MemberID);
//pass the session
int logid = (int)Session["MemberId"];
DateTime dateTime = DateTime.Now;
string s = dateTime.ToString();
//update record based on logid
SqlCommand cmd1 = new SqlCommand("UPDATE LoggedInUsers set LogoutTime = '" + s + "' Where MemberID = @MemberID");
//prepare sql statements
string sql1 = "UPDATE LoggedInUsers set LogoutTime= '" + s + "' where emailaddress=@EmailAddress";
//Response.Write(sql + "<br />");
//command = new SqlCommand(cmd1, connection);
//command.Parameters.Clear();
command.Parameters.AddWithValue("@LogoutTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
command.Parameters.AddWithValue("MemberID", MemberID);
int rowCount = command.ExecuteNonQuery();
//if (rowCount != 0)
if (rowCount == 1)
{
successFlag = true;
//Response.Write("Operation success.<br/>");
}
else
{
//Response.Write("Operation failed<br/>");
}
}
}
catch (Exception ex)
{
//Response.Write("Error:" + ex.Message);
}
//cleanup object
finally
{
if (connection != null)
connection.Close();
}
return successFlag;
}
}
}
gerrylowry
All-Star
20513 Points
5712 Posts
Re: logout time
Nov 17, 2011 01:34 AM|LINK
@ unleashed-my-freedom
why bother to capture log out time? imho, log out time has to be one of the most meaningless metrics ever.
let me explain:
(a) many end users simply forget to log out.
(b) a user who is about to log out at the end of her/his work day may first go to the washroom, chew the fat with co-workers, kill time in other ways, et cetera.
a better server side metric would be to log each activity and save the log for further analysis,
e.g.:
John Doe logged on at 09:23:16
" " selected accounting application at 09:23:57
" " posted sales transaction #622 at 09:25:02
" " posted sales transaction #658 at 09:29:22
" " posted sales transaction #789 at 09:45:07
et cetera
From the above, we can determine how much work John Doe has done
and compute averages and means; also we can determine whether
John Doe was not working on sales transactions for about 15 minutes
by examing #789 to determine whether it was a very large transaction
by counting its detail records or a very small sales transaction with only
a few details ... we can also compare John Doe's performance with
that of his peers. all of this without needing to know when John Doe logged out.
g.
unleashed-my...
Member
78 Points
57 Posts
Re: logout time
Nov 17, 2011 01:36 AM|LINK
Thank you for your help. But I need to do logout time. Is there something wrong with the code?
gerrylowry
All-Star
20513 Points
5712 Posts
Re: logout time
Nov 17, 2011 01:59 AM|LINK
@ unleashed-my-freedom
You tell us ... what happens when you run your code in debug mode and step through it line by line?
Debugging your code is the best way imho to find out what is wrong with it ... debugging your code helps you understand it better.
i'm assuming that you do know how to use the debugger.
sorry, you've really not provided enough information ... for example, you have not even mentioned whether your code compiles clean.
also, even when code does compile clean, you should look at the compiler warning messages since sometimes warning messages may reveal potential problems that may not show up when testing.
g.
unleashed-my...
Member
78 Points
57 Posts
Re: logout time
Nov 17, 2011 02:03 AM|LINK
My problem is i cannot capture the logout time.
Paul Linton
Star
13421 Points
2535 Posts
Re: logout time
Nov 17, 2011 02:14 AM|LINK
You keep posting this question. Have you worked out how to debug yet?
unleashed-my...
Member
78 Points
57 Posts
Re: logout time
Nov 17, 2011 02:16 AM|LINK
I need to insert breakpoint right?
Paul Linton
Star
13421 Points
2535 Posts
Re: logout time
Nov 17, 2011 02:18 AM|LINK
You and I have already been through this.
Yes, you need to set a breakpoint.
Then you need to run the code in such a way that the breakpoint is triggered. Last time we had this conversation you didn't seem to know what that means. Is there anyone who is physically near you that could give you some assistance on the most basic aspects of debugging? I tried to find some sites for your but none of them seemed to be sufficiently basic to cover what you need.
unleashed-my...
Member
78 Points
57 Posts
Re: logout time
Nov 17, 2011 02:26 AM|LINK
Thanks. But noone is using visual studio here. Is it possible if you tell me where I had done wrongly?
Paul Linton
Star
13421 Points
2535 Posts
Re: logout time
Nov 17, 2011 03:32 AM|LINK
What do you think that logging out means? Is there something in your website which is a button that says 'Logout'? Before you get to sorting out your code (which is a mess) you need to work out what is going to cause it to run. What do you think 'Logging out' means? Have you ever been to a web site were you 'Log out'? On that web site how did you log out?