Beispiel #1
0
        public static bool Update(Setting setting)
        {
            try
            {
                String update_sql       = "UPDATE " + TABLE_NAME + " SET NAME=@name ,VALUE=@value WHERE ID=@id";

                //Sql command
                sql_command             = new MySqlCommand();
                sql_command.Connection  = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText = update_sql;

                sql_command.Parameters.AddWithValue("@name", setting.name);
                sql_command.Parameters.AddWithValue("@value", setting.value);
                sql_command.Parameters.AddWithValue("@id", setting.id);
                sql_command.Prepare();

                //execute command
                database.Update(sql_command);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                CloseDatabaseConnection();
            }
        }
Beispiel #2
0
        public static bool Save(Setting setting)
        {
            try
            {
                //sql statement
                String insert_sql       = "INSERT INTO " + TABLE_NAME + " (NAME,VALUE) values(@name,@value)";

                //Sql command
                sql_command             = new MySqlCommand();
                sql_command.CommandText = insert_sql;
                sql_command.Connection  = (MySqlConnection)database.OpenConnection();
                sql_command.Parameters.AddWithValue("@name", setting.name);
                sql_command.Parameters.AddWithValue("@value", setting.value);

                sql_command.Prepare();

                //execute command
                database.Insert(sql_command);

                setting.id = Convert.ToInt32(sql_command.LastInsertedId);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                CloseDatabaseConnection();
            }
        }
Beispiel #3
0
 public static bool PopulateTable()
 {
     try
     {
         Setting similarity_threshold = new Setting("similarity_threshold", "70");
         Setting theme                = new Setting("theme", "Dark");
         SettingsManager.Save(similarity_threshold);
         SettingsManager.Save(theme);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Beispiel #4
0
        public static Setting GetSetting(SETTINGS settings_name)
        {
            String setting_name = GetSettingsName(settings_name);

            //resultant object
            Setting setting             = null;

            try
            {
                //sql
                String select_sql       = "SELECT * FROM " + TABLE_NAME + " WHERE NAME=@name";

                //Sql command
                sql_command             = new MySqlCommand();
                sql_command.Connection  = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText = select_sql;

                sql_command.Parameters.AddWithValue("@name", setting_name);

                sql_command.Prepare();

                //execute command
                data_reader             = database.Select(sql_command);

                //while there are results
                if (data_reader.Read())
                {
                    //create object
                    String value        = data_reader.GetString(VALUE);
                    int id              = data_reader.GetInt32(ID);
                    setting             = new Setting(id,setting_name,value);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            finally
            {
                //close reader
                CloseDatabaseConnection();
            }
            return setting;
        }
Beispiel #5
0
        public static Setting[] GetAllSettings()
        {
            //resultant object
            List<Setting> settings      = new List<Setting>();

            try
            {
                //sql
                String select_sql       = "SELECT * FROM " + TABLE_NAME;

                //Sql command
                sql_command             = new MySqlCommand();
                sql_command.CommandText = select_sql;
                sql_command.Prepare();

                //execute command
                data_reader             = database.Select(sql_command);

                //while there are results
                if (data_reader.Read())
                {
                    //create object
                    String name         = data_reader.GetString(NAME);
                    String value        = data_reader.GetString(VALUE);
                    int id              = data_reader.GetInt32(ID);

                    Setting setting     = new Setting(id,name, value);

                    //add to list
                    settings.Add(setting);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            finally
            {
                //close reader
                CloseDatabaseConnection();
            }
            return settings.ToArray();
        }
Beispiel #6
0
        private void user_login_Click(object sender, EventArgs e)
        {
            //ENABLE SOME STUFF
            timer1.Start();
            progressBar.Visible = true;

            //GET USER INPUT
            String username           = txtbox_username.Text;
            String email              = email_textbox.Text;
            String phone_number       = phone_textbox.Text;
            String password           = txtbox_password.Text;
            String confirmed_password = txtbox_confirmedPassword.Text;
            String images_folder      = txtbox_saveImagesPath.Text;

            //IF SOME FIELDS ARE EMPTY
            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(confirmed_password))
            {
                //disable some stuff
                timer1.Stop();
                progressBar.Enabled   = false;
                progressBar.Visible   = false;
                progressBar.Value     = 0;
                label5.Visible        = true;
                label5.Text           = "Please Enter A Valid Username/Password ";
                return;
            }

            //IF THE PASSWORDS DONT MATCH
            if (!password.Equals(confirmed_password))
            {
                //disable some stuff
                timer1.Stop();
                progressBar.Enabled   = false;
                progressBar.Visible   = false;
                progressBar.Value     = 0;
                label5.Visible        = true;
                label5.Text           = "Sorry!! Your Password Entries Dont Match ";
                return;
            }

            //CREATE OBJECTS

            Setting setting           = new Setting("images_folder", images_folder);
            Admin admin = new Admin(username, password, email, phone_number, "Admin");

            //DROP ALL TABLES IN DATABASE
            DatabaseManager.DropTables();

            //CREATE NEW TABLES
            DatabaseManager.CreateTables();

            //POPULATE THEM WITH INITIAL DATA
            DatabaseManager.PopulateTables();

            //SAVE HIS IMAGES FOLDER AS A SETTING
            SettingsManager.Save(setting);

            AdminManager.Save(admin);
        }