//======================================================================================= // // This source code is only intended as a supplement to existing Microsoft documentation. // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR // PURPOSE. // // Copyright (C) Microsoft Corporation. All Rights Reserved. // //======================================================================================= using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using Microsoft.ManagementConsole.Advanced; namespace Microsoft.ManagementConsole.Samples { /// /// Gets Name and Birthday /// public partial class UserPropertiesControl : UserControl { /// /// Parent property page to expose data and state of property sheet /// private UserPropertyPage userPropertyPage; /// /// Constructor /// /// Container property page for the control public UserPropertiesControl(UserPropertyPage parentPropertyPage) { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // keep reference to parent userPropertyPage = parentPropertyPage; } /// /// Populate control values from the SelectionObject (set in UserListView.SelectionOnChanged) /// public void RefreshData(ResultNode userNode) { this.UserName.Text = userNode.DisplayName; this.Birthday.Text = userNode.SubItemDisplayNames[0]; // first subitem userPropertyPage.Dirty = false; } /// /// Update the node with the controls values /// /// Node being updated by property page public void UpdateData(ResultNode userNode) { userNode.DisplayName = this.UserName.Text; userNode.SubItemDisplayNames[0] = this.Birthday.Text; // first subitem userPropertyPage.Dirty = false; } /// /// Check during UserProptertyPage.OnApply to ensure that changes can be Applied /// /// returns true if changes are valid public bool CanApplyChanges() { bool result = false; if (UserName.Text.Trim().Length == 0) { MessageBoxParameters messageBoxParameters = new MessageBoxParameters(); messageBoxParameters.Text = "Name cannot be blank"; userPropertyPage.ParentSheet.ShowDialog(messageBoxParameters); } else if (Birthday.Text.Trim().Length == 0) { MessageBoxParameters messageBoxParameters = new MessageBoxParameters(); messageBoxParameters.Text = "Birthday cannot be blank"; userPropertyPage.ParentSheet.ShowDialog(messageBoxParameters); } else { result = true; } return result; } /// /// Notifies the PropertyPage that info has changed and that the PropertySheet can change the /// buttons /// /// /// private void UserName_TextChanged(object sender, System.EventArgs e) { userPropertyPage.Dirty = true; } /// /// Notifies the PropertyPage that info has changed and that the PropertySheet can change the /// buttons /// /// /// private void Birthday_TextChanged(object sender, System.EventArgs e) { userPropertyPage.Dirty = true; } } }