Pavle_nis

Untitled

Oct 23rd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. public void Band_4()
  2. {
  3. if (radioButton1.Checked)
  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 (comboBox1.Text == "")
  11. {
  12. MessageBox.Show("Izaberi vrednost tolerancije!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  13. return;
  14. }
  15.  
  16. while (string.IsNullOrEmpty(res))
  17. {
  18. res = textBox1.Text;
  19. }
  20.  
  21. var lastChar = res.Last();
  22. var isUnitCorrect = factorDictionary.ContainsKey(lastChar);
  23. var value = res.Substring(0, res.Length - 1);
  24. var isValueCorrect = !value.Any(x => !char.IsDigit(x));
  25.  
  26. if (isUnitCorrect && isValueCorrect)
  27. {
  28. double mul = factorDictionary[lastChar];
  29. double val = double.Parse(value) * mul;
  30. int third = 0;
  31.  
  32. if (val < 0.1)
  33. {
  34. MessageBox.Show("Otpornost ne moze da bude manja od 0.1 oma!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  35. return;
  36. }
  37. if (val < 1)
  38. {
  39. val *= 100;
  40. third = 10;
  41. }
  42. else if (val < 10)
  43. {
  44. val *= 10;
  45. third = 11;
  46. }
  47.  
  48.  
  49. /*if (p <= val)
  50. {
  51. if (p < min)
  52. {
  53. min = E12[i];
  54. r = Math.Abs(val - p);
  55. }
  56. }*/
  57.  
  58. res = val.ToString();
  59.  
  60. if (res.Count() > 24)
  61. {
  62. MessageBox.Show("Pogresna vrednost!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
  63. return;
  64. }
  65.  
  66. else
  67. {
  68. label14.BackColor = Color.FromName(colours[res[0] - '0']);
  69. label15.BackColor = Color.FromName(colours[res[1] - '0']);
  70. label16.BackColor = Color.FromName(colours[third != 0 ? third : res.Count() - 2]);
  71. label4.Text = textBox1.Text;
  72. textBox2.Text = colours[res[0] - '0'];
  73. textBox3.Text = colours[res[1] - '0'];
  74. textBox4.Text = colours[third != 0 ? third : res.Count() - 2];
  75. }
  76. }
  77. if (radioButton1.Checked)
  78. {
  79. if (comboBox1.Text == "E24 (5%)")
  80. {
  81. label17.BackColor = Color.Gold;
  82. textBox5.Text = "Gold";
  83. }
  84. if (comboBox1.Text == "E12 (10%)")
  85. {
  86. label17.BackColor = Color.Silver;
  87. textBox5.Text = "Silver";
  88. }
  89. }
  90. }
  91. }
Add Comment
Please, Sign In to add comment