PanelClientData.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. this.Controls.Add(this.metingName);
  36. this.Dock = System.Windows.Forms.DockStyle.Top;
  37. this.Location = new System.Drawing.Point(0, 0);
  38. this.Name = "panel1";
  39. this.Size = new System.Drawing.Size(284, 80);
  40. //
  41. // metingName
  42. //
  43. this.metingName.AutoSize = true;
  44. this.metingName.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  45. this.metingName.Location = new System.Drawing.Point(12, 9);
  46. this.metingName.Name = "metingName";
  47. this.metingName.Size = new System.Drawing.Size(105, 21);
  48. this.metingName.TabIndex = 0;
  49. this.metingName.Text = name;
  50. //
  51. // progressBarMeting
  52. //
  53. this.progressBarMeting.Location = new System.Drawing.Point(16, 39);
  54. this.progressBarMeting.Name = "progressBarMeting";
  55. this.progressBarMeting.Size = new System.Drawing.Size(183, 23);
  56. this.progressBarMeting.TabIndex = 1;
  57. this.progressBarMeting.Value = 0;
  58. //
  59. // labelMetingCurrentValue
  60. //
  61. this.labelMetingCurrentValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  62. this.labelMetingCurrentValue.AutoSize = true;
  63. this.labelMetingCurrentValue.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  64. this.labelMetingCurrentValue.Location = new System.Drawing.Point(210, 32);
  65. this.labelMetingCurrentValue.Name = "labelMetingCurrentValue";
  66. this.labelMetingCurrentValue.Size = new System.Drawing.Size(57, 32);
  67. this.labelMetingCurrentValue.TabIndex = 2;
  68. this.labelMetingCurrentValue.Text = "0";
  69. //rpm check
  70. if (name == "RPM")
  71. {
  72. this.rpmpicturebox = new PictureBox();
  73. this.rpmpicturebox.Location = new System.Drawing.Point(210, 32);
  74. this.rpmpicturebox.Size = new System.Drawing.Size(57, 32);
  75. this.rpmpicturebox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  76. this.rpmpicturebox.AutoSize = true;
  77. this.rpmpicturebox.Name = "rpmbox";
  78. }
  79. }
  80. public void setText(string text)
  81. {
  82. this.metingName.Text = text;
  83. }
  84. public void updateValue(int value)
  85. {
  86. if(name == "RPM")
  87. {
  88. if(value < 45)
  89. {
  90. this.rpmpicturebox.Image = Properties.Resources.up;
  91. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Red;
  92. }
  93. else if( value > 55)
  94. {
  95. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Red;
  96. this.rpmpicturebox.Image = Properties.Resources.down;
  97. }
  98. else
  99. {
  100. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Green;
  101. this.rpmpicturebox.Image = Properties.Resources.stay;
  102. }
  103. }
  104. if (name == "Tijd")
  105. {
  106. this.labelMetingCurrentValue.Text = Helper.SecondsToTime(value);
  107. }
  108. else
  109. {
  110. this.labelMetingCurrentValue.Text = value.ToString();
  111. this.progressBarMeting.Value = ValueToPercentage(value);
  112. }
  113. }
  114. public void updateValue(double value)
  115. {
  116. this.labelMetingCurrentValue.Text = value.ToString();
  117. this.progressBarMeting.Value = ValueToPercentage((int)value);
  118. }
  119. public void updateValue(decimal value)
  120. {
  121. this.labelMetingCurrentValue.Text = value.ToString();
  122. this.progressBarMeting.Value = ValueToPercentage((int)value);
  123. }
  124. private int ValueToPercentage(int value)
  125. {
  126. if (value < min)
  127. return 0;
  128. if (value > max)
  129. return 100;
  130. return ((value - min) * 100) / (max - min);
  131. }
  132. }
  133. }