复选框应该是可见的或根据时间启用 [英] checkbox should be visible or enabled according to time

查看:105
本文介绍了复选框应该是可见的或根据时间启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开展1个医疗保健项目。在该项目中,有一项规定预约患者。对于预约,我使用复选框来选择时段。现在我想根据小时/时间显示/启用复选框。例如:如果现在时间是下午12点,那么用户不应该预约上午10点,她只能在12点之后预约。



有谁能说出我该怎么办?

提前谢谢....

Hello everyone,
I am working on 1 healthcare project. In that project there is a provision to book an appointment of patient. For appointment booking, I am using a check box to select time slot. Now I want to show/enable checkboxes according to hour/time. Example: if right now time is 12pm so user should not able to book appointment of 10 am, she only able to book appointment after 12pm.

Can anyone give some idea what should I do??
Thanks in advance....

推荐答案

你好Betu,



我试过你的要求,你可以利用它。

我有在这样的aspx页面中放置了三个复选框

Hi Betu,

I tried your requirement that you can make use of it.
I have placed three checkbox in aspx page like this
<asp:checkbox id="CheckBox1" runat="server" text="3 PM"/> <!--24Hr Text="15 PM"-->
<asp:checkbox id="CheckBox2" runat="server" text="4 PM"/> <!--24Hr Text="16 PM"-->
<asp:checkbox id="CheckBox3" runat="server" text="5 PM" /><!--24Hr Text="17 PM"-->



在服务器端,为复选框写了一个通用的验证函数


In server side, wrote a common validation function for checkbox

protected void checkboxHoursValidate(CheckBox chkBox)
       {
           int hours = Convert.ToInt32(DateTime.Now.ToString("hh")); // 12Hr time format
           // int hours = DateTime.Now.Hour; // 24hr time format
           int chkbxHr = Convert.ToInt32(chkBox.Text.Split(' ')[0]);
           chkBox.Enabled = hours < chkbxHr;
       }



在Page_Load方法中,我将所需的复选框传递给验证函数,如下所示


And in Page_Load method, am passing my required checkbox to the validation function like this

checkboxHoursValidate(CheckBox1);
checkboxHoursValidate(CheckBox2);
checkboxHoursValidate(CheckBox3);



我在IST下午4:45检查,当时它禁用了checkbox1(下午3点)和checkbox2(4 PM)分别

启用Checkbox3(下午5点)。


希望这能让你知道如何使用。



问候,

RK


I checked at 4:45 PM IST, at that time it disables checkbox1(3 PM) and checkbox2(4 PM) respectively
Checkbox3(5 PM) alone is enabled.

Hope this gives you some idea how to make use of.

Regards,
RK


您好,





添加一个名为Shift(AM / PM)的字段。



在数据库表中,在主表中添加Shift和Timing。



当你显示时间时只需检查



其中Now.ToString(tt)== DBValue.Shift



这只是暗示你可以用这个逻辑来解决你的问题。



--- Chetan
Hi,


Add one field called Shift (AM/PM).

In database table add Shift along with Timing in master table.

While you display that timing just check

Where Now.ToString("tt")== DBValue.Shift

This is just hint you may use this logic to solve your issue.

---Chetan


我将定义一个Dictionary< CheckBox,int>它将CheckBoxes对应于约会的时间段作为其键,以及从午夜到时间段开头的偏移量作为其值:
I would define a Dictionary<CheckBox,int> that held the CheckBoxes corresponding to the time-slots for appointments as its Keys, and the offset from midnight to the beginning of the time-slot as its values:
// code shown here is done in WinForms, but should map to ASP.NET easily

private Dictionary<CheckBox, int> dctCBxDTm;

// used to hold the current hour
private int currentHour;

private void YourApp_SomeInitializationEvent()
{
    // assume hourly appointments beginning at 8AM
    // an hour break for lunch, then 1PM ~ 4PM
    dctCBxDTm = new Dictionary<CheckBox, int>
    {
        {checkBox1, 8},
        {checkBox2, 9},
        {checkBox3, 10},
        {checkBox4, 11},
        {checkBox5, 13},
        {checkBox6, 14},
        {checkBox7, 15},
        {checkBox8, 16}
    };
}

然后我定义了一个计划更新功能:

Then I'd define a schedule update function:

private void ScheduleUpdate()
{
    // get the current hour
    currentHour = DateTime.Now.Hour;

    // test if in working hours assume:
    // appointments can be scheduled
    // beginning 6am up to 3:59PM
    if (currentHour < 6 || currentHour > 16)
    {
        // use whatever to show a dialog
        MessageBox.Show("Thank you for using ACA HealthCare.\r\n\r\nTry again tomorrow if you are not dead.", "Morituri te Salutamus", MessageBoxButtons.OK, MessageBoxIcon.Warning);

        // exit
        return;
    }

    foreach (var kvp in dctCBxDTm)
    {
        kvp.Key.Enabled = kvp.Value >= currentHour;
    }
}

显然你需要确定你想如何调用更新功能,频率等等。每当用户使用时,我都会按需这样做。在我假设登录过程之后,系统启动您的站点。

Obviously you need to determine how you want to call the update function, how frequently, etc. I'd do that "on demand" whenever a user of the system starts your site, after, I assume, a log-in process.


这篇关于复选框应该是可见的或根据时间启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