-1

I am creating emp_attendance register. In my form two command button Time-in and Time-out . I want employees to be able to click on timein and timeout buttons once a day.

Is it possible?

1
  • 3
    Asp.net, win, wpf? or what technology? Apr 8, 2014 at 5:38

4 Answers 4

1

You can do it for sure, but you have to handle it on your own. Simply set a flag somewhere to remind you that the user already pressed a certain button, and use this flag to set the button's Enabled property every time your form is opened.

>>> UPDATED <<<

Something like that should work:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TFF
{
    public partial class Form1 : Form
    {
        private static DateTime? button1ClickAt = null;
        private static DateTime? button2ClickAt = null;

        public Form1()
        {
            InitializeComponent();
            HandleButtonEnable();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1ClickAt = DateTime.Now;
            HandleButtonEnable();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button2ClickAt = DateTime.Now;
            HandleButtonEnable();
        }

        private void HandleButtonEnable()
        {
            button1.Enabled = (button1ClickAt == null || button1ClickAt.Value.Date != DateTime.Now.Date);
            button2.Enabled = (button2ClickAt == null || button2ClickAt.Value.Date != DateTime.Now.Date);
        }
    }
}

Every time you press a button you update the correspondent timestamp: a button is then enabled if it has never been clicked or if it is clicked in a different day (so you can click the buttons only once a day).

4
  • could you please explain thru example.. Apr 8, 2014 at 5:41
  • Good answer, It'll be good if you can say something about persistence of those date fields if op needs it(I believe op needs this to behave same way even when app is restarted). also there is no reason to make those fields static. +1 though. Apr 8, 2014 at 5:58
  • @SriramSakthivel: if you define those fields as static then they are persistent if you dispose the form and then open it again later on... this is the reason why I defined them static... Anyway you're right about persistence upon application restart... The "click timestamps" should be saved somewhere (file? DB?) to make them persistent upon application restart: the application should read them from the source (file? DB?) just during its startup
    – Morix Dev
    Apr 8, 2014 at 6:02
  • @user3488317: what do you mean? Have you defined button1ClickAt as nullable object? that is have you the question mark after DateTime (as in my example)? Have you written .Value with the capital letter (as in my example)? Have you got a specific error?
    – Morix Dev
    Apr 8, 2014 at 6:05
0

Yes it is Possible and can be done in two ways,

  1. The first option is setting only one button for both timein and timeout. If the EMP selects the button the Content is changed from TIME IN to TIME OUT based on your button click event.
  2. Secondly, You can have two buttons individually for Timein and Timeout, Set the Button click event for changing the Other button's property like enabled or Visibility. So that the EMP can only select only one button.
0
button1.Attributes.Add("onclick", "this.disabled =true;" + ClientScript.GetPostBackEventReference(button1, null) + ";");

this makes your button disable once you click it.

0
0

Yes, any thing is possible in IT,it depends on your approach......

Just write some logic on click event of both the buttons, that may be- storing a bit value for that employee for the same day in the data base ,after successful submit check for bit value and just disable the button and do the same logic on second button click event.

Hope this will create some logic for you. IF need more explanation let me know...

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.