Ejemplo n.º 1
0
        public void Apply(Form view)
        {
            var navigation = new ToolStrip()
                             .Button("Prev", "Передыдущая страница")
                             .Label("PageLabel", "")
                             .Button("Next", "Следующая страница");

            view.Controls.Add(navigation);

            var pager = (IPager)_presenter.GetType().GetProperty("page").GetValue(_presenter, null);

            navigation.ActAsPaginator(pager, page => {
                var paginator = Invoke(page);
                return(paginator);
            });

            var update = _presenter.GetType().GetEvent("Update");

            if (update != null)
            {
                update.AddEventHandler(_presenter, new Action <string, object>((n, v) => {
                    if (v is IPager)
                    {
                        navigation.UpdatePaginator((IPager)v);
                    }
                }));
            }
        }
Ejemplo n.º 2
0
        public ShowAssortmentForProducer(uint producerId, Pager <AssortmentDto> assortments)
        {
            Text        = "Ассортимент";
            MinimumSize = new Size(640, 480);

            var tools = new ToolStrip()
                        .Button("Удалить (Delete)", Delete);

            var navigationToolStrip = new ToolStrip()
                                      .Button("Prev", "Предыдущая страница")
                                      .Label("PageLabel", "")
                                      .Button("Next", "Следующая страница");

            assortmentTable = new VirtualTable(new TemplateManager <AssortmentDto>(
                                                   () => Row.Headers(new Header("Проверен").AddClass("CheckBoxColumn1"), "Продукт", "Производитель"),
                                                   a => {
                var row = Row.Cells(new CheckBoxInput(a.Checked).Attr("Name", "Checked"), a.Product, a.Producer);
                if (a.Id == Settings.Default.BookmarkAssortimentId)
                {
                    ((IDomElementWithChildren)row.Children.ElementAt(1)).Prepend(new TextBlock {
                        Class = "BookmarkGlyph"
                    });
                }
                return(row);
            }));
            assortmentTable.CellSpacing = 1;
            assortmentTable.RegisterBehavior(
                new RowSelectionBehavior(),
                new ToolTipBehavior(),
                new ColumnResizeBehavior(),
                new InputController());
            assortmentTable.Behavior <ColumnResizeBehavior>().ColumnResized += column => WidthHolder.Update(assortmentTable, column, WidthHolder.AssortimentWidths);
            assortmentTable.TemplateManager.ResetColumns();
            assortmentTable.Host
            .InputMap()
            .KeyDown(Keys.Delete, Delete);

            assortmentTable.Host.InputMap()
            .KeyDown(Keys.Escape, Close);

            Controls.Add(assortmentTable.Host);
            Controls.Add(navigationToolStrip);
            Controls.Add(tools);

            navigationToolStrip.ActAsPaginator(
                assortments,
                page => {
                Pager <AssortmentDto> pager = null;
                Action(s => { pager = s.ShowAssortmentForProducer(producerId, page); });
                assortmentTable.TemplateManager.Source = pager.Content.ToList();
                return(pager);
            });

            assortmentTable.TemplateManager.Source = assortments.Content.ToList();

            Shown += (s, a) => assortmentTable.Host.Focus();
        }
