DataComponentBase.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. namespace FastReport.Data
  7. {
  8. /// <summary>
  9. /// The base class for all data components such as data sources, columns.
  10. /// </summary>
  11. public partial class DataComponentBase : Base
  12. {
  13. #region Fields
  14. private string alias;
  15. private bool enabled;
  16. private string referenceName;
  17. private object reference;
  18. #endregion
  19. #region Properties
  20. /// <summary>
  21. /// Gets or sets alias of this object.
  22. /// </summary>
  23. /// <remarks>
  24. /// Alias is a human-friendly name of this object. It may contain any symbols (including
  25. /// spaces and national symbols).
  26. /// </remarks>
  27. [Category("Design")]
  28. public new string Alias
  29. {
  30. get { return alias; }
  31. set { alias = value; }
  32. }
  33. /// <summary>
  34. /// Gets or sets a value indicates that object is enabled and thus can be used in a report.
  35. /// </summary>
  36. /// <remarks>
  37. /// This property is used to hide an object from the Data Dictionary window. Hidden
  38. /// objects are still accessible in the "Data|Choose Data Source..." menu.
  39. /// </remarks>
  40. [Browsable(false)]
  41. public bool Enabled
  42. {
  43. get { return enabled; }
  44. set { enabled = value; }
  45. }
  46. /// <summary>
  47. /// Gets or sets a name of the data object.
  48. /// </summary>
  49. /// <remarks>
  50. /// This property is used to support FastReport.Net infrastructure. Do not use it directly.
  51. /// </remarks>
  52. [Browsable(false)]
  53. public string ReferenceName
  54. {
  55. get { return referenceName; }
  56. set { referenceName = value; }
  57. }
  58. /// <summary>
  59. /// Gets or sets a reference to the data object.
  60. /// </summary>
  61. /// <remarks>
  62. /// This property is used to support FastReport.Net infrastructure. Do not use it directly.
  63. /// </remarks>
  64. [Browsable(false)]
  65. public object Reference
  66. {
  67. get { return reference; }
  68. set { reference = value; }
  69. }
  70. /// <summary>
  71. /// Gets a value indicates that this object has an alias.
  72. /// </summary>
  73. [Browsable(false)]
  74. public bool IsAliased
  75. {
  76. get { return Name != Alias; }
  77. }
  78. #endregion
  79. #region Public Methods
  80. /// <inheritdoc/>
  81. public override void Assign(Base source)
  82. {
  83. BaseAssign(source);
  84. }
  85. /// <inheritdoc/>
  86. public override void SetName(string value)
  87. {
  88. bool changeAlias = String.IsNullOrEmpty(Alias) || String.Compare(Alias, Name, true) == 0;
  89. base.SetName(value);
  90. if (changeAlias)
  91. Alias = Name;
  92. }
  93. /// <inheritdoc/>
  94. public override void Serialize(FRWriter writer)
  95. {
  96. base.Serialize(writer);
  97. if (IsAliased)
  98. writer.WriteStr("Alias", Alias);
  99. if (!Enabled)
  100. writer.WriteBool("Enabled", Enabled);
  101. if (!String.IsNullOrEmpty(ReferenceName))
  102. writer.WriteStr("ReferenceName", ReferenceName);
  103. }
  104. /// <summary>
  105. /// Initializes the object before running a report.
  106. /// </summary>
  107. /// <remarks>
  108. /// This method is used by the report engine, do not call it directly.
  109. /// </remarks>
  110. public virtual void InitializeComponent()
  111. {
  112. }
  113. #endregion
  114. /// <summary>
  115. /// Initializes a new instance of the <see cref="DataComponentBase"/> class with default settings.
  116. /// </summary>
  117. public DataComponentBase()
  118. {
  119. Alias = "";
  120. ReferenceName = "";
  121. Enabled = true;
  122. SetFlags(Flags.CanEdit | Flags.CanCopy, false);
  123. }
  124. }
  125. }