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

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. namespace OThinker.H3.WorkSheet
  8. {
  9. /// <summary>
  10. /// SheetLabel 的摘要说明。
  11. /// </summary>
  12. /// 
  13. [ToolboxBitmap(typeof(SheetLabel),"OThinker.H3.WorkSheet.SheetLabel.bmp")]
  14. [ToolboxData("<{0}:SheetLabel runat=server></{0}:SheetLabel>")]
  15. public class SheetLabel : System.Web.UI.WebControls.Label, ISheetControl
  16. {
  17. public SheetLabel()
  18. {
  19. }
  20. #region 类SheetLabel属性
  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.         private RenderType _RenderType = RenderType.Normal;
  36.         [Category("WorkSheet"), DefaultValue(true)]
  37.         public RenderType RenderType
  38.         {
  39.             get
  40.             {
  41.                 return this._RenderType;
  42.             }
  43.             set
  44.             {
  45.                 this._RenderType = value;
  46.             }
  47.         }
  48.         private BindType _BindType = BindType.All;
  49.         [Bindable(true), Category("WorkSheet"), DefaultValue("")]
  50.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  51.         public BindType BindType
  52.         {
  53.             get
  54.             {
  55.                 return this._BindType;
  56.             }
  57.             set
  58.             {
  59.                 this._BindType = value;
  60.             }
  61.         }
  62. #endregion
  63. #region ISheetControl 成员
  64. public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  65. {
  66. if(this.DataField == null || this.DataField == "")
  67. {
  68. }
  69. else if(SheetPage.Enviroment.InstanceData[this.DataField] == null)
  70. {
  71. }
  72.             else if (SheetPage.Enviroment.InstanceData[this.DataField].Visible == false && this.BindType != BindType.OnlyData)
  73. {
  74.                 this.Visible = false;
  75. }
  76. else
  77. {
  78. if(this.BindType != BindType.OnlyVisibility)
  79.                 {
  80.                     if (SheetPage.Enviroment.InstanceData[this.DataField].Value == null)
  81.                     {
  82.                         this.Text = null;
  83.                     }
  84.                     else
  85.                     {
  86.                         this.Text = SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString();
  87.                     }
  88. }
  89. }
  90. }
  91.         public virtual bool ValidateDataField(
  92.             OThinker.H3.WorkSheet.SheetPage SheetPage,
  93.             System.Collections.Generic.List<string> Errors)
  94.         {
  95.             if (
  96.                 this.DataField != null &&
  97.                 this.DataField != "" &&
  98.                 (this.BindType == BindType.All || this.BindType == BindType.OnlyData) && 
  99.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  100.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  101.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable &&
  102.                 this.Text != "" &&
  103.                 this.Text != null)
  104.             {
  105.                 try
  106.                 {
  107.                     OThinker.Data.Convertor.Convert(
  108.                         this.Text,
  109.                         SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
  110.                 }
  111.                 catch
  112.                 {
  113.                     Errors.Add(
  114.                         "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
  115.                         "字段名称为:" + this.DataField + "," +
  116.                         "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  117.                     return false;
  118.                 }
  119.             }
  120.             return true;
  121.         }
  122. public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  123. {
  124. if(
  125. this.DataField != null &&
  126. this.DataField != "" &&
  127.                 (this.BindType == BindType.All || this.BindType == BindType.OnlyData) && 
  128. SheetPage.Enviroment.InstanceData[this.DataField] != null && 
  129. SheetPage.Enviroment.InstanceData[this.DataField].Visible && 
  130. SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  131. {
  132. //写回数据
  133. object convertedValue;
  134. try
  135. {
  136. convertedValue = OThinker.Data.Convertor.Convert(
  137. this.Text,
  138. SheetPage.Enviroment.InstanceData[this.DataField].ItemType, 
  139.                         true);
  140. }
  141. catch
  142. {
  143.                     SheetPage.Enviroment.NotifyMessage(
  144. "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" + 
  145. "字段名称为:" + this.DataField + "," + 
  146. "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  147. return;
  148. }
  149. SheetPage.Enviroment.InstanceData[DataField].Value = convertedValue;
  150. }
  151. }
  152. #endregion
  153.         protected override void Render(HtmlTextWriter writer)
  154.         {
  155.             if (this.RenderType != RenderType.Normal)
  156.             {
  157.                 this.Enabled = true;
  158.             }
  159.             base.Render(writer);
  160.         }
  161. }
  162. }