Example #1
0
        private void MainForm_Load
        (
            object sender,
            EventArgs e
        )
        {
            _client = new IrbisConnection();
            string connectionString = CM.AppSettings["connection-string"];

            _client.ParseConnectionString(connectionString);
            try
            {
                _client.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Application.Exit();
            }

            DatabaseInfo[] bases = _client.ListDatabases();
            _databaseBox.DisplayMember = "Name";
            _databaseBox.Items.AddRange(bases);
            _databaseBox.SelectedIndex = 0;
        }
Example #2
0
        private void Window_Initialized
        (
            object sender,
            EventArgs e
        )
        {
            string initialDatabase = null;

            using (IrbisConnection connection = GetConnection())
            {
                IniFile iniFile  = connection.IniFile;
                string  listFile = "dbnam1.mnu";
                if (!ReferenceEquals(iniFile, null))
                {
                    iniFile.GetValue("MAIN", "DBNNAMECAT", "dbnam1.mnu");
                    string ext = System.IO.Path.GetExtension(listFile);
                    if (string.IsNullOrEmpty(ext))
                    {
                        listFile += ".mnu";
                    }

                    initialDatabase = iniFile.GetValue("MAIN", "CURDBN", null);
                }

                databases = connection.ListDatabases(listFile);
                foreach (DatabaseInfo database in databases)
                {
                    DatabaseList.Items.Add(database);
                }
            }

            int initialIndex = 0;

            if (!string.IsNullOrEmpty(initialDatabase))
            {
                for (int i = 0; i < databases.Length; i++)
                {
                    if (initialDatabase.SameString(databases[i].Name))
                    {
                        initialIndex = i;
                        break;
                    }
                }
            }

            if (initialIndex >= 0 && initialIndex < databases.Length)
            {
                DatabaseList.SelectedIndex = initialIndex;
                object selectedItem = DatabaseList.SelectedItem;
                if (!ReferenceEquals(selectedItem, null))
                {
                    DatabaseList.ScrollIntoView(selectedItem);
                }
            }
        }
Example #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);
            }
        }