Example #1
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(SearchField))
            {
                MessageBox.Show("Není vybrána položka pro vyhledání záznamu.", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (String.IsNullOrWhiteSpace(SearchValue))
            {
                MessageBox.Show(String.Format("Není zadána hodnota pro {0}.", this.SearchFieldComboBox.Text), this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            try
            {
                this.Cursor = Cursors.Wait;
                this.SearchButton.IsEnabled = false;

                Report report = null;
                string barcode = null;

                switch (SearchField)
                {
                    case "barcode":
                        barcode = SearchValue;
                        report = DozpController.SearchBook(Settings.Default.SelectedCatalogueID, barcode: SearchValue);
                        break;
                    case "sysno":
                        report = DozpController.SearchBook(Settings.Default.SelectedCatalogueID, sysno: SearchValue);
                        break;
                    case "isbn":
                        report = DozpController.SearchBook(Settings.Default.SelectedCatalogueID, isbn: SearchValue);
                        break;
                    default:
                        break;
                }

                //nacteni MARC zaznamu z katalogu
                if (report != null)
                {
                    if (report.Success)
                    {
                        Marc21Records records = new Marc21Records(report.XmlData);

                        if (records == null || records.Count == 0)
                        {
                            MessageBox.Show("Publikace nebyla nalezena, zkuste vyhledat podle jiného parametru (SYSNO, ISBN).", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }
                        else if (records.Count == 1)
                        {
                            Marc21Record record = (records[0] as Marc21Record);
                            string[] isbns = record.FindAll(Marc21Tag.TAG_DF_InternationalStandardBookNumber, Marc21Tag.CODE_InternationalStandardBookNumber);

                            //kontrola existence publikace - UPRAVA DATABAZY - UniqueKey
                            Books = DozpController.GetBooks(Settings.Default.SelectedCatalogueID, record.RecordIdentifier);

                            if (isbns != null && isbns.Count() <= 1)
                            {
                                if (isbns.Count() == 0)
                                    NewBook = GetBookByISBN(null);
                                else if (isbns.Count() == 1)
                                    NewBook = GetBookByISBN(isbns[0]);
                            }

                            if (NewBook == null)
                            {
                                NewBook = new Book();
                                NewBook.CatalogueID = Settings.Default.SelectedCatalogueID;
                                NewBook.SysNo = record.RecordIdentifier;
                                NewBook.ISBN = GetNormalizedISN(record.Find(Marc21Tag.TAG_DF_InternationalStandardBookNumber, Marc21Tag.CODE_InternationalStandardBookNumber));
                                NewBook.ISSN = GetNormalizedISN(record.Find(Marc21Tag.TAG_DF_InternationalStandardSerialNumber, Marc21Tag.CODE_InternationalStandardSerialNumber));
                                NewBook.NBN = GetFirstOrDefaultCNB(record.FindAll(Marc21Tag.TAG_DF_NationalBibliographyNumber, Marc21Tag.CODE_NationalBibliographyNumber));
                                NewBook.OCLC = GetFirstOrDefaultOCLC(record.FindAll(Marc21Tag.TAG_DF_SystemControlNumber, Marc21Tag.CODE_SystemControlNumber));
                                NewBook.Author = record.Author.TrimEnd(' ', ',');
                                NewBook.Title = record.Title.TrimEnd(' ', ',', ':', '/', '=');
                                NewBook.Year = record.DateOfPublication.TrimStart('c').TrimEnd(' ', '-');
                                NewBook.Volume = record.NumberOfPart.TrimEnd(' ', ',');
                                NewBook.Barcode = barcode;
                            }
                            else
                            {
                                if (NewBook.IsExported())
                                {
                                    MessageBox.Show(String.Format("Publikace SYSNO: {0} [ISBN {1}] byla již exportována do ALEPHu, nelze skenovat!", NewBook.SysNo, NewBook.ISBN), this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                                    return;
                                }
                                else
                                {
                                    if (MessageBox.Show(String.Format("Publikace SYSNO: {0} [ISBN {1}] byla již skenována, chcete pokračovat?", NewBook.SysNo, NewBook.ISBN), this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                                        return;
                                }
                            }

                            //vicesvazkove dila
                            if (isbns != null && isbns.Count() > 1)
                            {
                                this.SearchFieldComboBox.IsReadOnly = true;
                                this.SearchValueTextBox.IsReadOnly = true;

                                //ISBN
                                this.IsbnLabel.Visibility = Visibility.Visible;
                                this.IsbnComboBox.Visibility = Visibility.Visible;
                                foreach (var isbn in isbns)
                                {
                                    Book book = GetBookByISBN(isbn);
                                    string volume = Regex.Match(isbn, @"\(([^)]*)\)").Groups[1].Value;

                                    if (book != null)
                                        volume = book.Volume;
                                    else if (!String.IsNullOrEmpty(NewBook.Volume))
                                        volume = NewBook.Volume;

                                    ComboBoxItem item = new ComboBoxItem();
                                    item.Content = isbn;
                                    item.Foreground = (book != null ? Brushes.Red : Brushes.Black);
                                    item.Tag = volume;
                                    this.IsbnComboBox.Items.Add(item);
                                }

                                //Díl, svazek
                                this.VolumeLabel.Visibility = Visibility.Visible;
                                this.ContentsLabel.Visibility = Visibility.Visible;
                                this.VolumeTextBox.Visibility = Visibility.Visible;

                                this.IsbnComboBox.SelectedIndex = 0;
                                this.SearchButton.Visibility = Visibility.Collapsed;
                                this.OkButton.Visibility = Visibility.Visible;

                                return;
                            }

                            this.DialogResult = true;
                        }
                        else
                        {
                            MessageBox.Show(String.Format("Nalezeno bylo {0} publikací, čárový kód není jedinečný.", records.Count), this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Chyba při vyhledání publikace: {0}", report.Errors), this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        this.DialogResult = false;
                    }
                }
                else
                {
                    MessageBox.Show("Žádná odpověd při vyhledání publikace.", this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    this.DialogResult = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                this.DialogResult = false;
            }
            finally
            {
                this.SearchButton.IsEnabled = true;
                this.Cursor = null;
            }
        }
Example #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.Cursor = Cursors.Wait;

            try
            {
                Report report = DozpController.SearchBook(Settings.Default.SelectedCatalogueID, sysno: this.NewBook.SysNo);

                if (report != null)
                {
                    if (report.Success)
                    {
                        Marc21Records records = new Marc21Records(report.XmlData);

                        if (records == null || records.Count == 0)
                        {
                            this.MarcRecordTextBox.Text = "Nebyla nalezená žádná publikace.";
                        }
                        else if (records.Count == 1)
                        {
                            Marc21Record record = (records[0] as Marc21Record);
                            this.MarcRecordTextBox.Text = record.ToString();
                        }
                        else
                        {
                            this.MarcRecordTextBox.Text = String.Format("Nalezeno bylo {0} publikací, SysNo není jedinečné.", records.Count);
                        }
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Chyba při vyhledání publikace: {0}", report.Errors), this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        this.DialogResult = false;
                    }
                }
                else
                {
                    MessageBox.Show("Žádná odpověd při vyhledání publikace.", this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    this.DialogResult = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                this.DialogResult = false;
            }
            finally
            {
                this.Cursor = null;
            }
        }