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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using System.ComponentModel;
  6. using System.Drawing;
  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(SheetTextBox), "OThinker.H3.WorkSheet.SheetTextBox.bmp")]
  15.     [DefaultProperty("Text"), ToolboxData("<{0}:SheetComment runat=server></{0}:SheetComment>")]
  16.     public class SheetComment : System.Web.UI.WebControls.WebControl, ISheetControl
  17.     {
  18.         /// <summary>
  19.         /// 分隔符
  20.         /// </summary>
  21.         public const char Seperator = ';';
  22.         /// <summary>
  23.         /// 用于读取其他人的意见的区域
  24.         /// </summary>
  25.         private System.Web.UI.WebControls.TextBox TextBoxReader;
  26.         private System.Web.UI.WebControls.Label LabelReader;
  27.         /// <summary>
  28.         /// 用于写自己意见的区域
  29.         /// </summary>
  30.         private System.Web.UI.WebControls.TextBox Writer;
  31.         /// <summary>
  32.         /// 用于标注是否为同意
  33.         /// </summary>
  34.         private System.Web.UI.WebControls.CheckBox Approval;
  35.         /// <summary>
  36.         /// 用于标注是添加新的意见还是修改原有的意见
  37.         /// </summary>
  38.         private System.Web.UI.WebControls.CheckBox Append;
  39.         public SheetComment()
  40.         {
  41.             this.TextBoxReader = new System.Web.UI.WebControls.TextBox();
  42.             this.TextBoxReader.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine;
  43.             this.TextBoxReader.ReadOnly = true;
  44.             this.Controls.Add(this.TextBoxReader);
  45.             this.LabelReader = new Label();
  46.             this.Controls.Add(this.LabelReader);
  47.             this.Writer = new System.Web.UI.WebControls.TextBox();
  48.             this.Writer.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine;
  49.             this.Controls.Add(this.Writer);
  50.             this.Approval = new CheckBox();
  51.             this.Approval.Text = "同意";
  52.             this.Controls.Add(this.Approval);
  53.             this.Append = new CheckBox();
  54.             this.Append.Text = "添加";
  55.             this.Append.Checked = false;
  56.             this.Controls.Add(this.Append);
  57.         }
  58.         private bool _Enabled = true;
  59.         public override bool Enabled
  60.         {
  61.             get
  62.             {
  63.                 return this._Enabled;
  64.             }
  65.             set
  66.             {
  67.                 this._Enabled = value;
  68.             }
  69.         }
  70.         #region 基本属性
  71.         private string _DataField = null;
  72.         /// <summary>
  73.         /// 绑定的数据项
  74.         /// </summary>
  75.         [Category("WorkSheet"), DefaultValue(""), Description("绑定的数据项")]
  76.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  77.         public string DataField
  78.         {
  79.             get
  80.             {
  81.                 return this._DataField;
  82.             }
  83.             set
  84.             {
  85.                 this._DataField = value;
  86.             }
  87.         }
  88.         private string _ReadDataFields;
  89.         /// <summary>
  90.         /// 读取绑定数据项。当该控件加载的时候,会读取这个数据项对应的意见信息,并显示出来。如果要汇总读取多个数据项对应的意见信息,可以用分号隔开
  91.         /// </summary>
  92.         [Category("WorkSheet"), DefaultValue(ReaderModalType.TextBox), Description("读取绑定数据项。当该控件加载的时候,会读取这个数据项对应的意见信息,并显示出来。如果要汇总读取多个数据项对应的意见信息,可以用分号隔开")]
  93.         public string ReadDataFields
  94.         {
  95.             get
  96.             {
  97.                 if (this.DataField == null || this.DataField == "")
  98.                 {
  99.                     return this.DataField;
  100.                 }
  101.                 else
  102.                 {
  103.                     return this._ReadDataFields;
  104.                 }
  105.             }
  106.             set
  107.             {
  108.                 this._ReadDataFields = value;
  109.             }
  110.         }
  111.         /// <summary>
  112.         /// 读取绑定的数据项列表
  113.         /// </summary>
  114.         [Browsable(false)]
  115.         public string[] ReadDataFieldArray
  116.         {
  117.             get
  118.             {
  119.                 return this.ReadDataFields == null ? new string[] { this.DataField } : this.ReadDataFields.Split(new char[] { Seperator });
  120.             }
  121.         }
  122.         private string _ApprovalDataField = null;
  123.         /// <summary>
  124.         /// 同意绑定的数据项。默认为空
  125.         /// </summary>
  126.         [Category("WorkSheet"), DefaultValue("")]
  127.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  128.         public string ApprovalDataField
  129.         {
  130.             get
  131.             {
  132.                 return this._ApprovalDataField;
  133.             }
  134.             set
  135.             {
  136.                 this._ApprovalDataField = value;
  137.             }
  138.         }
  139.         private string _CommentDataField = null;
  140.         [Category("WorkSheet"), DefaultValue("")]
  141.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  142.         public string CommentDataField
  143.         {
  144.             get
  145.             {
  146.                 return this._CommentDataField;
  147.             }
  148.             set
  149.             {
  150.                 this._CommentDataField = value;
  151.             }
  152.         }
  153.         private bool _DifferentiateActivity = true;
  154.         [Category("WorkSheet"), DefaultValue("是否根据活动来区分为不同的评论")]
  155.         [Editor(typeof(DataSelector), typeof(UITypeEditor))]
  156.         public bool DifferentiateActivity
  157.         {
  158.             get
  159.             {
  160.                 return this._DifferentiateActivity;
  161.             }
  162.             set
  163.             {
  164.                 this._DifferentiateActivity = value;
  165.             }
  166.         }
  167.         private bool _AutoHideWriter = true;
  168.         [Category("WorkSheet"), DefaultValue(true), Description("是否自动隐藏输入框")]
  169.         public bool AutoHideWriter
  170.         {
  171.             get
  172.             {
  173.                 return this._AutoHideWriter;
  174.             }
  175.             set
  176.             {
  177.                 this._AutoHideWriter = value;
  178.             }
  179.         }
  180.         private bool _ShowApproval = true;
  181.         [Category("WorkSheet"), DefaultValue(true), Description("是否显示填写同意信息的CheckBox")]
  182.         public bool ShowApproval
  183.         {
  184.             get
  185.             {
  186.                 return this._ShowApproval;
  187.             }
  188.             set
  189.             {
  190.                 this._ShowApproval = value;
  191.             }
  192.         }
  193.         /// <summary>
  194.         /// 是否什么类型的控件作为阅读器
  195.         /// </summary>
  196.         public enum ReaderModalType
  197.         {
  198.             TextBox,
  199.             Label
  200.         }
  201.         private ReaderModalType _ReaderModal = ReaderModalType.TextBox;
  202.         [Category("WorkSheet"), DefaultValue(ReaderModalType.TextBox), Description("显示意见的框的类型")]
  203.         public ReaderModalType ReaderModal
  204.         {
  205.             get
  206.             {
  207.                 return this._ReaderModal;
  208.             }
  209.             set
  210.             {
  211.                 this._ReaderModal = value;
  212.             }
  213.         }
  214.         #endregion
  215.         #region ISheetControl 成员
  216.         public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  217.         {
  218.             if (this.DataField == null || this.DataField == "")
  219.             {
  220.                 return;
  221.             }
  222.             else if (SheetPage.Enviroment.InstanceData[this.DataField] == null)
  223.             {
  224.                 this.Visible = false;
  225.             }
  226.             else if (!SheetPage.Enviroment.InstanceData[this.DataField].Visible)
  227.             {
  228.                 // 不可见
  229.                 this.Visible = false;
  230.             }
  231.             else
  232.             {
  233.                 // 获得评论
  234.                 OThinker.H3.Data.Comment[] comments = OThinker.H3.Server.Engine.InstanceDataManager.GetComments(
  235.                     SheetPage.Enviroment.InstanceId,
  236.                     this.ReadDataFieldArray,
  237.                     null,
  238.                     null);
  239.                 // 把评论组织成字符串
  240.                 System.Text.StringBuilder builder = new System.Text.StringBuilder();
  241.                 if (comments != null)
  242.                 {
  243.                     foreach (Data.Comment comment in comments)
  244.                     {
  245.                         string approvalText = null;
  246.                         switch (comment.Approval)
  247.                         {
  248.                             case OThinker.Data.BoolMatchValue.Unspecified:
  249.                                 approvalText = "";
  250.                                 break;
  251.                             case OThinker.Data.BoolMatchValue.True:
  252.                                 approvalText = "同意";
  253.                                 break;
  254.                             case OThinker.Data.BoolMatchValue.False:
  255.                                 approvalText = "不同意";
  256.                                 break;
  257.                             default:
  258.                                 throw new NotImplementedException();
  259.                         }
  260.                         string str =
  261.                             comment.LastModifyTime.ToShortDateString() + " " + comment.LastModifyTime.ToShortTimeString() + " " +
  262.                             SheetPage.Enviroment.Organization.GetFullName(comment.UserID) + ": " +
  263.                             approvalText + " " + 
  264.                             comment.Text;
  265.                         builder.Append(str + "rn");
  266.                     }
  267.                 }
  268.                 this.TextBoxReader.Text = builder.ToString();
  269.                 this.LabelReader.Text = builder.ToString();
  270.                 this.Visible = SheetPage.Enviroment.InstanceData[this.DataField].Visible;
  271.                 this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
  272.                 // 获得以前的评论
  273.                 OThinker.H3.Data.Comment[] myComments = OThinker.H3.Server.Engine.InstanceDataManager.GetComments(
  274.                     SheetPage.Enviroment.InstanceId,
  275.                     new string[] { this.DataField },
  276.                     SheetPage.Enviroment.Participant,
  277.                     (this.DifferentiateActivity ? SheetPage.Enviroment.ActivityName : null));
  278.                 if (myComments != null && myComments.Length != 0)
  279.                 {
  280.                     OThinker.H3.Data.Comment myComment = myComments[myComments.Length - 1];
  281.                     this.Writer.Text = myComment.Text;
  282.                     this.Approval.Checked = (myComment.Approval == OThinker.Data.BoolMatchValue.True);
  283.                 }
  284.             }
  285.         }
  286.         public virtual bool ValidateDataField(
  287.             OThinker.H3.WorkSheet.SheetPage SheetPage,
  288.             System.Collections.Generic.List<string> Errors)
  289.         {
  290.             return true;
  291.         }
  292.         public virtual void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  293.         {
  294.             if (
  295.                 this.DataField != null &&
  296.                 this.DataField != "" &&
  297.                 SheetPage.Enviroment.InstanceData[this.DataField] != null &&
  298.                 SheetPage.Enviroment.InstanceData[this.DataField].Visible &&
  299.                 SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  300.             {
  301.                 // 获得以前的评论
  302.                 OThinker.H3.Data.Comment myComment = null;
  303.                 // 如果为修改模式则查找到以前的意见
  304.                 if (this.Append.Checked == false)
  305.                 {
  306.                     OThinker.H3.Data.Comment[] myComments = OThinker.H3.Server.Engine.InstanceDataManager.GetComments(
  307.                         SheetPage.Enviroment.InstanceId,
  308.                         new string[] { this.DataField },
  309.                         SheetPage.Enviroment.Participant,
  310.                         this.DifferentiateActivity ? SheetPage.Enviroment.ActivityName : null);
  311.                     if (myComments != null && myComments.Length != 0)
  312.                     {
  313.                         myComment = myComments[myComments.Length - 1];
  314.                     }
  315.                 }
  316.                 // 同意信息
  317.                 OThinker.Data.BoolMatchValue approval = OThinker.Data.BoolMatchValue.Unspecified;
  318.                 if (!this.Approval.Visible)
  319.                 {
  320.                     approval = OThinker.Data.BoolMatchValue.Unspecified;
  321.                 }
  322.                 else if (this.Approval.Checked)
  323.                 {
  324.                     approval = OThinker.Data.BoolMatchValue.True;
  325.                 }
  326.                 else
  327.                 {
  328.                     approval = OThinker.Data.BoolMatchValue.False;
  329.                 }
  330.                 if (myComment == null)
  331.                 {
  332.                     myComment = new OThinker.H3.Data.Comment();
  333.                     //写回数据
  334.                     myComment.Activity = SheetPage.Enviroment.ActivityName;
  335.                     myComment.Approval = approval;
  336.                     myComment.CreatedTime = System.DateTime.Now;
  337.                     myComment.DataField = this.DataField;
  338.                     myComment.InstanceId = SheetPage.Enviroment.InstanceId;
  339.                     myComment.LastModifyTime = System.DateTime.Now;
  340.                     myComment.Text = this.Writer.Text;
  341.                     myComment.UserID = SheetPage.Enviroment.Participant;
  342.                     OThinker.H3.Server.Engine.InstanceDataManager.AddComment(SheetPage.Enviroment.InstanceId, this.DataField, myComment);
  343.                 }
  344.                 else
  345.                 {
  346.                     OThinker.H3.Server.Engine.InstanceDataManager.ModifyComment(
  347.                         SheetPage.Enviroment.InstanceId, 
  348.                         this.DataField, myComment.CommentID, 
  349.                         this.Writer.Text, 
  350.                         approval);
  351.                 }
  352.             }
  353.             if (this.ApprovalDataField != null &&
  354.                 this.ApprovalDataField != "" &&
  355.                 SheetPage.Enviroment.InstanceData[this.ApprovalDataField] != null &&
  356.                 SheetPage.Enviroment.InstanceData[this.ApprovalDataField].Visible &&
  357.                 SheetPage.Enviroment.InstanceData[this.ApprovalDataField].Editable)
  358.             {
  359.                 if (SheetPage.Enviroment.InstanceData[this.ApprovalDataField].ItemType != typeof(bool))
  360.                 {
  361.                     SheetPage.Enviroment.NotifyMessage("数据项" + this.ApprovalDataField + "不是布尔类型");
  362.                 }
  363.                 else
  364.                 {
  365.                     //写回数据
  366.                     SheetPage.Enviroment.InstanceData[this.ApprovalDataField].Value = this.Approval.Checked;
  367.                 }
  368.             }
  369.             if (this.CommentDataField != null &&
  370.                 this.CommentDataField != "" &&
  371.                 SheetPage.Enviroment.InstanceData[this.CommentDataField] != null &&
  372.                 SheetPage.Enviroment.InstanceData[this.CommentDataField].Visible &&
  373.                 SheetPage.Enviroment.InstanceData[this.CommentDataField].Editable)
  374.             {
  375.                 if (SheetPage.Enviroment.InstanceData[this.CommentDataField].ItemType != typeof(string))
  376.                 {
  377.                     SheetPage.Enviroment.NotifyMessage("数据项"" + this.CommentDataField + ""不是字符串类型");
  378.                 }
  379.                 else
  380.                 {
  381.                     //写回数据
  382.                     SheetPage.Enviroment.InstanceData[this.CommentDataField].Value = this.Writer.Text;
  383.                 }
  384.             }
  385.         }
  386.         #endregion
  387.         /// <summary> 
  388.         /// Render this control to the output parameter specified.
  389.         /// </summary>
  390.         /// <param name="output"> The HTML writer to write out to </param>
  391.         protected override void Render(HtmlTextWriter output)
  392.         {
  393.             // HTML化已有的意见
  394.             if (this.LabelReader.Text != null)
  395.             {
  396.                 this.LabelReader.Text = this.LabelReader.Text.Replace("rn", "<BR>");
  397.                 this.LabelReader.Text = this.LabelReader.Text.Replace(" ", "&nbsp;");
  398.             }
  399.             // 设置显示已有意见的方式
  400.             if (this.ReaderModal == ReaderModalType.TextBox)
  401.             {
  402.                 this.TextBoxReader.Visible = true;
  403.                 this.LabelReader.Visible = false;
  404.             }
  405.             else
  406.             {
  407.                 this.TextBoxReader.Visible = false;
  408.                 this.LabelReader.Visible = true;
  409.             }
  410.             this.TextBoxReader.Attributes.Add("style", "width:100%");
  411.             this.LabelReader.Attributes.Add("style", "width:100%");
  412.             // 设置CheckBox的显示
  413.             if (this.ShowApproval)
  414.             {
  415.                 this.Approval.Visible = true;
  416.             }
  417.             this.Writer.Attributes.Add("style", "width:100%;");
  418.             double topPer = 0.75;
  419.             if (!this.Enabled)
  420.             {
  421.                 if (this.AutoHideWriter)
  422.                 {
  423.                     this.Writer.Visible = false;
  424.                     this.Append.Visible = false;
  425.                     this.Approval.Visible = false;
  426.                     topPer = 1.00;
  427.                 }
  428.                 else
  429.                 {
  430.                     this.Writer.Enabled = false;
  431.                     this.Append.Enabled = false;
  432.                     this.Approval.Enabled = false;
  433.                     topPer = 0.75;
  434.                 }
  435.             }
  436.             output.Write("<TABLE WIDTH=" + this.Width + " HEIGHT=" + this.Height + " VALIGN=TOP cellpadding="0" cellspacing="0">");
  437.             #region 显示意见
  438.             output.Write("<TR VALIGN=TOP>");
  439.             output.Write("<TD>");
  440.             this.TextBoxReader.Height = Unit.Pixel((int)(this.Height.Value * topPer));
  441.             this.TextBoxReader.RenderControl(output);
  442.             this.LabelReader.Height = Unit.Pixel((int)(this.Height.Value * topPer));
  443.             this.LabelReader.RenderControl(output);
  444.             output.Write("<TD>");
  445.             output.Write("</TR>");
  446.             #endregion
  447.             output.Write("<TR VALIGN=TOP>");
  448.             output.Write("<TD>");
  449.             output.Write("<TABLE VALIGN=TOP cellpadding="0" cellspacing="0">");
  450.             output.Write("<TR VALIGN=TOP>");
  451.             output.Write("<TD WIDTH=80%>");
  452.             if (this.Writer.Visible)
  453.             {
  454.                 this.Writer.Height = Unit.Pixel((int)(this.Height.Value * (1 - topPer)));
  455.                 this.Writer.RenderControl(output);
  456.             }
  457.             output.Write("<TD>");
  458.             output.Write("<TD WIDTH=20%>");
  459.             if (this.Append.Visible)
  460.             {
  461.                 this.Append.RenderControl(output);
  462.             }
  463.             if (this.Approval.Visible)
  464.             {
  465.                 this.Approval.RenderControl(output);
  466.             }
  467.             output.Write("<TD>");
  468.             output.Write("</TR>");
  469.             output.Write("</TABLE>");
  470.             output.Write("<TD>");
  471.             output.Write("</TR>");
  472.             output.Write("</TABLE>");
  473.         }
  474.     }
  475. }