Ejemplo n.º 3
0
        public ShowAssortment(Pager <AssortmentDto> assortments)
        {
            Text        = "Ассортимент";
            MinimumSize = new Size(640, 480);

            tools = new ToolStrip()
                    .Edit("SearchText")
                    .Button("Поиск", Search)
                    .Separator()
                    .Button("Удалить (Delete)", Delete)
                    .Separator()
                    .Button("Удалить синоним", DeleteProducerSynonym)
                    .Button("Обновить (F11)", Reload);

            navigationToolStrip = new ToolStrip()
                                  .Button("К закаладке", MoveToBookmark)
                                  .Button("Установить закладку", SetBookmark)
                                  .Separator()
                                  .Button("Prev", "Предыдущая страница")
                                  .Label("PageLabel", "")
                                  .Button("Next", "Следующая страница");

            assortmentTable = new VirtualTable(new TemplateManager <AssortmentDto>(
                                                   () => Row.Headers("Продукт", "Производитель"),
                                                   a => {
                var row = Row.Cells(new Cell(new TextBlock(a.Product)), new Cell(new TextBlock(a.Producer)));
                if (a.Id == Settings.Default.BookmarkAssortimentId)
                {
                    ((IDomElementWithChildren)row.Children.ElementAt(1)).Prepend(new TextBlock {
                        Class = "BookmarkGlyph"
                    });
                }
                return(row);
            }));
            assortmentTable.CellSpacing = 1;
            assortmentTable.RegisterBehavior(
                new RowSelectionBehavior(),
                new ToolTipBehavior(),
                new ColumnResizeBehavior(),
                new InputController());
            assortmentTable.Behavior <ColumnResizeBehavior>().ColumnResized += column => WidthHolder.Update(assortmentTable, column, WidthHolder.AssortimentWidths);
            assortmentTable.TemplateManager.ResetColumns();
            assortmentTable.Host
            .InputMap()
            .KeyDown(Keys.Delete, Delete)
            .KeyDown(Keys.F11, Reload);

            UpdateAssortment(assortments);

            var searchText = ((ToolStripTextBox)tools.Items["SearchText"]);

            searchText.KeyDown += (sender, args) => {
                if (args.KeyCode == Keys.Enter)
                {
                    Search();
                }
            };

            assortmentTable.Host.InputMap()
            .KeyDown(Keys.Enter, Search)
            .KeyDown(Keys.Escape, () => {
                searchText.Text = "";
                if (!String.IsNullOrEmpty(_searchText))
                {
                    _searchText = "";
                    var pager   = Request(s => s.GetAssortmentPage(0));
                    UpdateAssortment(pager);
                    navigationToolStrip.UpdatePaginator(pager);
                }
            })
            .KeyPress((o, a) => {
                if (!Char.IsLetterOrDigit(a.KeyChar))
                {
                    return;
                }
                searchText.Text += a.KeyChar;
            });

            var behavior = assortmentTable.Behavior <IRowSelectionBehavior>();

            behavior.SelectedRowChanged += (oldRow, newRow) => SelectedAssortmentChanged(behavior.Selected <AssortmentDto>());

            synonymsTable = new VirtualTable(new TemplateManager <ProducerSynonymDto>(
                                                 () => {
                var row    = Row.Headers();
                var header = new Header("Синоним").Sortable("Name");
                header.InlineStyle.Set(StyleElementType.Width, WidthHolder.ProducerWidths[0]);
                row.Append(header);

                header = new Header("Поставщик").Sortable("Supplier");
                header.InlineStyle.Set(StyleElementType.Width, WidthHolder.ProducerWidths[1]);
                row.Append(header);

                header = new Header("Регион").Sortable("Region");
                header.InlineStyle.Set(StyleElementType.Width, WidthHolder.ProducerWidths[2]);
                row.Append(header);

                return(row);
            },
                                                 synonym => {
                var row = Row.Cells(synonym.Name,
                                    synonym.Supplier,
                                    synonym.Region);
                if (synonym.HaveOffers)
                {
                    row.AddClass("WithoutOffers");
                }
                return(row);
            }));
            synonymsTable.CellSpacing = 1;
            synonymsTable.RegisterBehavior(new ToolTipBehavior(),
                                           new SortInList(),
                                           new ColumnResizeBehavior(),
                                           new RowSelectionBehavior());

            synonymsTable.Host.InputMap();
            synonymsTable.Behavior <ColumnResizeBehavior>().ColumnResized += column => WidthHolder.Update(synonymsTable, column, WidthHolder.ProducerWidths);

            equivalentTable = new VirtualTable(new TemplateManager <ProducerEquivalentDto>(
                                                   () => Row.Headers("Эквивалент"), e => Row.Cells(e.Name)));

            var producersToSynonymsSplit = new SplitContainer {
                Dock        = DockStyle.Fill,
                Orientation = Orientation.Horizontal
            };
            var producersToEquivalentsSplit = new SplitContainer {
                Dock = DockStyle.Fill,
            };

            producersToEquivalentsSplit.Panel1.Controls.Add(assortmentTable.Host);
            producersToEquivalentsSplit.Panel2.Controls.Add(equivalentTable.Host);

            producersToSynonymsSplit.Panel1.Controls.Add(producersToEquivalentsSplit);
            producersToSynonymsSplit.Panel2.Controls.Add(synonymsTable.Host);

            Controls.Add(producersToSynonymsSplit);
            Controls.Add(navigationToolStrip);
            Controls.Add(tools);

            producersToSynonymsSplit.SplitterDistance    = (int)(0.5 * Height);
            producersToEquivalentsSplit.SplitterDistance = (int)(0.7 * producersToEquivalentsSplit.Width);

            assortmentTable.Host.Tag = PaginatorExtention.TableName;

            navigationToolStrip.ActAsPaginator(assortments, LoadPage);

            MoveToBookmark();
            Shown += (s, a) => assortmentTable.Host.Focus();

            var selected = assortmentTable.Selected <AssortmentDto>();

            SelectedAssortmentChanged(selected);
        }