Exemplo n.º 1
0
        private void OpenDatabase(string fileName)
        {
            try
            {
                CloseDBConnection();
                connStr    = "Data Source=" + fileName + ";Pooling=true;FailIfMissing=false";
                connSQLite = new SQLiteConnection(connStr);
                connSQLite.Open();
                culture     = new Culture(ref connSQLite);
                currentFile = fileName;
                captionStr  = fileName;
                dbType      = DBLangEngine.DatabaseType.dtSQLite;
                schema      = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to database ('" + ex.Message + "').", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SQLs.SetSchema(DBLangEngine.DatabaseType.dtSQLite, schema);

            Text                      = "DBLangVersion [" + captionStr + "]";
            mnuSave.Enabled           = true;
            mnuAddFromCulture.Enabled = true;
            mnuRemoveUnused.Enabled   = true;
            cmbCulture.Enabled        = true;

            mnuExportDatabase.Enabled = dbType == DBLangEngine.DatabaseType.dtSQLite;


            mnuAddFomEN_US.Enabled          = false;
            mnuSelectCurrentCulture.Enabled = true;
            mnuDumpData.Enabled             = true;

            cmbCulture.Items.AddRange(culture.Cultures.ToArray());
            for (int i = 0; i < cmbCulture.Items.Count; i++)
            {
                if ((cmbCulture.Items[i] as Culture).LCID == 1033)
                {
                    cmbCulture.SelectedIndex = i;
                }
                cmbCulture.AutoCompleteCustomSource.Add((cmbCulture.Items[i] as Culture).NativeName);
            }

            mnuSelectSomeCulture.Enabled = true;
            ListCulturesMenu();
        }
Exemplo n.º 2
0
        private void mnuLoadDB_Click(object sender, EventArgs e)
        {
            if (FormLoginDatabase.Execute(out dbType, out connStr, out captionStr, out schema))
            {
                CloseDBConnection();
                try
                {
                    if (dbType == DBLangEngine.DatabaseType.dtSQLite)
                    {
                        connSQLite = new SQLiteConnection(connStr);
                    }
                    else if (dbType == DBLangEngine.DatabaseType.dtMySQL)
                    {
                        connMySQL = new MySqlConnection(connStr);
                    }
                    else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL)
                    {
                        connPostgreSQL = new NpgsqlConnection(connStr);
                    }
                    else if (dbType == DBLangEngine.DatabaseType.dtMSSQL)
                    {
                        connMSSQL = new SqlConnection(connStr);
                    }

                    if (dbType == DBLangEngine.DatabaseType.dtSQLite)
                    {
                        connSQLite.Open();
                        culture = new Culture(ref connSQLite);
                    }
                    else if (dbType == DBLangEngine.DatabaseType.dtMySQL)
                    {
                        connMySQL.Open();
                        culture = new Culture(ref connMySQL);
                    }
                    else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL)
                    {
                        connPostgreSQL.Open();
                        culture = new Culture(ref connPostgreSQL);
                    }
                    else if (dbType == DBLangEngine.DatabaseType.dtMSSQL)
                    {
                        connMSSQL.Open();
                        culture = new Culture(ref connMSSQL);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to connect to database ('" + ex.Message + "').", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                SQLs.SetSchema(dbType, schema);

                Text                      = "DBLangVersion [" + captionStr + "]";
                mnuSave.Enabled           = true;
                mnuAddFromCulture.Enabled = true;
                mnuRemoveUnused.Enabled   = true;
                cmbCulture.Enabled        = true;


                mnuAddFomEN_US.Enabled          = false;
                mnuSelectCurrentCulture.Enabled = true;
                mnuDumpData.Enabled             = true;

                mnuExportDatabase.Enabled = dbType == DBLangEngine.DatabaseType.dtSQLite;

                cmbCulture.Items.AddRange(culture.Cultures.ToArray());
                for (int i = 0; i < cmbCulture.Items.Count; i++)
                {
                    if ((cmbCulture.Items[i] as Culture).LCID == 1033)
                    {
                        cmbCulture.SelectedIndex = i;
                    }
                    cmbCulture.AutoCompleteCustomSource.Add((cmbCulture.Items[i] as Culture).NativeName);
                }

                mnuSelectSomeCulture.Enabled = true;
                ListCulturesMenu();
            }
        }