@@ -64,14 +64,21 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
64
64
Foreground = new SolidColorBrush ( Colors . White )
65
65
} ) ;
66
66
67
- foreach ( var item in selectedItems )
67
+ var sortedItems = selectedItems
68
+ . Select ( ( value , index ) => new { value , originalIndex = index + 1 } )
69
+ . OrderBy ( item => weights . IndexOf ( item . value . Weight ) )
70
+ . ToList ( ) ;
71
+
72
+ foreach ( var item in sortedItems )
68
73
{
69
- ResultTextBlock . Inlines . Add ( new Run ( "Waga: " )
74
+ int itemNumber = weights . IndexOf ( item . value . Weight ) + 1 ;
75
+
76
+ ResultTextBlock . Inlines . Add ( new Run ( $ "Przedmiot { itemNumber } - Waga: ")
70
77
{
71
78
Foreground = new SolidColorBrush ( Colors . White )
72
79
} ) ;
73
80
74
- ResultTextBlock . Inlines . Add ( new Run ( item . Weight . ToString ( ) )
81
+ ResultTextBlock . Inlines . Add ( new Run ( item . value . Weight . ToString ( ) )
75
82
{
76
83
Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E6A8D7" ) )
77
84
} ) ;
@@ -81,7 +88,7 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
81
88
Foreground = new SolidColorBrush ( Colors . White )
82
89
} ) ;
83
90
84
- ResultTextBlock . Inlines . Add ( new Run ( item . Value . ToString ( ) )
91
+ ResultTextBlock . Inlines . Add ( new Run ( item . value . Value . ToString ( ) )
85
92
{
86
93
Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#ADD8E6" ) )
87
94
} ) ;
@@ -175,5 +182,36 @@ private void InputsChanged(object sender, TextChangedEventArgs e)
175
182
{
176
183
SolveButton . IsEnabled = ValidateInputs ( out _ , out _ , out _ ) ;
177
184
}
185
+ private void GenerateSampleDataButton_Click ( object sender , RoutedEventArgs e )
186
+ {
187
+ Random random = new Random ( ) ;
188
+
189
+ int capacity = random . Next ( 10 , 101 ) ;
190
+ CapacityTextBox . Text = capacity . ToString ( ) ;
191
+
192
+ int itemCount = random . Next ( 3 , 8 ) ;
193
+ List < int > weights = new List < int > ( ) ;
194
+ List < int > values = new List < int > ( ) ;
195
+
196
+ for ( int i = 0 ; i < itemCount ; i ++ )
197
+ {
198
+ weights . Add ( random . Next ( 1 , capacity / 2 ) ) ;
199
+ values . Add ( random . Next ( 10 , 101 ) ) ;
200
+ }
201
+
202
+ WeightsTextBox . Text = string . Join ( ", " , weights ) ;
203
+ ValuesTextBox . Text = string . Join ( ", " , values ) ;
204
+
205
+ CapacityTextBox . BorderBrush = Brushes . Black ;
206
+ CapacityTextBox . BorderThickness = new Thickness ( 1 ) ;
207
+
208
+ WeightsTextBox . BorderBrush = Brushes . Black ;
209
+ WeightsTextBox . BorderThickness = new Thickness ( 1 ) ;
210
+
211
+ ValuesTextBox . BorderBrush = Brushes . Black ;
212
+ ValuesTextBox . BorderThickness = new Thickness ( 1 ) ;
213
+
214
+ SolveButton . IsEnabled = ValidateInputs ( out _ , out _ , out _ ) ;
215
+ }
178
216
}
179
217
}
0 commit comments