比较两种形式之间的日期/时间 [英] comparing dates/times between 2 forms

查看:64
本文介绍了比较两种形式之间的日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较/验证2个不同形式的datetimePickers?例如,我有单独的签入/签出表单,我想验证用户在签入之前没有签出。

how do I compare/validate 2 datetimePickers that are in different forms? eg.I have separate check in/out forms ,and I want to validate that a user not check out before checking in.

推荐答案

checkout co= new checkout(datepicker);
            co.ShowDialog(this);







public CheckOut(string k)
       {

           InitializeComponent();
           lbldate.Text= k;


       }


两种形式都是用户界面组件。他们不应该存储信息,只是想象(包括改变的可能性)。因此,两种形式都应该针对相同的数据集。然后,值范围检查属于数据模型部分中的setter:
Both forms are User Interface components. They shouldn't store information, just visualize (including the possibility to change) it. So both forms should target the same data set. Value range checks then belong to setters in the data model part:
public class SomeTimeRelatedStuff
{
    private DateTime _checkInTime;
    private DateTime _checkOutTime;

    public DateTime CheckInTime
    {
        get { return(_checkInTime); }
        set { _checkInTime = value; }
    }

    public DateTime CheckOutTime
    {
        get { return(_checkOutTime); }
    }

    public bool SetCheckOutTime(DateTime checkOutTime)
    {
        if(checkOutTime < _checkInTime)
        {
            return(false);
        }

        _checkOutTime = checkOutTime;
        return(true);
    }
}

在您的UI代码中,然后使用用户输入的值调用 SetCheckOutTime()。返回值告诉您该值是否已被接受。



很好的部分是检查是在数据类中完成的。那个班级应该知道它的数据以及它必须与其几个部分之间的关​​系。这有助于保持UI代码清洁业务逻辑。

In your UI code, you then call SetCheckOutTime() with the value that user has entered. The return value tells you if that value has been accepted.

The nice part is that the checking is done in the data class. That class should know about its data and the relations that it has to have to its several parts. That helps keeping UI code clean of business logic.


这篇关于比较两种形式之间的日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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