public QRCodeAnalyser(Action <IList <Barcode>, int, int> listener)
            {
                var options = new BarcodeScannerOptions.Builder()
                              .SetBarcodeFormats(Barcode.FormatQrCode)
                              .Build();

                detector      = BarcodeScanning.GetClient(options);
                this.listener = listener;
            }
        private void scanningFinished( )
        {
            MemoryStream memoryHigh = new MemoryStream();
            MemoryStream memoryLow  = new MemoryStream();

            // rotate image
            scannedImgs.First( ).RotateFlip(RotateFlipType.Rotate90FlipNone);

            // convert to System.Media.Image
            scannedImgs.First( ).Save(memoryHigh, ImageFormat.Bmp);

            // URGENT To do compress to JPEG

            memoryHigh.Position = 0;
            BitmapImage bitmapImage = new BitmapImage();

            bitmapImage.BeginInit( );
            bitmapImage.StreamSource = memoryHigh;
            bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
            bitmapImage.EndInit( );

            ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);

            // Create an Encoder object based on the GUID
            // for the Quality parameter category.
            System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;

            // Create an EncoderParameters object.
            // An EncoderParameters object has an array of EncoderParameter
            // objects. In this case, there is only one
            // EncoderParameter object in the array.
            EncoderParameters myEncoderParameters = new EncoderParameters(1);


            EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);

            myEncoderParameters.Param[0] = myEncoderParameter;

            Bitmap bit = new Bitmap(bitmapImage.StreamSource);

            bit.Save(memoryLow, jgpEncoder, myEncoderParameters);

            imgHolder.Source = bitmapImage;

            ArrayList barcodes;

            System.Drawing.Bitmap bmp = new Bitmap(scannedImgs.First());
            barcodes = BarcodeScanning.ScanImgForBarcode(bmp);
            Championship Championship;
            AEvent       Event;

            if (barcodes.Count == 1)
            {
                // successfully found a barcode
                // MessageBox.Show("Barcode found" + barcodes[0].ToString());


                if (parseBarcode(barcodes[0].ToString( ), out Championship, out Event))
                {
                    file = new FileStorage(
                        Event.ShortName + " Result Card",
                        "bmp",
                        memoryLow.ToArray( ));

                    //if (Event.Files == null)
                    //    Event.Files = new List<FileStorage>();

                    Event.AddFile(file);



                    //SaveChanges();
                    //MainWindow.SQLiteSubmit();
                    //MainWindow.Context.SaveChanges();

                    MessageBox.Show("Result card for " + Event.Name + " has been successfully stored");
                }
                else
                {
                    MessageBox.Show("Sorry, I could not understand the barcode on this sheet.\nPlease select an even from the next screen.");

                    SelectEvent se = new SelectEvent();

                    //se.cbxSelectEvent.ItemsSource = MainWindow.CurrentChampionship.listAllEvents();
                    se.cbxSelectEvent.ItemsSource = ((App)Application.Current).CurrentChampionship.Championship.Events;

                    if (se.ShowDialog( ) == true)
                    {
                        Event = se.SelectedEvent;

                        if (Event != null)
                        {
                            file = new FileStorage(
                                Event.ShortName + " Result Card",
                                "bmp",
                                memoryHigh.ToArray( ));

                            Event.AddFile(file);

                            //SaveChanges();
                            MessageBox.Show("Result card for " + Event.Name + " has been successfully stored");
                        }
                        else
                        {
                            MessageBox.Show("This scan has not been saved!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("This scan has not been saved!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Two Barcodes were detected, please select an event from the next screen.");
                SelectEvent se = new SelectEvent();

                //se.cbxSelectEvent.ItemsSource = MainWindow.CurrentChampionship.listAllEvents();
                se.cbxSelectEvent.ItemsSource = ((App)Application.Current).CurrentChampionship.Events;

                if (se.ShowDialog( ) == true)
                {
                    Event = se.SelectedEvent;

                    if (Event != null)
                    {
                        //if (Event.Files == null)
                        //    Event.Files = new List<FileStorage>();

                        Event.AddFile(file);

                        //MainWindow.SQLiteSubmit();
                        //SaveChanges();
                        MessageBox.Show("Result card for " + Event.Name + " has been successfully stored");
                    }
                    else
                    {
                        MessageBox.Show("This scan has not been saved!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("This scan has not been saved!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #3
0
        private void BarcodeScanPort_SecurityBadgeScanReceived(BarcodeScanning.Barcode barcode)
        {
            int systemUserId = Convert.ToInt32(barcode.ID);

            if (this.m_User.UserId == systemUserId)
            {
                this.m_User = YellowstonePathology.Business.User.SystemUserCollectionInstance.Instance.SystemUserCollection.GetSystemUserByUserName(System.Windows.Forms.SystemInformation.UserName);
            }
            else
            {
                this.m_User = YellowstonePathology.Business.User.SystemUserCollectionInstance.Instance.SystemUserCollection.GetSystemUserById(systemUserId);
            }

            this.NotifyPropertyChanged("User");
        }