Exemple #1
0
        private void _barcodeBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            _browser.DocumentText = string.Empty;
            _lines = null;

            string barcode = _barcodeBox.Text.Trim();

            if (string.IsNullOrEmpty(barcode))
            {
                return;
            }

            _barcodeBox.Clear();

            try
            {
                string connectionString = CM.AppSettings["connectionString"];
                using (IrbisConnection connection = new IrbisConnection(connectionString))
                {
                    MarcRecord record = connection.SearchReadOneRecord("\"IN={0}\"", barcode);
                    if (ReferenceEquals(record, null))
                    {
                        _browser.DocumentText = "Не найдена книга";
                        _barcodeBox.Focus();
                        return;
                    }

                    string formatted = connection.FormatRecord("@", record.Mfn);
                    _browser.DocumentText = formatted;

                    string firstLine = record.FM(906), secondLine = record.FM(908);
                    if (string.IsNullOrEmpty(firstLine))
                    {
                        _browser.DocumentText = "Не введен систематический шифр (поле 906)";
                        _barcodeBox.Focus();
                        return;
                    }
                    if (string.IsNullOrEmpty(secondLine))
                    {
                        _browser.DocumentText = "Не введен авторский знак (поле 908)";
                        _barcodeBox.Focus();
                        return;
                    }

                    _lines = new[] { firstLine, secondLine };
                }
            }
            catch (Exception exception)
            {
                _browser.DocumentText = exception.ToString();
            }
        }
Exemple #2
0
        public void Search_ReadOneRecord()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            MarcRecord record = connection.SearchReadOneRecord("T=A$");

            Write(record.ToVisibleString().Substring(0, 50));
        }
Exemple #3
0
        private static void Main()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                string connectionString = ConfigurationUtility
                                          .GetString("connectionString")
                                          .ThrowIfNull("connectionString not set");

                int delay = ConfigurationUtility
                            .GetInt32("delay");

                DateTime threshold = DateTime.Today
                                     .AddMonths(-delay);

                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    DatabaseInfo[] databases
                        = connection.ListDatabases();

                    DebtorManager manager
                        = new DebtorManager(connection)
                        {
                        ToDate = threshold
                        };
                    manager.BatchRead += (sender, args) =>
                    {
                        Console.Write(".");
                    };
                    DebtorInfo[] debtors = manager.GetDebtors
                                           (
                        connection.Search("RB=$")
                                           );
                    debtors = debtors.Where
                              (
                        debtor => !debtor.WorkPlace
                        .SafeContains(LibraryName)
                              )
                              .ToArray();
                    Console.WriteLine();
                    Console.WriteLine
                    (
                        "Debtors: {0}",
                        debtors.Length
                    );

                    VisitInfo[] allDebt = debtors.SelectMany
                                          (
                        debtor => debtor.Debt
                                          )
                                          .ToArray();
                    Console.WriteLine
                    (
                        "Books in debt: {0}",
                        allDebt.Length
                    );


                    Workbook workbook = new Workbook();
                    workbook.CreateNewDocument();
                    Worksheet worksheet = workbook.Worksheets[0];

                    int row = 0;

                    worksheet.Cells[row, 0].Value = "ФИО";
                    worksheet.Cells[row, 1].Value = "Билет";
                    worksheet.Cells[row, 2].Value = "Краткое описание";
                    worksheet.Cells[row, 3].Value = "Год";
                    worksheet.Cells[row, 4].Value = "Номер";
                    worksheet.Cells[row, 5].Value = "Цена";
                    worksheet.Cells[row, 6].Value = "Хранение";
                    worksheet.Cells[row, 7].Value = "Дата";
                    worksheet.Cells[row, 8].Value = "Отдел";

                    row++;

                    for (int i = 0; i < allDebt.Length; i++)
                    {
                        if (i % 100 == 0)
                        {
                            Console.Write(".");
                        }

                        VisitInfo debt = allDebt[i];

                        string description = debt.Description;
                        string inventory   = debt.Inventory;
                        string database    = debt.Database;
                        string year        = string.Empty;
                        string index       = debt.Index;
                        string price       = string.Empty;

                        if (!string.IsNullOrEmpty(index) &&
                            !string.IsNullOrEmpty(database))
                        {
                            if (databases.FirstOrDefault
                                (
                                    db => db.Name.SameString(database)
                                )
                                == null)
                            {
                                continue;
                            }

                            try
                            {
                                connection.Database = database;
                                MarcRecord record
                                    = connection.SearchReadOneRecord
                                      (
                                          "\"I={0}\"",
                                          index
                                      );
                                if (!ReferenceEquals(record, null))
                                {
                                    description = connection.FormatRecord
                                                  (
                                        FormatName,
                                        record.Mfn
                                                  );
                                    year  = GetYear(record);
                                    price = GetPrice(debt, record);
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }

                        worksheet.Cells[row, 0].Value = debt.Reader.FullName;
                        worksheet.Cells[row, 1].Value = debt.Reader.Ticket;
                        worksheet.Cells[row, 2].Value = description;
                        worksheet.Cells[row, 3].Value = year;
                        worksheet.Cells[row, 4].Value = inventory;
                        worksheet.Cells[row, 5].Value = price;
                        worksheet.Cells[row, 6].Value = debt.Sigla;
                        worksheet.Cells[row, 7].Value = debt.DateExpectedString;
                        worksheet.Cells[row, 8].Value = debt.Department;

                        for (int j = 0; j <= 6; j++)
                        {
                            Cell cell = worksheet.Cells[row, j];
                            cell.Borders.SetAllBorders
                            (
                                Color.Black,
                                BorderLineStyle.Hair
                            );
                        }

                        row++;
                    }

                    workbook.SaveDocument(OutputFile);

                    Console.WriteLine("All done");

                    stopwatch.Stop();
                    TimeSpan elapsed = stopwatch.Elapsed;
                    Console.WriteLine("Elapsed: {0}", elapsed);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #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();
        }
        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("==========================================");
        }