DialogBaseComponent.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Threading.Tasks;
  5. using System.IO;
  6. using System.Windows.Forms;
  7. using Microsoft.AspNetCore.Components;
  8. using FastReport.Dialog;
  9. using System.Globalization;
  10. namespace FastReport.Web.Blazor.Components.Internal.Dialog
  11. {
  12. public abstract class DialogBaseComponent<T> : Microsoft.AspNetCore.Components.ComponentBase
  13. where T : DialogControl
  14. {
  15. [Parameter]
  16. public WebReport WebReport { get; set; }
  17. [Parameter]
  18. public T Control { get; set; }
  19. protected virtual string GetStyle
  20. => $"{GetControlPosition()} {GetControlFont()} {GetForeColor()} {GetBackColor()}";
  21. protected string GetForeColor()
  22. {
  23. if (!Control.ForeColor.IsEmpty)
  24. return $"color: {ColorTranslator.ToHtml(Control.ForeColor)};";
  25. return string.Empty;
  26. }
  27. protected string GetBackColor()
  28. {
  29. if (!Control.BackColor.IsEmpty)
  30. return $"background-color: {ColorTranslator.ToHtml(Control.BackColor)};";
  31. return string.Empty;
  32. }
  33. protected string GetControlFont()
  34. {
  35. Font font = Control.Font;
  36. string fontStyle = (((font.Style & FontStyle.Bold) > 0) ? "font-weight:bold;" : String.Empty) +
  37. (((font.Style & FontStyle.Italic) > 0) ? "font-style:italic;" : "font-style:normal;");
  38. if ((font.Style & FontStyle.Underline) > 0 && (font.Style & FontStyle.Strikeout) > 0)
  39. fontStyle += "text-decoration:underline|line-through;";
  40. else if ((font.Style & FontStyle.Underline) > 0)
  41. fontStyle += "text-decoration:underline;";
  42. else if ((font.Style & FontStyle.Strikeout) > 0)
  43. fontStyle += "text-decoration:line-through;";
  44. return $"font-size:{WebReport.Dialog.Zoom(font.Size)}pt;font-family:{font.FontFamily.Name};{fontStyle};display:inline-block;";
  45. }
  46. protected string GetControlPosition()
  47. {
  48. Web.Dialog dialog = WebReport.Dialog;
  49. return $"position:absolute;" +
  50. $"left:{dialog.ZoomWithRescale(Control.Left)}px;" +
  51. $"top:{dialog.ZoomWithRescale(Control.Top)}px;" +
  52. $"width:{dialog.ZoomWithRescale(Control.Width)}px;" +
  53. $"height:{dialog.ZoomWithRescale(Control.Height)}px;" +
  54. $"padding:0px;margin:0px;";
  55. }
  56. protected virtual string GetControlAlign()
  57. {
  58. if (Control is LabelControl labelControl)
  59. return GetAlign(labelControl.TextAlign);
  60. return string.Empty;
  61. }
  62. protected string GetEditAlign(HorizontalAlignment align)
  63. {
  64. if (align == HorizontalAlignment.Left)
  65. return "text-align:left;";
  66. else if (align == HorizontalAlignment.Center)
  67. return "text-align:center;";
  68. else if (align == HorizontalAlignment.Right)
  69. return "text-align:right;";
  70. else
  71. return "";
  72. }
  73. protected string GetAlign(ContentAlignment align)
  74. {
  75. if (align == ContentAlignment.TopLeft)
  76. return "text-align:left;vertical-align:top;";
  77. else if (align == ContentAlignment.TopCenter)
  78. return "text-align:center;vertical-align:top;";
  79. else if (align == ContentAlignment.TopRight)
  80. return "text-align:right;vertical-align:top;";
  81. else if (align == ContentAlignment.BottomLeft)
  82. return "text-align:left;vertical-align:bottom;";
  83. else if (align == ContentAlignment.BottomCenter)
  84. return "text-align:center;vertical-align:bottom;";
  85. else if (align == ContentAlignment.TopRight)
  86. return "text-align:right;vertical-align:bottom;";
  87. else if (align == ContentAlignment.MiddleLeft)
  88. return "text-align:left;vertical-align:middle;";
  89. else if (align == ContentAlignment.MiddleCenter)
  90. return "text-align:center;vertical-align:middle;";
  91. else if (align == ContentAlignment.MiddleRight)
  92. return "text-align:right;vertical-align:middle;";
  93. else
  94. return "";
  95. }
  96. }
  97. }