예제 #1
0
        private void _buildButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            ListVariant currentVariant
                = (ListVariant)_variantBox.SelectedItem;

            try
            {
                Controller.DisableControls();

                List <object[]> books = null;

                if (!Run
                    (
                        () =>
                {
                    books = BuildBookList(currentVariant);
                }
                    ))
                {
                    return;
                }

                IDictionary <string, object> dictionary
                    = new Dictionary <string, object>();
                dictionary.Add("books", books);

                using (ExcelForm excelForm = new ExcelForm())
                {
                    excelForm.ShowBooks
                    (
                        Connection,
                        currentVariant.FileName.ThrowIfNull(),
                        currentVariant.Columns.ThrowIfNull(),
                        dictionary,
                        _header,
                        books,
                        _footer,
                        currentVariant.FirstLine
                    );
                    excelForm.ShowDialog(this);
                }
            }
            finally
            {
                Controller.EnableControls();
            }
        }
예제 #2
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);
        }