Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Band_4()
- {
- if (comboBox1.Text == "4")
- {
- if (textBox1.Text == "0")
- {
- MessageBox.Show("Otpornost mora biti veca od nule!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if (comboBox2.Text == "")
- {
- MessageBox.Show("Izaberi vrednost tolerancije!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- List<double> E6 = new List<double> { 1, 1.5, 2.2, 3.3, 4.7, 6.8, 10 };
- 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 };
- 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 };
- var colours = new string[] { "Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Grey", "White", "Silver", "Gold" };
- 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 } };
- string res = string.Empty;
- while (string.IsNullOrEmpty(res))
- {
- res = textBox1.Text;
- }
- var lastChar = res.Last();
- var isUnitCorrect = factorDictionary.ContainsKey(lastChar);
- var value = res.Substring(0, res.Length - 1);
- var isValueCorrect = !value.Any(x => !char.IsDigit(x));
- if (comboBox2.Text == "E12 (10%)")
- {
- for (int i = 0; i < E12.Count; i++)
- {
- if (isUnitCorrect && isValueCorrect)
- {
- double mul = factorDictionary[lastChar];
- double val = double.Parse(value) * mul;
- min = mul * E12[0];
- p = mul * E12[i];
- int third = 0;
- if (val < 0.1)
- {
- MessageBox.Show("Otpornost ne moze da bude manja od 0.1 oma!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if (val < 1)
- {
- val *= 100;
- third = 10;
- }
- else if (val < 10)
- {
- val *= 10;
- third = 11;
- }
- if (p <= val)
- {
- if (p < min)
- {
- r = Math.Abs(p - val);
- /* r = p - val;
- if(r<)*/
- label5.Text = Convert.ToString(p);
- }
- }
- res = val.ToString();
- if (res.Count() > 24)
- {
- MessageBox.Show("Pogresna vrednost!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- else
- {
- label15.BackColor = Color.FromName(colours[res[0] - '0']);
- label16.BackColor = Color.FromName(colours[res[1] - '0']);
- label17.BackColor = Color.FromName(colours[third != 0 ? third : res.Count() - 2]);
- label6.Text = textBox1.Text;
- textBox2.Text = colours[res[0] - '0'];
- textBox3.Text = colours[res[1] - '0'];
- textBox4.Text = colours[third != 0 ? third : res.Count() - 2];
- //label5.Text = Convert.ToString(p);
- }
- }
- if (comboBox1.Text == "4")
- {
- if (comboBox2.Text == "E24 (5%)")
- {
- label18.BackColor = Color.Gold;
- textBox5.Text = "Gold";
- }
- if (comboBox2.Text == "E12 (10%)")
- {
- label18.BackColor = Color.Silver;
- textBox5.Text = "Silver";
- }
- }
- }
- }
- else
- {
- MessageBox.Show("Invalid value!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- }
- }
Add Comment
Please, Sign In to add comment