Exemplo n.º 1
0
 public BeersViewModel()
 {
     Dao                  = new BL();
     Beers                = new BindingList <IBeer>(Dao.getData().getBeers());
     Producents           = new BindingList <IProducent>(Dao.getData().getProducents());
     BeerDetailsView      = new BindingList <string>();
     ProducentDetailsView = new BindingList <string>();
     makeDetailsOfSelectedBeer(Beers[0]);
     makeDetailsOfSelectedProducent(Producents[0]);
     BeerToAdd = Dao.getData().GetNewBeer();
     //     BeerToEdit = new EditedBeer(Dao.getData().GetNewBeer());
     ProducentToAdd          = Dao.getData().GetNewProducent();
     CommandAdd              = new CommandButtons(param => this.onAddClicked(BeerToAdd), param => this.CanCreateBeer());
     SelectedItemIndex       = 0;
     CommandListItemSelected = new CommandItemSelected(param => this.onItemSelected(SelectedItemIndex));
     //   CommandEdit = new CommandButtons(param => this.onEditClicked());
     //   CommandRemove = new CommandButtons(param => this.onRemoveClicked());
 }
Exemplo n.º 2
0
        public void BuildForm()
        {
            var form_height = 0;

            // Setup Main Instruction
            switch (MainIcon)
            {
            case ESysIcons.Information: imgMain.Image = SystemIcons.Information.ToBitmap(); break;

            case ESysIcons.Question: imgMain.Image = SystemIcons.Question.ToBitmap(); break;

            case ESysIcons.Warning: imgMain.Image = SystemIcons.Warning.ToBitmap(); break;

            case ESysIcons.Error: imgMain.Image = SystemIcons.Error.ToBitmap(); break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //AdjustLabelHeight(lbMainInstruction);
            //pnlMainInstruction.Height = Math.Max(41, lbMainInstruction.Height + 16);
            if (_mainInstructionHeight == 0)
            {
                GetMainInstructionTextSizeF();
            }
            pnlMainInstruction.Height = Math.Max(41, _mainInstructionHeight + 16);

            form_height += pnlMainInstruction.Height;

            // Setup Content
            pnlContent.Visible = (Content != "");
            if (Content != "")
            {
                AdjustLabelHeight(lbContent);
                pnlContent.Height = lbContent.Height + 4;
                form_height      += pnlContent.Height;
            }

            var show_verify_checkbox = (cbVerify.Text != "");

            cbVerify.Visible = show_verify_checkbox;

            // Setup Expanded Info and Buttons panels
            if (ExpandedInfo == "")
            {
                pnlExpandedInfo.Visible   = false;
                lbShowHideDetails.Visible = false;
                cbVerify.Top      = 12;
                pnlButtons.Height = 40;
            }
            else
            {
                AdjustLabelHeight(lbExpandedInfo);
                pnlExpandedInfo.Height       = lbExpandedInfo.Height + 4;
                pnlExpandedInfo.Visible      = Expanded;
                lbShowHideDetails.Text       = (Expanded ? "        Hide details" : "        Show details");
                lbShowHideDetails.ImageIndex = (Expanded ? 0 : 3);
                if (!show_verify_checkbox)
                {
                    pnlButtons.Height = 40;
                }
                if (Expanded)
                {
                    form_height += pnlExpandedInfo.Height;
                }
            }

            // Setup RadioButtons
            pnlRadioButtons.Visible = (RadioButtons != "");
            if (RadioButtons != "")
            {
                var arr        = RadioButtons.Split(new char[] { '|' });
                var pnl_height = 12;
                for (var i = 0; i < arr.Length; i++)
                {
                    var rb = new RadioButton();
                    rb.Parent   = pnlRadioButtons;
                    rb.Location = new Point(60, 4 + (i * rb.Height));
                    rb.Text     = arr[i];
                    rb.Tag      = i;
                    rb.Checked  = (DefaultButtonIndex == i);
                    rb.Width    = Width - rb.Left - 15;
                    pnl_height += rb.Height;
                    _radioButtonCtrls.Add(rb);
                }
                pnlRadioButtons.Height = pnl_height;
                form_height           += pnlRadioButtons.Height;
            }

            // Setup CommandButtons
            pnlCommandButtons.Visible = (CommandButtons != "");
            if (CommandButtons != "")
            {
                var arr        = CommandButtons.Split(new char[] { '|' });
                var t          = 8;
                var pnl_height = 16;
                for (var i = 0; i < arr.Length; i++)
                {
                    var btn = new CommandButton();
                    btn.Parent   = pnlCommandButtons;
                    btn.Location = new Point(50, t);
                    if (_isVista)  // <- tweak font if vista
                    {
                        btn.Font = new Font(btn.Font, FontStyle.Regular);
                    }
                    btn.Text    = arr[i];
                    btn.Size    = new Size(Width - btn.Left - 15, btn.GetBestHeight());
                    t          += btn.Height;
                    pnl_height += btn.Height;
                    btn.Tag     = i;
                    btn.Click  += new EventHandler(CommandButton_Click);
                    if (i == DefaultButtonIndex)
                    {
                        _focusControl = btn;
                    }
                }
                pnlCommandButtons.Height = pnl_height;
                form_height += pnlCommandButtons.Height;
            }

            // Setup Buttons
            switch (Buttons)
            {
            case ETaskDialogButtons.YesNo:
                bt1.Visible      = false;
                bt2.Text         = "&Yes";
                bt2.DialogResult = DialogResult.Yes;
                bt3.Text         = "&No";
                bt3.DialogResult = DialogResult.No;
                AcceptButton     = bt2;
                CancelButton     = bt3;
                break;

            case ETaskDialogButtons.YesNoCancel:
                bt1.Text         = "&Yes";
                bt1.DialogResult = DialogResult.Yes;
                bt2.Text         = "&No";
                bt2.DialogResult = DialogResult.No;
                bt3.Text         = "&Cancel";
                bt3.DialogResult = DialogResult.Cancel;
                AcceptButton     = bt1;
                CancelButton     = bt3;
                break;

            case ETaskDialogButtons.OkCancel:
                bt1.Visible      = false;
                bt2.Text         = "&OK";
                bt2.DialogResult = DialogResult.OK;
                bt3.Text         = "&Cancel";
                bt3.DialogResult = DialogResult.Cancel;
                AcceptButton     = bt2;
                CancelButton     = bt3;
                break;

            case ETaskDialogButtons.Ok:
                bt1.Visible      = false;
                bt2.Visible      = false;
                bt3.Text         = "&OK";
                bt3.DialogResult = DialogResult.OK;
                AcceptButton     = bt3;
                CancelButton     = bt3;
                break;

            case ETaskDialogButtons.Close:
                bt1.Visible      = false;
                bt2.Visible      = false;
                bt3.Text         = "&Close";
                bt3.DialogResult = DialogResult.Cancel;
                CancelButton     = bt3;
                break;

            case ETaskDialogButtons.Cancel:
                bt1.Visible      = false;
                bt2.Visible      = false;
                bt3.Text         = "&Cancel";
                bt3.DialogResult = DialogResult.Cancel;
                CancelButton     = bt3;
                break;

            case ETaskDialogButtons.None:
                bt1.Visible = false;
                bt2.Visible = false;
                bt3.Visible = false;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            ControlBox = (Buttons == ETaskDialogButtons.Cancel ||
                          Buttons == ETaskDialogButtons.Close ||
                          Buttons == ETaskDialogButtons.OkCancel ||
                          Buttons == ETaskDialogButtons.YesNoCancel);

            if (!show_verify_checkbox && ExpandedInfo == "" && Buttons == ETaskDialogButtons.None)
            {
                pnlButtons.Visible = false;
            }
            else
            {
                form_height += pnlButtons.Height;
            }

            pnlFooter.Visible = (Footer != "");
            if (Footer != "")
            {
                AdjustLabelHeight(lbFooter);
                pnlFooter.Height = Math.Max(28, lbFooter.Height + 16);
                switch (FooterIcon)
                {
                case ESysIcons.Information:
                    // SystemIcons.Information.ToBitmap().GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    imgFooter.Image = ResizeBitmap(SystemIcons.Information.ToBitmap(), 16, 16);
                    break;

                case ESysIcons.Question:
                    // SystemIcons.Question.ToBitmap().GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    imgFooter.Image = ResizeBitmap(SystemIcons.Question.ToBitmap(), 16, 16);
                    break;

                case ESysIcons.Warning:
                    // SystemIcons.Warning.ToBitmap().GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    imgFooter.Image = ResizeBitmap(SystemIcons.Warning.ToBitmap(), 16, 16);
                    break;

                case ESysIcons.Error:
                    // SystemIcons.Error.ToBitmap().GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    imgFooter.Image = ResizeBitmap(SystemIcons.Error.ToBitmap(), 16, 16);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                form_height += pnlFooter.Height;
            }

            ClientSize = new Size(ClientSize.Width, form_height);

            _formBuilt = true;
        }