比较两种形式之间的日期/时间

编程入门 行业动态 更新时间:2024-10-17 04:54:43
本文介绍了比较两种形式之间的日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何比较/验证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.

更多推荐

比较两种形式之间的日期/时间

本文发布于:2023-11-30 16:06:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   形式   日期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!