Exemple #1
0
        static void AnalyzeCategories
        (
            int year,
            int month
        )
        {
            string expression = string.Format
                                (
                CultureInfo.InvariantCulture,
                "RD={0:0000}{1:00}$",
                year,
                month
                                );

            int[]             found   = connection.Search(expression);
            List <MarcRecord> records = new BatchRecordReader
                                        (
                connection,
                connection.Database,
                500,
                true,
                found
                                        )
                                        .ReadAll(true);

            ReaderInfo[] readers = records.Select(ReaderInfo.Parse).ToArray();
            DictionaryCounterInt32 <string> counter = new DictionaryCounterInt32 <string>();

            foreach (ReaderInfo reader in readers)
            {
                string category = reader.Category;
                if (!string.IsNullOrEmpty(category))
                {
                    counter.Increment(category);
                }
            }

            CultureInfo        culture = CultureInfo.CurrentCulture;
            DateTimeFormatInfo format  = culture.DateTimeFormat;

            Console.Write("{0} {1}", format.GetAbbreviatedMonthName(month), year);
            foreach (string category in knownCategories)
            {
                Console.Write("\t{0}", counter.GetValue(category));
            }
            int others = 0;

            foreach (string key in counter.Keys)
            {
                if (!knownCategories.Contains(key))
                {
                    int value = counter[key];
                    others += value;
                }
            }

            Console.WriteLine("\t{0}", others);
        }
Exemple #2
0
        //[TestMethod]
        public void Search_Many()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            string saveDatabase = connection.Database;

            try
            {
                // connection.Database = "ISTU";
                int[] found = connection.Search("K=А$");
                Write
                (
                    "Found: " + found.Length + ": "
                    + string.Join
                    (
                        ", ",
                        found.Select
                        (
                            mfn => mfn.ToInvariantString()
                        )
                    )
                    .Substring(0, 50)
                );
            }
            finally
            {
                connection.Database = saveDatabase;
            }
        }
Exemple #3
0
        private void _searchButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            _resultBox.Clear();
            _loginBox.Clear();
            _passwordBox.Clear();

            string ticket = _ticketBox.Text.Trim();

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

                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]);
                string     description = connection.FormatRecord("@brief", found[0]);
                _resultBox.Text = Environment.NewLine + description;

                RecordField litresField = record.Fields
                                          .GetFirstField(_litresTag);
                if (!ReferenceEquals(litresField, null))
                {
                    _loginBox.Text    = litresField.GetFirstSubFieldValue('a');
                    _passwordBox.Text = litresField.GetFirstSubFieldValue('b');
                }

                _loginBox.Focus();
            }
        }
Exemple #4
0
        public void Search_Few()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            int[] found = connection.Search("T=A$");
            Write
            (
                string.Join
                (
                    ", ",
                    found.Select(mfn => mfn.ToInvariantString())
                )
                .Substring(0, 50)
            );
        }
Exemple #5
0
        public static void Main()
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            try
            {
                using (connection = new IrbisConnection())
                {
                    connection.ParseConnectionString(ConnectionString);
                    connection.Connect();
                    Console.WriteLine("Подключились");

                    connection.Database = MainDatabase;
                    int[] found = connection.Search(SearchExpression);
                    Console.WriteLine("Отобрано записей: {0}", found.Length);


                    foreach (int mfn in found)
                    {
                        if (Cancel)
                        {
                            break;
                        }
                        try
                        {
                            ProcessRecord(mfn);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine
                            (
                                "MFN={0}, {1}: {2}",
                                mfn,
                                exception.GetType(),
                                exception.Message
                            );
                        }
                    }
                }
                Console.WriteLine("Отключились");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemple #6
0
        private static void ProcessReader
        (
            int index,
            string ticket
        )
        {
            if (string.IsNullOrEmpty(ticket))
            {
                return;
            }

            Console.Write
            (
                "{0}: {1}",
                index,
                ticket
            );

            foreach (string database in databases)
            {
                connection.Database = database;
                int[] found = connection.Search
                              (
                    "\"RI={0}\"",
                    ticket
                              );
                if (found.Length == 0)
                {
                    Console.Write(" {0} [not found]", database);
                }
                else if (found.Length > 1)
                {
                    Console.Write(" {0} [too many!]", database);
                }
                else
                {
                    int mfn = found[0];
                    Console.Write
                    (
                        " {0} [MFN {1}]",
                        database,
                        mfn
                    );
                    if (doDelete)
                    {
                        try
                        {
                            connection.DeleteRecord(mfn, true);
                            Console.Write(" <deleted>");
                        }
                        catch (Exception exception)
                        {
                            Console.Write
                            (
                                " <exception>: {0}",
                                exception.GetType().Name
                            );
                        }
                    }
                }
            }

            Console.WriteLine(" done");
        }
Exemple #7
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 #8
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);
            }
        }
