SheetComment.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:19k
源码类别:
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>
- /// 这个控件用于进行汇签,填写大家的意见
- /// </summary>
- [ToolboxBitmap(typeof(SheetTextBox), "OThinker.H3.WorkSheet.SheetTextBox.bmp")]
- [DefaultProperty("Text"), ToolboxData("<{0}:SheetComment runat=server></{0}:SheetComment>")]
- public class SheetComment : System.Web.UI.WebControls.WebControl, ISheetControl
- {
- /// <summary>
- /// 分隔符
- /// </summary>
- public const char Seperator = ';';
- /// <summary>
- /// 用于读取其他人的意见的区域
- /// </summary>
- private System.Web.UI.WebControls.TextBox TextBoxReader;
- private System.Web.UI.WebControls.Label LabelReader;
- /// <summary>
- /// 用于写自己意见的区域
- /// </summary>
- private System.Web.UI.WebControls.TextBox Writer;
- /// <summary>
- /// 用于标注是否为同意
- /// </summary>
- private System.Web.UI.WebControls.CheckBox Approval;
- /// <summary>
- /// 用于标注是添加新的意见还是修改原有的意见
- /// </summary>
- private System.Web.UI.WebControls.CheckBox Append;
- public SheetComment()
- {
- this.TextBoxReader = new System.Web.UI.WebControls.TextBox();
- this.TextBoxReader.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine;
- this.TextBoxReader.ReadOnly = true;
- this.Controls.Add(this.TextBoxReader);
- this.LabelReader = new Label();
- this.Controls.Add(this.LabelReader);
- this.Writer = new System.Web.UI.WebControls.TextBox();
- this.Writer.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine;
- this.Controls.Add(this.Writer);
- this.Approval = new CheckBox();
- this.Approval.Text = "同意";
- this.Controls.Add(this.Approval);
- this.Append = new CheckBox();
- this.Append.Text = "添加";
- this.Append.Checked = false;
- this.Controls.Add(this.Append);
- }
- private bool _Enabled = true;
- public override bool Enabled
- {
- get
- {
- return this._Enabled;
- }
- set
- {
- this._Enabled = value;
- }
- }
- #region 基本属性
- private string _DataField = null;
- /// <summary>
- /// 绑定的数据项
- /// </summary>
- [Category("WorkSheet"), DefaultValue(""), Description("绑定的数据项")]
- [Editor(typeof(DataSelector), typeof(UITypeEditor))]
- public string DataField
- {
- get
- {
- return this._DataField;
- }
- set
- {
- this._DataField = value;
- }
- }
- private string _ReadDataFields;
- /// <summary>
- /// 读取绑定数据项。当该控件加载的时候,会读取这个数据项对应的意见信息,并显示出来。如果要汇总读取多个数据项对应的意见信息,可以用分号隔开
- /// </summary>
- [Category("WorkSheet"), DefaultValue(ReaderModalType.TextBox), Description("读取绑定数据项。当该控件加载的时候,会读取这个数据项对应的意见信息,并显示出来。如果要汇总读取多个数据项对应的意见信息,可以用分号隔开")]
- public string ReadDataFields
- {
- get
- {
- if (this.DataField == null || this.DataField == "")
- {
- return this.DataField;
- }
- else
- {
- return this._ReadDataFields;
- }
- }
- set
- {
- this._ReadDataFields = value;
- }
- }
- /// <summary>
- /// 读取绑定的数据项列表
- /// </summary>
- [Browsable(false)]
- public string[] ReadDataFieldArray
- {
- get
- {
- return this.ReadDataFields == null ? new string[] { this.DataField } : this.ReadDataFields.Split(new char[] { Seperator });
- }
- }
- private string _ApprovalDataField = null;
- /// <summary>
- /// 同意绑定的数据项。默认为空
- /// </summary>
- [Category("WorkSheet"), DefaultValue("")]
- [Editor(typeof(DataSelector), typeof(UITypeEditor))]
- public string ApprovalDataField
- {
- get
- {
- return this._ApprovalDataField;
- }
- set
- {
- this._ApprovalDataField = value;
- }
- }
- private string _CommentDataField = null;
- [Category("WorkSheet"), DefaultValue("")]
- [Editor(typeof(DataSelector), typeof(UITypeEditor))]
- public string CommentDataField
- {
- get
- {
- return this._CommentDataField;
- }
- set
- {
- this._CommentDataField = value;
- }
- }
- private bool _DifferentiateActivity = true;
- [Category("WorkSheet"), DefaultValue("是否根据活动来区分为不同的评论")]
- [Editor(typeof(DataSelector), typeof(UITypeEditor))]
- public bool DifferentiateActivity
- {
- get
- {
- return this._DifferentiateActivity;
- }
- set
- {
- this._DifferentiateActivity = value;
- }
- }
- private bool _AutoHideWriter = true;
- [Category("WorkSheet"), DefaultValue(true), Description("是否自动隐藏输入框")]
- public bool AutoHideWriter
- {
- get
- {
- return this._AutoHideWriter;
- }
- set
- {
- this._AutoHideWriter = value;
- }
- }
- private bool _ShowApproval = true;
- [Category("WorkSheet"), DefaultValue(true), Description("是否显示填写同意信息的CheckBox")]
- public bool ShowApproval
- {
- get
- {
- return this._ShowApproval;
- }
- set
- {
- this._ShowApproval = value;
- }
- }
- /// <summary>
- /// 是否什么类型的控件作为阅读器
- /// </summary>
- public enum ReaderModalType
- {
- TextBox,
- Label
- }
- private ReaderModalType _ReaderModal = ReaderModalType.TextBox;
- [Category("WorkSheet"), DefaultValue(ReaderModalType.TextBox), Description("显示意见的框的类型")]
- public ReaderModalType ReaderModal
- {
- get
- {
- return this._ReaderModal;
- }
- set
- {
- this._ReaderModal = value;
- }
- }
- #endregion
- #region ISheetControl 成员
- public virtual void LoadDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
- {
- if (this.DataField == null || this.DataField == "")
- {
- return;
- }
- else if (SheetPage.Enviroment.InstanceData[this.DataField] == null)
- {
- this.Visible = false;
- }
- else if (!SheetPage.Enviroment.InstanceData[this.DataField].Visible)
- {
- // 不可见
- this.Visible = false;
- }
- else
- {
- // 获得评论
- OThinker.H3.Data.Comment[] comments = OThinker.H3.Server.Engine.InstanceDataManager.GetComments(
- SheetPage.Enviroment.InstanceId,
- this.ReadDataFieldArray,
- null,
- null);
- // 把评论组织成字符串
- System.Text.StringBuilder builder = new System.Text.StringBuilder();
- if (comments != null)
- {
- foreach (Data.Comment comment in comments)
- {
- string approvalText = null;
- switch (comment.Approval)
- {
- case OThinker.Data.BoolMatchValue.Unspecified:
- approvalText = "";
- break;
- case OThinker.Data.BoolMatchValue.True:
- approvalText = "同意";
- break;
- case OThinker.Data.BoolMatchValue.False:
- approvalText = "不同意";
- break;
- default:
- throw new NotImplementedException();
- }
- string str =
- comment.LastModifyTime.ToShortDateString() + " " + comment.LastModifyTime.ToShortTimeString() + " " +
- SheetPage.Enviroment.Organization.GetFullName(comment.UserID) + ": " +
- approvalText + " " +
- comment.Text;
- builder.Append(str + "rn");
- }
- }
- this.TextBoxReader.Text = builder.ToString();
- this.LabelReader.Text = builder.ToString();
- this.Visible = SheetPage.Enviroment.InstanceData[this.DataField].Visible;
- this.Enabled = SheetPage.Enviroment.InstanceData[this.DataField].Editable;
- // 获得以前的评论
- OThinker.H3.Data.Comment[] myComments = OThinker.H3.Server.Engine.InstanceDataManager.GetComments(
- SheetPage.Enviroment.InstanceId,
- new string[] { this.DataField },
- SheetPage.Enviroment.Participant,
- (this.DifferentiateActivity ? SheetPage.Enviroment.ActivityName : null));
- if (myComments != null && myComments.Length != 0)
- {
- OThinker.H3.Data.Comment myComment = myComments[myComments.Length - 1];
- this.Writer.Text = myComment.Text;
- this.Approval.Checked = (myComment.Approval == OThinker.Data.BoolMatchValue.True);
- }
- }
- }
- 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].Visible &&
- SheetPage.Enviroment.InstanceData[this.DataField].Editable)
- {
- // 获得以前的评论
- OThinker.H3.Data.Comment myComment = null;
- // 如果为修改模式则查找到以前的意见
- if (this.Append.Checked == false)
- {
- OThinker.H3.Data.Comment[] myComments = OThinker.H3.Server.Engine.InstanceDataManager.GetComments(
- SheetPage.Enviroment.InstanceId,
- new string[] { this.DataField },
- SheetPage.Enviroment.Participant,
- this.DifferentiateActivity ? SheetPage.Enviroment.ActivityName : null);
- if (myComments != null && myComments.Length != 0)
- {
- myComment = myComments[myComments.Length - 1];
- }
- }
- // 同意信息
- OThinker.Data.BoolMatchValue approval = OThinker.Data.BoolMatchValue.Unspecified;
- if (!this.Approval.Visible)
- {
- approval = OThinker.Data.BoolMatchValue.Unspecified;
- }
- else if (this.Approval.Checked)
- {
- approval = OThinker.Data.BoolMatchValue.True;
- }
- else
- {
- approval = OThinker.Data.BoolMatchValue.False;
- }
- if (myComment == null)
- {
- myComment = new OThinker.H3.Data.Comment();
- //写回数据
- myComment.Activity = SheetPage.Enviroment.ActivityName;
- myComment.Approval = approval;
- myComment.CreatedTime = System.DateTime.Now;
- myComment.DataField = this.DataField;
- myComment.InstanceId = SheetPage.Enviroment.InstanceId;
- myComment.LastModifyTime = System.DateTime.Now;
- myComment.Text = this.Writer.Text;
- myComment.UserID = SheetPage.Enviroment.Participant;
- OThinker.H3.Server.Engine.InstanceDataManager.AddComment(SheetPage.Enviroment.InstanceId, this.DataField, myComment);
- }
- else
- {
- OThinker.H3.Server.Engine.InstanceDataManager.ModifyComment(
- SheetPage.Enviroment.InstanceId,
- this.DataField, myComment.CommentID,
- this.Writer.Text,
- approval);
- }
- }
- if (this.ApprovalDataField != null &&
- this.ApprovalDataField != "" &&
- SheetPage.Enviroment.InstanceData[this.ApprovalDataField] != null &&
- SheetPage.Enviroment.InstanceData[this.ApprovalDataField].Visible &&
- SheetPage.Enviroment.InstanceData[this.ApprovalDataField].Editable)
- {
- if (SheetPage.Enviroment.InstanceData[this.ApprovalDataField].ItemType != typeof(bool))
- {
- SheetPage.Enviroment.NotifyMessage("数据项" + this.ApprovalDataField + "不是布尔类型");
- }
- else
- {
- //写回数据
- SheetPage.Enviroment.InstanceData[this.ApprovalDataField].Value = this.Approval.Checked;
- }
- }
- if (this.CommentDataField != null &&
- this.CommentDataField != "" &&
- SheetPage.Enviroment.InstanceData[this.CommentDataField] != null &&
- SheetPage.Enviroment.InstanceData[this.CommentDataField].Visible &&
- SheetPage.Enviroment.InstanceData[this.CommentDataField].Editable)
- {
- if (SheetPage.Enviroment.InstanceData[this.CommentDataField].ItemType != typeof(string))
- {
- SheetPage.Enviroment.NotifyMessage("数据项"" + this.CommentDataField + ""不是字符串类型");
- }
- else
- {
- //写回数据
- SheetPage.Enviroment.InstanceData[this.CommentDataField].Value = this.Writer.Text;
- }
- }
- }
- #endregion
- /// <summary>
- /// Render this control to the output parameter specified.
- /// </summary>
- /// <param name="output"> The HTML writer to write out to </param>
- protected override void Render(HtmlTextWriter output)
- {
- // HTML化已有的意见
- if (this.LabelReader.Text != null)
- {
- this.LabelReader.Text = this.LabelReader.Text.Replace("rn", "<BR>");
- this.LabelReader.Text = this.LabelReader.Text.Replace(" ", " ");
- }
- // 设置显示已有意见的方式
- if (this.ReaderModal == ReaderModalType.TextBox)
- {
- this.TextBoxReader.Visible = true;
- this.LabelReader.Visible = false;
- }
- else
- {
- this.TextBoxReader.Visible = false;
- this.LabelReader.Visible = true;
- }
- this.TextBoxReader.Attributes.Add("style", "width:100%");
- this.LabelReader.Attributes.Add("style", "width:100%");
- // 设置CheckBox的显示
- if (this.ShowApproval)
- {
- this.Approval.Visible = true;
- }
- this.Writer.Attributes.Add("style", "width:100%;");
- double topPer = 0.75;
- if (!this.Enabled)
- {
- if (this.AutoHideWriter)
- {
- this.Writer.Visible = false;
- this.Append.Visible = false;
- this.Approval.Visible = false;
- topPer = 1.00;
- }
- else
- {
- this.Writer.Enabled = false;
- this.Append.Enabled = false;
- this.Approval.Enabled = false;
- topPer = 0.75;
- }
- }
- output.Write("<TABLE WIDTH=" + this.Width + " HEIGHT=" + this.Height + " VALIGN=TOP cellpadding="0" cellspacing="0">");
- #region 显示意见
- output.Write("<TR VALIGN=TOP>");
- output.Write("<TD>");
- this.TextBoxReader.Height = Unit.Pixel((int)(this.Height.Value * topPer));
- this.TextBoxReader.RenderControl(output);
- this.LabelReader.Height = Unit.Pixel((int)(this.Height.Value * topPer));
- this.LabelReader.RenderControl(output);
- output.Write("<TD>");
- output.Write("</TR>");
- #endregion
- output.Write("<TR VALIGN=TOP>");
- output.Write("<TD>");
- output.Write("<TABLE VALIGN=TOP cellpadding="0" cellspacing="0">");
- output.Write("<TR VALIGN=TOP>");
- output.Write("<TD WIDTH=80%>");
- if (this.Writer.Visible)
- {
- this.Writer.Height = Unit.Pixel((int)(this.Height.Value * (1 - topPer)));
- this.Writer.RenderControl(output);
- }
- output.Write("<TD>");
- output.Write("<TD WIDTH=20%>");
- if (this.Append.Visible)
- {
- this.Append.RenderControl(output);
- }
- if (this.Approval.Visible)
- {
- this.Approval.RenderControl(output);
- }
- output.Write("<TD>");
- output.Write("</TR>");
- output.Write("</TABLE>");
- output.Write("<TD>");
- output.Write("</TR>");
- output.Write("</TABLE>");
- }
- }
- }