You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data;
  6. using System.Web.UI.WebControls;
  7. using System.ComponentModel;
  8. using System.Data.SqlClient;
  9. using System.Text;
  10. using System.Drawing;
  11. #region histroy
  12. ///程式代號:UCCalendar
  13. ///程式名稱:系統共用多日期選擇控件
  14. ///程式說明:
  15. ///xx.YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
  16. ///01.2012/08/03 1.0 Ethan CREATE
  17. #endregion
  18. namespace OT.Controls
  19. {
  20. public class Calendar : System.Web.UI.WebControls.Calendar
  21. {
  22. public List<DateTime> SelectDate
  23. {
  24. set
  25. {
  26. ViewState["SelectDate"] = value;
  27. }
  28. get
  29. {
  30. if (ViewState["SelectDate"] == null)
  31. ViewState["SelectDate"] = new List<DateTime>();
  32. return (List<DateTime>)ViewState["SelectDate"];
  33. }
  34. }
  35. public Dictionary<string, string> NameAndColors
  36. {
  37. set;
  38. get;
  39. //set
  40. //{
  41. // ViewState["NameAndColors"] = value;
  42. //}
  43. //get
  44. //{
  45. // if (ViewState["NameAndColors"] == null)
  46. // ViewState["NameAndColors"] = new Dictionary<string, string>();
  47. // return (Dictionary<string, string>)ViewState["NameAndColors"];
  48. //}
  49. }
  50. public int ColumsCount
  51. {
  52. set
  53. {
  54. ViewState["ColumsCount"] = value;
  55. }
  56. get
  57. {
  58. if (ViewState["ColumsCount"] == null)
  59. ViewState["ColumsCount"] = 3;
  60. return Convert.ToInt32(ViewState["ColumsCount"]);
  61. }
  62. }
  63. protected override void OnLoad(EventArgs e)
  64. {
  65. base.OnLoad(e);
  66. }
  67. protected override void OnDayRender(TableCell cell, CalendarDay day)
  68. {
  69. cell.VerticalAlign = VerticalAlign.Top;
  70. cell.HorizontalAlign = HorizontalAlign.Left;
  71. List<DateTime> lstSelectData = SelectDate;
  72. CheckBox chkSelect = new CheckBox(); ;
  73. chkSelect.ID = day.Date.ToString("yyyy/MM/dd");
  74. chkSelect.Attributes.Add("Date", day.Date.ToString("yyyy/MM/dd"));
  75. chkSelect.Attributes.Add("onclick", "fnSelectDate(this);");
  76. chkSelect.Text = day.Date.Day.ToString().PadLeft(2, '0');
  77. if (lstSelectData.Contains(day.Date))
  78. {
  79. chkSelect.Checked = true;
  80. }
  81. if (day.IsWeekend)
  82. {
  83. chkSelect.ForeColor = System.Drawing.Color.Red;
  84. }
  85. cell.Controls.Clear();
  86. if (!day.IsOtherMonth)
  87. {
  88. cell.Controls.Add(chkSelect);
  89. if (NameAndColors != null)
  90. {
  91. int intCount = 3;
  92. foreach (KeyValuePair<string, string> item in NameAndColors)
  93. {
  94. if (item.Value.IndexOf(day.Date.ToString("yyyy/MM/dd")) > -1)
  95. {
  96. Label lblGoodDayName = new Label();
  97. lblGoodDayName.Text = "■";
  98. lblGoodDayName.ToolTip = item.Key;
  99. //lblGoodDayName.BackColor = ColorTranslator.FromHtml(item.Value.Split(';')[0]);
  100. lblGoodDayName.ForeColor = ColorTranslator.FromHtml(item.Value.Split(';')[0]);
  101. lblGoodDayName.Font.Bold = true;
  102. if (intCount % ColumsCount == 0)
  103. {
  104. Literal ltrBr = new Literal();
  105. ltrBr.Text = "<br />";
  106. cell.Controls.Add(ltrBr);
  107. }
  108. cell.Controls.Add(lblGoodDayName);
  109. intCount++;
  110. }
  111. }
  112. }
  113. }
  114. //base.OnDayRender(cell, day);
  115. }
  116. }
  117. }