Pavlex4

Untitled

Oct 16th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. void Band_4()
  2. {
  3. if (comboBox1.Text == "4")
  4. {
  5. if (textBox1.Text == "0")
  6. {
  7. MessageBox.Show("Otpornost mora biti veca od nule!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  8. return;
  9. }
  10. if (comboBox2.Text == "")
  11. {
  12. MessageBox.Show("Izaberi vrednost tolerancije!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  13. return;
  14. }
  15. List<double> E6 = new List<double> { 1, 1.5, 2.2, 3.3, 4.7, 6.8, 10 };
  16. List<double> E12 = new List<double> { 1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10 };
  17. List<double> E24 = new List<double> { 1, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1, 10 };
  18. var colours = new string[] { "Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Grey", "White", "Silver", "Gold" };
  19. var factorDictionary = new Dictionary<char, double>() { { 'p', 0.000000000001 }, { 'n', 0.000000001 }, { 'u', 0.000001 }, { 'm', 0.001 }, { 'R', 1 }, { 'K', 1000 }, { 'M', 1000000 }, { 'G', 1000000000 } };
  20. string res = string.Empty;
  21.  
  22. while (string.IsNullOrEmpty(res))
  23. {
  24. res = textBox1.Text;
  25. }
  26.  
  27. var lastChar = res.Last();
  28. var isUnitCorrect = factorDictionary.ContainsKey(lastChar);
  29. var value = res.Substring(0, res.Length - 1);
  30. var isValueCorrect = !value.Any(x => !char.IsDigit(x));
  31.  
  32.  
  33. if (comboBox2.Text == "E12 (10%)")
  34. {
  35. for (int i = 0; i < E12.Count; i++)
  36. {
  37. if (isUnitCorrect && isValueCorrect)
  38. {
  39. double mul = factorDictionary[lastChar];
  40. double val = double.Parse(value) * mul;
  41. min = mul * E12[0];
  42. p = mul * E12[i];
  43. int third = 0;
  44.  
  45. if (val < 0.1)
  46. {
  47. MessageBox.Show("Otpornost ne moze da bude manja od 0.1 oma!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  48. return;
  49. }
  50. if (val < 1)
  51. {
  52. val *= 100;
  53. third = 10;
  54. }
  55. else if (val < 10)
  56. {
  57. val *= 10;
  58. third = 11;
  59. }
  60.  
  61.  
  62. if (p <= val)
  63. {
  64. if (p < min)
  65. {
  66. r = Math.Abs(p - val);
  67. /* r = p - val;
  68. if(r<)*/
  69. label5.Text = Convert.ToString(p);
  70. }
  71. }
  72.  
  73. res = val.ToString();
  74.  
  75. if (res.Count() > 24)
  76. {
  77. MessageBox.Show("Pogresna vrednost!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  78. return;
  79. }
  80.  
  81. else
  82. {
  83. label15.BackColor = Color.FromName(colours[res[0] - '0']);
  84. label16.BackColor = Color.FromName(colours[res[1] - '0']);
  85. label17.BackColor = Color.FromName(colours[third != 0 ? third : res.Count() - 2]);
  86. label6.Text = textBox1.Text;
  87. textBox2.Text = colours[res[0] - '0'];
  88. textBox3.Text = colours[res[1] - '0'];
  89. textBox4.Text = colours[third != 0 ? third : res.Count() - 2];
  90. //label5.Text = Convert.ToString(p);
  91. }
  92. }
  93. if (comboBox1.Text == "4")
  94. {
  95. if (comboBox2.Text == "E24 (5%)")
  96. {
  97. label18.BackColor = Color.Gold;
  98. textBox5.Text = "Gold";
  99. }
  100. if (comboBox2.Text == "E12 (10%)")
  101. {
  102. label18.BackColor = Color.Silver;
  103. textBox5.Text = "Silver";
  104. }
  105. }
  106. }
  107. }
  108. else
  109. {
  110. MessageBox.Show("Invalid value!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  111. return;
  112. }
  113. }
  114. }
Add Comment
Please, Sign In to add comment