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

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.     /// SheetInstancePrioritySelector 的摘要说明。
  13.     /// </summary>
  14.     [ToolboxBitmap(typeof(SheetInstancePrioritySelector), "OThinker.H3.WorkSheet.SheetInstancePrioritySelector.bmp")]
  15.     [ToolboxData("<{0}:SheetInstancePrioritySelector runat=server></{0}:SheetInstancePrioritySelector>")]
  16.     public class SheetInstancePrioritySelector : System.Web.UI.WebControls.DropDownList, ISheetControl
  17.     {
  18.         public SheetInstancePrioritySelector()
  19.         {
  20.             // this.EnableViewState = false;
  21.         }
  22.         public const string DataField = "InstancePriority";
  23.         public const string Html = "<select name="" + DataField + "" />";
  24.         private RenderType _RenderType = RenderType.LabelWhenDisable;
  25.         /// <summary>
  26.         /// 显示方式
  27.         /// </summary>
  28.         [Bindable(true), Category("WorkSheet"), Description("控制控件的显示方式")]
  29.         public RenderType RenderType
  30.         {
  31.             get
  32.             {
  33.                 return this._RenderType;
  34.             }
  35.             set
  36.             {
  37.                 this._RenderType = value;
  38.             }
  39.         }
  40.         #region ISheetControl 成员
  41.         public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  42.         {
  43.             // 获得优先级
  44.             Instance.PriorityType priority = SheetPage.Enviroment.InstanceManager.GetInstancePriority(SheetPage.Enviroment.InstanceId);
  45.             string priorityName = Instance.PriorityTypeConvertor.ToString(priority);
  46.             if (SheetPage.Enviroment.Workflow.StartActivity == SheetPage.Enviroment.ActivityName)
  47.             {
  48.                 string[] names = Instance.PriorityTypeConvertor.GetAllPriority();
  49.                 foreach (string name in names)
  50.                 {
  51.                     this.Items.Add(name);
  52.                 }
  53.                 this.SelectedValue = priorityName;
  54.                 // 如果当期活动为发起活动的话,则允许写
  55.                 this.Enabled = true;
  56.             }
  57.             else
  58.             {
  59.                 this.Items.Add(priorityName);
  60.                 this.Enabled = false;
  61.             }
  62.         }
  63.         public virtual bool ValidateDataField(OThinker.H3.WorkSheet.SheetPage SheetPage, System.Collections.Generic.List<string> Errors)
  64.         {
  65.             return true;
  66.         }
  67.         public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  68.         {
  69.             if (SheetPage.Enviroment.Workflow.StartActivity == SheetPage.Enviroment.ActivityName)
  70.             {
  71.                 // 获得优先级
  72.                 string priorityName = this.SelectedValue;
  73.                 Instance.PriorityType priority = Instance.PriorityTypeConvertor.ToPriorityType(priorityName);
  74.                 SheetPage.Enviroment.InstanceManager.SetInstancePriority(SheetPage.Enviroment.InstanceId, priority);
  75.                 SheetPage.Enviroment.WorkItemManager.UpdatePriority(SheetPage.Enviroment.WorkItemID, priority);
  76.             }
  77.         }
  78.         #endregion
  79.         protected override void Render(HtmlTextWriter writer)
  80.         {
  81.             if (this.Enabled || this.RenderType != RenderType.LabelWhenDisable)
  82.             {
  83.                 base.Render(writer);
  84.             }
  85.             else
  86.             {
  87.                 writer.Write(this.SelectedItem.Text);
  88.             }
  89.         }
  90.     }
  91. }