如果他在datetimepicker中选择的日期是c#中的假期,我如何向用户显示按摩 [英] How i show massage to the user if the day that he choose in datetimepicker is holiday in c#
本文介绍了如果他在datetimepicker中选择的日期是c#中的假期,我如何向用户显示按摩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户选择时喜欢这一天19-2-2016是星期五并向用户显示消息告诉他
这一天是星期五和它的假期
我尝试了什么:
i希望在C#WinApp
When User choose Like this day 19-2-2016 is Friday and show message to the user tell him
this day is Friday and its Holiday
What I have tried:
i want this using datetimepicker in C#WinApp
推荐答案
1)定义假期课程。例如。开始日期,结束日期和名称。
2)定义一个包含1)所有假日对象的类,并提供添加假日的方法,并检查某个日期是否属于某个假日。然后,该方法将遍历所有存储的假期,并检查storedHoliday.StartingDate< = dateInQuestion< = storedHoliday.EndingDate,如果找到命中,则返回true,可选择使用假期的名称(例如作为out-parameter) 。
1) Define a class for holidays. E.g. starting-date, ending-date and name.
2) Define a class that holds all holiday-objects of 1) and offers methods to add a holiday and to check whether a certain date falls into some holiday. That method would then loop over all stored holidays and check for storedHoliday.StartingDate <= dateInQuestion <= storedHoliday.EndingDate and return true if it finds a hit, maybe optionally with the name of the holidays (e.g. as an out-parameter).
尝试使用以下代码:
添加ValueChanged
事件到的DateTimePicker。
Try with below code:
AddValueChanged
event to DateTimePicker.
this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
然后添加以下代码来处理 ValueChanged
事件:
Then add following code to handle ValueChanged
event:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
// Declare holiday list
string[] holidayList = { "03/01/2016", "02/20/2016", "02/17/2016" };
// Check if selected value is holiday and display message
if (holidayList.Contains(dateTimePicker1.Value.ToString("MM/dd/yyyy")))
{
MessageBox.Show("Selected date is holiday");
}
// Check if selected value is Friday then display message
if (dateTimePicker1.Value.ToString("dddd") == "Friday")
{
MessageBox.Show("Selected date is holiday");
}
}
尝试
try
if (datetimepicker1.Value.ToString("ddd") == "Fri")
{
MessageBox.Show("Holiday");
}
这篇关于如果他在datetimepicker中选择的日期是c#中的假期,我如何向用户显示按摩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文