Ejemplo n.º 1
0
        private void CreateButton_Click(object sender, EventArgs e)
        {
            bool   ok   = true;
            string name = nameTB.Text.TrimStart();

            if (string.IsNullOrEmpty(name))
            {
                nameTB.BorderColor = Color.Red;
                ok = false;
            }
            if (string.IsNullOrEmpty(pathTB.Text))
            {
                pathTB.BorderColor = Color.Red;
                ok = false;
            }

            if (!ok)
            {
                return;
            }

            string path = fs.Combine(pathTB.Text, name);

            if (fs.ExistsFile(path + ".mhdb"))
            {
                errorbox.Show(
                    $@"[MochaDB-Studio]
A database with this name already exists on this path.");
                return;
            }

            try {
                MochaDatabase.CreateMochaDB(path, descriptionTB.Text, passwordTB.Text);
                MochaDatabase db = new MochaDatabase($"path={path}; password={passwordTB.Text};logs=false;AutoConnect=true");

                var connectionPanel = new cncpanel(db);
                CNCList.AddItem(new sbutton()
                {
                    Text = name, Tag = connectionPanel
                });
                Close();
            } catch (MochaException excep) {
                if (excep.Message == "The password did not meet the password conventions!")
                {
                    passwordTB.BorderColor = Color.Red;
                }
                errorbox.Show("[MochaException]\n" + excep.Message);
            } catch (Exception excep) {
                errorbox.Show("[Exception]\n" + excep.Message + excep);
            }
        }
Ejemplo n.º 2
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(pathTB.Text))
            {
                pathTB.BorderColor = Color.Red;
                return;
            }

            MochaDatabase db = null;

            try {
                db = new MochaDatabase($@"
                    AutoConnect=True; Path={pathTB.Text};
                    Password={passwordTB.Text};
                    Logs={logToggle.Checked}");

                var connectionPanel = new cncpanel(db);
                CNCList.AddItem(new sbutton()
                {
                    Text = fs.GetFileNameFromPath(pathTB.Text), Tag = connectionPanel
                });
                Close();
            } catch (MochaException excep) {
                if (db != null)
                {
                    db.Dispose();
                }
                if (excep.Message == "MochaDB database password does not match the password specified!" ||
                    excep.Message == "The MochaDB database is password protected!")
                {
                    passwordTB.BorderColor = Color.Red;
                }
                else
                {
                    errorbox.Show("[MochaException]\n" + excep.Message);
                }
            } catch (Exception excep) {
                if (db != null)
                {
                    db.Dispose();
                }
                errorbox.Show("[Exception]\n" + excep.Message + excep);
            }
        }