SheetTextBox.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:9k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Design;
- [assembly:TagPrefix("OThinker.H3.WorkSheet","SheetControls")]
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// SheetTextBox 的摘要说明。
- /// </summary>
- [ToolboxBitmap(typeof(SheetTextBox),"OThinker.H3.WorkSheet.SheetTextBox.bmp")]
- [DefaultProperty("Text"),ToolboxData("<{0}:SheetTextBox runat=server></{0}:SheetTextBox>")]
- public class SheetTextBox : System.Web.UI.WebControls.TextBox, ISheetControl
- {
- /// <summary>
- /// 默认值的类型
- /// </summary>
- public enum DefaultValueType
- {
- /// <summary>
- /// 无
- /// </summary>
- None,
- /// <summary>
- /// 当前用户
- /// </summary>
- CurrentUser,
- /// <summary>
- /// 当前时间
- /// </summary>
- CurrentTime,
- /// <summary>
- /// 当前日期
- /// </summary>
- CurrentDate,
- /// <summary>
- /// 发起时间
- /// </summary>
- OriginateTime,
- /// <summary>
- /// 发起日期
- /// </summary>
- OriginateDate
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- public SheetTextBox()
- {
- }
- private RenderType _RenderType = RenderType.LabelWhenDisable;
- /// <summary>
- /// 显示方式
- /// </summary>
- [Bindable(true), Category("WorkSheet"), Description("控制控件的显示方式")]
- public RenderType RenderType
- {
- get
- {
- return this._RenderType;
- }
- set
- {
- this._RenderType = value;
- }
- }
- #region 字段和默认值
- private string _DataField = null;
- [Category("WorkSheet"),DefaultValue("")]
- [Editor(typeof(DataSelector), typeof(UITypeEditor))]
- public string DataField
- {
- get
- {
- return this._DataField;
- }
- set
- {
- this._DataField = value;
- }
- }
- private DefaultValueType _DefaultValue = DefaultValueType.None;
- [Category("WorkSheet"), DefaultValue(DefaultValueType.None)]
- public DefaultValueType DefaultValue
- {
- get
- {
- return this._DefaultValue;
- }
- set
- {
- this._DefaultValue = 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
- {
- if (
- SheetPage.Enviroment.InstanceData[this.DataField].Editable == true &&
- this.DefaultValue == DefaultValueType.CurrentUser &&
- SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(string) &&
- (SheetPage.Enviroment.InstanceData[this.DataField].Value == null || SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString() == ""))
- {
- // 如果使用当前用户作为默认值,并且当前该值为空,则使用当前用户作为默认值
- this.Text = SheetPage.Enviroment.Organization.GetFullName(SheetPage.Enviroment.Participant);
- }
- else if (
- SheetPage.Enviroment.InstanceData[this.DataField].Editable == true &&
- (
- this.DefaultValue == DefaultValueType.CurrentTime || this.DefaultValue == DefaultValueType.CurrentDate || this.DefaultValue == DefaultValueType.OriginateTime || this.DefaultValue == DefaultValueType.OriginateDate) &&
- (
- (SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(string) &&
- (
- SheetPage.Enviroment.InstanceData[this.DataField].Value == null ||
- (string)SheetPage.Enviroment.InstanceData[this.DataField].Value == ""
- )
- ) ||
- (
- SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(System.DateTime) &&
- ((System.DateTime)SheetPage.Enviroment.InstanceData[this.DataField].Value).CompareTo(
- System.DateTime.Parse(OThinker.Data.Convertor.GetDefaultValue(typeof(System.Data.SqlTypes.SqlDateTime)).ToString())
- ) <= 0
- )
- )
- )
- {
- switch (this.DefaultValue)
- {
- case DefaultValueType.CurrentTime:
- this.Text = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
- break;
- case DefaultValueType.CurrentDate:
- this.Text = System.DateTime.Now.ToShortDateString();
- break;
- case DefaultValueType.OriginateTime:
- this.Text = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateDate].Value + " " + SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateTime].Value;
- break;
- case DefaultValueType.OriginateDate:
- this.Text = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateDate] + "";
- break;
- default:
- throw new NotImplementedException();
- }
- }
- else if (SheetPage.Enviroment.InstanceData[this.DataField].Value != null)
- {
- this.Text = SheetPage.Enviroment.InstanceData[this.DataField].Value.ToString();
- }
- this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
- }
- }
- 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.Text != "" &&
- this.Text != null)
- {
- try
- {
- OThinker.Data.Convertor.Convert(
- this.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)
- {
- //写回数据
- object convertedValue;
- try
- {
- convertedValue = OThinker.Data.Convertor.Convert(
- this.Text,
- SheetPage.Enviroment.InstanceData[this.DataField].ItemType);
- }
- catch
- {
- SheetPage.Enviroment.NotifyMessage(
- "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
- "字段名称为:" + this.DataField + "," +
- "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
- return;
- }
- SheetPage.Enviroment.InstanceData[DataField].Value = convertedValue;
- }
- }
- #endregion
- protected override void Render(HtmlTextWriter writer)
- {
- if (this.Enabled || this.RenderType != RenderType.LabelWhenDisable)
- {
- base.Render(writer);
- }
- else
- {
- writer.Write(this.Text);
- }
- }
- }
- }