//-------------------------------------------------------------------------------- public static DialogResult ShowTaskDialogBox(string Title, string MainInstruction, string Content, string ExpandedInfo, string Footer, string VerificationText, string RadioButtons, string CommandButtons, TaskDialogButtons Buttons, TaskDialogIcons MainIcon, TaskDialogIcons FooterIcon) { if (VistaTaskDialog.IsAvailableOnThisOS && !ForceEmulationMode) { // [OPTION 1] Show Vista TaskDialog VistaTaskDialog vtd = new VistaTaskDialog(); vtd.WindowTitle = Title; vtd.MainInstruction = MainInstruction; vtd.Content = Content; vtd.ExpandedInformation = ExpandedInfo; vtd.Footer = Footer; // Radio Buttons if (RadioButtons != "") { List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>(); string[] arr = RadioButtons.Split(new char[] { '|' }); for (int i = 0; i < arr.Length; i++) { try { VistaTaskDialogButton button = new VistaTaskDialogButton(); button.ButtonId = 1000 + i; button.ButtonText = arr[i]; lst.Add(button); } catch (FormatException) { } } vtd.RadioButtons = lst.ToArray(); } // Custom Buttons if (CommandButtons != "") { List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>(); string[] arr = CommandButtons.Split(new char[] { '|' }); for (int i = 0; i < arr.Length; i++) { try { VistaTaskDialogButton button = new VistaTaskDialogButton(); button.ButtonId = 2000 + i; button.ButtonText = arr[i]; lst.Add(button); } catch (FormatException) { } } vtd.Buttons = lst.ToArray(); } switch (Buttons) { case TaskDialogButtons.YesNo: vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No; break; case TaskDialogButtons.YesNoCancel: vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No | VistaTaskDialogCommonButtons.Cancel; break; case TaskDialogButtons.OKCancel: vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok | VistaTaskDialogCommonButtons.Cancel; break; case TaskDialogButtons.OK: vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok; break; case TaskDialogButtons.Close: vtd.CommonButtons = VistaTaskDialogCommonButtons.Close; break; case TaskDialogButtons.Cancel: vtd.CommonButtons = VistaTaskDialogCommonButtons.Cancel; break; default: vtd.CommonButtons = 0; break; } switch (MainIcon) { case TaskDialogIcons.Information: vtd.MainIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Question: vtd.MainIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Warning: vtd.MainIcon = VistaTaskDialogIcon.Warning; break; case TaskDialogIcons.Error: vtd.MainIcon = VistaTaskDialogIcon.Error; break; } switch (FooterIcon) { case TaskDialogIcons.Information: vtd.FooterIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Question: vtd.FooterIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Warning: vtd.FooterIcon = VistaTaskDialogIcon.Warning; break; case TaskDialogIcons.Error: vtd.FooterIcon = VistaTaskDialogIcon.Error; break; } vtd.EnableHyperlinks = false; vtd.ShowProgressBar = false; vtd.AllowDialogCancellation = (Buttons == TaskDialogButtons.Cancel || Buttons == TaskDialogButtons.Close || Buttons == TaskDialogButtons.OKCancel || Buttons == TaskDialogButtons.YesNoCancel); vtd.CallbackTimer = false; vtd.ExpandedByDefault = false; vtd.ExpandFooterArea = false; vtd.PositionRelativeToWindow = true; vtd.RightToLeftLayout = false; vtd.NoDefaultRadioButton = false; vtd.CanBeMinimized = false; vtd.ShowMarqueeProgressBar = false; vtd.UseCommandLinks = (CommandButtons != ""); vtd.UseCommandLinksNoIcon = false; vtd.VerificationText = VerificationText; vtd.VerificationFlagChecked = false; vtd.ExpandedControlText = Properties.Resources.TASKDIALOG_HIDEDETAILS; vtd.CollapsedControlText = Properties.Resources.TASKDIALOG_SHOWDETAILS; vtd.Callback = null; // Show the Dialog DialogResult result = (DialogResult)vtd.Show((vtd.CanBeMinimized ? null : Form.ActiveForm), out VerificationChecked, out RadioButtonResult); // if a command button was clicked, then change return result // to "DialogResult.OK" and set the CommandButtonResult if ((int)result >= 2000) { CommandButtonResult = ((int)result - 2000); result = DialogResult.OK; } if (RadioButtonResult >= 1000) RadioButtonResult -= 1000; // deduct the ButtonID start value for radio buttons return result; } else { // [OPTION 2] Show Emulated Form EmulatedTaskDialog td = new EmulatedTaskDialog(); //ML-2422: Can't confirm error message, with a lot of detailed information. td.ExpandedInfo = ExpandedInfo; try { int expandedInfoHeight = td.GetExpandedInfoLabelHeight; if (expandedInfoHeight > maxHeightExpandedInfo) td.ExpandedInfo = td.ExpandedInfo.Substring(0, (int)(td.ExpandedInfo.Length * ((int)(maxHeightExpandedInfo / expandedInfoHeight)))); } catch (Exception e) { Trace.WriteLine("Can't cut text in EmulatedTaskDialog: " + e.ToString()); } td.TopMost = true; td.Title = Title; td.MainInstruction = MainInstruction; td.Content = Content; td.Footer = Footer; td.RadioButtons = RadioButtons; td.CommandButtons = CommandButtons; td.Buttons = Buttons; td.MainIcon = MainIcon; td.FooterIcon = FooterIcon; td.VerificationText = VerificationText; td.Width = EmulatedFormWidth; td.BuildForm(); DialogResult result = td.ShowDialog(); RadioButtonResult = td.RadioButtonIndex; CommandButtonResult = td.CommandButtonClickedIndex; VerificationChecked = td.VerificationCheckBoxChecked; return result; } }
/// <summary> /// Shows the resize dialog. /// </summary> /// <returns></returns> /// <remarks>Documented by Dev05, 2007-11-29</remarks> private TaskDialogResult ShowResizeDialog() { EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Title = Resources.CARD_EDIT_RESIZE_TITLE; dialog.MainInstruction = Resources.CARD_EDIT_RESIZE_TEXT; dialog.Content = Resources.CARD_EDIT_RESIZE_DESCRIPTION; dialog.CommandButtons = string.Format(Resources.CARD_EDIT_RESIZE_BUTTONS, new object[] { Settings.Default.resizeSmall.Width, Settings.Default.resizeSmall.Height, Settings.Default.resizeMedium.Width, Settings.Default.resizeMedium.Height, Settings.Default.resizeLarge.Width, Settings.Default.resizeLarge.Height }); dialog.VerificationText = Resources.CARD_EDIT_RESIZE_CHECKBOX; dialog.VerificationCheckBoxChecked = true; dialog.Buttons = TaskDialogButtons.Cancel; dialog.MainIcon = TaskDialogIcons.Question; dialog.FooterIcon = TaskDialogIcons.Warning; dialog.MainImages = new Image[] { Resources.resizeS, Resources.resizeM, Resources.resizeL, Resources.resize }; dialog.HoverImages = new Image[] { Resources.resizeS, Resources.resizeM, Resources.resizeL, Resources.resize }; dialog.CenterImages = true; dialog.BuildForm(); DialogResult dialogResult = dialog.ShowDialog(); if (dialog.VerificationCheckBoxChecked && dialogResult != DialogResult.Cancel) { changingCheckstate = true; checkBoxResizeAnswer.Checked = (dialog.CommandButtonClickedIndex < 3); checkBoxResizeQuestion.Checked = (dialog.CommandButtonClickedIndex < 3); changingCheckstate = false; } TaskDialogResult result = new TaskDialogResult(); result.CommandButtonsIndex = dialog.CommandButtonClickedIndex; result.VerificationChecked = dialog.VerificationCheckBoxChecked; return result; }
/// <summary> /// Opens the config file. /// </summary> /// <param name="file">The file.</param> /// <remarks>Documented by Dev08, 2009-02-27</remarks> public void OpenConfigFile(string file) { EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Owner = this; dialog.StartPosition = FormStartPosition.CenterParent; dialog.Title = Resources.DRAG_CFG_DIALOG_TITLE; dialog.MainInstruction = Resources.DRAG_CFG_DIALOG_MAIN; dialog.Content = Resources.DRAG_CFG_DIALOG_CONTENT; dialog.CommandButtons = Resources.DRAG_CFG_DIALOG_BUTTONS; dialog.Buttons = TaskDialogButtons.None; dialog.MainIcon = TaskDialogIcons.Question; dialog.MainImages = new Image[] { Resources.applications_system, Resources.process_stop }; dialog.HoverImages = new Image[] { Resources.applications_system, Resources.process_stop }; dialog.CenterImages = true; dialog.BuildForm(); DialogResult dialogResult = dialog.ShowDialog(); //[ML-1773] Imported connection file is not saved on stick string appConfigFile = Setup.GlobalConfigPath; string usrConfigFile = Setup.UserConfigPath; switch (dialog.CommandButtonClickedIndex) { //Import case 0: int successfulImportedConnections = 0; try { successfulImportedConnections = ConnectionStringHandler.ImportConfigFile(file, appConfigFile, usrConfigFile); } catch (InvalidConfigFileException) { TaskDialog.MessageBox(Resources.DRAG_INVALID_CFG_FILE_TITLE, Resources.DRAG_INVALID_CFG_FILE_MAININSTRUCTION, Resources.DRAG_INVALID_CFG_FILE_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); return; } catch (Exception exc) { TaskDialog.MessageBox(Resources.DRAG_CFG_GENERAL_ERROR_TITLE, Resources.DRAG_CFG_GENERAL_ERROR_MAININSTRUCTION, exc.Message, exc.ToString(), string.Empty, string.Empty, TaskDialogButtons.OK, TaskDialogIcons.Error, TaskDialogIcons.Error); return; } if (successfulImportedConnections == 0) TaskDialog.MessageBox(Resources.DRAG_CFG_SUCCESS_TITLE, Resources.DRAG_CFG_SUCCESS_MAIN_NOTHING_IMPORTED, Resources.DRAG_CFG_SUCCESS_MAIN_NOTHING_IMPORTED_DETAIL, TaskDialogButtons.OK, TaskDialogIcons.Information); else if (successfulImportedConnections == 1) TaskDialog.MessageBox(Resources.DRAG_CFG_SUCCESS_TITLE, Resources.DRAG_CFG_SUCCESS_MAIN, Resources.DRAG_CFG_SUCCESS_CONTENT_SING, TaskDialogButtons.OK, TaskDialogIcons.Information); else TaskDialog.MessageBox(Resources.DRAG_CFG_SUCCESS_TITLE, Resources.DRAG_CFG_SUCCESS_MAIN, string.Format(Resources.DRAG_CFG_SUCCESS_CONTENT_PLUR, successfulImportedConnections), TaskDialogButtons.OK, TaskDialogIcons.Information); break; //Cancel case 1: default: return; } }
/// <summary> /// Initializes the control with the specified connection (name). /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="connection">The connection.</param> /// <remarks>Documented by Dev05, 2009-03-03</remarks> public UserStruct?Initialize(ConnectionStringStruct connection, UserStruct lastUser) { ConnectionString = LearningModulesIndex.ConnectionsHandler.GetConnectionFromConnectionStringStruct(connection); if (ConnectionString == null) { LearningModulesIndexEntry entry = RecentLearningModules.GetRecentModules().Find(m => m.ConnectionString.ConnectionString == connection.ConnectionString); if (entry != null) { ConnectionString = entry.Connection; } } ConnectionName = connection.Typ != DatabaseType.MsSqlCe ? (ConnectionString != null ? ConnectionString.Name : Resources.NO_CONNECTION_NAME) : Path.GetFileName(connection.ConnectionString); Connection = connection; if (connection.Typ == DatabaseType.MsSqlCe) { comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDownList; } else { comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDown; } #region error handling switch (lastUser.LastLoginError) { case LoginError.AlreadyLoggedIn: EmulatedTaskDialog taskDialog = new EmulatedTaskDialog(); taskDialog.Title = Resources.TASKDIALOG_KICK_TITLE; taskDialog.MainInstruction = string.Format(Resources.TASKDIALOG_KICK_MAIN, lastUser.UserName); taskDialog.Content = string.Format(Resources.TASKDIALOG_KICK_CONTENT, ConnectionName); taskDialog.CommandButtons = Resources.TASKDIALOG_KICK_BUTTONS; taskDialog.VerificationText = string.Empty; taskDialog.VerificationCheckBoxChecked = false; taskDialog.Buttons = TaskDialogButtons.None; taskDialog.MainIcon = TaskDialogIcons.Warning; taskDialog.FooterIcon = TaskDialogIcons.Warning; taskDialog.MainImages = new Image[] { Resources.system_log_out, Resources.processStopBig }; taskDialog.HoverImages = new Image[] { Resources.system_log_out, Resources.processStopBig }; taskDialog.CenterImages = true; taskDialog.BuildForm(); DialogResult dialogResult = taskDialog.ShowDialog(); if (dialogResult != DialogResult.Cancel && taskDialog.CommandButtonClickedIndex == 0) { lastUser.CloseOpenSessions = true; return(lastUser); } else { AllowAutoLogin = false; } break; case LoginError.InvalidUsername: TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_USER_TITLE, Resources.TASKDIALOG_WRONG_USER_MAIN, Resources.TASKDIALOG_WRONG_USER_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); break; case LoginError.InvalidPassword: TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_PASSWORD_TITLE, Resources.TASKDIALOG_WRONG_PASSWORD_MAIN, Resources.TASKDIALOG_WRONG_PASSWORD_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); break; case LoginError.WrongAuthentication: case LoginError.ForbiddenAuthentication: TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_TITLE, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_MAIN, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); break; case LoginError.NoError: default: break; } #endregion labelHeader.Text = string.Format(Resources.LOGIN_HEADER_TEXT, ConnectionName); buttonCancel.Enabled = connection.Typ != DatabaseType.MsSqlCe; try { SetListItems(); UpdateSelection(false); #region persitancy Stream outputStream = null; try { BinaryFormatter binary = new BinaryFormatter(); IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly(); outputStream = new IsolatedStorageFileStream(Settings.Default.AuthDataFile, FileMode.Open, storageFile); outputStream = new CryptoStream(outputStream, Rijndael.Create().CreateDecryptor(Encoding.Unicode.GetBytes("mlifter"), Encoding.Unicode.GetBytes("omicron")), CryptoStreamMode.Read); persitancyData = binary.Deserialize(outputStream) as Dictionary <string, SavedUserData>; outputStream.Close(); } catch { persitancyData = new Dictionary <string, SavedUserData>(); } finally { if (outputStream != null) { outputStream.Close(); } } if (ConnectionString != null && persitancyData.ContainsKey(ConnectionString.ConnectionString)) { SavedUserData data = persitancyData[ConnectionString.ConnectionString]; if (data.SaveUsername) { checkBoxSaveUsername.Checked = true; ShowOptions = true; comboBoxUserSelection.Text = data.Username; if (data.SavePassword) { checkBoxSavePassword.Checked = true; textBoxPassword.Text = data.Password; textBoxPassword.Tag = PasswordType.Hashed; if (data.AutoLogin) { checkBoxAutoLogin.Checked = true; if (AllowAutoLogin && !MLifter.BusinessLayer.User.PreventAutoLogin) { Login(); return(GetActualUser()); } } else { checkBoxAutoLogin.Checked = false; } } else { checkBoxSavePassword.Checked = false; } } else { checkBoxSaveUsername.Checked = false; ShowOptions = false; } } #endregion comboBoxUserSelection.Focus(); if (lastUser.LastLoginError != LoginError.NoError) { comboBoxUserSelection.Text = lastUser.UserName; textBoxPassword.Text = string.Empty; textBoxPassword.Tag = PasswordType.ClearText; } LoginError = lastUser.LastLoginError; } catch (ConnectionNotSetException ex) { Debug.WriteLine(ex.ToString()); } return(null); }
/// <summary> /// Handles the Click event of the saveAsToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-04-25</remarks> private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { if (!File.Exists(LearnLogic.Dictionary.DictionaryDAL.Connection)) return; EmulatedTaskDialog dialog = null; if (Properties.Settings.Default.ShowBackupDialog) { // display notice that LM must be closed and reopened to make backup dialog = new EmulatedTaskDialog(); dialog.Title = Resources.MAINFORM_CREATE_BACKUP_DIALOG_TITLE; dialog.MainInstruction = Resources.MAINFORM_CREATE_BACKUP_DIALOG_MAIN; dialog.CommandButtons = Resources.MAINFORM_CREATE_BACKUP_DIALOG_BUTTONS; dialog.Buttons = TaskDialogButtons.None; dialog.MainIcon = TaskDialogIcons.Information; dialog.CenterImages = true; dialog.VerificationText = Resources.MAINFORM_CREATE_BACKUP_DIALOG_VERIFICATION; dialog.BuildForm(); dialog.ShowDialog(); if (dialog.CommandButtonClickedIndex == 1) return; } SaveDialog.Title = Resources.MAINFORM_CREATE_BACKUP_DIALOG_TITLE; SaveDialog.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Path.GetFileName(LearnLogic.Dictionary.DictionaryPath)); SaveDialog.Filter = String.Format(Resources.MAINFORM_CREATE_BACKUP_DIALOG_FILTER, DAL.Helper.EmbeddedDbExtension); if (SaveDialog.ShowDialog() == DialogResult.OK) { string sourcePath = LearnLogic.Dictionary.DictionaryPath; LearnLogic.CloseLearningModule(); this.Enabled = false; Copy copy = new Copy(); copy.SaveCopyAs(sourcePath, SaveDialog.FileName); this.Enabled = true; this.OpenLearningModule(RecentLearningModules.MostRecentLearningModule); //save "don't show this message again" if (Properties.Settings.Default.ShowBackupDialog == true && dialog != null) { if (dialog.VerificationCheckBoxChecked) { Properties.Settings.Default.ShowBackupDialog = false; Properties.Settings.Default.Save(); } } } }
/// <summary> /// Shows the file exists drag and drop dialog. /// </summary> /// <returns></returns> /// <remarks>Documented by Dev08, 2009-03-02</remarks> private TaskDialogResult ShowFileExistsDragAndDropDialog() { EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Title = Resources.DRAG_FILE_EXISTS_TITLE; dialog.MainInstruction = Resources.DRAG_LM_EXISTS_DIALOG_MAININTRODUCTION; dialog.Content = string.Empty; dialog.CommandButtons = Resources.DRAG_LM_EXISTS_DIALOG_BUTTONS; dialog.Buttons = TaskDialogButtons.None; dialog.MainIcon = TaskDialogIcons.Question; dialog.MainImages = new Image[] { Resources.edit_find_replace, Resources.MLIcon32, Resources.process_stop }; dialog.HoverImages = new Image[] { Resources.edit_find_replace, Resources.MLIcon32, Resources.process_stop }; dialog.CenterImages = true; dialog.BuildForm(); DialogResult dialogResult = dialog.ShowDialog(); TaskDialogResult result = new TaskDialogResult(); result.CommandButtonsIndex = dialog.CommandButtonClickedIndex; return result; }
/// <summary> /// Watches a drive to detect removal. /// </summary> /// <param name="drive">The drive.</param> /// <remarks>Documented by Dev02, 2007-12-13</remarks> void driveDetector_WatchDevice(string drive) { if (driveDetector == null) { driveDetector = new DriveDetector(this); driveDetector.DeviceRemoved += new MLifter.Components.DriveDetectorEventHandler(driveDetector_DeviceRemoved); driveDetector.QueryRemove += new DriveDetectorEventHandler(driveDetector_QueryRemove); } driveDetector.EnableQueryRemove(drive); //prepare message (so that ressources are loaded while the stick is still plugged in) if (LearnLogic.Dictionary != null) { driveRemoved = new MLifter.Controls.EmulatedTaskDialog(); driveRemoved.Title = Properties.Resources.MAINFORM_STICKREMOVED_CAPTION; driveRemoved.MainInstruction = Properties.Resources.MAINFORM_STICKREMOVED_MAININSTRUCTION; driveRemoved.Content = string.Format(Properties.Resources.MAINFORM_STICKREMOVED_DESCRIPTION, LearnLogic.Dictionary.DictionaryPath); driveRemoved.CommandButtons = Properties.Resources.MAINFORM_STICKREMOVED_CLOSEDIC; driveRemoved.Buttons = MLifter.Controls.TaskDialogButtons.None; driveRemoved.MainIcon = MLifter.Controls.TaskDialogIcons.Warning; driveRemoved.TopMost = true; driveRemoved.BuildForm(); } }
/// <summary> /// Initializes the control with the specified connection (name). /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="connection">The connection.</param> /// <remarks>Documented by Dev05, 2009-03-03</remarks> public UserStruct? Initialize(ConnectionStringStruct connection, UserStruct lastUser) { ConnectionString = LearningModulesIndex.ConnectionsHandler.GetConnectionFromConnectionStringStruct(connection); if (ConnectionString == null) { LearningModulesIndexEntry entry = RecentLearningModules.GetRecentModules().Find(m => m.ConnectionString.ConnectionString == connection.ConnectionString); if (entry != null) ConnectionString = entry.Connection; } ConnectionName = connection.Typ != DatabaseType.MsSqlCe ? (ConnectionString != null ? ConnectionString.Name : Resources.NO_CONNECTION_NAME) : Path.GetFileName(connection.ConnectionString); Connection = connection; if (connection.Typ == DatabaseType.MsSqlCe) comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDownList; else comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDown; #region error handling switch (lastUser.LastLoginError) { case LoginError.AlreadyLoggedIn: EmulatedTaskDialog taskDialog = new EmulatedTaskDialog(); taskDialog.Title = Resources.TASKDIALOG_KICK_TITLE; taskDialog.MainInstruction = string.Format(Resources.TASKDIALOG_KICK_MAIN, lastUser.UserName); taskDialog.Content = string.Format(Resources.TASKDIALOG_KICK_CONTENT, ConnectionName); taskDialog.CommandButtons = Resources.TASKDIALOG_KICK_BUTTONS; taskDialog.VerificationText = string.Empty; taskDialog.VerificationCheckBoxChecked = false; taskDialog.Buttons = TaskDialogButtons.None; taskDialog.MainIcon = TaskDialogIcons.Warning; taskDialog.FooterIcon = TaskDialogIcons.Warning; taskDialog.MainImages = new Image[] { Resources.system_log_out, Resources.processStopBig }; taskDialog.HoverImages = new Image[] { Resources.system_log_out, Resources.processStopBig }; taskDialog.CenterImages = true; taskDialog.BuildForm(); DialogResult dialogResult = taskDialog.ShowDialog(); if (dialogResult != DialogResult.Cancel && taskDialog.CommandButtonClickedIndex == 0) { lastUser.CloseOpenSessions = true; return lastUser; } else AllowAutoLogin = false; break; case LoginError.InvalidUsername: TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_USER_TITLE, Resources.TASKDIALOG_WRONG_USER_MAIN, Resources.TASKDIALOG_WRONG_USER_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); break; case LoginError.InvalidPassword: TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_PASSWORD_TITLE, Resources.TASKDIALOG_WRONG_PASSWORD_MAIN, Resources.TASKDIALOG_WRONG_PASSWORD_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); break; case LoginError.WrongAuthentication: case LoginError.ForbiddenAuthentication: TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_TITLE, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_MAIN, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); break; case LoginError.NoError: default: break; } #endregion labelHeader.Text = string.Format(Resources.LOGIN_HEADER_TEXT, ConnectionName); buttonCancel.Enabled = connection.Typ != DatabaseType.MsSqlCe; try { SetListItems(); UpdateSelection(false); #region persitancy Stream outputStream = null; try { BinaryFormatter binary = new BinaryFormatter(); IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly(); outputStream = new IsolatedStorageFileStream(Settings.Default.AuthDataFile, FileMode.Open, storageFile); outputStream = new CryptoStream(outputStream, Rijndael.Create().CreateDecryptor(Encoding.Unicode.GetBytes("mlifter"), Encoding.Unicode.GetBytes("omicron")), CryptoStreamMode.Read); persitancyData = binary.Deserialize(outputStream) as Dictionary<string, SavedUserData>; outputStream.Close(); } catch { persitancyData = new Dictionary<string, SavedUserData>(); } finally { if (outputStream != null) outputStream.Close(); } if (ConnectionString != null && persitancyData.ContainsKey(ConnectionString.ConnectionString)) { SavedUserData data = persitancyData[ConnectionString.ConnectionString]; if (data.SaveUsername) { checkBoxSaveUsername.Checked = true; ShowOptions = true; comboBoxUserSelection.Text = data.Username; if (data.SavePassword) { checkBoxSavePassword.Checked = true; textBoxPassword.Text = data.Password; textBoxPassword.Tag = PasswordType.Hashed; if (data.AutoLogin) { checkBoxAutoLogin.Checked = true; if (AllowAutoLogin && !MLifter.BusinessLayer.User.PreventAutoLogin) { Login(); return GetActualUser(); } } else checkBoxAutoLogin.Checked = false; } else checkBoxSavePassword.Checked = false; } else { checkBoxSaveUsername.Checked = false; ShowOptions = false; } } #endregion comboBoxUserSelection.Focus(); if (lastUser.LastLoginError != LoginError.NoError) { comboBoxUserSelection.Text = lastUser.UserName; textBoxPassword.Text = string.Empty; textBoxPassword.Tag = PasswordType.ClearText; } LoginError = lastUser.LastLoginError; } catch (ConnectionNotSetException ex) { Debug.WriteLine(ex.ToString()); } return null; }
static private int maxHeightExpandedInfo = 700; //ToDo: Use Screen Height //-------------------------------------------------------------------------------- #region ShowTaskDialogBox //-------------------------------------------------------------------------------- static public DialogResult ShowTaskDialogBox(string Title, string MainInstruction, string Content, string ExpandedInfo, string Footer, string VerificationText, string RadioButtons, string CommandButtons, TaskDialogButtons Buttons, TaskDialogIcons MainIcon, TaskDialogIcons FooterIcon) { if (VistaTaskDialog.IsAvailableOnThisOS && !ForceEmulationMode) { // [OPTION 1] Show Vista TaskDialog VistaTaskDialog vtd = new VistaTaskDialog(); vtd.WindowTitle = Title; vtd.MainInstruction = MainInstruction; vtd.Content = Content; vtd.ExpandedInformation = ExpandedInfo; vtd.Footer = Footer; // Radio Buttons if (RadioButtons != "") { List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>(); string[] arr = RadioButtons.Split(new char[] { '|' }); for (int i = 0; i < arr.Length; i++) { try { VistaTaskDialogButton button = new VistaTaskDialogButton(); button.ButtonId = 1000 + i; button.ButtonText = arr[i]; lst.Add(button); } catch (FormatException) { } } vtd.RadioButtons = lst.ToArray(); } // Custom Buttons if (CommandButtons != "") { List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>(); string[] arr = CommandButtons.Split(new char[] { '|' }); for (int i = 0; i < arr.Length; i++) { try { VistaTaskDialogButton button = new VistaTaskDialogButton(); button.ButtonId = 2000 + i; button.ButtonText = arr[i]; lst.Add(button); } catch (FormatException) { } } vtd.Buttons = lst.ToArray(); } switch (Buttons) { case TaskDialogButtons.YesNo: vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No; break; case TaskDialogButtons.YesNoCancel: vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No | VistaTaskDialogCommonButtons.Cancel; break; case TaskDialogButtons.OKCancel: vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok | VistaTaskDialogCommonButtons.Cancel; break; case TaskDialogButtons.OK: vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok; break; case TaskDialogButtons.Close: vtd.CommonButtons = VistaTaskDialogCommonButtons.Close; break; case TaskDialogButtons.Cancel: vtd.CommonButtons = VistaTaskDialogCommonButtons.Cancel; break; default: vtd.CommonButtons = 0; break; } switch (MainIcon) { case TaskDialogIcons.Information: vtd.MainIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Question: vtd.MainIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Warning: vtd.MainIcon = VistaTaskDialogIcon.Warning; break; case TaskDialogIcons.Error: vtd.MainIcon = VistaTaskDialogIcon.Error; break; } switch (FooterIcon) { case TaskDialogIcons.Information: vtd.FooterIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Question: vtd.FooterIcon = VistaTaskDialogIcon.Information; break; case TaskDialogIcons.Warning: vtd.FooterIcon = VistaTaskDialogIcon.Warning; break; case TaskDialogIcons.Error: vtd.FooterIcon = VistaTaskDialogIcon.Error; break; } vtd.EnableHyperlinks = false; vtd.ShowProgressBar = false; vtd.AllowDialogCancellation = (Buttons == TaskDialogButtons.Cancel || Buttons == TaskDialogButtons.Close || Buttons == TaskDialogButtons.OKCancel || Buttons == TaskDialogButtons.YesNoCancel); vtd.CallbackTimer = false; vtd.ExpandedByDefault = false; vtd.ExpandFooterArea = false; vtd.PositionRelativeToWindow = true; vtd.RightToLeftLayout = false; vtd.NoDefaultRadioButton = false; vtd.CanBeMinimized = false; vtd.ShowMarqueeProgressBar = false; vtd.UseCommandLinks = (CommandButtons != ""); vtd.UseCommandLinksNoIcon = false; vtd.VerificationText = VerificationText; vtd.VerificationFlagChecked = false; vtd.ExpandedControlText = Properties.Resources.TASKDIALOG_HIDEDETAILS; vtd.CollapsedControlText = Properties.Resources.TASKDIALOG_SHOWDETAILS; vtd.Callback = null; // Show the Dialog DialogResult result = (DialogResult)vtd.Show((vtd.CanBeMinimized ? null : Form.ActiveForm), out VerificationChecked, out RadioButtonResult); // if a command button was clicked, then change return result // to "DialogResult.OK" and set the CommandButtonResult if ((int)result >= 2000) { CommandButtonResult = ((int)result - 2000); result = DialogResult.OK; } if (RadioButtonResult >= 1000) { RadioButtonResult -= 1000; // deduct the ButtonID start value for radio buttons } return(result); } else { // [OPTION 2] Show Emulated Form EmulatedTaskDialog td = new EmulatedTaskDialog(); //ML-2422: Can't confirm error message, with a lot of detailed information. td.ExpandedInfo = ExpandedInfo; try { int expandedInfoHeight = td.GetExpandedInfoLabelHeight; if (expandedInfoHeight > maxHeightExpandedInfo) { td.ExpandedInfo = td.ExpandedInfo.Substring(0, (int)(td.ExpandedInfo.Length * ((int)(maxHeightExpandedInfo / expandedInfoHeight)))); } } catch (Exception e) { Trace.WriteLine("Can't cut text in EmulatedTaskDialog: " + e.ToString()); } td.TopMost = true; td.Title = Title; td.MainInstruction = MainInstruction; td.Content = Content; td.Footer = Footer; td.RadioButtons = RadioButtons; td.CommandButtons = CommandButtons; td.Buttons = Buttons; td.MainIcon = MainIcon; td.FooterIcon = FooterIcon; td.VerificationText = VerificationText; td.Width = EmulatedFormWidth; td.BuildForm(); DialogResult result = td.ShowDialog(); RadioButtonResult = td.RadioButtonIndex; CommandButtonResult = td.CommandButtonClickedIndex; VerificationChecked = td.VerificationCheckBoxChecked; return(result); } }