SheetTime.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:4k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using System.Drawing.Design;
  8. namespace OThinker.H3.WorkSheet
  9. {
  10. /// <summary>
  11. /// Summary description for SheetDropDownTime.
  12. /// </summary>
  13. [DefaultProperty("Text"), 
  14. ToolboxData("<{0}:SheetDropDownTime runat=server></{0}:SheetDropDownTime>")]
  15. public class SheetTime : DropDownTime, ISheetControl
  16. {
  17. /// <summary>
  18. /// 默认值的类型
  19. /// </summary>
  20. public enum DefaultValueType
  21. {
  22. None, 
  23. CurrentTime, 
  24. CurrentDate, 
  25. OriginateTime, 
  26. OriginateDate
  27. }
  28. public SheetTime()
  29. {
  30. }
  31. #region 类SMTextBox属性
  32. private string _DataField = null;
  33. [Category("WorkSheet"),DefaultValue("")]
  34. [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  35. public string DataField
  36. {
  37. get
  38. {
  39. return this._DataField;
  40. }
  41. set
  42. {
  43. this._DataField = value;
  44. }
  45. }
  46. private DefaultValueType _DefaultValue = DefaultValueType.None;
  47. [Category("WorkSheet"), DefaultValue(DefaultValueType.None)]
  48. public DefaultValueType DefaultValue
  49. {
  50. get
  51. {
  52. return this._DefaultValue;
  53. }
  54. set
  55. {
  56. this._DefaultValue = value;
  57. }
  58. }
  59. #endregion
  60. #region ISheetControl 成员
  61.         public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  62. {
  63. if(this.DataField == null || this.DataField == "")
  64. {
  65. }
  66. else if(SheetPage.Enviroment.InstanceData[this.DataField] == null)
  67. {
  68. }
  69. else if(SheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
  70. {
  71. this.Visible = false;
  72. }
  73. else if(SheetPage.Enviroment.InstanceData[this.DataField].ItemType != typeof(System.DateTime))
  74. {
  75. // 类型不匹配
  76. }
  77. else
  78. {
  79. if(
  80. SheetPage.Enviroment.InstanceData[this.DataField].Editable == true &&
  81. this.DefaultValue != DefaultValueType.None && 
  82. ((System.DateTime)SheetPage.Enviroment.InstanceData[this.DataField].Value).CompareTo(System.DateTime.Parse(OThinker.Data.Convertor.GetDefaultValue(typeof(System.Data.SqlTypes.SqlDateTime)).ToString())) <= 0
  83. )
  84. {
  85. // 如果使用当前时间作为默认值,并且当前该值为空,则使用当前时间作为默认值
  86. switch(this.DefaultValue)
  87. {
  88. case DefaultValueType.CurrentTime:
  89. this.TimeValue = System.DateTime.Now;
  90. break;
  91. case DefaultValueType.CurrentDate:
  92. this.TextValue = System.DateTime.Now.ToShortDateString();
  93. break;
  94. case DefaultValueType.OriginateTime:
  95.                             this.TextValue = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateTime].Value.ToString();
  96. break;
  97. case DefaultValueType.OriginateDate:
  98.                             this.TextValue = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateDate].Value.ToString();
  99. break;
  100. default:
  101. throw new NotImplementedException();
  102. }
  103. }
  104. else if(SheetPage.Enviroment.InstanceData[this.DataField].Value != null)
  105. {
  106. this.TimeValue = (System.DateTime)SheetPage.Enviroment.InstanceData[this.DataField].Value;
  107. }
  108. this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
  109. }
  110. }
  111.         public virtual bool ValidateDataField(
  112.             OThinker.H3.WorkSheet.SheetPage SheetPage,
  113.             System.Collections.Generic.List<string> Errors)
  114.         {
  115.             return true;
  116.         }
  117.         public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  118. {
  119. if(
  120. this.DataField != null &&
  121. this.DataField != "" &&
  122. SheetPage.Enviroment.InstanceData[this.DataField] != null && 
  123. SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(System.DateTime) && 
  124. SheetPage.Enviroment.InstanceData[this.DataField].Visible && 
  125. SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  126. {
  127. //写回数据
  128. SheetPage.Enviroment.InstanceData[DataField].Value = this.TimeValue;
  129. }
  130. }
  131. #endregion
  132.         protected override void Render(HtmlTextWriter writer)
  133.         {
  134.             if (this.Enabled)
  135.             {
  136.                 base.Render(writer);
  137.             }
  138.             else
  139.             {
  140.                 writer.Write(this.TimeValue);
  141.             }
  142.         }
  143. }
  144. }