如何在特定时间段内禁用命令按钮

本文关键字:命令 按钮 时间段 定时间 | 更新日期: 2023-09-27 17:57:11

我正在创建emp_attendance寄存器。在我的表单中,两个命令按钮超时和超时。我希望员工能够每天点击一次timeintimeout按钮。

可能吗?

如何在特定时间段内禁用命令按钮

你当然可以做到,但你必须自己处理。只需在某处设置一个标志来提醒您用户已经按下了某个按钮,并在每次打开窗体时使用此标志设置按钮的Enabled属性。

>>>更新<<<</strong>

这样的事情应该有效:

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);
        }
    }
}

每次按下按钮时,您都会更新相应的时间戳:如果按钮从未被单击过或在其他日期被单击,则会启用该按钮(因此您每天只能单击一次按钮)。

是的,这是可能的,可以通过两种方式完成,

  1. 第一个选项是为超时和超时仅设置一个button如果 EMP 选择button则内容将根据您的按钮单击事件从"输入时间"更改为"超时"。
  2. 其次,您可以分别为TimeinTimeout设置两个buttons,设置按钮单击事件以更改其他按钮的属性,如enabledVisibility。这样 EMP 只能选择一个按钮。
button1.Attributes.Add("onclick", "this.disabled =true;" + ClientScript.GetPostBackEventReference(button1, null) + ";");

这使您的按钮在单击后将其禁用。

是的,在IT中任何事情都是可能的,这取决于你的方法......

只需在两个按钮的点击事件上编写一些逻辑,这可能是 - 在数据库中存储该员工同一天的位值,成功提交后检查位值,只需禁用按钮并在第二个按钮单击事件上执行相同的逻辑。

希望这会为您创建一些逻辑。如果需要更多解释,请告诉我...