locked
i need to store employee login/logout timings everyday RRS feed

  • Question

  • User711643727 posted

    hello...

    A website which will store the employee id in sql table when employee enters the id first time.....

    and next time when employee enters his id first time in textbox in website in a day ,it needs to store the employee entry time(in time)....

    and in the same day...when he enters the same id ,it needs to store the out time of employee....

    finally the whole data i.e date,intime,outtime,id has to store in database everyday......

    and other requirment is the admin with some other id can see the total employee timings according to date wise in gridview

    Tuesday, August 6, 2013 1:37 AM

Answers

  • User260886948 posted

    Hi,

    You can store the login/logout time as following, and I use the login time as an example:

    protected void loginButton_Click(object sender, EventArgs e)
    
    {
    
      Boolean validUser = false;
    
      string displayname = TextBox1.Text.Trim() ;
    
      string password = TextBox2.Text.Trim();
    
      SqlConnection connection = null;
    
      SqlCommand command = null;
    
      SqlDataReader dataReader = null;
    
      try
    
      {
    
        string connectionString = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
    
        connection = new SqlConnection(connectionString);
    
        connection.Open();
    
        //prepare sql statements
    
        string sql = "SELECT * from Member where name='" + name + "' 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["displayName"] = displayname;
          validUser = true;
    
          /* Logging Information to Logtable */
     
    
          command = new SqlCommand("insert into LogTableName(name,logintime) values(@name,@logintime)", connection);
    
          command.Parameters.Clear();
    
          command.Parameters.AddWithValue("@name", displayname);
    
          command.Parameters.AddWithValue("@logintime", DateTime.Now.ToShortDateString());
    
          command.ExecuteNonQuery();
    
          connection.Close();
    
     
          /* Redirect user to Home Page */
    
          Response.Redirect("memberhome.aspx");
    
        }
    
        else
    
        {
    
          Response.Redirect("login.aspx");
    
        }
    
      }
    
      catch (Exception ex)
    
      {
    
        Response.Write(ex.Message);
    
      }
    
    }

    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 19, 2013 3:51 AM

All replies

  • User-306750178 posted

    Hi,

    Create a table with name "User_Login_Log" with columns UserID, Login_date, Logout_date.

    when employee enters his id first time in textbox in website in a day insert his login_date in table.

    he same day when he enters the same id update table with Logout_date.

    Hope you understand.

    Tuesday, August 6, 2013 1:47 AM
  • User711643727 posted

    i need to store login/logout timings in a day and as well as dates

    please give me suggetions .......Cry

    Thanks in advance......

    Tuesday, August 6, 2013 1:53 AM
  • User260886948 posted

    Hi,

    You can store the login/logout time as following, and I use the login time as an example:

    protected void loginButton_Click(object sender, EventArgs e)
    
    {
    
      Boolean validUser = false;
    
      string displayname = TextBox1.Text.Trim() ;
    
      string password = TextBox2.Text.Trim();
    
      SqlConnection connection = null;
    
      SqlCommand command = null;
    
      SqlDataReader dataReader = null;
    
      try
    
      {
    
        string connectionString = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
    
        connection = new SqlConnection(connectionString);
    
        connection.Open();
    
        //prepare sql statements
    
        string sql = "SELECT * from Member where name='" + name + "' 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["displayName"] = displayname;
          validUser = true;
    
          /* Logging Information to Logtable */
     
    
          command = new SqlCommand("insert into LogTableName(name,logintime) values(@name,@logintime)", connection);
    
          command.Parameters.Clear();
    
          command.Parameters.AddWithValue("@name", displayname);
    
          command.Parameters.AddWithValue("@logintime", DateTime.Now.ToShortDateString());
    
          command.ExecuteNonQuery();
    
          connection.Close();
    
     
          /* Redirect user to Home Page */
    
          Response.Redirect("memberhome.aspx");
    
        }
    
        else
    
        {
    
          Response.Redirect("login.aspx");
    
        }
    
      }
    
      catch (Exception ex)
    
      {
    
        Response.Write(ex.Message);
    
      }
    
    }

    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 19, 2013 3:51 AM