1 / 1 / 0
Регистрация: 03.05.2022
Сообщений: 23
|
|
|
|
WPF Вычислить сколько осталось до ТО циклом While
09.05.2022, 11:13. Показов 2537. Ответов 22
Здравствуйте, в общем учусь писать программы и выбрал себе на голову дипломную создать программу... В общем суть проблемы, у меня не получается сделать высчитывание цикла While после нажатия кнопки, а так же чтобы результат выводился во второй текстбокс, задача программы: человек вводит в первый текстбокс например кол-во моточасов, и нажимая кнопку вычислить запускается цикл while, в котором, например у трактора МТЗ-80 каждые 60 моточасов делается ТО-1, и человек например ввел там 120, и высвечивается в текстбокс 2 - пора проводить ТО-1, а если человек ввел например 140, то пишет: до следующего ТО-1 осталось ... моточасов, если кому не тяжело очень прошу помочь
Вот Код XML:
| XML | 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
| <Window x:Class="VichysleniyeTO.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VichysleniyeTO"
mc:Ignorable="d"
Title="Вычисление ТО" Height="589" Width="1062" Icon="/hammer_wrench_icon_135529.png">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image Margin="-1,-1,-1,-1" Grid.ColumnSpan="4" RenderTransformOrigin="0.5,0.5" Source="/60c1c12c3d5ef1d6ea8baf8ff9ae8da9.jpg" Stretch="Fill" Grid.RowSpan="8">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleY="-0.108"/>
<RotateTransform Angle="0.149"/>
<TranslateTransform X="-0.004" Y="-1.041"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<ComboBox x:Name="comboBox1" Margin="52,31,52,30" Grid.Row="1" Grid.Column="0" Width="250" Height="35"/>
<ComboBox x:Name="comboBox2" Grid.Column="1" HorizontalAlignment="Center" Grid.Row="1" VerticalAlignment="Center" Width="250" Height="35" SelectionChanged="comboBox2_SelectionChanged"/>
<ComboBox x:Name="comboBox3" Grid.Column="2" HorizontalAlignment="Center" Grid.Row="1" VerticalAlignment="Center" Width="250" Height="35" SelectionChanged="comboBox3_SelectionChanged"/>
<TextBox x:Name="Tb1" Grid.Column="1" PreviewTextInput="textBox_PreviewTextInput" HorizontalAlignment="Center" Grid.Row="5" TextWrapping="Wrap" VerticalAlignment="Center" Width="250" Height="35" TextChanged="Tb1_TextChanged" FontSize="24"/>
<Label Content="Выберите Тип Техники" HorizontalAlignment="Center" Margin="0,82,0,0" VerticalAlignment="Top" FontSize="20" FontWeight="Bold" Grid.RowSpan="2"/>
<Label Grid.Column="1" Content="Выберите Марку Автомобиля" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="20" FontWeight="Bold" Margin="0,82,0,0" Grid.RowSpan="2"/>
<Label Grid.Column="2" Content="Выберите ТО" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransformOrigin="0.474,0.714" FontWeight="Bold" FontSize="20" Margin="112,82,0,0" Grid.RowSpan="2" Width="142" Height="37"/>
<Button x:Name="Bt1" Grid.Column="1" Content="Вычислить" HorizontalAlignment="Left" Margin="307,0,0,0" Grid.Row="5" VerticalAlignment="Center" Height="35" Width="124" Grid.ColumnSpan="2" FontSize="20" Click="Bt1_Click"/>
<TextBox x:Name="Tb2" Grid.Column="1" HorizontalAlignment="Center" Grid.Row="3" IsReadOnly="True" TextWrapping="Wrap" VerticalAlignment="Center" Width="250" Height="35" FontSize="20"/>
</Grid>
</Window> |
|
Вот код C#
| C# | 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VichysleniyeTO
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
comboBox1.Items.Add(new ComboBoxItem() { Content = "Трактора" });
comboBox1.Items.Add(new ComboBoxItem() { Content = "Комбайны" });
comboBox1.Items.Add(new ComboBoxItem() { Content = "Грузовики" });
comboBox1.SelectedItem = comboBox1.Items[0];
comboBox1.SelectedIndex = 0;
comboBox1.SelectionChanged += ComboBox_SelectionChanged;
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
comboBox2.Items.Clear();
comboBox2.Items.Add(new ComboBoxItem() { Content = "МТЗ-80" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "МТЗ-82" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "Т-150К" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "John Deere-7830" });
comboBox2.SelectedItem = comboBox2.Items[0];
comboBox2.SelectedIndex = 0;
}
else if (comboBox1.SelectedIndex == 1)
{
comboBox2.Items.Clear();
comboBox2.Items.Add(new ComboBoxItem() { Content = "Дон-1500Б" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "Acros-530" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "Claas Tucano-500" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "New Holland CX8080" });
comboBox2.SelectedItem = comboBox2.Items[0];
comboBox2.SelectedIndex = 0;
}
else if (comboBox1.SelectedIndex == 2)
{
comboBox2.Items.Clear();
comboBox2.Items.Add(new ComboBoxItem() { Content = "ЗИЛ-130" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "ЗИЛ-131" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "КамАЗ-6520" });
comboBox2.Items.Add(new ComboBoxItem() { Content = "ГАЗ-САЗ-3507" });
comboBox2.SelectedItem = comboBox2.Items[0];
comboBox2.SelectedIndex = 0;
}
comboBox2.SelectionChanged += comboBox2_SelectionChanged;
}
private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(comboBox1.SelectedIndex == 0 & comboBox2.SelectedIndex == 0)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 0 & comboBox2.SelectedIndex == 1)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 0 & comboBox2.SelectedIndex == 2)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 0 & comboBox2.SelectedIndex == 3)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 1 & comboBox2.SelectedIndex == 0)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 1 & comboBox2.SelectedIndex == 1)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 1 & comboBox2.SelectedIndex == 2)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 1 & comboBox2.SelectedIndex == 3)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 2 & comboBox2.SelectedIndex == 0)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 2 & comboBox2.SelectedIndex == 1)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 2 & comboBox2.SelectedIndex == 2)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 2 & comboBox2.SelectedIndex == 3)
{
comboBox3.Items.Clear();
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-1" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-2" });
comboBox3.Items.Add(new ComboBoxItem() { Content = "ТО-3" });
comboBox3.SelectedItem = comboBox3.Items[0];
comboBox3.SelectedIndex = 0;
}
}
private void comboBox3_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Tb1_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void textBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (!Char.IsDigit(e.Text, 0))
{
e.Handled = true;
}
}
private void Bt1_Click(object sender, RoutedEventArgs e)
{
if (comboBox1.SelectedIndex == 0 & comboBox2.SelectedIndex == 0 & comboBox3.SelectedIndex == 0)
{
int MTZ80TO1 = 60;
int znachTb = Convert.ToInt32(Tb1.Text);
znachTb = Int32.Parse(Tb1.Text);
while (MTZ80TO1 < znachTb)
{
MTZ80TO1 += 60;
}
if (MTZ80TO1 == znachTb)
{
Tb2.Text = ("Время проводить ТО-1");
}
}
}
}
} |
|
вот фото проги
0
|