Advertisement
peterzig

Steel Ball Voltage Calculator v2

Jun 11th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication3
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         float temperature = 0;
  16.         float pressure = 0;
  17.         bool polarity = false;
  18.         float space = 0;
  19.         double result, result1 = 0;
  20.         double a, b, c, d, k = 0;
  21.         int index = 0;
  22.         //array z wartościami
  23.         double[,] array = new double[,]
  24.         {
  25.             //polaryzacja ujemna
  26.             {-7.0278, 36.679, 0.9537}, // dla 2 array 0
  27.             {-3.1197, 34.267, 1.0852}, // dla 5
  28.             {-2.5274, 33.751, 0.6446}, // 6,25
  29.             {-1.5805, 32.356, 0.9248}, // 10
  30.             {-1.2233, 31.466,1.4188}, // 12,5
  31.             {-1.0359, 31.261,1.3121}, // 15
  32.             {-0.6224, 30.424, 1.4651}, // 25
  33.             {-0.3158, 29.175, 1.9239}, //50
  34.             {-0.2677, 28.347, 3.6374 }, //75
  35.             {-0.1616, 28.359, 1.3109}, //100
  36.             {-0.109, 27.637, 4.892}, //150
  37.             {-0.0782, 26.234 , 27.778}, //200
  38.  
  39.             // polaryzacja dodatnia
  40.             {-7.6027, 37.814, 0.4703},
  41.             {-2.4876,34.219,0.6911},
  42.             {-2.1011,33.342,0.8251},
  43.             {-1.2439,31.94,0.8181},
  44.             {-0.9963,31.478,0.7935},
  45.             {-0.8891,31.434,0.4858},
  46.             {-0.5498,30.754,-0.4025},
  47.             {-0.3005,29.831,-2.1153},
  48.             {-0.2037,29.154,-1.8502},
  49.             {-0.1576,28.819,-3.3674},
  50.             {0.107,28.039,27.753},
  51.             {0.0819, 27.753, -5.472},
  52.         };
  53.  
  54.         double calculateResult(double a, double b, double c, double d)
  55.         {
  56.             result = (a * space * space) + (b * space) + c;
  57.             return result;
  58.         }
  59.  
  60.         double calculateDiameter(double space, double d)
  61.         {
  62.             result1 = space / d;
  63.             return result1;
  64.         }
  65.  
  66.         double calculateParameter(double pressure, double temperature)
  67.         {
  68.             double density = ((293*pressure*100)/(1013*100*(temperature+273)));
  69.             double k = 0.9358*density + 0.0664;
  70.             return k;
  71.         }
  72.  
  73.         public Form1()
  74.         {
  75.             InitializeComponent();
  76.             this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  77.  
  78.         }
  79.  
  80.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  81.         {
  82.             if (checkBox1.Checked)
  83.             {
  84.                 bool isChecked = true;
  85.                 temperature = 20;
  86.                 pressure = 1013;
  87.                 textBox2.Text = pressure.ToString();
  88.                 textBox1.Text = temperature.ToString();
  89.             }
  90.             else
  91.             {
  92.                 bool isChecked = false;
  93.                 temperature = 0;
  94.                 pressure = 0;
  95.                 textBox2.Text = pressure.ToString();
  96.                 textBox1.Text = temperature.ToString();
  97.             }
  98.         }
  99.        
  100.  
  101.         private void button1_Click(object sender, EventArgs e)
  102.         {
  103.             polarity = true;
  104.             label5.Text = "Dodatnia";
  105.         }
  106.  
  107.         private void button2_Click(object sender, EventArgs e)
  108.         {
  109.             polarity = false;
  110.             label5.Text = "Ujemna";
  111.         }
  112.  
  113.         private void button6_Click(object sender, EventArgs e)
  114.         {
  115.             pressure++;
  116.             textBox2.Text = pressure.ToString();
  117.         }
  118.  
  119.         private void button5_Click(object sender, EventArgs e)
  120.         {
  121.             pressure--;
  122.             textBox2.Text = pressure.ToString();
  123.         }
  124.  
  125.         private void button3_Click(object sender, EventArgs e)
  126.         {
  127.             temperature--;
  128.             textBox1.Text = temperature.ToString();
  129.         }
  130.  
  131.         private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
  132.         {
  133.             char ch = e.KeyChar;
  134.  
  135.             if (ch == 46 && textBox3.Text.IndexOf('.') != -1)
  136.             {
  137.                 e.Handled = true;
  138.                 return;
  139.             }
  140.  
  141.             if (!Char.IsDigit(ch) && ch != 8 && ch != 46)
  142.             {
  143.                 e.Handled = true;
  144.             }
  145.         }
  146.  
  147.         private void button7_Click(object sender, EventArgs e)
  148.         {
  149.             if (polarity == false) {
  150.                 calculateResult(array[index, 0], array[index, 1], array[index, 2], d);
  151.             } else
  152.             {
  153.                 calculateResult(array[(index+12), 0], array[(index+12), 1], array[(index+12), 2], d);
  154.             }
  155.            
  156.             double value = calculateDiameter(space, d);
  157.             double k = calculateParameter(pressure, temperature);
  158.             double newResult = result * k;
  159.  
  160.             MessageBox.Show(newResult.ToString()+" kV\n", "Napięcie przeskoku: ");
  161.             textBox4.Text = value.ToString();
  162.             textBox5.Text = Math.Round(k,3).ToString();
  163.  
  164.             if(value > 0.05 && value < 0.75)
  165.             {
  166.                 label14.ForeColor = System.Drawing.Color.Black;
  167.                 label14.Text = "Jednorodny rozkład pola";
  168.             }
  169.             else
  170.             {
  171.                 label14.ForeColor = System.Drawing.Color.Red;
  172.                 label14.Text = "Niejednorodny rozkład pola";
  173.             }
  174.  
  175.             label15.Text = "Napięcie przeskoku:" + newResult.ToString() + " kV";
  176.         }
  177.  
  178.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  179.         {
  180.             index = comboBox1.SelectedIndex;
  181.             d = Convert.ToDouble(comboBox1.Items[index]);
  182.         }
  183.  
  184.         private void textBox4_TextChanged(object sender, EventArgs e)
  185.         {
  186.  
  187.         }
  188.  
  189.         private void button4_Click(object sender, EventArgs e)
  190.         {
  191.             temperature++;
  192.             textBox1.Text = temperature.ToString();
  193.         }
  194.  
  195.         private void textBox3_TextChanged(object sender, EventArgs e)
  196.         {
  197.             if (textBox3.Text == "")
  198.             {
  199.                 MessageBox.Show("Wprowadź wartość do pola 'Odstęp kul'");
  200.             }
  201.             else
  202.             {
  203.                 space = (float)Convert.ToDouble(textBox3.Text);
  204.                 bool valid = float.TryParse(textBox3.Text.ToString(), out space);
  205.             }
  206.         }
  207.  
  208.  
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement