using System using System Collections Generic using System ComponentMo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.SelectedIndex = 0;
comboBox2.SelectedIndex = 0;
textBox1.Text = "1";
}
private double getValue(string a, string b)
{
double finalValue = 1;
double aValue = 1;
double bValue= 1;
if (a == "грамм")
aValue = 1;
if (b == "грамм")
bValue = 1;
if (a == "килограмм")
aValue = 1000;
if (b == "килограмм")
bValue = 1000;
if (a == "центнер")
aValue = 100000;
if (b == "центнер")
bValue = 100000;
if (a == "тонна")
aValue = 1000000;
if (b == "тонна")
bValue = 1000000;
finalValue = aValue / bValue;
return finalValue;
}
private void button1_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(this.textBox1.Text) || String.IsNullOrEmpty(this.textBox2.Text))
{
double result = 1;
result = Convert.ToDouble(this.textBox1.Text) * getValue(this.comboBox1.Text, this.comboBox2.Text);
this.textBox2.Text = Convert.ToString(result);
}
}
}
}