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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Web.UI.Design;
  7. using System.Drawing.Design;
  8. [assembly:TagPrefix("OThinker.H3.WorkSheet","SheetControls")]
  9. namespace OThinker.H3.WorkSheet
  10. {
  11. /// <summary>
  12. /// 表单下拉框
  13. /// </summary>
  14. [ToolboxBitmap(typeof(SheetDropDownList),"OThinker.H3.WorkSheet.SheetDropDownList.bmp")]
  15. [ToolboxData("<{0}:SheetDropDownList runat=server></{0}:SheetDropDownList>")]
  16. public class SheetDropDownList : System.Web.UI.WebControls.DropDownList, ISheetControl
  17. {
  18. public SheetDropDownList()
  19. {
  20. }
  21.         private RenderType _RenderType = RenderType.LabelWhenDisable;
  22.         /// <summary>
  23.         /// 显示方式
  24.         /// </summary>
  25.         [Bindable(true), Category("WorkSheet"), Description("控制控件的显示方式")]
  26.         public RenderType RenderType
  27.         {
  28.             get
  29.             {
  30.                 return this._RenderType;
  31.             }
  32.             set
  33.             {
  34.                 this._RenderType = value;
  35.             }
  36.         }
  37.         #region SheetDropDownList属性
  38.         private string _DataField = null;
  39.         [Bindable(true), Category("WorkSheet"), DefaultValue("")]
  40.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  41.         public string DataField
  42.         {
  43.             get
  44.             {
  45.                 return this._DataField;
  46.             }
  47.             set
  48.             {
  49.                 this._DataField = value;
  50.             }
  51.         }
  52.         private string _SourceDataField = null;
  53.         [Bindable(true), Category("WorkSheet"), DefaultValue("")]
  54.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  55.         public string SourceDataField
  56.         {
  57.             get
  58.             {
  59.                 return this._SourceDataField;
  60.             }
  61.             set
  62.             {
  63.                 this._SourceDataField = value;
  64.             }
  65.         }
  66.         #endregion
  67.         #region ISheetControl 成员
  68.         public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  69.         {
  70.             if (this.SourceDataField == null || this.SourceDataField == "")
  71.             {
  72.             }
  73.             else if (SheetPage.Enviroment.InstanceData[this.SourceDataField] == null)
  74.             {
  75.             }
  76.             else
  77.             {
  78.                 object source = SheetPage.Enviroment.InstanceData[this.SourceDataField].Value;
  79.                 if (source != null)
  80.                 {
  81.                     this.DataSource = source;
  82.                     this.DataBind();
  83.                 }
  84.             }
  85.             if (this.DataField == null || this.DataField == "")
  86.             {
  87.             }
  88.             else if (SheetPage.Enviroment.InstanceData[this.DataField] == null)
  89.             {
  90.             }
  91.             else if (SheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
  92.             {
  93.                 this.Visible = false;
  94.             }
  95.             else
  96.             {
  97.                 object selectedValue = SheetPage.Enviroment.InstanceData[this.DataField].Value;
  98.                 if (selectedValue == null)
  99.                 {
  100.                 }
  101.                 else if (this.Items.FindByValue(selectedValue.ToString()) != null)
  102.                 {
  103.                     this.SelectedValue = selectedValue.ToString();
  104.                 }
  105.                 else if (selectedValue.ToString() != "")
  106.                 {
  107.                     this.Items.Add(selectedValue.ToString());
  108.                     this.SelectedValue = selectedValue.ToString();
  109.                 }
  110.                 this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
  111.             }
  112.         }
  113.         public virtual bool ValidateDataField(OThinker.H3.WorkSheet.SheetPage SheetPage, System.Collections.Generic.List<string> Errors)
  114.         {
  115.             if (
  116.                 this.DataField != null &&
  117.                 this.DataField != "" &&
  118.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  119.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  120.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  121.             {
  122.                 //写回数据
  123.                 object convertedValue;
  124.                 try
  125.                 {
  126.                     convertedValue = OThinker.Data.Convertor.Convert(
  127.                         this.SelectedValue,
  128.                         SheetPage.Enviroment.InstanceData[this.DataField].ItemType,
  129.                         true);
  130.                 }
  131.                 catch
  132.                 {
  133.                     Errors.Add(
  134.                         "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
  135.                         "字段名称为:" + this.DataField + "," +
  136.                         "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  137.                     return false;
  138.                 }
  139.             }
  140.             return true;
  141.         }
  142.         public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  143.         {
  144.             if (
  145.                 this.DataField != null &&
  146.                 this.DataField != "" &&
  147.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  148.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  149.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  150.             {
  151.                 //写回数据
  152.                 object convertedValue;
  153.                 try
  154.                 {
  155.                     convertedValue = OThinker.Data.Convertor.Convert(
  156.                         this.SelectedValue,
  157.                         SheetPage.Enviroment.InstanceData[this.DataField].ItemType,
  158.                         true);
  159.                 }
  160.                 catch
  161.                 {
  162.                     SheetPage.Enviroment.NotifyMessage(
  163.                         "数据格式不正确,发生转换错误,请确认输入数据的格式正确!" +
  164.                         "字段名称为:" + this.DataField + "," +
  165.                         "类型为:" + OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(SheetPage.Enviroment.InstanceData[this.DataField].LogicType));
  166.                     return;
  167.                 }
  168.                 SheetPage.Enviroment.InstanceData[DataField].Value = convertedValue;
  169.             }
  170.         }
  171.         #endregion
  172.         protected override void Render(HtmlTextWriter writer)
  173.         {
  174.             if (this.Enabled || this.RenderType != RenderType.LabelWhenDisable)
  175.             {
  176.                 base.Render(writer);
  177.             }
  178.             else if (this.SelectedIndex == -1)
  179.             {
  180.                 writer.Write("");
  181.             }
  182.             else
  183.             {
  184.                 writer.Write(this.SelectedItem.Text);
  185.             }
  186.         }
  187. }
  188. }