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