SheetTime.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:4k
源码类别:
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;
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// Summary description for SheetDropDownTime.
- /// </summary>
- [DefaultProperty("Text"),
- ToolboxData("<{0}:SheetDropDownTime runat=server></{0}:SheetDropDownTime>")]
- public class SheetTime : DropDownTime, ISheetControl
- {
- /// <summary>
- /// 默认值的类型
- /// </summary>
- public enum DefaultValueType
- {
- None,
- CurrentTime,
- CurrentDate,
- OriginateTime,
- OriginateDate
- }
- public SheetTime()
- {
- }
- #region 类SMTextBox属性
- 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].ItemType != typeof(System.DateTime))
- {
- // 类型不匹配
- }
- else
- {
- if(
- SheetPage.Enviroment.InstanceData[this.DataField].Editable == true &&
- this.DefaultValue != DefaultValueType.None &&
- ((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.TimeValue = System.DateTime.Now;
- break;
- case DefaultValueType.CurrentDate:
- this.TextValue = System.DateTime.Now.ToShortDateString();
- break;
- case DefaultValueType.OriginateTime:
- this.TextValue = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateTime].Value.ToString();
- break;
- case DefaultValueType.OriginateDate:
- this.TextValue = SheetPage.Enviroment.InstanceData[H3.Data.Keywords.InstanceParser.OriginateDate].Value.ToString();
- break;
- default:
- throw new NotImplementedException();
- }
- }
- else if(SheetPage.Enviroment.InstanceData[this.DataField].Value != null)
- {
- this.TimeValue = (System.DateTime)SheetPage.Enviroment.InstanceData[this.DataField].Value;
- }
- this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
- }
- }
- public virtual bool ValidateDataField(
- OThinker.H3.WorkSheet.SheetPage SheetPage,
- System.Collections.Generic.List<string> Errors)
- {
- 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].ItemType == typeof(System.DateTime) &&
- SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
- SheetPage.Enviroment.InstanceData[this.DataField].Editable)
- {
- //写回数据
- SheetPage.Enviroment.InstanceData[DataField].Value = this.TimeValue;
- }
- }
- #endregion
- protected override void Render(HtmlTextWriter writer)
- {
- if (this.Enabled)
- {
- base.Render(writer);
- }
- else
- {
- writer.Write(this.TimeValue);
- }
- }
- }
- }