private void AbortGroupCreation()
 {
     sql.Open();
     sql.TransactionBegin();
     try
     {
         sql.ExecuteNonQuery($"DELETE FROM Groups WHERE ID = '{GroupID}'");
         sql.ExecuteNonQuery($"DELETE FROM GroupAssigns WHERE GroupID = '{GroupID}'");
         sql.TransactionCommit();
     }
     catch
     {
         sql.TransactionRollback();
     }
     sql.Close();
 }
示例#2
0
        private bool SaveChanges()
        {
            QDLoader qdLoader = new QDLoader();

            qdLoader.Show();

            bool successOnline = false;
            bool successLocal  = false;

            if (!QDLib.ManagedDBOpen(mysql))
            {
                QDLib.DBOpenFailed(); return(false);
            }
            mysql.TransactionBegin();
            try
            {
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanToggleKeepLoggedIn.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanToggleKeepLoggedIn);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanSelfRegister.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanSelfRegister);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanAddPublicDrives.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanAddPublicDrive);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanAddPrivateDrives.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanAddPrivateDrive);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUseLoginAsDriveAuthentication.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UseLoginAsDriveAuthentication);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglForceLoginAsDriveAuthentication.ToggleState == ToggleButtonState.Active, QDInfo.DBO.ForceLoginAsDriveAuthentication);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglDisconnectDrivesAtShutdown.ToggleState == ToggleButtonState.Active, QDInfo.DBO.DisconnectDrivesAtShutdown);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglLogUserActions.ToggleState == ToggleButtonState.Active, QDInfo.DBO.LogUserActions);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanChangeManagerSettings.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanChangeManagerSettings);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", txbDefaultDomain.Text, QDInfo.DBO.DefaultDomain);

                mysql.TransactionCommit();
                successOnline = true;
            }
            catch
            {
                mysql.TransactionRollback();
            }

            mysql.Close();

            WrapMySQLData newDBConnection = new WrapMySQLData()
            {
                Hostname = txbDBHostname.Text,
                Database = txbDBDatabase.Text,
                Username = txbDBUsername.Text,
                Password = txbDBPassword.Text,
                Pooling  = false
            };

            using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
            {
                if (QDLib.TestConnection(newDBConnection, false))
                {
                    if (!QDLib.ManagedDBOpen(sqlite))
                    {
                        QDLib.DBOpenFailed(); return(false);
                    }
                    sqlite.TransactionBegin();

                    try
                    {
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Hostname, QDInfo.LocalCipherKey), QDInfo.DBL.DBHost);
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Database, QDInfo.LocalCipherKey), QDInfo.DBL.DBName);
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Username, QDInfo.LocalCipherKey), QDInfo.DBL.DBUsername);
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Password, QDInfo.LocalCipherKey), QDInfo.DBL.DBPassword);

                        sqlite.TransactionCommit();
                        successLocal = true;
                    }
                    catch
                    {
                        sqlite.TransactionRollback();
                    }

                    sqlite.Close();
                }
            }

            if (!successOnline || !successLocal)
            {
                if (MessageBox.Show("Could not save the changes made. Please check your MySQL-Connection and try again. \r\n\r\nDo you want to close the admin-console anyway?", "Could not save settins", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    successOnline = true;
                }
            }

            qdLoader.Close();

            return(successOnline && successLocal);
        }
示例#3
0
        private void CreateLocalDB(bool onlineLinked)
        {
            try
            {
                using (WrapSQLite sql = new WrapSQLite(QDInfo.ConfigFile))
                {
                    if (!QDLib.ManagedDBOpen(sql))
                    {
                        QDLib.DBOpenFailed(); return;
                    }
                    sql.TransactionBegin();
                    try
                    {
                        // Delete old tables
                        sql.ExecuteNonQuery("DROP TABLE IF EXISTS qd_info");
                        sql.ExecuteNonQuery("DROP TABLE IF EXISTS qd_drives");

                        // Create new tables
                        sql.ExecuteNonQuery(@"CREATE TABLE ""qd_info"" ( ""QDKey"" TEXT, ""QDValue"" TEXT, PRIMARY KEY(""QDKey""));");
                        sql.ExecuteNonQuery(@"CREATE TABLE ""qd_drives"" (""ID"" TEXT, ""LocalPath"" TEXT, ""RemotePath"" TEXT, ""Username"" TEXT, ""Password"" TEXT, ""Domain"" TEXT, ""DriveLetter"" TEXT, ""DriveName"" TEXT, PRIMARY KEY(""ID""));");

                        // Create pre-defined settings
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.IsOnlineLinked, onlineLinked);
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.AlwaysPromptPassword, alwaysPromptPassword);
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.SetupSuccess, true);

                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBHost, Cipher.Encrypt(onlineDBConDat.Hostname, QDInfo.LocalCipherKey));
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBName, Cipher.Encrypt(onlineDBConDat.Database, QDInfo.LocalCipherKey));
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBUsername, Cipher.Encrypt(onlineDBConDat.Username, QDInfo.LocalCipherKey));
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBPassword, Cipher.Encrypt(onlineDBConDat.Password, QDInfo.LocalCipherKey));

                        if (onlineLinked)
                        {
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultUsername, DBNull.Value);
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultPassword, DBNull.Value);
                        }
                        else
                        {
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultUsername, "local");
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultPassword, Cipher.Encrypt(localPassword, QDInfo.LocalCipherKey));
                        }


                        sql.TransactionCommit();
                    }
                    catch (Exception ex)
                    {
                        sql.TransactionRollback();
                        errorEncountered   = true;
                        txbS3ErrorLog.Text = ex.Message + " " + ex.StackTrace;
                    }
                    sql.Close();

                    if (errorEncountered)
                    {
                        MessageBox.Show("Could not create local database. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create local database. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorEncountered   = true;
                txbS3ErrorLog.Text = ex.Message + " " + ex.StackTrace;
            }
        }