I need help on login, logout and timer. If a user enters a password once it must allow another user to enter theirs (login) without logging off to the 1st user, but if the user enters twice it must logout. The following is the source code;
if (textBox1.Text == "")
{
MessageBox.Show("please enter employee number");
textBox1.Focus();
}
else
try
var strconn = ConfigurationManager.ConnectionStrings["tk"].ConnectionString;
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd = new SqlCommand("SELECT employee_number FROM employeedetails WHERE employee_number = @employee_number", conn);
SqlParameter employee_number = new SqlParameter("@employee_number", SqlDbType.NChar);
employee_number.Value = textBox1.Text;
cmd.Parameters.Add(employee_number);
cmd.Connection.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (myReader.Read() == true)
search();
if (textBox1.TextLength == 4 & radioButton1.Checked == false)
textBox1.Text = myReader[0].ToString();
login = DateTime.Now;
txtstart.Text = login.ToShortTimeString();
txtDate.Text = login.ToShortDateString();
radioButton1.Checked = true;
textBox1.Text = "";
else if (textBox1.TextLength == 4 & radioButton1.Checked == true)
logout = DateTime.Now;
txtend.Text = logout.ToLongTimeString();
//display on the textbox
listBox1.Items.Add("employee number:" + textBox1.Text);
listBox1.Items.Add("login duration - Min :" + logout.Subtract(login).Minutes);
listBox1.Items.Add("login duration - hour :" + logout.Subtract(login).Hours);
listBox1.Items.Add("login duration - mili :" + logout.Subtract(login).Milliseconds);
listBox1.Items.Add("login duration - Sec :" + logout.Subtract(login).Seconds);
listBox1.Items.Add("--------------------------------------------------------");
txtnumberofhours.Text = "min" + logout.Subtract(login).Minutes;
radioButton1.Checked = false;
insert();
else if (textBox1.TextLength != 4)
MessageBox.Show("Enter whatever");
MessageBox.Show(this, "Login Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Clear();
if (conn.State == ConnectionState.Open)
conn.Dispose();