SheetEditableHyperlink.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:5k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.ComponentModel;
- using System.Drawing.Design;
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// Summary description for SheetEditableHyperlink.
- /// </summary>
- [DefaultProperty("Text"),
- ToolboxData("<{0}:SheetEditableHyperlink runat=server></{0}:SheetEditableHyperlink>")]
- public class SheetEditableHyperlink : System.Web.UI.WebControls.WebControl, ISheetControl
- {
- public SheetEditableHyperlink()
- {
- this.CurrentLink = new HyperLink();
- this.Controls.Add(this.CurrentLink);
- this.NewLinkPrompt = new Label();
- this.NewLinkPrompt.Text = "新地址:";
- this.Controls.Add(this.NewLinkPrompt);
- this.NewLink = new TextBox();
- this.Controls.Add(this.NewLink);
- }
- // 当前的链接
- private System.Web.UI.WebControls.HyperLink CurrentLink;
- private System.Web.UI.WebControls.Label NewLinkPrompt;
- // 新的链接
- private System.Web.UI.WebControls.TextBox NewLink;
- public override bool Enabled
- {
- get
- {
- return this.NewLink.Visible;
- }
- set
- {
- this.NewLinkPrompt.Visible = value;
- this.NewLink.Visible = value;
- }
- }
- #region 类SheetHyperLink成员
- private string _DataField = null;
- [Browsable(true), Category("WorkSheet"), DefaultValue("")]
- [Editor(typeof(DataSelector), typeof(UITypeEditor))]
- public string DataField
- {
- get
- {
- return this._DataField;
- }
- set
- {
- this._DataField = value;
- }
- }
- #endregion
- #region ISheetControl 成员
- public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
- {
- if( this.DataField == null || this.DataField == "" )
- {
- }
- else if(SheetPage.Enviroment.InstanceData[this.DataField] == null)
- {
- }
- else if(SheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
- {
- this.Visible = false;
- }
- else
- {
- // 设置当前链接
- this.CurrentLink.Text = this.DataField;
- if(SheetPage.Enviroment.InstanceData[this.DataField].Value != null)
- {
- this.CurrentLink.NavigateUrl = SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString();
- }
- // 设置新地址链接
- if(SheetPage.Enviroment.InstanceData[this.DataField].Editable)
- {
- this.NewLinkPrompt.Visible = true;
- this.NewLink.Visible = true;
- }
- else
- {
- this.NewLinkPrompt.Visible = false;
- this.NewLink.Visible = false;
- }
- }
- }
- public virtual bool ValidateDataField(OThinker.H3.WorkSheet.SheetPage SheetPage, System.Collections.Generic.List<string> Errors)
- {
- if (
- this.DataField != null &&
- this.DataField != "" &&
- SheetPage.Enviroment.InstanceData[this.DataField] != null &&
- SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
- SheetPage.Enviroment.InstanceData[this.DataField].Editable &&
- this.NewLink.Text != "" &&
- this.NewLink.Text != null)
- {
- //写回数据
- try
- {
- OThinker.Data.Convertor.Convert(
- this.NewLink.Text,
- SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
- }
- catch
- {
- Errors.Add(
- "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
- "字段名称为:" + this.DataField + "," +
- "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
- return false;
- }
- }
- return true;
- }
- public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
- {
- if(
- this.DataField != null &&
- this.DataField != "" &&
- SheetPage.Enviroment.InstanceData[this.DataField] != null &&
- SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
- SheetPage.Enviroment.InstanceData[this.DataField].Editable &&
- this.NewLink.Text != "" &&
- this.NewLink.Text != null)
- {
- //写回数据
- object convertedValue;
- try
- {
- convertedValue = OThinker.Data.Convertor.Convert(
- this.NewLink.Text,
- SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
- }
- catch
- {
- throw new FormatException("数据格式不正确,发生转换错误,请确认输入数据的格式正确");
- }
- SheetPage.Enviroment.InstanceData[this.DataField].Value = convertedValue;
- }
- }
- #endregion
- }
- }