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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Design;
  7. [assembly:TagPrefix("OThinker.H3.WorkSheet","SheetControls")]
  8. namespace OThinker.H3.WorkSheet
  9. {
  10. /// <summary>
  11. /// SheetCalendar1 的摘要说明。
  12. /// </summary>
  13. [ToolboxBitmap(typeof(SheetCalendar),"OThinker.H3.WorkSheet.SheetCalendar.bmp")]
  14. [ToolboxData("<{0}:SheetCalendar runat=server></{0}:SheetCalendar>")]
  15. public class SheetCalendar:System.Web.UI.WebControls.Calendar, ISheetControl
  16. {
  17. public SheetCalendar()
  18. {
  19. }
  20. #region 类SheetCalendar属性
  21. private string _DataField = null;
  22. [Bindable(true),Category("WorkSheet"),DefaultValue("")] 
  23. [Editor(typeof(DataSelector),typeof(UITypeEditor))]
  24. public string DataField
  25. {
  26. get
  27. {
  28. return this._DataField;
  29. }
  30. set
  31. {
  32. this._DataField = value;
  33. }
  34. }
  35. #endregion
  36. #region ISheetControl 成员
  37. public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  38. {
  39. if(this.DataField == null || this.DataField == "")
  40. {
  41. }
  42. else if(SheetPage.Enviroment.InstanceData[this.DataField] == null)
  43. {
  44. }
  45.             else if (SheetPage.Enviroment.InstanceData[this.DataField].ItemType != typeof(System.DateTime))
  46.             {
  47.                 // 类型不匹配
  48.             }
  49.             else if (SheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
  50.             {
  51.                 this.Visible = false;
  52.             }
  53.             else
  54.             {
  55.                 this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
  56.                 this.SelectedDate = (System.DateTime)SheetPage.Enviroment.InstanceData[this.DataField].Value;
  57.             }
  58. }
  59.         public virtual bool ValidateDataField(
  60.             OThinker.H3.WorkSheet.SheetPage SheetPage,
  61.             System.Collections.Generic.List<string> Errors)
  62.         {
  63.             if (
  64.                 this.DataField != null &&
  65.                 this.DataField != "" &&
  66.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  67.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  68.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  69.             {
  70.                 try
  71.                 {
  72.                     OThinker.Data.Convertor.Convert(
  73.                         this.SelectedDate,
  74.                         SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
  75.                 }
  76.                 catch
  77.                 {
  78.                     Errors.Add(
  79.                         "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
  80.                         "字段名称为:" + this.DataField + "," +
  81.                         "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  82.                     return false;
  83.                 }
  84.             }
  85.             return true;
  86.         }
  87. public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  88. {
  89. if(
  90. this.DataField != null &&
  91. this.DataField != "" && 
  92. SheetPage.Enviroment.InstanceData[this.DataField] != null && 
  93. SheetPage.Enviroment.InstanceData[this.DataField].Visible && 
  94. SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  95. {
  96. //写回数据
  97. object convertedValue;
  98. try
  99. {
  100. convertedValue = OThinker.Data.Convertor.Convert(
  101. this.SelectedDate, 
  102. SheetPage.Enviroment.InstanceData[this.DataField].ItemType, 
  103.                         true);
  104. }
  105. catch
  106. {
  107.                     SheetPage.Enviroment.NotifyMessage(
  108. "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" + 
  109. "字段名称为:" + this.DataField + "," + 
  110. "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  111. return;
  112. }
  113. SheetPage.Enviroment.InstanceData[DataField].Value = convertedValue;
  114. }
  115. }
  116. #endregion
  117. }
  118. }