As a result of the work required to write a procedure, judge a year all the holiday date, according to the national holidays and compensatory leave date of judgment.
protected voidButton1_Click (Objectsender, EventArgs e) { stringsql =""; //number of weeks of January 1, 2015 intYear = -; intWeek =4; for(intmonth =1; Month <= A; month++) { intDay = to; Switch(month) { Case 2: if(Isleapyear (year)) { Day= in; } Else{ Day= -; } Break; Case 4: Day= -; Break; Case 6: Day= -; Break; Case 9: Day= -; Break; Case One: Day= -; Break; } for(intA =1; A <= day; a++) { stringTime =string. Format ("{0}-{1}-{2}", year, month, a); if(Week = =7||Checkfangjia (Time)) { if(!Bufangjia (Time)) { stringm =string. Format ("INSERT into [dbo]. [Tm_holidays] ([ID], [year], [date]) VALUES (N '"+ year +"', N ' {0} 00:00:00.000 ');</br>", time); SQL+=m; Response.Write (m); //Response.Write ("2015" + month + "Month" + A + "day" + "Week" + Week + "</br>"); } } if(Week = =7) {Week=1; } Else{Week++; } } } } //judge whether a day is a holiday Public BOOLCheckfangjia (stringDay ) { //all dates for the holidays string[] Fangjia = {"2015-1-1","2015-1-2","2015-1-3","2015-2-18","2015-2-19","2015-2-20","2015-2-21","2015-2-22","2015-2-23","2015-2-24","2015-4-4","2015-4-5","2015-4-6","2015-5-1","2015-5-2","2015-5-3","2015-6-20","2015-6-21","2015-6-22","2015-9-26","2015-9-27","2015-10-1","2015-10-2","2015-10-3","2015-10-4","2015-10-5","2015-10-6","2015-10-7" }; foreach(stringSinchFangjia) { if(S.equals (day)) {return true; } } return false; } //judge whether a day is take some Public BOOLBufangjia (stringDay ) { //Date with Saturday Sunday take some string[] Bufangjia = {"2015-1-4","2015-2-15","2015-2-28","2015-10-10" }; foreach(stringSinchBufangjia) { if(S.equals (day)) {return true; } } return false; } //Judging the common year or leap year Private BOOLIsleapyear (intYear ) { if(Year% -==0) { if(Year% -==0) { return true; } } Else { if(Year%4==0) { return true; } } return false; }
. NET determine the date of all holidays for a given year