PanelClientData.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using ErgometerLibrary;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace ErgometerApplication
  9. {
  10. public class PanelClientData : Panel
  11. {
  12. public Label labelMetingCurrentValue;
  13. public ProgressBar progressBarMeting;
  14. public PictureBox rpmpicturebox;
  15. public Label metingName;
  16. private int min { get; set; }
  17. public int max { get; set; }
  18. private string name;
  19. public PanelClientData(string name, int min, int max) : base()
  20. {
  21. this.min = min;
  22. this.max = max;
  23. this.name = name;
  24. this.metingName = new System.Windows.Forms.Label();
  25. this.progressBarMeting = new System.Windows.Forms.ProgressBar();
  26. this.labelMetingCurrentValue = new System.Windows.Forms.Label();
  27. //
  28. // initialize panel
  29. //
  30. this.BackColor = System.Drawing.SystemColors.ControlLightLight;
  31. this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  32. this.Controls.Add(this.labelMetingCurrentValue);
  33. if(name != "Tijd")
  34. this.Controls.Add(this.progressBarMeting);
  35. if (name == "RPM")
  36. {
  37. this.rpmpicturebox = new PictureBox();
  38. this.Controls.Add(this.rpmpicturebox);
  39. }
  40. this.Controls.Add(this.metingName);
  41. this.Dock = System.Windows.Forms.DockStyle.Top;
  42. this.Location = new System.Drawing.Point(0, 0);
  43. this.Name = "panel1";
  44. this.Size = new System.Drawing.Size(284, 80);
  45. //
  46. // metingName
  47. //
  48. this.metingName.AutoSize = true;
  49. this.metingName.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  50. this.metingName.Location = new System.Drawing.Point(12, 9);
  51. this.metingName.Name = "metingName";
  52. this.metingName.Size = new System.Drawing.Size(105, 21);
  53. this.metingName.TabIndex = 0;
  54. this.metingName.Text = name;
  55. //
  56. // progressBarMeting
  57. //
  58. this.progressBarMeting.Location = new System.Drawing.Point(16, 39);
  59. this.progressBarMeting.Name = "progressBarMeting";
  60. this.progressBarMeting.Size = new System.Drawing.Size(183, 23);
  61. this.progressBarMeting.TabIndex = 1;
  62. this.progressBarMeting.Value = 0;
  63. //
  64. // labelMetingCurrentValue
  65. //
  66. this.labelMetingCurrentValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  67. this.labelMetingCurrentValue.AutoSize = true;
  68. this.labelMetingCurrentValue.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  69. this.labelMetingCurrentValue.Location = new System.Drawing.Point(210, 32);
  70. this.labelMetingCurrentValue.Name = "labelMetingCurrentValue";
  71. this.labelMetingCurrentValue.Size = new System.Drawing.Size(57, 32);
  72. this.labelMetingCurrentValue.TabIndex = 2;
  73. this.labelMetingCurrentValue.Text = "0";
  74. //rpm check
  75. if (name == "RPM")
  76. {
  77. this.rpmpicturebox.Location = new System.Drawing.Point(210, 0);
  78. this.rpmpicturebox.Size = new System.Drawing.Size(57, 32);
  79. this.rpmpicturebox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  80. this.rpmpicturebox.AutoSize = true;
  81. this.rpmpicturebox.Name = "rpmbox";
  82. }
  83. }
  84. public void setText(string text)
  85. {
  86. this.metingName.Text = text;
  87. }
  88. public void updateValue(int value)
  89. {
  90. if(name == "RPM")
  91. {
  92. if(value < 45)
  93. {
  94. this.rpmpicturebox.Image = Properties.Resources.up;
  95. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Red;
  96. }
  97. else if( value > 55)
  98. {
  99. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Red;
  100. this.rpmpicturebox.Image = Properties.Resources.down;
  101. }
  102. else
  103. {
  104. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Green;
  105. this.rpmpicturebox.Image = Properties.Resources.stay;
  106. }
  107. }
  108. if (name == "Tijd")
  109. {
  110. this.labelMetingCurrentValue.Text = Helper.SecondsToTime(value);
  111. }
  112. else
  113. {
  114. this.labelMetingCurrentValue.Text = value.ToString();
  115. this.progressBarMeting.Value = ValueToPercentage(value);
  116. }
  117. }
  118. public void updateValue(double value)
  119. {
  120. this.labelMetingCurrentValue.Text = value.ToString();
  121. this.progressBarMeting.Value = ValueToPercentage((int)value);
  122. }
  123. public void updateValue(decimal value)
  124. {
  125. this.labelMetingCurrentValue.Text = value.ToString();
  126. this.progressBarMeting.Value = ValueToPercentage((int)value);
  127. }
  128. private int ValueToPercentage(int value)
  129. {
  130. if (value < min)
  131. return 0;
  132. if (value > max)
  133. return 100;
  134. return ((value - min) * 100) / (max - min);
  135. }
  136. }
  137. }