Exemplo n.º 1
0
        private void buttonRegister_Click(object sender, EventArgs e)
        {
            DB db = new DB();

            MySqlDataReader reader;

            MySqlCommand command_log = new MySqlCommand("select sotrudnik.id from `sotrudnik` join vxod on SOTRUDNIK.id = SOTRUDNIK_id WHERE login = @login", db.getConnection());

            command_log.Parameters.Add("@login", MySqlDbType.VarChar).Value = userNameField.Text;


            db.openConnection();

            reader = command_log.ExecuteReader();
            while (reader.Read())
            {
                log_id = reader["id"].ToString();
            }

            db.closeConnection();

            MySqlCommand command_vxod_id = new MySqlCommand("select vxod.id from `sotrudnik` join vxod on SOTRUDNIK.id = SOTRUDNIK_id WHERE login = @login", db.getConnection());

            command_vxod_id.Parameters.Add("@login", MySqlDbType.VarChar).Value = userNameField.Text;


            db.openConnection();

            reader = command_vxod_id.ExecuteReader();
            while (reader.Read())
            {
                vxod_id = reader["id"].ToString();
            }

            db.closeConnection();

            MySqlCommand command_del_vxod = new MySqlCommand("DELETE FROM `oborot`.`vxod` WHERE (`id` = @vxod_id);", db.getConnection());

            command_del_vxod.Parameters.Add("@vxod_id", MySqlDbType.VarChar).Value = vxod_id;

            db.openConnection();

            command_del_vxod.ExecuteNonQuery();

            db.closeConnection();

            MySqlCommand command = new MySqlCommand("DELETE FROM `oborot`.`sotrudnik` WHERE (`id` = @log_id);", db.getConnection());

            command.Parameters.Add("@log_id", MySqlDbType.VarChar).Value = log_id;

            db.openConnection();

            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Аккаунт удален");
            }
            else
            {
                MessageBox.Show("Аккаунт не удален");
            }

            db.closeConnection();
        }