Beispiel #1
0
        private void Connect(SQLType dbtype)
        {
            DatabaseAccess data;

            if (this.DbAccessSetter == null)
            {
                GlobalData.makeInstance(text_host.Text, text_port.Text, text_user.Text, text_pass.Text, text_dbname.Text, dbtype);
                GlobalData.Instance.data.isReadonly = checkBox_MySQL_readonly.Checked;
                data = GlobalData.Instance.data;
            }
            else
            {
                data            = new DatabaseAccess(text_host.Text, text_port.Text, text_user.Text, text_pass.Text, text_dbname.Text, dbtype);
                data.isReadonly = true;
                this.DbAccessSetter(data);
            }

            //Config取得
            DbConfig cfg = null;

            try
            {
                cfg = DbConfig.MakeFromDB(data);
            }
            catch (Exception ecfg)
            {
                MessageBox.Show("データベースから設定が取得できませんでした。正しい接続先・ファイルを指定していますか?\n"
                                + ecfg.Message);
                if (this.DbAccessSetter == null)
                {
                    GlobalData.disposeInstance();
                }
                else
                {
                    this.DbAccessSetter(null);
                }
                return;
            }

            data.bumonName      = cfg.getValue("bumonname");
            data.companyName    = cfg.getValue("companyname");
            data.symbolColor    = System.Drawing.Color.FromArgb(cfg.getValueInt("symbolcolor_argb"));
            data.bumonTextColor = System.Drawing.Color.FromArgb(cfg.getValueInt("bumontextcolor_argb"));

            if (this.DbAccessSetter == null)
            {
                GlobalData.Instance.windowTitle = "ゆかり姫萌え萌えソフトウェア";

                GlobalData.Instance.barcodePrefix = cfg.getValue("barcodeprefix");
                if (!Globals.isValidBarcodePrefix(GlobalData.Instance.barcodePrefix))
                {
                    MessageBox.Show("バーコード識別子 (barcodeprefix) が不正です。正常なバーコードが印刷されませんよ");
                    GlobalData.Instance.barcodePrefix = "00";
                }
                GlobalData.Instance.itemNameImeOn = cfg.getValueBool("itemname_imeon");
                GlobalData.Instance.enterToTab    = cfg.getValueBool("entertotab");

                Program.config.BackupDirectory = this.textBox_backupdest.Text;

                GlobalData.Instance.recentItemForm = new RecentItem();
            }

            if (data.db_type == SQLType.SQLite)
            {
                Program.config.AddRecentSQLite(data.companyName, text_dbname.Text);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }