Exemplo n.º 1
0
        public void DeleteRecord_Delete()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            MarcRecord record = _GetRecord();

            record = connection.WriteRecord(record);
            int mfn = record.Mfn;

            Write("MFN={0}: ", mfn);
            Write("created | ");

            connection.DeleteRecord(mfn);
            Write("deleted");
        }
Exemplo n.º 2
0
        private static void DoFormat
        (
            object arg
        )
        {
            try
            {
                RecordTask taskInfo = (RecordTask)arg;
                using (IrbisConnection client = new IrbisConnection())
                {
                    client.ParseConnectionString(ConnectionString);
                    client.Connect();

                    MarcRecord targetRecord = Fst.Execute
                                              (
                        client,
                        taskInfo.Record
                                              );
                    if (targetRecord != null)
                    {
                        targetRecord.SetSubField(463, 'w', taskInfo.CurrentIssue);
                        targetRecord.SetSubField(463, 'c', taskInfo.Magazine.Title);

                        lock (SyncRoot)
                        {
                            RecordCount++;
                            //Buffer.Append(targetRecord);
                            client.WriteRecord(targetRecord, false, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogLine("EXCEPTION: {0}", ex);
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                Threshold = new DateTime(DateTime.Today.Year, 1, 1);

                string thresholdString = CM.AppSettings["threshold"];

                if (!string.IsNullOrEmpty(thresholdString))
                {
                    Threshold = DateTime.Parse(thresholdString);
                }

                TailDb = CM.AppSettings["tail-db"];

                int total   = 0;
                int cropped = 0;

                string connectionString = CM.AppSettings["connection-string"];
                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    int[] mfns = connection.Search
                                 (
                        "RI=$"
                                 );

                    const int delta = 1000;

                    for (int i = 0; i < mfns.Length; i += delta)
                    {
                        int[] sub = mfns
                                    .Skip(i)
                                    .Take(delta)
                                    .ToArray();

                        MarcRecord[] records = connection.ReadRecords
                                               (
                            connection.Database,
                            sub
                                               );

                        foreach (MarcRecord record in records)
                        {
                            if (record.Deleted)
                            {
                                continue;
                            }

                            total++;

                            Console.WriteLine("ELAPSED: {0}", FormatSpan(stopwatch.Elapsed));
                            ReaderInfo reader = ReaderInfo.Parse(record);
                            Console.WriteLine(reader);

                            VisitInfo[] visits = record
                                                 .Fields
                                                 .GetField(40)
                                                 .Select(VisitInfo.Parse)
                                                 .Where(loan => loan.IsVisit ||
                                                        loan.IsReturned)
                                                 .ToArray();

                            VisitInfo[] old = visits
                                              .Where(visit => visit.DateGiven < Threshold)
                                              .ToArray();

                            Console.WriteLine("VISITS TOTAL:     {0}", visits.Length);
                            Console.WriteLine("VISITS TO DELETE: {0}", old.Length);

                            if (old.Length != 0)
                            {
                                if (!string.IsNullOrEmpty(TailDb))
                                {
                                    connection.PushDatabase(TailDb);
                                    int[] tailMfns = new int[0];
                                    try
                                    {
                                        tailMfns = connection.Search("\"RI={0}\"", reader.Ticket);
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine(ex);
                                    }
                                    MarcRecord copy;
                                    if (tailMfns.Length != 0)
                                    {
                                        copy = connection.ReadRecord(tailMfns[0]);
                                        Console.WriteLine("USING OLD RECORD {0}", tailMfns[0]);
                                    }
                                    else
                                    {
                                        copy = new MarcRecord();
                                        RecordField[] non40 = record
                                                              .Fields
                                                              .Where(field => field.Tag != 40)
                                                              .ToArray();
                                        copy.Fields.AddRange(non40);
                                        Console.WriteLine("COPY CREATED");
                                    }

                                    RecordField[] old40 = old.Select(loan => loan.Field).ToArray();
                                    copy.Fields.AddRange(old40);

                                    try
                                    {
                                        connection.WriteRecord(copy, false, true);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("CAN'T WRITE COPY, SKIP");
                                        Debug.WriteLine(ex);
                                        continue;
                                    }
                                    finally
                                    {
                                        connection.PopDatabase();
                                    }

                                    Console.WriteLine("COPY WRITTEN");
                                }

                                MarcRecord r2;
                                try
                                {
                                    r2 = connection.ReadRecord(record.Mfn);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("CAN'T REREAD RECORD, SKIP");
                                    Debug.WriteLine(ex);
                                    continue;
                                }

                                RecordField[] toDelete = r2
                                                         .Fields
                                                         .GetField(40)
                                                         .Select(VisitInfo.Parse)
                                                         .Where(loan => loan.IsVisit || loan.IsReturned)
                                                         .Where(visit => visit.DateGiven < Threshold)
                                                         .Select(visit => visit.Field)
                                                         .ToArray();

                                foreach (RecordField field in toDelete)
                                {
                                    r2.Fields.Remove(field);
                                }

                                try
                                {
                                    connection.WriteRecord(r2, false, true);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("CAN'T WRITE MODIFIED RECORD, SKIP");
                                    Debug.WriteLine(ex);
                                    continue;
                                }

                                Console.WriteLine("RECORD WRITTEN");

                                cropped++;
                            }

                            Console.WriteLine(new string('=', 60));
                        }
                    }
                }

                stopwatch.Stop();

                Console.WriteLine("TOTAL={0}", total);
                Console.WriteLine("CROPPED={0}", cropped);
                Console.WriteLine("ELAPSED={0}", FormatSpan(stopwatch.Elapsed));
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 4
0
        private static void ProcessRecord
        (
            int mfn
        )
        {
            connection.Database = MainDatabase;
            MarcRecord mainRecord = connection.ReadRecord(mfn);
            string     linkValue  = mainRecord.FM(LinkTag);

            connection.Database = BackupDatabase;
            MarcRecord backupRecord = connection.SearchReadOneRecord
                                      (
                "\"{0}{1}\"",
                LinkPrefix,
                linkValue
                                      );

            if (ReferenceEquals(backupRecord, null))
            {
                Console.WriteLine
                (
                    "Не нашлось парной записи для MFN={0} ({1}{2})",
                    mfn,
                    LinkPrefix,
                    linkValue
                );
                Console.WriteLine(new string('=', 70));
                return;
            }

            Console.WriteLine("MFN={0}", mfn);
            RevisionInfo[] revisions = RevisionInfo.Parse(mainRecord)
                                       .Where(rev => rev.Name != "avd")
                                       .ToArray();
            if (revisions.Length == 0)
            {
                Console.WriteLine("Запись без ревизий!");
                Console.WriteLine(new string('=', 70));
                return;
            }

            RevisionInfo lastRevision = revisions.Last();
            DateTime     lastEdit     = IrbisDate.ConvertStringToDate(lastRevision.Date);

            Console.WriteLine
            (
                "Последнее редактирование: {0} {1:d}",
                lastRevision.Name,
                lastEdit
            );
            if (lastEdit > ThresholdDate)
            {
                Console.WriteLine("Запись редактировалась, надо восстанавливать вручную");
                Console.WriteLine(new string('=', 70));
                return;
            }

            if (CompareRecords(mainRecord, backupRecord))
            {
                Console.WriteLine("Нет различий между MAIN и BACKUP");
                goto DONE;
            }

            if (DoRestore)
            {
                RecordField[] residuaryFields = mainRecord.Fields
                                                .Where(field => field.Tag.OneOf(ResiduaryTags))
                                                .Select(field => field.Clone())
                                                .ToArray();
                RecordField[] backupFields = backupRecord.Fields
                                             .Where(field => !field.Tag.OneOf(ResiduaryTags))
                                             .Select(field => field.Clone())
                                             .ToArray();
                mainRecord.Fields.Clear();
                mainRecord.Fields.AddRange(backupFields);
                mainRecord.Fields.AddRange(residuaryFields);
                Console.WriteLine
                (
                    "Сформирована новая версия записи: {0} новых и {1} старых полей",
                    residuaryFields.Length,
                    backupFields.Length
                );
                connection.WriteRecord(mainRecord);
            }

DONE:
            Console.WriteLine(new string('=', 70));
            Console.WriteLine();
        }
Exemplo n.º 5
0
        private void _bindButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            _resultBox.Clear();

            string ticket = _ticketBox.Text.Trim();

            if (string.IsNullOrEmpty(ticket))
            {
                _resultBox.Text = Environment.NewLine
                                  + Resources.MainForm_NoIogunbTicket;
                _ticketBox.Focus();

                return;
            }
            string login   = _loginBox.Text.Trim();
            string pasword = _passwordBox.Text.Trim();

            if (string.IsNullOrEmpty(login)
                != string.IsNullOrEmpty(pasword))
            {
                _resultBox.Text = Environment.NewLine
                                  + Resources.MainForm_BothLoginAndPasswordRequired;
                _loginBox.Focus();

                return;
            }

            using (IrbisConnection connection = GetConnection())
            {
                string expression = string.Format
                                    (
                    "\"RI={0}\"",
                    ticket
                                    );
                int[] found = connection.Search(expression);
                if (found.Length == 0)
                {
                    _resultBox.Text = Environment.NewLine
                                      + Resources.MainForm_NoReaderFound;
                    _ticketBox.Focus();

                    return;
                }
                if (found.Length != 1)
                {
                    _resultBox.Text = Environment.NewLine
                                      + Resources.MainForm_ManyReadersFound;
                    _ticketBox.Focus();

                    return;
                }

                MarcRecord record = connection.ReadRecord(found[0]);
                record.Modified = false;
                RecordField litresField = record.Fields
                                          .GetFirstField(_litresTag);
                if (ReferenceEquals(litresField, null))
                {
                    if (!string.IsNullOrEmpty(login))
                    {
                        litresField = new RecordField(_litresTag)
                                      .AddSubField('a', login)
                                      .AddSubField('b', pasword);
                        record.Fields.Add(litresField);
                    }
                    else
                    {
                        MessageBox.Show
                        (
                            Resources.MainForm_NothingToDo,
                            Resources.MainForm_QuestionTitle,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );
                    }
                }
                else
                {
                    if (_AskForRewrite())
                    {
                        if (string.IsNullOrEmpty(login))
                        {
                            litresField.RemoveSubField('a');
                        }
                        else
                        {
                            litresField.SetSubField('a', login);
                        }
                        if (string.IsNullOrEmpty(pasword))
                        {
                            litresField.RemoveSubField('b');
                        }
                        else
                        {
                            litresField.SetSubField('b', pasword);
                        }
                    }
                }

                if (record.Modified)
                {
                    connection.WriteRecord(record);
                    _resultBox.Text = Environment.NewLine
                                      + Resources.MainForm_DataWasCommited;
                }

                _ticketBox.Clear();
                _loginBox.Clear();
                _passwordBox.Clear();
                _ticketBox.Focus();
            }
        }
Exemplo n.º 6
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("==========================================");
        }
Exemplo n.º 7
0
        private void _okButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            if (_currentRecord == null ||
                _currentExemplar == null)
            {
                XtraMessageBox.Show
                (
                    "Невозможно подтвердить книгу"
                );
                return;
            }

            RecordField field = _currentExemplar.Field;

            if (field == null)
            {
                return;
            }
            field.SetSubField('!', CurrentFond);
            field.SetSubField('s', CurrentDate);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            _client.WriteRecord
            (
                _currentRecord,
                false,
                true
            );
            stopwatch.Stop();
            _logBox.Output.WriteLine
            (
                "Подтвержден номер {0}: {1} ({2})",
                _currentExemplar.Number,
                _currentRecord.UserData,
                stopwatch.Elapsed
            );

            BookInfo book = new BookInfo
            {
                Number      = _currentExemplar.Number,
                Description = (string)_currentRecord.UserData
            };

            ConfirmedBooks.Add(book);
            _counterLabel.Text = string.Format
                                 (
                "Подтверждено: {0}",
                ConfirmedBooks.Count
                                 );

            _SetHtml(string.Empty);

            _currentRecord   = null;
            _currentExemplar = null;

            if (_numberBox.Enabled)
            {
                _numberBox.Focus();
            }
        }