Xiao Ming, the Moonlight clan, applied for a credit card, and the bank stipulated that it would be able to collect the credit card after 10 working days after the successful reception (assuming normal double breaks do not work). Tags: Xiao Ming's This card business will be completed on that day?
Analysis requirements: According to the admissibility date, 10 working days from this limit, the deadline can be calculated, which need to normal double, national holidays, supplementary classes and other situations to deal with.
Solution:
1. Create a table to hold the national holidays and the date data of the supplementary classes. (The country publishes new holiday data every year).
2, according to the start time and the effective working day 2 input conditions, the output due date.
Code snippet:
1 /// <summary>2 ///according to the start time and the effective working day, calculate the due date, including the treatment of the holidays, the replenishment, the double Hugh3 /// </summary>4 /// <param name= "DT" >Date of processing</param>5 /// <param name= "WorkDay" >How many working days</param>6 /// <returns></returns>7 PublicDateTime calculateenddate (DateTime DT,intWorkDay)8 {9DateTime tempdate =DT;Ten while(workday-->1) One { A //① judge whether it is a statutory holiday - BOOLHoilday =false; -Tempdate = Ishoilday (Tempdate,refhoilday); the if(Hoilday) - Continue; - //② judge Whether it is a double break or a supplementary class - if(Tempdate.dayofweek = = Dayofweek.saturday | | tempdate.dayofweek = =dayofweek.sunday) + { -Tempdate =isweeked (tempdate); + Continue; A } at //The last day for the weekend, the next business day to push - if(WorkDay = =0&& (Tempdate.dayofweek = = Dayofweek.saturday | | tempdate.dayofweek = =dayofweek.sunday)) - { -Tempdate = isweeked (Tempdate.adddays (1)); - } - } in return new DateTime (tempdate.year,tempdate.month,tempdate.day,23,59,59); -}
To determine whether the statutory supplementary classes:
1 /// <summary>2 ///Check whether it is a statutory supplementary course3 /// </summary>4 /// <param name= "DT" >Date</param>5 /// <returns></returns>6 Privatedatetime isweeked (datetime dt)7 {8 BOOLIsworkday =false;9DateTime tempdate =DT;Ten BOOLresult = Oracleservicefactory.loadservice<ihoildayservice> (). Ishoilday (tempdate, enum_ holiday type. Supplementary classes); One if(!result) A { - while(!isworkday) - { theTempdate = Tempdate.adddays (1); -result = Oracleservicefactory.loadservice<ihoildayservice> (). Ishoilday (tempdate, enum_ holiday type. Supplementary classes); - if(!result) - { +Tempdate = Tempdate.adddays (1); -Isworkday =true; + Break; A } at } - } - returntempdate; -}
Decide whether it is holiday holidays:
1 /// <summary>2 ///decide whether it is holiday holidays3 /// </summary>4 /// <param name= "DT" >Date</param>5 /// <param name= "Ishoilday" >Initialize</param>6 /// <returns></returns>7 PrivateDateTime ishoilday (DateTime DT,ref BOOLishoilday)8 {9DateTime tempdate =DT;Ten BOOLresult = Oracleservicefactory.loadservice<ihoildayservice> (). Ishoilday (tempdate, enum_ holiday type. Statutory holidays); One if(!result) ATempdate = Tempdate.adddays (1);//Normal working day - Else - { the //is a holiday - while(!ishoilday)//push forward until it's not a holiday. - { -Tempdate = Tempdate.adddays (1); +result = Oracleservicefactory.loadservice<ihoildayservice> (). Ishoilday (tempdate, enum_ holiday type. Statutory holidays); - if(!result) + { AIshoilday =true; at Break; - } - } - } - returntempdate; -}
Get deadlines, including the handling of holidays, replenishment, and double breaks