using System.Windows; using System.Windows.Input; namespace Lab8 { public partial class MainWindow : Window { private readonly BusQueueManager _manager = new BusQueueManager(); private readonly List _commandHistory = new List(); private int _historyIndex = 0; public MainWindow() { InitializeComponent(); } private void ExecuteButton_Click(object sender, RoutedEventArgs e) { ExecuteCurrentCommand(); } private void CommandTextBox_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { ExecuteCurrentCommand(); e.Handled = true; return; } if (e.Key == Key.Up) { ShowPreviousCommand(); e.Handled = true; return; } if (e.Key == Key.Down) { ShowNextCommand(); e.Handled = true; } } private void ExecuteCurrentCommand() { string command = CommandTextBox.Text?.Trim() ?? string.Empty; ErrorTextBlock.Text = string.Empty; if (string.IsNullOrWhiteSpace(command)) { ErrorTextBlock.Text = "Команда не введена."; CommandTextBox.Focus(); return; } _commandHistory.Add(command); _historyIndex = _commandHistory.Count; string result = _manager.ExecuteCommand(command); if (result.StartsWith("Ошибка:")) { ErrorTextBlock.Text = result; } else { HistoryListBox.Items.Add($"> {command}"); HistoryListBox.Items.Add(result); } UpdateQueueView(); CommandTextBox.Clear(); CommandTextBox.Focus(); } private void ShowPreviousCommand() { if (_commandHistory.Count == 0) return; if (_historyIndex > 0) _historyIndex--; CommandTextBox.Text = _commandHistory[_historyIndex]; CommandTextBox.CaretIndex = CommandTextBox.Text.Length; } private void ShowNextCommand() { if (_commandHistory.Count == 0) return; if (_historyIndex < _commandHistory.Count - 1) { _historyIndex++; CommandTextBox.Text = _commandHistory[_historyIndex]; } else { _historyIndex = _commandHistory.Count; CommandTextBox.Clear(); } CommandTextBox.CaretIndex = CommandTextBox.Text.Length; } private void UpdateQueueView() { QueueListBox.Items.Clear(); foreach (string passenger in _manager.Passengers) { QueueListBox.Items.Add(passenger); } } } }