XRPattern.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Drawing.Design;
  5. using CustomControls.Pattern.DataModels;
  6. using DevExpress.Utils.Serializing;
  7. using DevExpress.XtraPrinting;
  8. using DevExpress.XtraReports;
  9. using DevExpress.XtraReports.Expressions;
  10. using DevExpress.XtraReports.UI;
  11. using DevExpress.XtraReports.UserDesigner;
  12. namespace CustomControls.Pattern
  13. {
  14. /// <summary>
  15. /// 控件
  16. /// </summary>
  17. [ToolboxItem(true)]
  18. [XRDesigner("CustomControls.Design.XRPatternDesigner,CustomControls.Design")]
  19. [Designer("CustomControls.Design._XRPatternDesigner,CustomControls.Design")]
  20. [XRToolboxSubcategory(0, 7)]
  21. [DefaultBindableProperty(nameof(StringData))]
  22. public class XRPattern : XRControl
  23. {
  24. PatternDataItem patternDataItem = new PatternDataItem();
  25. #region 隐藏属性
  26. [Browsable(false)]
  27. [EditorBrowsable(EditorBrowsableState.Never)]
  28. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  29. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  30. public override string Text
  31. {
  32. get => base.Text;
  33. set => base.Text = value;
  34. }
  35. [Browsable(false)]
  36. [EditorBrowsable(EditorBrowsableState.Never)]
  37. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  38. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  39. public override string TextFormatString
  40. {
  41. get => base.TextFormatString;
  42. set => base.TextFormatString = value;
  43. }
  44. [Browsable(false)]
  45. [EditorBrowsable(EditorBrowsableState.Never)]
  46. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  47. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  48. public override string XlsxFormatString
  49. {
  50. get => base.XlsxFormatString;
  51. set => base.XlsxFormatString = value;
  52. }
  53. [Browsable(false)]
  54. [EditorBrowsable(EditorBrowsableState.Never)]
  55. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  56. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  57. public override bool WordWrap
  58. {
  59. get => base.WordWrap;
  60. set => base.WordWrap = value;
  61. }
  62. [Browsable(false)]
  63. [EditorBrowsable(EditorBrowsableState.Never)]
  64. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  65. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  66. public override bool KeepTogether
  67. {
  68. get => base.KeepTogether;
  69. set => base.KeepTogether = value;
  70. }
  71. [Browsable(false)]
  72. [EditorBrowsable(EditorBrowsableState.Never)]
  73. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  74. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  75. public override HorizontalAnchorStyles AnchorHorizontal
  76. {
  77. get => base.AnchorHorizontal;
  78. set => base.AnchorHorizontal = value;
  79. }
  80. [Browsable(false)]
  81. [EditorBrowsable(EditorBrowsableState.Never)]
  82. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  83. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  84. public override VerticalAnchorStyles AnchorVertical
  85. {
  86. get => base.AnchorVertical;
  87. set => base.AnchorVertical = value;
  88. }
  89. [Browsable(false)]
  90. [EditorBrowsable(EditorBrowsableState.Never)]
  91. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  92. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  93. public override bool CanPublish
  94. {
  95. get => base.CanPublish;
  96. set => base.CanPublish = value;
  97. }
  98. [Browsable(false)]
  99. [EditorBrowsable(EditorBrowsableState.Never)]
  100. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  101. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  102. public override Color BackColor
  103. {
  104. get => base.BackColor;
  105. set => base.BackColor = value;
  106. }
  107. [Browsable(false)]
  108. [EditorBrowsable(EditorBrowsableState.Never)]
  109. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  110. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  111. public override Color BorderColor
  112. {
  113. get => base.BorderColor;
  114. set => base.BorderColor = value;
  115. }
  116. [Browsable(false)]
  117. [EditorBrowsable(EditorBrowsableState.Never)]
  118. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  119. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  120. public override BorderDashStyle BorderDashStyle
  121. {
  122. get => base.BorderDashStyle;
  123. set => base.BorderDashStyle = value;
  124. }
  125. [Browsable(false)]
  126. [EditorBrowsable(EditorBrowsableState.Never)]
  127. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  128. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  129. public override float BorderWidth
  130. {
  131. get => base.BorderWidth;
  132. set => base.BorderWidth = value;
  133. }
  134. [Browsable(false)]
  135. [EditorBrowsable(EditorBrowsableState.Never)]
  136. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  137. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  138. public override BorderSide Borders
  139. {
  140. get => base.Borders;
  141. set => base.Borders = value;
  142. }
  143. [Browsable(false)]
  144. [EditorBrowsable(EditorBrowsableState.Never)]
  145. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  146. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  147. public override Font Font
  148. {
  149. get => base.Font;
  150. set => base.Font = value;
  151. }
  152. [Browsable(false)]
  153. [EditorBrowsable(EditorBrowsableState.Never)]
  154. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  155. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  156. public override Color ForeColor
  157. {
  158. get => base.ForeColor;
  159. set => base.ForeColor = value;
  160. }
  161. [Browsable(false)]
  162. [EditorBrowsable(EditorBrowsableState.Never)]
  163. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  164. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  165. public override PaddingInfo Padding
  166. {
  167. get => base.Padding;
  168. set => base.Padding = value;
  169. }
  170. [Browsable(false)]
  171. [EditorBrowsable(EditorBrowsableState.Never)]
  172. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  173. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  174. public override StylePriority StylePriority => base.StylePriority;
  175. [Browsable(false)]
  176. [EditorBrowsable(EditorBrowsableState.Never)]
  177. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  178. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  179. public override XRControlStyles Styles => base.Styles;
  180. [Browsable(false)]
  181. [EditorBrowsable(EditorBrowsableState.Never)]
  182. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  183. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  184. public override TextAlignment TextAlignment
  185. {
  186. get => base.TextAlignment;
  187. set => base.TextAlignment = value;
  188. }
  189. [Bindable(false), EditorBrowsable(EditorBrowsableState.Never)]
  190. public override event BindingEventHandler EvaluateBinding
  191. {
  192. add { }
  193. remove { }
  194. }
  195. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  196. public override event PrintOnPageEventHandler PrintOnPage
  197. {
  198. add { }
  199. remove { }
  200. }
  201. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  202. public override event PreviewMouseEventHandler PreviewMouseMove
  203. {
  204. add { }
  205. remove { }
  206. }
  207. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  208. public override event PreviewMouseEventHandler PreviewMouseDown
  209. {
  210. add { }
  211. remove { }
  212. }
  213. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  214. public override event PreviewMouseEventHandler PreviewMouseUp
  215. {
  216. add { }
  217. remove { }
  218. }
  219. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  220. public override event PreviewMouseEventHandler PreviewClick
  221. {
  222. add { }
  223. remove { }
  224. }
  225. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  226. public override event PreviewMouseEventHandler PreviewDoubleClick
  227. {
  228. add { }
  229. remove { }
  230. }
  231. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  232. public override event DrawEventHandler Draw
  233. {
  234. add { }
  235. remove { }
  236. }
  237. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  238. public override event HtmlEventHandler HtmlItemCreated
  239. {
  240. add { }
  241. remove { }
  242. }
  243. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  244. public override event EventHandler TextChanged
  245. {
  246. add { }
  247. remove { }
  248. }
  249. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  250. public override event DevExpress.XtraReports.UI.ChangeEventHandler SizeChanged
  251. {
  252. add { }
  253. remove { }
  254. }
  255. #endregion
  256. #region 属性和方法
  257. public new XRPatternScripts Scripts => (XRPatternScripts)fEventScripts;
  258. [DisplayName("String Data")]
  259. [Description("String Data description")]
  260. [Category("Data")]
  261. [XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
  262. [RefreshProperties(RefreshProperties.All)]
  263. public string StringData
  264. {
  265. get => patternDataItem.PatternData;
  266. set => patternDataItem.PatternData = value;
  267. }
  268. bool ShouldSerializeStringData() => false;
  269. [DisplayName("Row Space")]
  270. [Description("Row Space description")]
  271. [Category("Data")]
  272. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  273. [XtraSerializableProperty(XtraSerializationVisibility.Content)]
  274. public int RowSpace
  275. {
  276. get => patternDataItem.RowSpace;
  277. set => patternDataItem.RowSpace = value;
  278. }
  279. [DisplayName("Column Space")]
  280. [Description("Column Space description")]
  281. [Category("Data")]
  282. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  283. [XtraSerializableProperty(XtraSerializationVisibility.Content)]
  284. public int ColumnSpace
  285. {
  286. get => patternDataItem.ColumnSpace;
  287. set => patternDataItem.ColumnSpace = value;
  288. }
  289. [DisplayName("Is Draw Horizontal Line")]
  290. [Description("Is Draw Horizontal Line description")]
  291. [Category("Data")]
  292. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  293. [XtraSerializableProperty(XtraSerializationVisibility.Content)]
  294. public bool IsDrawHorizontalLine
  295. {
  296. get => patternDataItem.IsDrawHorizontalLine;
  297. set => patternDataItem.IsDrawHorizontalLine = value;
  298. }
  299. [DisplayName("Code Options")]
  300. [Description("Code Options description")]
  301. [Category("Data")]
  302. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  303. [XtraSerializableProperty(XtraSerializationVisibility.Content)]
  304. public CodeOptions CodeOptions { get; } = new CodeOptions();
  305. #endregion
  306. #region 构造函数
  307. static XRPattern()
  308. {
  309. ExpressionBindingDescriptor.SetPropertyDescription(typeof(XRPattern), nameof(StringData), new ExpressionBindingDescription(new string[] { "BeforePrint" }, 1000, new string[0]));
  310. }
  311. public XRPattern()
  312. {
  313. }
  314. #endregion
  315. #region 重写属性和方法
  316. /// <summary>
  317. /// 固定模块大小
  318. /// </summary>
  319. //public override RectangleF BoundsF
  320. //{
  321. // get => AdaptBounds(base.BoundsF);
  322. // set => base.BoundsF = value;
  323. //}
  324. RectangleF AdaptBounds(RectangleF rect)
  325. {
  326. if (RootReport != null)
  327. {
  328. rect.Size = GraphicsUnitConverter.Convert(GetActualSize(), GraphicsDpi.Millimeter, Dpi);
  329. }
  330. return rect;
  331. }
  332. SizeF GetActualSize() => Constants.Bounds.Size;
  333. protected override XRControlScripts CreateScripts() => new XRPatternScripts(this);
  334. protected override int DefaultHeight =>
  335. ConvertFromMMToDpi(Constants.Bounds.Height, GraphicsDpi.HundredthsOfAnInch);
  336. protected override int DefaultWidth =>
  337. ConvertFromMMToDpi(Constants.Bounds.Width, GraphicsDpi.HundredthsOfAnInch);
  338. int ConvertFromMMToDpi(float mmValue, float targetDpi) => (int)GraphicsUnitConverter.Convert(mmValue, GraphicsDpi.Millimeter, targetDpi);
  339. protected override VisualBrick CreateBrick(VisualBrick[] childrenBricks) => new PatternBrick(this);
  340. protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps)
  341. {
  342. base.PutStateToBrick(brick, ps);
  343. if (!(brick is PatternBrick patternBrick)) return;
  344. patternBrick.CodeOptions.Assign(CodeOptions);
  345. patternBrick.GenerateContent(patternDataItem);
  346. }
  347. protected override void GetStateFromBrick(VisualBrick brick) => base.GetStateFromBrick(brick);
  348. #endregion
  349. }
  350. }