WPF determines whether the date is a work day or holiday, or a wpf holiday

Source: Internet
Author: User

WPF determines whether the date is a work day or holiday, or a wpf holiday

Get returned information via API (http://www.easybots.cn/holiday_api.net)

Write a function for receiving feedback IsHoliday

Public string IsHoliday (string date) {string url = @ "http://www.easybots.cn/api/holiday.php? D = "; url = url + date; HttpWebRequest httpRequest = (HttpWebRequest) WebRequest. create (url); httpRequest. timeout = 2000; httpRequest. method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse) httpRequest. getResponse (); StreamReader sr = new StreamReader (httpResponse. getResponseStream (), System. text. encoding. getEncoding ("gb2312"); string result = sr. readToEnd (); result = result. replace ("\ r ",""). replace ("\ n ",""). replace ("\ t", ""); int status = (int) httpResponse. statusCode; sr. close (); return result ;}Holiday Functions

Based on the API, you can find that the returned content includes the following three types:
{& Quot; 20130101 & quot;: & quot; 2 & quot "}

{& Quot; 20130103 & quot;: & quot; 1 & quot "}

{& Quot; 20130201 & quot;: 0}

Because we only need to determine whether it is a working day, we need to determine two types, that is, 0 or not.

If the value is 0, "" does not exist, and "" exists for 1 and 2. Note that

Simple Field Truncation

Substring (s. length-2, 1 );

You can determine whether the intercepted field is 0.

Then write a MouseLeave event to the datepicker control.

Private void DP_MouseLeave (object sender, MouseEventArgs e) {string date = Convert. toDateTime (DP. text. toString ()). toString ("yyyyMMdd"); string num = IsHoliday (date ). substring (IsHoliday (date ). length-2, 1); switch (num) {case "0": TB. text = "workday"; break; default: TB. text = "Holidays"; break ;}}Departure event of the Time Control

As follows:

Of course, the first two days of News said that some units in Beijing had a holiday in November 7-12, which is not supported.

 


C # enter a time period to determine the number of working days in the time period (excluding holidays)

I wrote it and implemented it using an extension method. I have made some adjustments according to the answers in a Foreign Forum. Thanks to Alexander! The following is the complete source code with the core code in the attachment. If you have any questions, please contact us.

Note: The original method is very well written. You can specify a national holiday, but it is not used in the instance source code. Please take a look at it yourself.

Core code:
// ------------------------------------------------------------------------- // <Copyright file = "DateTimeExtention. cs "Author =" do not know Taipei Road "> // TODO: Update copyright text. // </copyright> // ----------------------------------------------------------------------------- namespace WorkingDays {using System; // <summary> // TODO: Update summary. /// </summary> public static class DateTimeExtention {// <summary> // Calculates number of business days, taking into account: ///-weekends (Saturdays and Sundays) ///-bank holidays in the middle of the week // </summary> /// <param name = "firstDay"> First day in the time interval </param> /// <param name = "lastDay"> Last day in the time interval </param> /// <param name = "bankHolidays"> List of bank holidays excluding weekends </ param> // <returns> Number of business days during the 'SIZE' </returns> public static int BusinessDaysUntil (this DateTime firstDay, dateTime lastDay, param ...... remaining full text>


How to Use js to determine that the computing date is within three working days

Blame
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.