/// <summary> /// Update product info view and set _isEditedProductInfo in the presentation model. /// </summary> private void UpdateProductInfoViewAndSetIsEditedProductInfo() { if (_productManagementPresentationModel.CurrentSelectedProduct == null) { throw new ArgumentException(ERROR_NULL_CURRENT_SELECTED_PRODUCT); } _productNameField.Text = _productManagementPresentationModel.CurrentSelectedProduct.Name; _productPriceField.Text = _productManagementPresentationModel.CurrentSelectedProduct.Price.GetString(); _productTypeField.Text = _productManagementPresentationModel.CurrentSelectedProduct.Type; _productImagePathField.Text = _productManagementPresentationModel.CurrentSelectedProduct.ImagePath; _productDescriptionField.Text = _productManagementPresentationModel.CurrentSelectedProduct.Description; _productManagementPresentationModel.SetIsEditedProductInfo(false); }
public ProductManagementForm(ProductManagementPresentationModel productManagementPresentationModelData, Model modelData) { InitializeComponent(); _productManagementPresentationModel = productManagementPresentationModelData; _model = modelData; this.Disposed += RemoveEvents; // Observers _model.ProductInfoChanged += ResetViewOnProductInfoChangedOrOnProductAdded; _model.ProductAdded += ResetViewOnProductInfoChangedOrOnProductAdded; _productManagementPresentationModel.CurrentSelectedProductChanged += UpdateProductInfoViewAndSetIsEditedProductInfo; _productManagementPresentationModel.SaveButtonEnabledChanged += UpdateSaveButtonView; // UI _productsListBox.SelectedIndexChanged += ChangeProductsListBoxSelectedIndex; _productPriceField.KeyPress += InputHelper.InputNumbersOrBackSpace; _productImageBrowseButton.Click += (sender, eventArguments) => BrowseImageAndSetProductImagePath(); _saveButton.Click += (sender, eventArguments) => _productManagementPresentationModel.ClickSaveButton(new Product(_productNameField.Text, _productTypeField.Text, _productPriceField.Text, _productDescriptionField.Text, _productImagePathField.Text)); _addProductButton.Click += (sender, eventArguments) => SetStateAndUpdateViewOnAddProductButtonClicked(); // Product info _productNameField.TextChanged += (sender, eventArguments) => _productManagementPresentationModel.SetIsEditedProductInfo(true); _productPriceField.TextChanged += (sender, eventArguments) => _productManagementPresentationModel.SetIsEditedProductInfo(true); _productTypeField.TextChanged += (sender, eventArguments) => _productManagementPresentationModel.SetIsEditedProductInfo(true); _productImagePathField.TextChanged += (sender, eventArguments) => _productManagementPresentationModel.SetIsEditedProductInfo(true); _productDescriptionField.TextChanged += (sender, eventArguments) => _productManagementPresentationModel.SetIsEditedProductInfo(true); // Input inspecting textboxes InitializeInputInspectingTextBoxesTextBoxInspectors(); InitializeInputInspectingTextBoxes(); InitializeInputInspectingTextBoxesTextBoxInspectorsCollectionChangedEventHandlers(); // Input inspecting drop-down lists InitializeInputInspectingDropDownListsDropDownListInspectors(); InitializeInputInspectingDropDownLists(); InitializeInputInspectingDropDownListsDropDownListInspectorsCollectionChangedEventHandlers(); // Input inspectors collection InitializeInputInspectorsCollection(); // Initial UI States InitializeProductTypeField(); InitializeProductsListBox(); UpdateSaveButtonView(); }