/// <summary> /// Handles the VisibleChanged event of the WelcomePage 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 Dev05, 2009-02-27</remarks> private void WelcomePage_VisibleChanged(object sender, EventArgs e) { if (this.DesignMode) { return; } if (Visible) { try { if (ParentWizard == null) { return; } SourceSelectionPage sp = ParentWizard.Pages.Find(p => p is SourceSelectionPage) as SourceSelectionPage; dictionaryProperties.DictionaryLocation = sp.ConnectionString.ConnectionString; } catch (NullReferenceException) { dictionaryProperties.DictionaryLocation = MLifter.BusinessLayer.LearningModulesIndex.WritableConnections[0].ConnectionString; } } }
private void CreateNewLearningModule() { try { if (LearningModulesIndex.WritableConnections.Count <= 0) throw new NoWritableConnectionAvailableException(); //Close the current learning module if (LearnLogic.LearningModuleLoaded) if (!LearnLogic.CloseLearningModule()) return; //Create the wizard Wizard dicWizard = new Wizard(); dicWizard.HelpFile = MLifter.Classes.Help.HelpPath; dicWizard.Text = Resources.NEWDIC_CAPTION; SourceSelectionPage sourceSelectionPage = null; WelcomePage welcomePage = new WelcomePage(); SideSettingsPage sideSettingsPage = new SideSettingsPage(); // only one connection available? if (LearningModulesIndex.WritableConnections.Count <= 0) throw new NoWritableConnectionAvailableException(); else if (LearningModulesIndex.WritableConnections.Count > 1) { sourceSelectionPage = new SourceSelectionPage(); dicWizard.Pages.Add(sourceSelectionPage); } dicWizard.Pages.Add(welcomePage); dicWizard.Pages.Add(sideSettingsPage); //Show the Wizards if (dicWizard.ShowDialog() == DialogResult.OK) { try { newLM = true; IConnectionString connectionString; if (sourceSelectionPage != null) connectionString = sourceSelectionPage.ConnectionString; else connectionString = LearningModulesIndex.WritableConnections[0]; string dicName = welcomePage.DictionaryName; if (!LearningModulesIndex.ConnectionUsers.ContainsKey(connectionString)) { FolderIndexEntry folderEntry = new FolderIndexEntry(connectionString is UncConnectionStringBuilder ? connectionString.ConnectionString : string.Empty, connectionString.Name, connectionString, null, Setup.SyncedModulesPath, LearnLogic.GetLoginDelegate, LearnLogic.DataAccessErrorDelegate); LearningModulesIndex.ConnectionUsers[connectionString] = folderEntry.CurrentUser; } LearnLogic.User.SetBaseUser(LearningModulesIndex.ConnectionUsers[connectionString]); ConnectionStringStruct connectionStringStruct; using (MLifter.DAL.Interfaces.IDictionary newDic = LearnLogic.User.CreateLearningModule(welcomePage.DictionaryCategory.Id, welcomePage.DictionaryName)) { newDic.Author = welcomePage.DictionaryAuthor; newDic.Category = welcomePage.DictionaryCategory; newDic.Description = welcomePage.DictionaryDescription; newDic.DefaultSettings.AnswerCaption = sideSettingsPage.AnswerTitle; newDic.DefaultSettings.QuestionCaption = sideSettingsPage.QuestionTitle; newDic.DefaultSettings.AnswerCulture = sideSettingsPage.AnswerCulture; newDic.DefaultSettings.QuestionCulture = sideSettingsPage.QuestionCulture; newDic.Save(); connectionStringStruct = new ConnectionStringStruct(connectionString.ConnectionType == DatabaseType.Unc ? DatabaseType.MsSqlCe : connectionString.ConnectionType, newDic.Connection, newDic.Id, LearnLogic.User.SessionId); connectionStringStruct.LearningModuleFolder = connectionString.ConnectionString; } LearningModulesIndexEntry entry = new LearningModulesIndexEntry(); entry.ConnectionString = connectionStringStruct; entry.Author = welcomePage.DictionaryAuthor; entry.DisplayName = welcomePage.DictionaryName; entry.Description = welcomePage.DictionaryDescription; entry.Connection = connectionString; entry.User = LearningModulesIndex.ConnectionUsers[connectionString]; OpenLearningModule(entry); LearnLogic.SaveLearningModule(); this.Activate(); //[ML-763] Window is not focused after creation of a new dictionary OnLMOptionsChanged(); newLM = false; } catch (Exception exp) { Trace.WriteLine(exp.ToString()); TaskDialog.MessageBox(Resources.NEW_DICT_CAPTION, Resources.NEW_DICT_CAPTION, Resources.NEW_DICT_TEXT, exp.ToString(), string.Empty, string.Empty, TaskDialogButtons.OK, TaskDialogIcons.Error, TaskDialogIcons.Error); } } else ShowLearningModulesPage(); } catch (NoWritableConnectionAvailableException) { TaskDialog.MessageBox(Resources.NEW_DIC_NO_CONNECTION_CAPTION, Resources.NEW_DIC_NO_CONNECTION_CAPTION, Resources.NEW_DIC_NO_CONNECTION_TEXT, TaskDialogButtons.OK, TaskDialogIcons.Error); } }