Пример #1
0
        /// <summary>
        /// This checks if database is opened already,
        /// If it is then it asks of it can be closed
        /// </summary>
        /// <returns>True if no database was opened or if previous one was closed, false otherwise</returns>
        internal bool CheckCloseCurrentDatabase(string newDatabaseFilePath, DbEditorVM dbEditorVM)
        {
            if (workspaceMan.UnitOfWork != null)
            {
                if (IOHelper.GetNormalizedPath(newDatabaseFilePath) == IOHelper.GetNormalizedPath(DbName))
                {
                    //Root.Logger.Warning("Database already opened.");
                    return(false);
                }

                var answer = dialogProvider.ShowMessageWithQuestion($"Another database ({DbName}) is already opened. Do you want to close it?",
                                                                    "Close current database?",
                                                                    QuestionDialogButtons.OKCancel);
                if (answer != DialogAnswer.OK)
                {
                    return(false);
                }

                if (!TryCloseDatabase(dbEditorVM))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public bool TryOpenXmlDatabase(DbEditorVM dbEditorVM)
        {
            var openFileDialog = dialogProvider.OpenFileDialog();

            openFileDialog.Title            = "Select an Open Breed Editor Database file to open...";
            openFileDialog.Filter           = "Open Breed Editor Database files (*.xml)|*.xml|All Files (*.*)|*.*";
            openFileDialog.InitialDirectory = XmlDatabase.DefaultDirectoryPath;
            openFileDialog.Multiselect      = false;

            var answer = openFileDialog.Show();

            if (answer != DialogAnswer.OK)
            {
                return(false);
            }

            string databaseFilePath = openFileDialog.FileName;

            if (!CheckCloseCurrentDatabase(databaseFilePath, dbEditorVM))
            {
                return(false);
            }

            application.OpenXmlDatabase(databaseFilePath);

            DbName = workspaceMan.UnitOfWork.Name;

            return(true);
        }
Пример #3
0
        public void Initialize(DbEditorVM vm)
        {
            _vm = vm ?? throw new ArgumentNullException(nameof(vm));

            _vm.EntryEditorOpeningAction = (editor) => OnEntryEditorOpening(editor);
            //_vm.EntryEditorActivateAction = (editor) => OnEntryEditorActivate(editor);

            RestoreLayout();
        }
Пример #4
0
        public bool TryCloseDatabase(DbEditorVM dbEditorVM)
        {
            if (TrySaveBeforeClosing(dbEditorVM))
            {
                DbName = null;
                application.CloseDatabase();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        private bool TrySaveBeforeClosing(DbEditorVM dbEditorVM)
        {
            if (workspaceMan.UnitOfWork != null)
            {
                if (dbEditorVM.IsModified)
                {
                    var answer = application.DialogProvider.ShowMessageWithQuestion("Current database has been modified. Do you want to save it before closing?",
                                                                                    "Save database before closing?", QuestionDialogButtons.YesNoCancel);

                    if (answer == DialogAnswer.Cancel)
                    {
                        return(false);
                    }
                    else if (answer == DialogAnswer.Yes)
                    {
                        application.SaveDatabase();
                    }
                }
            }

            return(true);
        }