SheetEditableHyperlink.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.Design;
  6. namespace OThinker.H3.WorkSheet
  7. {
  8. /// <summary>
  9. /// Summary description for SheetEditableHyperlink.
  10. /// </summary>
  11. [DefaultProperty("Text"), 
  12. ToolboxData("<{0}:SheetEditableHyperlink runat=server></{0}:SheetEditableHyperlink>")]
  13. public class SheetEditableHyperlink : System.Web.UI.WebControls.WebControl, ISheetControl
  14. {
  15. public SheetEditableHyperlink()
  16. {
  17. this.CurrentLink = new HyperLink();
  18. this.Controls.Add(this.CurrentLink);
  19. this.NewLinkPrompt = new Label();
  20. this.NewLinkPrompt.Text = "新地址:";
  21. this.Controls.Add(this.NewLinkPrompt);
  22. this.NewLink = new TextBox();
  23. this.Controls.Add(this.NewLink);
  24. }
  25. // 当前的链接
  26. private System.Web.UI.WebControls.HyperLink CurrentLink;
  27. private System.Web.UI.WebControls.Label NewLinkPrompt;
  28. // 新的链接
  29. private System.Web.UI.WebControls.TextBox NewLink;
  30.         public override bool Enabled
  31.         {
  32.             get
  33.             {
  34.                 return this.NewLink.Visible;
  35.             }
  36.             set
  37.             {
  38.                 this.NewLinkPrompt.Visible = value;
  39.                 this.NewLink.Visible = value;
  40.             }
  41.         }
  42. #region 类SheetHyperLink成员
  43. private string _DataField = null;
  44. [Browsable(true), Category("WorkSheet"), DefaultValue("")]
  45. [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  46. public string DataField
  47. {
  48. get
  49. {
  50. return this._DataField;
  51. }
  52. set
  53. {
  54. this._DataField = value;
  55. }
  56. }
  57. #endregion
  58. #region ISheetControl 成员
  59.         public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  60. {
  61. if( this.DataField == null || this.DataField == "" )
  62. {
  63. }
  64. else if(SheetPage.Enviroment.InstanceData[this.DataField] == null)
  65. {
  66. }
  67. else if(SheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
  68. {
  69. this.Visible = false;
  70. }
  71. else
  72. {
  73. // 设置当前链接
  74. this.CurrentLink.Text = this.DataField;
  75. if(SheetPage.Enviroment.InstanceData[this.DataField].Value != null)
  76. {
  77. this.CurrentLink.NavigateUrl = SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString();
  78. }
  79. // 设置新地址链接
  80. if(SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  81. {
  82. this.NewLinkPrompt.Visible = true;
  83. this.NewLink.Visible = true;
  84. }
  85. else
  86. {
  87. this.NewLinkPrompt.Visible = false;
  88. this.NewLink.Visible = false;
  89. }
  90. }
  91. }
  92.         public virtual bool ValidateDataField(OThinker.H3.WorkSheet.SheetPage SheetPage, System.Collections.Generic.List<string> Errors)
  93.         {
  94.             if (
  95.                 this.DataField != null &&
  96.                 this.DataField != "" &&
  97.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  98.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  99.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable &&
  100.                 this.NewLink.Text != "" &&
  101.                 this.NewLink.Text != null)
  102.             {
  103.                 //写回数据
  104.                 try
  105.                 {
  106.                     OThinker.Data.Convertor.Convert(
  107.                         this.NewLink.Text,
  108.                         SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
  109.                 }
  110.                 catch
  111.                 {
  112.                     Errors.Add(
  113.                         "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
  114.                         "字段名称为:" + this.DataField + "," +
  115.                         "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  116.                     return false;
  117.                 }
  118.             }
  119.             return true;
  120.         }
  121.         public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  122. {
  123. if(
  124. this.DataField != null &&
  125. this.DataField != "" && 
  126. SheetPage.Enviroment.InstanceData[this.DataField] != null && 
  127. SheetPage.Enviroment.InstanceData[this.DataField].Visible && 
  128. SheetPage.Enviroment.InstanceData[this.DataField].Editable && 
  129. this.NewLink.Text != "" && 
  130. this.NewLink.Text != null)
  131. {
  132. //写回数据
  133. object convertedValue;
  134. try
  135. {
  136. convertedValue = OThinker.Data.Convertor.Convert(
  137. this.NewLink.Text, 
  138. SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
  139. }
  140. catch
  141. {
  142. throw new FormatException("数据格式不正确,发生转换错误,请确认输入数据的格式正确");
  143. }
  144. SheetPage.Enviroment.InstanceData[this.DataField].Value = convertedValue;
  145. }
  146. }
  147. #endregion
  148. }
  149. }