using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using System.Windows.Forms; using System.Drawing; namespace Foo.ClientServices.GUIWPForms { /// /// Interaction logic for WorkspaceSelector_NewWorkspacePage.xaml /// public partial class WorkspaceSelector_NewWorkspacePage : Page { // passed to us by parent private WorkspaceSelector m_WorkspaceSelectorObj = null; private bool m_bPerformanceCache = false; // private state variables private bool m_bIsValidName; public WorkspaceSelector_NewWorkspacePage(bool bPerformanceCache) { m_bPerformanceCache = bPerformanceCache; if (!m_bPerformanceCache) { } InitializeComponent(); } private void Page_Loaded(object sender, RoutedEventArgs e) { if (!m_bPerformanceCache) { // Make sure that the Selector Frame is big enough to hold this page m_WorkspaceSelectorObj = (WorkspaceSelector)this.Tag; m_WorkspaceSelectorObj.Height = this.Height + m_WorkspaceSelectorObj.MarginTopBottom; m_WorkspaceSelectorObj.Width = this.Width; // Set the Warning Label for this Particular Workspace ConstructAreYouSureMessage(); // Set intial Error Message SetWarningMessage("Enter Characters"); m_bIsValidName = false; // Set intial focus txtNewName.Focus(); } } /// /// Constructs a renaming Message to be displayed to the user /// private void ConstructAreYouSureMessage() { StringBuilder sr = new StringBuilder(); sr.Append("Create New Workspace \n"); txtCreateWorkspaceTitle.Text = sr.ToString(); } /// /// Sets the validator label to a warning message /// /// private void SetWarningMessage(string strMessage) { lblWarningMessage.Foreground = new SolidColorBrush(Colors.OrangeRed); lblWarningMessage.Content = strMessage; } /// /// Sets the validator label to a success message /// /// private void SetSuccessMessage(string strMessage) { lblWarningMessage.Foreground = new SolidColorBrush(Colors.RoyalBlue); lblWarningMessage.Content = strMessage; } /// /// Button Yes Event Handler - Go ahead and Create the new WorkspaceName /// private void btnYes_Click(object sender, RoutedEventArgs e) { if (m_bIsValidName) { if (!DataAccessLayer.Data.Workspace.InsertWorkspaceName(txtNewName.Text)) { // an error occured Foo.Platform.ErrorReporting.UserError.Show("An Error Occurred", "Creating the Workspace Failed! Navigating you back to the WorkspaceSelector"); m_WorkspaceSelectorObj.NavigateToChildPage(ChildPages.WorkspaceSelector_StandardPage); } else { // Set GUI State GUIState.LastSelectedWorkspaceName = txtNewName.Text; // Show Success Message ShowMessageAndNavigateBack(String.Format("Workspace '{0}' has been successfully created", txtNewName.Text)); } } } /// /// Shows the passed in message in the text box and then navigates back to the main page /// /// private void ShowMessageAndNavigateBack(string strMessage) { // Hide the buttons btnYes.Visibility = Visibility.Hidden; btnNo.Visibility = Visibility.Hidden; // Hide the textbox and Labels lblEnterNewName.Visibility = Visibility.Hidden; txtNewName.Visibility = Visibility.Hidden; lblWarningMessage.Visibility = Visibility.Hidden; // Show Message txtCreateWorkspaceTitle.Text = strMessage; // Dynamically calculate the height of the textbox * No need to do this in this case * // System.Drawing.Size sz = new System.Drawing.Size((int)this.Width, int.MaxValue); // Font font = new Font(txtRenameWorkspaceTitle.FontFamily.ToString(), (float)txtRenameWorkspaceTitle.FontSize); // sz = TextRenderer.MeasureText(txtRenameWorkspaceTitle.Text, font, sz, TextFormatFlags.WordBreak); // Change Height as needed // lblRenameWorkspaceTitle.Height = sz.Height; // txtRenameWorkspaceTitle.Height = sz.Height; // default to change height to Max available space lblCreateWorkspaceTitle.Height = this.Height - m_WorkspaceSelectorObj.MarginTopBottom; txtCreateWorkspaceTitle.Height = this.Height - m_WorkspaceSelectorObj.MarginTopBottom; // Pause for 1.5 second and Navigate Back DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1, 500); dispatcherTimer.Start(); } /// /// Timer set specifically to allow the message to be seen for a little bit before navigating back /// void dispatcherTimer_Tick(object sender, EventArgs e) { DispatcherTimer dispatcherTimer = (DispatcherTimer)sender; dispatcherTimer.Stop(); // Navigate Back m_WorkspaceSelectorObj.NavigateToChildPage(ChildPages.WorkspaceSelector_StandardPage); } /// /// Button No Event Handler - Go back to parent /// private void btnNo_Click(object sender, RoutedEventArgs e) { m_WorkspaceSelectorObj.NavigateToChildPage(ChildPages.WorkspaceSelector_StandardPage); } /// /// Perform NewWorkspaceName TextBox Validation /// private void txtNewName_TextChanged(object sender, TextChangedEventArgs e) { System.Windows.Controls.TextBox textBox = (System.Windows.Controls.TextBox)sender; if (String.IsNullOrEmpty(textBox.Text)) { SetWarningMessage("Enter Characters"); m_bIsValidName = false; } else if (!DataAccessLayer.DataTypes.DataTypeValidation.IsValidWorkspaceName(textBox.Text)) { SetWarningMessage("Invalid Workspace Name"); m_bIsValidName = false; } else if (DataAccessLayer.Data.Workspace.DoesWorkspaceNameExist(textBox.Text)) { SetWarningMessage("Workspace Name Already Exists"); m_bIsValidName = false; } else { SetSuccessMessage("Valid Workspace Name"); m_bIsValidName = true; } } } }