Ejemplo n.º 1
0
        private BaseForm CreateForm(BaseAcceptableViewModel viewModel)
        {
            if (viewModel is IngredientEditorViewModel)
            {
                var ingredient = (IngredientEditorViewModel)viewModel;
                var txtName    = new TextEdit();
                txtName.BindText(ingredient, i => i.Name);
                return(FormBuilder.CreateSimpleOKCancel("Edit Ingredient", ingredient, txtName, "Name:"));
            }
            else if (viewModel is RecipeEditorViewModel)
            {
                var recipe = (RecipeEditorViewModel)viewModel;

                var txtName = new TextEdit();
                txtName.BindText(recipe, r => r.Name);

                var tbl = new TableLayoutPanel();
                tbl.ColumnCount = 4;
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                tbl.RowCount = 1;
                tbl.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tbl.Height      = 28;
                tbl.MinimumSize = new Size(0, 28);

                var btnModify = new SimpleButton();
                btnModify.Margin = new Padding(3);
                btnModify.Text   = "Modify Recipe";
                btnModify.Size   = new Size(96, 22);
                btnModify.Bind(recipe.ModifyRecipeCommand);

                var btnReduce = new SimpleButton();
                btnReduce.Margin = new Padding(3);
                btnReduce.Text   = "Reduce";
                btnReduce.Size   = new Size(96, 22);
                btnReduce.Bind(recipe.ReduceRecipeCommand);

                tbl.SuspendLayout();
                tbl.Controls.Add(btnModify, 1, 0);
                tbl.Controls.Add(btnReduce, 2, 0);
                tbl.ResumeLayout();

                var ctrlAmount = new AmountControl(false);
                ctrlAmount.BindAmount(recipe, r => r.Amount);
                ctrlAmount.BindMeasurement(recipe, r => r.Measurement);

                var grid = new EditableListGridControl <IngredientReferenceViewModel>(recipe);
                return(FormBuilder.CreateOKCancel("Edit Recipe", recipe,
                                                  new FormBuilderItem(txtName, "Name:"),
                                                  new FormBuilderItem(grid, "Items:"),
                                                  new FormBuilderItem(tbl),
                                                  new FormBuilderItem(ctrlAmount, "Makes:")));
            }
            else if (viewModel is IngredientReferenceEditorViewModel)
            {
                var ingredient = (IngredientReferenceEditorViewModel)viewModel;

                var cboIngredients = new SearchLookUpEdit();
                cboIngredients.Properties.View.Columns.AddVisible("Display").SortOrder = ColumnSortOrder.Ascending;
                cboIngredients.Properties.View.OptionsView.ShowColumnHeaders           = false;
                cboIngredients.Properties.View.OptionsView.ShowIndicator = false;
                cboIngredients.Properties.DataSource       = ingredient.Ingredients;
                cboIngredients.Properties.ValueMember      = "Value";
                cboIngredients.Properties.DisplayMember    = "Display";
                cboIngredients.Properties.ShowAddNewButton = true;
                cboIngredients.AddNewValue += (o, e) =>
                {
                    // execute the add ingredient command
                    ingredient.SearchText = cboIngredients.GetFilterText();
                    ingredient.AddIngredientCommand.Execute(this);
                    e.Cancel = true;
                };

                var binding = cboIngredients.BindEditValue(ingredient, (i => i.IngredientID));
                binding.DataSourceNullValue = null;

                var ctrlAmount = new AmountControl();
                ctrlAmount.BindAmount(ingredient, r => r.Amount);
                ctrlAmount.BindMeasurement(ingredient, r => r.Measurement);

                return(FormBuilder.CreateOKCancel("Edit Recipe Ingredient", ingredient,
                                                  new FormBuilderItem(cboIngredients, "Ingredient:"),
                                                  new FormBuilderItem(ctrlAmount)));
            }
            else if (viewModel is ModifyRecipeViewModel)
            {
                return(new ModifyRecipeDialog((ModifyRecipeViewModel)viewModel));
            }
            else if (viewModel is ReduceRecipeViewModel)
            {
                return(new ReduceRecipeDialog((ReduceRecipeViewModel)viewModel));
            }

            return(null);
        }