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

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. [assembly:TagPrefix("OThinker.H3.WorkSheet","SheetControls")]
  9. namespace OThinker.H3.WorkSheet
  10. {
  11. /// <summary>
  12. /// SheetTextBox 的摘要说明。
  13. /// </summary>
  14. [ToolboxBitmap(typeof(SheetTextBox),"OThinker.H3.WorkSheet.SheetTextBox.bmp")]
  15. [DefaultProperty("Text"),ToolboxData("<{0}:SheetTextBox runat=server></{0}:SheetTextBox>")]
  16. public class SheetTextBox : System.Web.UI.WebControls.TextBox, ISheetControl
  17. {
  18. /// <summary>
  19. /// 默认值的类型
  20. /// </summary>
  21. public enum DefaultValueType
  22. {
  23.             /// <summary>
  24.             /// 无
  25.             /// </summary>
  26. None, 
  27.             /// <summary>
  28.             /// 当前用户
  29.             /// </summary>
  30. CurrentUser,
  31.             /// <summary>
  32.             /// 当前时间
  33.             /// </summary>
  34. CurrentTime,
  35.             /// <summary>
  36.             /// 当前日期
  37.             /// </summary>
  38. CurrentDate,
  39.             /// <summary>
  40.             /// 发起时间
  41.             /// </summary>
  42. OriginateTime, 
  43.             /// <summary>
  44.             /// 发起日期
  45.             /// </summary>
  46. OriginateDate
  47. }
  48.         /// <summary>
  49.         /// 构造函数
  50.         /// </summary>
  51. public SheetTextBox()
  52. {
  53. }
  54.         private RenderType _RenderType = RenderType.LabelWhenDisable;
  55.         /// <summary>
  56.         /// 显示方式
  57.         /// </summary>
  58.         [Bindable(true), Category("WorkSheet"), Description("控制控件的显示方式")]
  59.         public RenderType RenderType
  60.         {
  61.             get
  62.             {
  63.                 return this._RenderType;
  64.             }
  65.             set
  66.             {
  67.                 this._RenderType = value;
  68.             }
  69.         }
  70. #region 字段和默认值
  71. private string _DataField = null;
  72. [Category("WorkSheet"),DefaultValue("")]
  73. [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  74. public string DataField
  75. {
  76. get
  77. {
  78. return this._DataField;
  79. }
  80. set
  81. {
  82. this._DataField = value;
  83. }
  84. }
  85. private DefaultValueType _DefaultValue = DefaultValueType.None;
  86. [Category("WorkSheet"), DefaultValue(DefaultValueType.None)]
  87. public DefaultValueType DefaultValue
  88. {
  89. get
  90. {
  91. return this._DefaultValue;
  92. }
  93. set
  94. {
  95. this._DefaultValue = value;
  96. }
  97. }
  98. #endregion
  99. #region ISheetControl 成员
  100. public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  101. {
  102. if(this.DataField == null || this.DataField == "")
  103. {
  104. }
  105. else if(SheetPage.Enviroment.InstanceData[this.DataField] == null)
  106. {
  107. }
  108.             else if (SheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
  109.             {
  110.                 this.Visible = false;
  111.             }
  112.             else
  113.             {
  114.                 if (
  115.                     SheetPage.Enviroment.InstanceData[this.DataField].Editable == true &&
  116.                     this.DefaultValue == DefaultValueType.CurrentUser &&
  117.                     SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(string) &&
  118.                     (SheetPage.Enviroment.InstanceData[this.DataField].Value == null || SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString() == ""))
  119.                 {
  120.                     // 如果使用当前用户作为默认值,并且当前该值为空,则使用当前用户作为默认值
  121.                     this.Text = SheetPage.Enviroment.Organization.GetFullName(SheetPage.Enviroment.Participant);
  122.                 }
  123.                 else if (
  124.                     SheetPage.Enviroment.InstanceData[this.DataField].Editable == true &&
  125.                     (
  126.                         this.DefaultValue == DefaultValueType.CurrentTime || this.DefaultValue == DefaultValueType.CurrentDate || this.DefaultValue == DefaultValueType.OriginateTime || this.DefaultValue == DefaultValueType.OriginateDate) &&
  127.                         (
  128.                             (SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(string) &&
  129.                             (
  130.                                 SheetPage.Enviroment.InstanceData[this.DataField].Value == null ||
  131.                                 (string)SheetPage.Enviroment.InstanceData[this.DataField].Value == ""
  132.                             )
  133.                         ) ||
  134.                         (
  135.                             SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(System.DateTime) &&
  136.                             ((System.DateTime)SheetPage.Enviroment.InstanceData[this.DataField].Value).CompareTo(
  137.                                 System.DateTime.Parse(OThinker.Data.Convertor.GetDefaultValue(typeof(System.Data.SqlTypes.SqlDateTime)).ToString())
  138.                             ) <= 0
  139.                         )
  140.                     )
  141.                     )
  142.                 {
  143.                     switch (this.DefaultValue)
  144.                     {
  145.                         case DefaultValueType.CurrentTime:
  146.                             this.Text = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
  147.                             break;
  148.                         case DefaultValueType.CurrentDate:
  149.                             this.Text = System.DateTime.Now.ToShortDateString();
  150.                             break;
  151.                         case DefaultValueType.OriginateTime:
  152.                             this.Text = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateDate].Value + " " + SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateTime].Value;
  153.                             break;
  154.                         case DefaultValueType.OriginateDate:
  155.                             this.Text = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateDate] + "";
  156.                             break;
  157.                         default:
  158.                             throw new NotImplementedException();
  159.                     }
  160.                 }
  161.                 else if (SheetPage.Enviroment.InstanceData[this.DataField].Value != null)
  162.                 {
  163.                     this.Text = SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString();
  164.                 }
  165.                 this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
  166.             }
  167. }
  168.         public virtual bool ValidateDataField(
  169.             OThinker.H3.WorkSheet.SheetPage SheetPage,
  170.             System.Collections.Generic.List<string> Errors)
  171.         {
  172.             if (
  173.                 this.DataField != null &&
  174.                 this.DataField != "" &&
  175.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  176.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  177.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable &&
  178.                 this.Text != "" &&
  179.                 this.Text != null)
  180.             {
  181.                 try
  182.                 {
  183.                     OThinker.Data.Convertor.Convert(
  184.                         this.Text,
  185.                         SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
  186.                 }
  187.                 catch
  188.                 {
  189.                     Errors.Add(
  190.                         "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
  191.                         "字段名称为:" + this.DataField + "," +
  192.                         "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  193.                     return false;
  194.                 }
  195.             }
  196.             return true;
  197.         }
  198.         public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  199. {
  200. if(
  201. this.DataField != null &&
  202. this.DataField != "" &&
  203. SheetPage.Enviroment.InstanceData[this.DataField] != null && 
  204. SheetPage.Enviroment.InstanceData[this.DataField].Visible && 
  205. SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  206. {
  207. //写回数据
  208. object convertedValue;
  209. try
  210. {
  211. convertedValue = OThinker.Data.Convertor.Convert(
  212. this.Text, 
  213. SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
  214. }
  215. catch
  216. {
  217.                     SheetPage.Enviroment.NotifyMessage(
  218. "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" + 
  219. "字段名称为:" + this.DataField + "," + 
  220. "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  221. return;
  222. }
  223. SheetPage.Enviroment.InstanceData[DataField].Value = convertedValue;
  224. }
  225. }
  226. #endregion
  227.         protected override void Render(HtmlTextWriter writer)
  228.         {
  229.             if (this.Enabled || this.RenderType != RenderType.LabelWhenDisable)
  230.             {
  231.                 base.Render(writer);
  232.             }
  233.             else
  234.             {
  235.                 writer.Write(this.Text);
  236.             }
  237.         }
  238. }
  239. }