/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Show the dialog to allow the user to specify a FieldWorks database as a data source.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void HandleAddFw7DataSourceClick(object sender, EventArgs e)
        {
            string name;
            string server;

            if (!FwDBUtils.GetFw7Project(this, out name, out server))
            {
                return;
            }

            Utils.WaitCursors(true);
            var info = new FwDataSourceInfo(name, server, DataSourceType.FW7);

            if (ProjectContainsFwDataSource(info) &&
                Utils.MsgBox(string.Format(DupDataSourceMsg, info.ProjectName),
                             MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            _dataSources.Add(new PaDataSource(Project.Fields, info));
            LoadGrid(m_grid.Rows.Count);
            m_dirty = true;
            Utils.WaitCursors(false);
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        private IEnumerable <FieldMapping> CreateDefaultFw7Mappings(IEnumerable <PaField> projectFields)
        {
            var prjFields         = projectFields.ToArray();
            var writingSystems    = FwDataSourceInfo.GetWritingSystems().ToArray();
            var defaultFieldNames = Properties.Settings.Default.DefaultMappedFw7Fields.Cast <string>()
                                    .Where(n => n != PaField.kAudioFileFieldName).ToList();

            // Add a mapping for the phonetic field.
            //yield return new FieldMapping(prjFields.First(f => f.Type == FieldType.Phonetic), true)
            //	{ FwWsId = FwDBUtils.GetDefaultPhoneticWritingSystem(writingSystems).Id };

            // Add a mapping for the audio file field.
            var    audioWs   = FwDBUtils.GetDefaultAudioWritingSystem(writingSystems);
            string audioWsId = audioWs != null ? audioWs.Id : null;

            yield return(new FieldMapping(prjFields.Single(f => f.Type == FieldType.AudioFilePath), false)
            {
                FwWsId = audioWsId
            });

            // Add mappings for all the other fields.
            foreach (var mapping in prjFields.Where(f => defaultFieldNames.Contains(f.Name))
                     .Select(field => new FieldMapping(field, Properties.Settings.Default.ParsedFw7Fields.Cast <string>())))
            {
                FieldMapping.CheckMappingsFw7WritingSystem(mapping, writingSystems);
                yield return(mapping);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Show the dialog to allow the user to specify a FieldWorks database as a data source.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void HandleAddFw6DataSourceClick(object sender, EventArgs e)
        {
            // Make sure SQL Server is started.
            if (!FwDBUtils.IsSQLServerStarted && !FwDBUtils.StartSQLServer(true))
            {
                return;
            }

            using (var dlg = new FwProjectsDlg())
            {
                if (dlg.ShowDialog(this) == DialogResult.OK && dlg.ChosenDatabase != null)
                {
                    if (ProjectContainsFwDataSource(dlg.ChosenDatabase) &&
                        Utils.MsgBox(string.Format(DupDataSourceMsg, dlg.ChosenDatabase.ProjectName),
                                     MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }

                    _dataSources.Add(new PaDataSource(Project.Fields, dlg.ChosenDatabase));
                    LoadGrid(m_grid.Rows.Count);
                    m_dirty = true;
                }
            }
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Verifies the existence of the specified FW data source.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void CheckExistenceOfFwDatabase(PaDataSource ds)
        {
            if (ds == null)
            {
                return;
            }

            if (!FwDBUtils.IsSQLServerStarted && !FwDBUtils.StartSQLServer(true))
            {
                return;
            }

            if (ds.FwDataSourceInfo != null)
            {
                var fwDBInfoList =
                    FwDBUtils.GetFwDataSourceInfoList(ds.FwDataSourceInfo.Server, false);

                if (fwDBInfoList.Any(fwinfo => ds.FwPrjName == fwinfo.Name))
                {
                    return;
                }

                ds.FwDataSourceInfo.IsMissing = true;
            }

            MissingFWDatabaseMsgBox.ShowDialog(ds.ToString(true));
            ds.SkipLoadingBecauseOfProblem = true;
        }
        /// ------------------------------------------------------------------------------------
        public ProjectSettingsDlg(PaProject project)
            : this()
        {
            Application.DoEvents();

            _isProjectNew          = (project == null);
            _chkMakeFolder.Visible = (_isProjectNew && !Properties.Settings.Default.AutoCreateProjectFilesAndFolderOnProjectCreation);
            _chkMakeFolder.Checked = (Properties.Settings.Default.CreateProjectFolderForNewProject || !_chkMakeFolder.Visible);

            BuildGrid();
            pnlGridHdg.ControlReceivingFocusOnMnemonic = m_grid;
            pnlGridHdg.BorderStyle = BorderStyle.None;

            if (project == null)
            {
                Project = new PaProject(true);
            }
            else
            {
                Project = project;
                _originallyMappedFields = project.GetMappedFields().Select(f => f.Name).ToList();
                _dataSources            = project.DataSources.Select(ds => ds.Copy()).ToList();
                txtProjName.Text        = project.Name;
                txtLanguageName.Text    = project.LanguageName;
                txtLanguageCode.Text    = project.LanguageCode;
                txtResearcher.Text      = project.Researcher;
                txtTranscriber.Text     = project.Transcriber;
                txtSpeaker.Text         = project.SpeakerName;
                txtComments.Text        = project.Comments;
                LoadGrid(-1);
            }

            WaitCursor.Show();

            if (Project.DistinctiveFeatureSet == BFeatureCache.DefaultFeatureSetName)
            {
                _comboDistinctiveFeaturesSet.SelectedIndex = 0;
            }
            else
            {
                _comboDistinctiveFeaturesSet.SelectedItem = Project.DistinctiveFeatureSet;
            }

            if (_dataSources.Any(ds => ds.Type == DataSourceType.FW))
            {
                FwDBUtils.StartSQLServer(true);
            }

            mnuAddFw6DataSource.Enabled = FwDBUtils.IsSQLServerInstalled(false);
            mnuAddFw7DataSource.Enabled = FwDBUtils.IsFw7Installed;

            DialogResult   = DialogResult.Cancel;
            m_dirty        = _isProjectNew;
            m_grid.IsDirty = false;
            WaitCursor.Hide();

            UpdateButtonStates();
        }
Exemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        private IEnumerable <FieldMapping> CreateDefaultFw6Mappings(IEnumerable <PaField> projectFields)
        {
            var writingSystems    = FwDataSourceInfo.GetWritingSystems();
            var defaultFieldNames = Properties.Settings.Default.DefaultMappedFw6Fields.Cast <string>();

            // Add mappings for all the other fields.
            return(from field in projectFields.Where(f => defaultFieldNames.Contains(f.Name))
                   let wsId = (field.Type == FieldType.Phonetic ?
                               FwDBUtils.GetDefaultPhoneticWritingSystem(writingSystems).Hvo.ToString() :
                               FieldMapping.GetDefaultFw6WsIdForField(field, writingSystems))
                              select new FieldMapping(field, field.Type == FieldType.Phonetic)
            {
                FwWsId = wsId
            });
        }
Exemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Cycles through the data sources, checking if any are sources directly from a
        /// FW database. If so, then an attempt is made to start SQL server if it isn't
        /// already started.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void CheckNeedForSQLServer(IEnumerable <PaDataSource> dataSourcesToLoad)
        {
            bool alreadyTriedToStartSQLServer = false;

            foreach (var ds in dataSourcesToLoad.Where(ds => ds.Type == DataSourceType.FW && ds.FwSourceDirectFromDB))
            {
                if (!alreadyTriedToStartSQLServer && FwDBUtils.StartSQLServer(true))
                {
                    return;
                }

                alreadyTriedToStartSQLServer   = true;
                ds.SkipLoadingBecauseOfProblem = true;
            }
        }
Exemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        private void InitializePhoneticAndAudioFieldInfo()
        {
            var vernOptions = m_potentialVernacularFields.Select(f => f.Name).ToArray();

            cboVernacularOptions.Items.AddRange(vernOptions);
            cboVernacularOptions.SelectedItem = null;
            if (m_vernacularMapping != null)
            {
                cboVernacularOptions.SelectedItem = vernOptions.FirstOrDefault(v => v == m_vernacularMapping.NameInDataSource);
                m_selectedvernacularItem          = m_vernacularMapping.Field;
            }
            if (cboVernacularOptions.SelectedItem == null)
            {
                cboVernacularOptions.SelectedItem = vernOptions.Contains("LexemeForm") ? "LexemeForm" : cboVernacularOptions.Items[0];
                m_selectedvernacularItem          = m_potentialVernacularFields.FirstOrDefault(v => v.Name == "LexemeForm");
            }
            cboPhoneticWritingSystem.Items.AddRange(m_datasource.FwDataSourceInfo.GetWritingSystems()
                                                    .Where(ws => ws.Type == FwDBUtils.FwWritingSystemType.Vernacular)
                                                    .Select(ws => ws.Name).ToArray());

            // Set the phonetic writing system combo's initial value.
            var writingSystems = m_datasource.FwDataSourceInfo.GetWritingSystems().ToArray();
            var fwws           = writingSystems.SingleOrDefault(ws => ws.Id == m_phoneticMapping.FwWsId);

            cboPhoneticWritingSystem.SelectedItem = (fwws != null ? fwws.Name : cboPhoneticWritingSystem.Items[0]);

            InitializePronunciationCombo();

            if (m_datasource.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.PronunciationField)
            {
                cboPronunciationOptions.SelectedIndex = 0;
            }
            else if (m_datasource.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.AllPronunciationFields)
            {
                cboPronunciationOptions.SelectedIndex = 1;
            }

            rbVernForm.Checked =
                (m_datasource.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.LexemeForm);

            rbPronunField.Checked =
                (m_datasource.FwDataSourceInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.LexemeForm);

            // update audio WS in case it changed or has now been defined
            var audioWs = FwDBUtils.GetDefaultAudioWritingSystem(writingSystems);

            m_audioFileMapping.FwWsId = audioWs != null ? audioWs.Id : null;
        }
Exemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        private void HandleNetworkTreeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            var node = e.Node as NetworkTreeNode;

            if (node == null)
            {
                return;
            }

            Utils.WaitCursors(true);
            btnOK.Enabled = false;
            lstFwProjects.SelectedIndex = -1;
            lstFwProjects.Items.Clear();
            txtMsg.Text           = string.Empty;
            txtMsg.Visible        = true;
            lstFwProjects.Visible = false;

            if (!string.IsNullOrEmpty(node.MachineName))
            {
                txtMsg.Text    = LocalizationManager.GetString("DialogBoxes.Fw6ProjectsDlg.SearchingForFwDatabasesMsg", "Searching...");
                txtMsg.Visible = true;
                Application.DoEvents();

                lstFwProjects.Items.Clear();

                var dsInfo = FwDBUtils.GetFwDataSourceInfoList(node.MachineName, true).ToArray();
                if (dsInfo.Length > 0)
                {
                    lstFwProjects.Items.AddRange(dsInfo);
                    lstFwProjects.SelectedIndex = 0;
                    lstFwProjects.Visible       = true;
                    txtMsg.Visible = false;
                }
                else
                {
                    var fmt = LocalizationManager.GetString("DialogBoxes.Fw6ProjectsDlg.NoFwProjectsFoundMsg", "No projects found on '{0}'.");
                    txtMsg.Text = string.Format(fmt, node.MachineName);
                }
            }

            Utils.WaitCursors(false);
        }