Пример #1
0
        private void btnOK_Clicked(object o, EventArgs args)
        {
            string newDb = DatabaseName;

            if (newDb.Length == 0)
            {
                MessageError.ShowDialog(Translator.GetString("Please, enter the name of the new database!"),
                                        "Icons.Database32.png");
                txtName.GrabFocus();
                return;
            }

            if (!BusinessDomain.IsValidDatabaseName(newDb))
            {
                MessageError.ShowDialog(Translator.GetString("The entered database name contains invalid characters!"),
                                        "Icons.Database32.png");
                txtName.GrabFocus();
                return;
            }

            if (BusinessDomain.SetCurrentDatabase(newDb))
            {
                MessageError.ShowDialog(string.Format(Translator.GetString("A database with the name of \"{0}\" already exists!"), newDb),
                                        "Icons.Database32.png");
                txtName.GrabFocus();
                return;
            }

            // We don't need that dialog to clutter the visual space any more
            dlgNewDatabase.Hide();

            try {
                if (DatabaseType != CreateDatabaseType.Other)
                {
                    using (MessageProgress dlgProg = new MessageProgress(
                               Translator.GetString("Creating New Database"), "Icons.DBNew24.png",
                               string.Format(Translator.GetString("Creating database \"{0}\"..."), newDb))) {
                        dlgProg.Show();

                        BusinessDomain.CreateDatabase(newDb, DatabaseType, dlgProg.ProgressCallback);
                    }
                }
                else
                {
                    foreach (KeyValuePair <RadioButton, IDatabaseCreator> creator in customCreators.Where(creator => creator.Key.Active))
                    {
                        if (!creator.Value.Create(newDb))
                        {
                            dlgNewDatabase.Respond(ResponseType.Apply);
                            return;
                        }

                        break;
                    }
                }
            } catch (Exception ex) {
                IOException ioException = ex as IOException;
                if (ioException != null && ioException.Data.Contains("Path"))
                {
                    MessageError.ShowDialog(string.Format(Translator.GetString("Error occurred while creating database \"{0}\"! Please check if you have permissions to create a new database file: \"{1}\"."), newDb, ioException.Data ["Path"]),
                                            ErrorSeverity.Error, ex);
                }
                else
                {
                    MessageError.ShowDialog(string.Format(Translator.GetString("Error occurred while creating database \"{0}\"! Please check the database name for invalid characters and if you have permissions to create a new database."), newDb),
                                            ErrorSeverity.Error, ex);
                }

                dlgNewDatabase.Respond(ResponseType.Cancel);
                return;
            }

            dlgNewDatabase.Respond(ResponseType.Ok);
        }