asp.net3.5 csharp Calendar 控件显示周次

ExpandedBlockStart.gif javascript代码
 1       < script type = " text/javascript " >
 2           function  addWkColumn(tblId, wkStart)
 3          {
 4               var  tbl  =  document.getElementById(tblId);
 5 
 6               var  tblBodyObj  =  tbl.tBodies[ 0 ];
 7               for  ( var  i = 0 ; i < tblBodyObj.rows.length; i ++
 8              {
 9                   //  Month Header
10                   if  (i == 0 )
11                  {
12                       //  Add extra colspan column
13                      tblBodyObj.rows[i].cells[ 0 ].colSpan = 8 ;
14                  }
15                   //  Week Header
16                   if  (i == 1 )
17                  {
18                       //  Add week column headline
19                       var  newCell  =  tblBodyObj.rows[i].insertCell( 0 );
20                      newCell.innerHTML  =   ' wk ' ;
21                      newCell.style.fontSize =   ' 8px ' ;
22                      newCell.style.fontWeight =   ' bold ' ;
23                      newCell.style.verticalAlign =   ' bottom ' ;
24                      newCell.style.backgroundColor  =   ' #ffffee ' ;
25                  }    
26                      
27                   //  Normal row
28                   if  (i  >=   2  )
29                  {
30                       //  Add the weeknumbers
31                       var  newCell  =  tblBodyObj.rows[i].insertCell( 0 );
32                       if  (tblBodyObj.rows[i].cells[ 1 ].style.color  !=   ' white '   ||  tblBodyObj.rows[i].cells[ 2 ].style.color  !=   ' white '   ||  tblBodyObj.rows[i].cells[ 3 ].style.color  !=   ' white '   ||  tblBodyObj.rows[i].cells[ 4 ].style.color  !=   ' white '   ||  tblBodyObj.rows[i].cells[ 5 ].style.color  !=   ' white '   ||  tblBodyObj.rows[i].cells[ 6 ].style.color  !=   ' white '   ||  tblBodyObj.rows[i].cells[ 7 ].style.color  !=   ' white '   )
33                      {
34                          newCell.innerHTML  =  wkStart;
35                          wkStart  +=   1 ;
36                      }
37                      newCell.style.fontSize =   ' 8px ' ;
38                      newCell.style.backgroundColor  =   ' #ffffee ' ;
39                  }
40              }
41          }
42 
43           < / script>

C#代码

 

ExpandedBlockStart.gif csharp 代码
  1  // 涂聚文注:在1月份的周次显示出显问题,请能纠正过来修改,谢谢
  2       protected   void  Page_Load( object  sender, EventArgs e)
  3      {
  4          HtmlHead head  =  (HtmlHead)Page.Header;
  5           this .Calendar1.ToolTip  =   " 缔友计算机信息技术有限有公司日历 " ;
  6 
  7          Page.Header.Title  =   " 缔友计算机信息技术有限有公司日历--显示周次 " ;
  8          HtmlMeta meta  =   new  HtmlMeta();
  9          meta.Name  =   " Author " ;
 10          meta.Attributes.Add( " Content  " " geovindu " );
 11          head.Controls.AddAt( 1 , meta);
 12 
 13          HtmlMeta key  =   new  HtmlMeta();
 14          key.Name  =   " keywords " ;
 15          key.Attributes.Add( " Content  " " Geovin Du " );
 16          head.Controls.AddAt( 2 , key);
 17 
 18          HtmlLink ico  =   new  HtmlLink();
 19          ico.Href  =   " ~/favicon.ico " ;
 20          ico.Attributes.Add( " rel " " icon " );
 21          ico.Attributes.Add( " type " " image/ico " );
 22          head.Controls.AddAt( 3 , ico);
 23 
 24 
 25          HtmlLink bookmark  =   new  HtmlLink();
 26          bookmark.Href  =   " ~/favicon.ico " ;
 27          bookmark.Attributes.Add( " rel " " bookmark " );
 28           // bookmark.Attributes.Add("type", "image/ico");
 29          head.Controls.AddAt( 4 , bookmark);
 30 
 31          HtmlLink shortcut  =   new  HtmlLink();
 32          shortcut.Href  =   " ~/favicon.ico " ;
 33          shortcut.Attributes.Add( " rel " " shortcut icon " );
 34          shortcut.Attributes.Add( " type " " image/x-icon " );
 35          head.Controls.AddAt( 5 , shortcut);
 36 
 37          HtmlMeta description  =   new  HtmlMeta();
 38          description.Name  =   " description " ;
 39          description.Attributes.Add( " Content  " " 涂聚文,缔友计算机信息技术有限公司,经营信息流,物流,人力资源流,资本流的系统解决方案的开发与设计和服务 " );
 40          head.Controls.AddAt( 6 , description);
 41           int  i = getISOWeek(DateTime.Today);
 42          Response.Write(i.ToString() + " weeks " );
 43          Response.Write(Calendar1.TodaysDate.ToShortDateString());
 44          
 45      }
 46       ///   <summary>
 47       ///  添加周列
 48       ///   </summary>
 49       ///   <param name="curMonth"></param>
 50       private   void  addWeekNumberColumn(DateTime curMonth) //
 51      {
 52           string  jscript;
 53           //DateTime   curMonth = Convert.ToDateTime(Calendar1.VisibleDate.Year.ToString() + "-" + Calendar1.VisibleDate.Month.ToString() + "-01");
Get the date shown in the calendar control
 54          //  curMonth = Calendar1.VisibleDate;
 55          
 56           //  Find first day of the current month
 57           //  58 
 59           //  Build javascript
 60  //         if (curMonth.Month == 1 && curMonth.Day == 1)
 61  //         {
 62  //             int w = 1;
 63  //              jscript = @"<script type='text/javascript'> 
 64  //                         addWkColumn('" + Calendar1.ClientID + "', " + w.ToString() + @");
 65  //                         </script>";
 66  //         }
 67          jscript  =   @" <script type='text/javascript'> 
 68                          addWkColumn(' "   +  Calendar1.ClientID  +   " ',  "   +  getISOWeek(curMonth).ToString()  +   @" );
 69                          </script> " ;
 70 
 71           //  Add script to page for execution of addWkColumn javascript function
 72          Page.ClientScript.RegisterStartupScript( this .GetType(),  " AddWeeknumbers " , jscript);
 73      }
 74 
 75       ///   <summary>
 76       ///  获取几周
 77       ///   </summary>
 78       ///   <param name="day"></param>
 79       ///   <returns></returns>
 80       private   int  getISOWeek(DateTime day)
 81      {
 82           return  System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(day, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
 83      }
 84 
 85 
 86       protected   void  Calendar1_PreRender( object  sender, EventArgs e)
 87      {
 88           if  (Calendar1.VisibleDate.Year  ==   1   &&  Calendar1.VisibleDate.Month  ==   1 )
 89          {
 90               //  Add weeknumbers
 91              DateTime curMonth  =  Calendar1.TodaysDate;
 92              Calendar1.VisibleDate  =   new  DateTime(curMonth.Year, curMonth.Month,  1 );
 93              addWeekNumberColumn(Calendar1.VisibleDate);
 94          }
 95           if  (Calendar1.VisibleDate.Month  ==   1 )
 96          {
 97               // DateTime curMonth;
 98              Calendar1.VisibleDate  =   new  DateTime(Calendar1.VisibleDate.Year,  1 1 );
 99              addWeekNumberColumn(Calendar1.VisibleDate);
100          }
101          Calendar1.VisibleDate  =   new  DateTime(Calendar1.VisibleDate.Year, Calendar1.VisibleDate.Month,  1 );
102 
103          addWeekNumberColumn(Calendar1.VisibleDate);
104 
105           int  i  =  getISOWeek(Calendar1.VisibleDate);
106          Response.Write(i.ToString()  +   " weeks " );
107      }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
之前在网上想找一个简单易用的周日历选择插件,发现这种前端周日历插件很少,而且很多文章写的周的算法都不是统一的,所以自己实现了一个基于jquery的周日历插件(还支持跳转到指定年份和周哦)。 插件中周的算法:每周以周日为起始,第一周以每年第一个星期四所在的周为第一周(网上找的好像这个算法比较正规) 实现的效果是在手机端,也可以在PC端用,毕竟功能才是主要的。如果觉得样式不入眼可以自行随意修改。 //调用周日历方法 var weekfn = new jcalendar_week({ element: "#jcalendar_week",//填充日历的dom元素 dayaddclass:function(date){ //添加某天时给添加类名(参数:1.日期)(返回类名字符串,多个以空格分开) return ""; }, dayclick:function(date,obj){ //day点击事件(参数:1.日期,2.所点击DOM元素) $(obj).addClass("calendar_day_act").siblings().removeClass("calendar_day_act"); } }); 点击上方显示当前年份和周的DOM部分可选择并跳转到指定年份和周。 插件提供的方法: //获取周第一天方法weekfirstdate(),传入年份和周数 console.log(weekfn.weekfirstdate(2018,36)); //获取传入日期为当年第几周getweeknum(),传入年,月,日(注:这里的月份从0开始) console.log(weekfn.getweeknum(2018,0,16)); //跳转到指定周confirmweek(),传入年份和周数 weekfn.confirmweek(getyear,getweek); //跳转到本周nowweek() weekfn.nowweek();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值