Advertisement
peterzig

Steel Ball Voltage Calculator

Jun 6th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.17 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 = 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.            
  77.         }
  78.  
  79.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  80.         {
  81.             if (checkBox1.Checked)
  82.             {
  83.                 bool isChecked = true;
  84.                 temperature = 20;
  85.                 pressure = 1013;
  86.                 textBox2.Text = pressure.ToString();
  87.                 textBox1.Text = temperature.ToString();
  88.             }
  89.             else
  90.             {
  91.                 bool isChecked = false;
  92.                 temperature = 0;
  93.                 pressure = 0;
  94.                 textBox2.Text = pressure.ToString();
  95.                 textBox1.Text = temperature.ToString();
  96.             }
  97.         }
  98.        
  99.  
  100.         private void button1_Click(object sender, EventArgs e)
  101.         {
  102.             polarity = true;
  103.             label5.Text = "Dodatnia";
  104.         }
  105.  
  106.         private void button2_Click(object sender, EventArgs e)
  107.         {
  108.             polarity = false;
  109.             label5.Text = "Ujemna";
  110.         }
  111.  
  112.         private void button6_Click(object sender, EventArgs e)
  113.         {
  114.             pressure++;
  115.             textBox2.Text = pressure.ToString();
  116.         }
  117.  
  118.         private void button5_Click(object sender, EventArgs e)
  119.         {
  120.             pressure--;
  121.             textBox2.Text = pressure.ToString();
  122.         }
  123.  
  124.         private void button3_Click(object sender, EventArgs e)
  125.         {
  126.             temperature--;
  127.             textBox1.Text = temperature.ToString();
  128.         }
  129.  
  130.         private void button7_Click(object sender, EventArgs e)
  131.         {
  132.             if (polarity == false) {
  133.                 calculateResult(array[index, 0], array[index, 1], array[index, 2], d);
  134.             } else
  135.             {
  136.                 calculateResult(array[(index+12), 0], array[(index+12), 1], array[(index+12), 2], d);
  137.             }
  138.            
  139.             double value = calculateDiameter(space, d);
  140.             double k = calculateParameter(pressure, temperature);
  141.  
  142.             MessageBox.Show(result.ToString()+" kV\n", "Napięcie przeskoku: ");
  143.             textBox4.Text = value.ToString();
  144.             textBox5.Text = Math.Round(k,3).ToString();
  145.         }
  146.  
  147.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  148.         {
  149.             index = comboBox1.SelectedIndex;
  150.             d = Convert.ToDouble(comboBox1.Items[index]);
  151.         }
  152.  
  153.         private void textBox4_TextChanged(object sender, EventArgs e)
  154.         {
  155.  
  156.         }
  157.  
  158.         private void button4_Click(object sender, EventArgs e)
  159.         {
  160.             temperature++;
  161.             textBox1.Text = temperature.ToString();
  162.         }
  163.  
  164.         private void textBox3_TextChanged(object sender, EventArgs e)
  165.         {
  166.            
  167.             space = (float)Convert.ToDouble(textBox3.Text);
  168.             bool valid = float.TryParse(textBox3.Text.ToString(), out space);
  169.  
  170.         }
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement