示例#1
0
        public static bool Execute(out DBLangEngine.DatabaseType dbType, out string connStr, out string captionStr, out string schema)
        {
            FormLoginDatabase frm = new FormLoginDatabase();

            schema = string.Empty;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                KeyValuePair <DBLangEngine.DatabaseType, string> v = (KeyValuePair <DBLangEngine.DatabaseType, string>)frm.cmbDatabaseType.SelectedItem;
                dbType = v.Key;
                switch (v.Key)
                {
                case DBLangEngine.DatabaseType.dtSQLite:
                    connStr    = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : "Data Source=" + frm.tbServer.Text + ";Pooling=true;FailIfMissing=false";
                    captionStr = frm.tbServer.Text;
                    break;

                case DBLangEngine.DatabaseType.dtMySQL:
                    connStr    = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};CharSet=utf8;", frm.tbServer.Text, frm.nudPort.Value, frm.tbDatabase.Text, frm.tbUser.Text, frm.tbPassword.Text);
                    captionStr = frm.tbServer.Text + ":" + frm.tbDatabase.Text;
                    break;

                case DBLangEngine.DatabaseType.dtPostgreSQL:
                    connStr    = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", frm.tbServer.Text, frm.nudPort.Value, frm.tbDatabase.Text, frm.tbUser.Text, frm.tbPassword.Text);
                    captionStr = frm.tbServer.Text + ":" + frm.tbDatabase.Text;
                    schema     = frm.tbSchema.Text;
                    break;

                case DBLangEngine.DatabaseType.dtMSSQL:
                    connStr    = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : string.Format("Persist Security Info=False;User ID={3};Password={4};Initial Catalog={2};Server={0};", frm.tbServer.Text, frm.nudPort.Value, frm.tbDatabase.Text, frm.tbUser.Text, frm.tbPassword.Text);
                    captionStr = frm.tbServer.Text + ":" + frm.tbDatabase.Text;
                    schema     = frm.tbSchema.Text;
                    break;

                default:
                    connStr    = string.Empty;
                    captionStr = "DBLangVersion";
                    break;
                }
                return(true);
            }
            connStr    = string.Empty;
            dbType     = DBLangEngine.DatabaseType.dtSQLite;
            captionStr = "DBLangVersion";
            return(false);
        }
示例#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();
            }
        }
示例#3
0
        public FormSelectDBType()
        {
            InitializeComponent();
            Array dbs = Enum.GetValues(typeof(DBLangEngine.DatabaseType));

            cmbDatabaseType.DisplayMember = "Value";

            foreach (var value in dbs)
            {
                KeyValuePair <DBLangEngine.DatabaseType, string> v = new KeyValuePair <DBLangEngine.DatabaseType, string>((DBLangEngine.DatabaseType)value, FormLoginDatabase.GetEnumDescription((DBLangEngine.DatabaseType)value));
                cmbDatabaseType.Items.Add(v);
            }

            cmbDatabaseType.SelectedIndex = 0;
        }