diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index f7028b1..c36a786 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -10,6 +10,10 @@ using System.IO; using ZXing.Common; // Para DecodingOptions y otros using ZXing.Windows.Compatibility; using BarcodeReader = ZXing.OpenCV.BarcodeReader; // Asegúrate de añadir este using +using System.Media; +using System.Windows.Controls; +using Brushes = System.Windows.Media.Brushes; + namespace QRReaderFromAndroid { @@ -22,6 +26,8 @@ namespace QRReaderFromAndroid private BarcodeReader _reader; private HashSet _scannedBarcodes = new HashSet(); private const string FilePath = "scanned_barcodes.txt"; + private SoundPlayer _soundPlayer = new SoundPlayer("D:\\Proyectos\\VisualStudio\\QRReaderFromAndroid\\store-scanner-beep-90395.wav"); // Configura la ruta al archivo de sonido + public MainWindow() { @@ -61,21 +67,46 @@ namespace QRReaderFromAndroid { var bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(frame); var result = ScanBarcode(bitmap); - if (result != null && result.Text.Length == 13 && _scannedBarcodes.Add(result.Text)) + if (result != null && result.Text.Length == 13) { // Actualizar UI de forma segura + barcodeText.Text = $"Scanned: {result.Text}"; Dispatcher.Invoke(() => { - barcodeList.Items.Add(result.Text); - barcodeText.Text = $"Scanned: {result.Text}"; - }); - SaveBarcode(result.Text); + if (!_scannedBarcodes.Contains(result.Text)) + { + _scannedBarcodes.Add(result.Text); + AddBarcodeToList(result.Text); + SaveBarcode(result.Text); + _soundPlayer.Play(); + } + else + { + SelectBarcodeInList(result.Text); + //_soundPlayer.Play(); + } + }); } cameraImage.Source = BitmapToImageSource(bitmap); } } } + private void AddBarcodeToList(string barcode) + { + barcodeList.Items.Add(barcode); + } + + private void SelectBarcodeInList(string barcode) + { + int index = barcodeList.Items.IndexOf(barcode); + if (index != -1) + { + barcodeList.SelectedIndex = index; + barcodeList.ScrollIntoView(barcodeList.SelectedItem); // Asegura que el ítem seleccionado sea visible + } + } + private void LoadScannedBarcodes() { if (File.Exists(FilePath)) diff --git a/store-scanner-beep-90395.mp3 b/store-scanner-beep-90395.mp3 new file mode 100644 index 0000000..ac50b9c Binary files /dev/null and b/store-scanner-beep-90395.mp3 differ diff --git a/store-scanner-beep-90395.wav b/store-scanner-beep-90395.wav new file mode 100644 index 0000000..38bd324 Binary files /dev/null and b/store-scanner-beep-90395.wav differ