SheetSign.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. namespace OThinker.H3.WorkSheet
  6. {
  7. /// <summary>
  8. /// Summary description for SheetSign.
  9. /// </summary>
  10. [DefaultProperty("Text"), 
  11. ToolboxData("<{0}:SheetSign runat=server></{0}:SheetSign>")]
  12. public class SheetSign : SheetLabel
  13. {
  14. public SheetSign()
  15. {
  16. }
  17. private string PackSign(string Signer, string SignDate)
  18. {
  19. return Signer + " " + SignDate;
  20. }
  21. private string UnpackSign(string Sign)
  22. {
  23. if(Sign == null || Sign.IndexOf(" ") == -1)
  24. {
  25.                 return null;
  26. }
  27. else
  28. {
  29. int index = Sign.IndexOf(" ");
  30. string Signer = Sign.Substring(0, index);
  31.                 string SignDate = Sign.Substring(index + 1);
  32.                 return this.GetText(Signer, SignDate);
  33. }
  34. }
  35.         private string GetText(string Signer, string SignDate)
  36.         {
  37.             return "签名:" + Signer + "  日期:" + SignDate;
  38.         }
  39.         public override void LoadDataField(SheetPage SheetPage)
  40. {
  41. }
  42.         public override void SaveDataField(OThinker.H3.WorkSheet.SheetPage SheetPage)
  43. {
  44. if(
  45. this.DataField != null &&
  46. this.DataField != "" &&
  47. SheetPage.Enviroment.InstanceData[this.DataField] != null && 
  48. SheetPage.Enviroment.InstanceData[this.DataField].ItemType == typeof(string) && 
  49.                 SheetPage.Enviroment.InstanceData[this.DataField].ToString().Trim() != "" &&
  50.                 SheetPage.Enviroment.InstanceData[this.DataField].ToString().Trim() != null && 
  51. SheetPage.Enviroment.InstanceData[this.DataField].Visible && 
  52. SheetPage.Enviroment.InstanceData[this.DataField].Editable)
  53. {
  54. // 如果允许写的话,则读取当前用户
  55.                 string Signer = SheetPage.Enviroment.Organization.GetFullName(SheetPage.Enviroment.Participant);
  56. string SignDate = System.DateTime.Now.ToShortDateString();
  57. // 打包
  58. SheetPage.Enviroment.InstanceData[DataField].Value = this.PackSign(Signer, SignDate);
  59. }
  60. }
  61. /// <summary> 
  62. /// Render this control to the output parameter specified.
  63. /// </summary>
  64. /// <param name="output"> The HTML writer to write out to </param>
  65.         protected override void Render(HtmlTextWriter output)
  66.         {
  67.             SheetPage sheetPage = (SheetPage)this.Page;
  68.             if (this.DataField == null || this.DataField == "" ||
  69.                 sheetPage.Enviroment.InstanceData[this.DataField] == null ||
  70.                 sheetPage.Enviroment.InstanceData[this.DataField].ItemType != typeof(string) ||
  71.                 sheetPage.Enviroment.InstanceData[this.DataField].Visible == false)
  72.             {
  73.                 this.Text = null;
  74.             }
  75.             else if (sheetPage.Enviroment.InstanceData[this.DataField].Value != null &&
  76.                     ((string)sheetPage.Enviroment.InstanceData[this.DataField].Value) != "")
  77.             {
  78.                 // 获得签名的全部内容
  79.                 string sign = sheetPage.Enviroment.InstanceData[this.DataField].Value.ToString();
  80.                 // 解开签名
  81.                 this.Text = this.UnpackSign(sign);
  82.             }
  83.             else if (sheetPage.Enviroment.InstanceData[this.DataField].Editable)
  84.             {
  85.                 // 如果允许写的话,则读取当前用户
  86.                 string Signer = sheetPage.Enviroment.Organization.GetFullName(sheetPage.Enviroment.Participant);
  87.                 string SignDate = System.DateTime.Now.ToShortDateString();
  88.                 this.Text = this.GetText(Signer, SignDate);
  89.             }
  90.             else
  91.             {
  92.                 this.Text = null;
  93.             }
  94.             base.Render(output);
  95.         }
  96. }
  97. }