Example #1
0
        /// <summary>
        /// Поиск записей согласно спецификации.
        /// </summary>
        public List <IrbisRecord> SearchRecords
        (
            SelectionQuery query
        )
        {
            if (ReferenceEquals(query, null))
            {
                throw new ArgumentNullException("query");
            }
            if (!query.IsValid())
            {
                throw new ArgumentOutOfRangeException("query");
            }

            NumberRangeCollection ranges = null;

            if ((query.SelectionType == SelectionType.Mfn) ||
                (query.SelectionType == SelectionType.Sequential))
            {
                ranges = NumberRangeCollection.Parse(query.Statement);
            }

            Dictionary <int, IrbisRecord> result
                = new Dictionary <int, IrbisRecord>();

            bool databaseChanged = false;

            if (!string.IsNullOrEmpty(query.Database))
            {
                Client.PushDatabase(query.Database);
                databaseChanged = true;
            }

            _maxMfn = Client.GetMaxMfn();

            switch (query.SelectionType)
            {
            case SelectionType.Mfn:
                _SearchByMfn
                (
                    result,
                    ranges
                );
                break;

            case SelectionType.Sequential:
                _SearchBySequential
                (
                    result,
                    query.Prefix,
                    ranges
                );
                break;

            case SelectionType.Dictionary:
                _SearchByDictionary
                (
                    result,
                    query.Prefix,
                    ranges
                );
                break;

            case SelectionType.Search:
                _SearchByQuery
                (
                    result,
                    query.Statement
                );
                break;

            case SelectionType.Deep:
                _SearchByDeep
                (
                    result,
                    query.Prefix,
                    query.Statement
                );
                break;
            }

            if (databaseChanged)
            {
                Client.PopDatabase();
            }

            Output.WriteLine
            (
                "Total found={0}",
                result.Count
            );

            return(result.Values.ToList());
        }
Example #2
0
        private void GoButton_Click(object sender, RoutedEventArgs e)
        {
            _index     = IndexBox.Text.Trim();
            _year      = YearBox.Text.Trim();
            _issues    = IssueBox.Text.Trim();
            _month     = MonthBox.Text.Trim();
            _number    = NumberBox.Text.Trim();
            _inventory = InventoryBox.Text.Trim();
            _fond      = FondBox.Text.Trim();
            _complect  = ComplectBox.Text.Trim();
            if (string.IsNullOrEmpty(_index) ||
                string.IsNullOrEmpty(_year) ||
                string.IsNullOrEmpty(_issues) ||
                string.IsNullOrEmpty(_month) ||
                string.IsNullOrEmpty(_number) ||
                string.IsNullOrEmpty(_inventory) ||
                string.IsNullOrEmpty(_fond) ||
                string.IsNullOrEmpty(_complect))
            {
                WriteLog("Empty data");
                return;
            }

            var collection = NumberRangeCollection.Parse(_issues);

            _description = $"Подшивка N{_number} {_month} ({_issues})";
            _reference   = $"{_index}/{_year}/{_description}";

            string connectionString = CM.AppSettings["connectionString"];

            using (_connection = new IrbisConnection(connectionString))
            {
                WriteLog("Connected");

                _mainRecord = _connection.SearchReadOneRecord("\"I={0}\"", _index);
                if (_mainRecord == null)
                {
                    WriteLog("Main record not found");
                    return;
                }

                MagazineInfo magazine = MagazineInfo.Parse(_mainRecord);
                WriteLog("Main: {0}", magazine.ExtendedTitle);

                foreach (NumberText number in collection)
                {
                    MarcRecord issue = new MarcRecord
                    {
                        Database = _connection.Database
                    };

                    string issueIndex = $"{_index}/{_year}/{number}";
                    issue
                    .AddField(933, _index)
                    .AddField(903, issueIndex)
                    .AddField(934, _year)
                    .AddField(936, number)
                    .AddField(920, "NJP")
                    .AddField
                    (
                        new RecordField(910)
                        .AddSubField('a', "0")
                        .AddSubField('b', _complect)
                        .AddSubField('c', "?")
                        .AddSubField('d', _fond)
                        .AddSubField('p', _reference)
                        .AddSubField('i', _inventory)
                    )
                    .AddField
                    (
                        new RecordField(463)
                        .AddSubField('w', _reference)
                    );

                    _connection.WriteRecord(issue);
                    WriteLog("Issue record created: N={0}, MFN={1}", number, issue.Mfn);
                }

                MarcRecord binding = new MarcRecord
                {
                    Database = _connection.Database
                };
                binding
                .AddField(933, _index)
                .AddField(903, _reference)
                .AddField(904, _year)
                .AddField(936, _description)
                .AddField(931, _issues)
                .AddField(920, "NJK")
                .AddField
                (
                    new RecordField(910)
                    .AddSubField('a', "0")
                    .AddSubField('b', _inventory)
                    .AddSubField('c', "?")
                    .AddSubField('d', _fond)
                );

                _connection.WriteRecord(binding);
                WriteLog("Binding record created: MFN={0}", binding.Mfn);

                _mainRecord.AddField
                (
                    new RecordField(909)
                    .AddSubField('q', _year)
                    .AddSubField('d', _fond)
                    .AddSubField('k', _complect)
                    .AddSubField('h', _issues)
                );
                _connection.WriteRecord(_mainRecord);
                WriteLog("Cumulation updated");
            }

            WriteLog("Disconnected");
            WriteLog("==========================================");
        }