Exemple #9
0
        private InventoryResult _CheckInventory
        (
            IrbisConnection client,
            string number
        )
        {
            if (string.IsNullOrEmpty(number))
            {
                throw new ArgumentNullException("number");
            }

            InventoryResult result = new InventoryResult
            {
                Number = number
            };

            int[] found = client.Search
                          (
                "\"IN={0}\"",
                number
                          );

            bool writtenOff = CheckWrittenOff(number);

            if (writtenOff)
            {
                if (found.Length != 0)
                {
                    result.Status = InventoryStatus.Problem;
                    result.Text   = "проблема: то ли списан, то ли нет";
                }
                else
                {
                    result.Status = InventoryStatus.WrittenOff;
                    result.Text   = "списан";
                }
            }
            else
            {
                switch (found.Length)
                {
                case 0:
                    result.Status = InventoryStatus.NotFound;
                    result.Text   = "не найден";
                    break;

                case 1:
                    string format      = CM.AppSettings["format"];
                    string description = client.FormatRecord
                                         (
                        format,
                        found[0]
                                         );
                    if (!string.IsNullOrEmpty(description))
                    {
                        description = description.Trim();
                    }
                    result.Status = InventoryStatus.Found;
                    result.Text   = string.Format
                                    (
                        "найден: {0}",
                        description
                                    );
                    break;

                default:
                    result.Status = InventoryStatus.Problem;
                    result.Text   =
                        "проблема: много найдено";
                    break;
                }
            }

            return(result);
        }
Exemple #10
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();
            }
        }
Exemple #11
0
        private void _HandleNumber
        (
            [CanBeNull] string number
        )
        {
            _currentRecord   = null;
            _currentExemplar = null;
            _SetHtml(string.Empty);

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

            _logBox.Output.WriteLine
            (
                "Введен номер: {0}",
                number
            );

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

            int[] found = _client.Search
                          (
                "\"{0}{1}\"",
                prefix,
                number
                          );
            if (found.Length == 0)
            {
                _SetHtml
                (
                    "Не найден номер {0}",
                    number
                );
                return;
            }
            if (found.Length != 1)
            {
                _SetHtml
                (
                    "Много записей для номера {0}",
                    number
                );
                return;
            }

            MarcRecord record = _client.ReadRecord(found[0]);

            RecordField[] fields = record.Fields
                                   .GetField(910)
                                   .GetField('b', number);

            if (fields.Length == 0)
            {
                _SetHtml
                (
                    "Не найдено поле с номером {0}",
                    number
                );
                return;
            }
            if (fields.Length != 1)
            {
                _SetHtml
                (
                    "Много полей с номером {0}",
                    number
                );
                return;
            }

            ExemplarInfo exemplar = ExemplarInfo.Parse(fields[0]);

            StringBuilder diagnosis = new StringBuilder();

            diagnosis.AppendFormat
            (
                "<b>{0}</b><br/>",
                number
            );
            if (!string.IsNullOrEmpty(exemplar.RealPlace))
            {
                diagnosis.AppendFormat
                (
                    "<font color='red'>Экземпляр уже был проверен "
                    + "в фонде</font> <b>{0}</b> ({1})<br/>",
                    exemplar.RealPlace,
                    exemplar.CheckedDate
                );
            }
            if (exemplar.Status != "0")
            {
                diagnosis.AppendFormat
                (
                    "<font color='red'>Неверный статус "
                    + "экземпляра: </font><b>{0}</b><br/>",
                    exemplar.Status
                );
            }
            if (!exemplar.Place.SameString(CurrentFond))
            {
                diagnosis.AppendFormat
                (
                    "<font color='red'>Неверное место хранения "
                    + "экземпляра: </font><b>{0}</b><br/>",
                    exemplar.Place
                );
            }
            string currentShelf = CurrentShelf;

            if (!string.IsNullOrEmpty(currentShelf))
            {
                string[] items = currentShelf
                                 .Split(',', ';')
                                 .Select(item => item.Trim())
                                 .NonEmptyLines()
                                 .Select(item => item.ToUpperInvariant())
                                 .ToArray();

                string shelf = record.FM(906);
                if (string.IsNullOrEmpty(shelf))
                {
                    diagnosis.AppendFormat
                    (
                        "<font color='red'>Для книги не указан "
                        + "расстановочный шифр</font><br/>"
                    );
                }
                else if (items.Length != 0)
                {
                    shelf = shelf.ToUpperInvariant();
                    bool good = false;
                    foreach (string item in items)
                    {
                        if (shelf.StartsWith(item))
                        {
                            good = true;
                            break;
                        }
                    }
                    if (!good)
                    {
                        diagnosis.AppendFormat
                        (
                            "<font color='red'>Неверный шифр: "
                            + "</font><b>{0}</b><br/>",
                            shelf
                        );
                    }
                }
            }

            string currentCollection = CurrentCollection;

            if (!string.IsNullOrEmpty(currentCollection))
            {
                string collection = exemplar.Collection;
                if (currentCollection != collection)
                {
                    if (string.IsNullOrEmpty(collection))
                    {
                        diagnosis.AppendFormat
                        (
                            "<font color='red'>Для книги не указана "
                            + "коллекция"
                        );
                    }
                    else
                    {
                        diagnosis.AppendFormat
                        (
                            "<font color='red'>Неверная коллекция: "
                            + "</font><b>{0}</b><br/>",
                            collection
                        );
                    }
                }
            }

            diagnosis.AppendLine("<br/>");

            string cardFormat       = CM.AppSettings["card-format"];
            string briefDescription = _client.FormatRecord
                                      (
                cardFormat,
                record.Mfn
                                      ).Trim();

            diagnosis.Append(briefDescription);
            record.UserData = briefDescription;

            _SetHtml
            (
                "{0}",
                diagnosis.ToString()
            );

            _currentRecord   = record;
            _currentExemplar = exemplar;
        }