示例#1
0
        private void LoadExemplars()
        {
            if (!File.Exists("list.sav"))
            {
                return;
            }

            ExemplarInfo[] array = null;
            Run
            (
                () =>
            {
                array = SerializationUtility
                        .RestoreArrayFromFile <ExemplarInfo>("list.sav");
            }
            );

            if (ReferenceEquals(array, null))
            {
                return;
            }

            ExemplarList.Clear();
            _bindingSource.SuspendBinding();
            foreach (ExemplarInfo exemplar in array)
            {
                ExemplarList.Add(exemplar);
            }
            _bindingSource.ResumeBinding();
        }
示例#2
0
 private void _clearButton_Click
 (
     object sender,
     EventArgs e
 )
 {
     ExemplarList.Clear();
     SaveExemplars();
 }
示例#3
0
        private void SaveExemplars()
        {
            Run
            (
                () =>
            {
                ExemplarInfo[] array = ExemplarList.ToArray();

                FileUtility.DeleteIfExists("list.tmp");
                array.SaveToFile("list.tmp");
                FileUtility.DeleteIfExists("list.sav");
                File.Move("list.tmp", "list.sav");
            }
            );
        }
示例#4
0
        private List <object[]> BuildBookList
        (
            ListVariant currentVariant
        )
        {
            IComparer <ExemplarInfo> comparer;
            ListSort sort = null;

            this.InvokeIfRequired
            (
                () =>
            {
                sort = (ListSort)_sortBox.SelectedItem;
            }
            );

            switch (sort.Field)
            {
            case "Description":
                comparer = ExemplarInfoComparer.ByDescription();
                break;

            case "Number":
                comparer = ExemplarInfoComparer.ByNumber();
                break;

            default:
                throw new ApplicationException
                      (
                          "Unknown field: "
                          + sort.Field.ToVisibleString()
                      );
            }

            ExemplarInfo[] array = ExemplarList
                                   .OrderBy(book => book, comparer)
                                   .ToArray();

            int firstNumber = Convert.ToInt32(_firstNumberBox.Value);

            foreach (ExemplarInfo item in array)
            {
                item.SequentialNumber = firstNumber;
                firstNumber++;
            }

            List <object[]> books = new List <object[]>(array.Length);

            foreach (ExemplarInfo exemplar in array)
            {
                List <object> list = new List <object>();
                foreach (ExcelColumn column in currentVariant.Columns)
                {
                    object o = ReflectionUtility.GetPropertyValue
                               (
                        exemplar,
                        column.Expression
                               );
                    list.Add(o);
                }

                books.Add(list.ToArray());
            }

            ExcelForm.DummyMethod();

            return(books);
        }
示例#5
0
        private void _addButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            UniversalForm mainForm = MainForm;

            if (ReferenceEquals(mainForm, null) ||
                !mainForm.Active)
            {
                WriteLine("Приложение не активно");

                return;
            }

            string number = _numberBox.Text.Trim();

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

            _numberBox.Clear();
            _numberBox.Focus();
            Application.DoEvents();

            if (AlreadyHave(number))
            {
                WriteLine("Уже есть экземпляр: {0}", number);

                return;
            }

            ExemplarInfo exemplar = null;

            Manager.Format = ((ListFormat)_formatBox.SelectedItem)
                             .Format
                             .ThrowIfNull("Manager.Format");

            try
            {
                Run
                (
                    () =>
                {
                    exemplar = Manager.ReadExtend(number);
                }
                );
            }
            catch (Exception exception)
            {
                WriteLine("Ошибка: {0}", exception.Message);

                return;
            }

            if (ReferenceEquals(exemplar, null))
            {
                WriteLine("Не удалось найти экземпляр: {0}", number);

                return;
            }

            if (!string.IsNullOrEmpty(exemplar.Description))
            {
                exemplar.Description = exemplar.Description.Replace
                                       (
                    "[Текст] ",
                    string.Empty
                                       );
            }

            MarcRecord  record = exemplar.Record.ThrowIfNull("exemplar.Record");
            RecordField field  = exemplar.Field.ThrowIfNull("exemplar.Field");

            if (_statusBox.Checked &&
                exemplar.Status != "0")
            {
                exemplar.Status = "0";
                field.SetSubField('A', "0");
                WriteLine("Статус экземпляра {0} изменён на 0", number);
            }

            if (_exhibitionBox.Checked)
            {
                field.SetSubField('9', "Выставка новых поступлений");
                WriteLine("Экземпляр {0} передан на выставку", number);
            }

            if (record.Modified)
            {
                Run
                (
                    () =>
                {
                    MainForm.Provider.WriteRecord(record);
                    WriteLine("Изменения сохранены на сервере");
                }
                );
            }

            ExemplarList.Add(exemplar);
            _bindingSource.Position = ExemplarList.Count - 1;

            SaveExemplars();
            _numberBox.Focus();

            WriteLine
            (
                "Добавлено: {0} {1}",
                exemplar.Number,
                exemplar.Description.ToVisibleString()
            );
        }