using System;
using MySql.Data.MySqlClient;
using System.Collections.Generic;

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
}

public class DatabaseConnection
{
    private readonly string _connectionString;

    public DatabaseConnection(string connectionString)
    {
        _connectionString = connectionString;
    }

    // Get all products from the database.
    public List<Product> GetAllProducts()
    {
        var products = new List<Product>();

        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("SELECT * FROM products;", connection))
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    products.Add(new Product
                    {
                        Id = reader.GetInt32(0),
                        Name = reader.GetString(1),
                        Description = reader.GetString(2),
                        Price = reader.GetDecimal(3),
                        Quantity = reader.GetInt32(4)
                    });
                }
            }
        }

        return products;
    }

    // Add a new product to the database.
    public void AddProduct(Product product)
    {
        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("INSERT INTO products (name, description, price, quantity) VALUES (@Name, @Description, @Price, @Quantity);", connection))
            {
                command.Parameters.AddWithValue("@Name", product.Name);
                command.Parameters.AddWithValue("@Description", product.Description);
                command.Parameters.AddWithValue("@Price", product.Price);
                command.Parameters.AddWithValue("@Quantity", product.Quantity);

                command.ExecuteNonQuery();
            }
        }
    }

    // Update an existing product in the database.
    public void UpdateProduct(Product product)
    {
        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("UPDATE products SET name=@Name, description=@Description, price=@Price, quantity=@Quantity WHERE id=@Id;", connection))
            {
                command.Parameters.AddWithValue("@Id", product.Id);
                command.Parameters.AddWithValue("@Name", product.Name);
                command.Parameters.AddWithValue("@Description", product.Description);
                command.Parameters.AddWithValue("@Price", product.Price);
                command.Parameters.AddWithValue("@Quantity", product.Quantity);

                command.ExecuteNonQuery();
            }
        }
    }

    // Delete a product from the database by its ID.
    public void DeleteProduct(int id)
    {
        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("DELETE FROM products WHERE id=@Id;", connection))
            {
                command.Parameters.AddWithValue("@Id", id);
                command.ExecuteNonQuery();
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        // Replace with your own connection string.
        var connectionString = "server=localhost;user=root;password=your_password;database=test";
        var dbConnection = new DatabaseConnection(connectionString);

        while (true)
        {
            Console.WriteLine("1. View products");
            Console.WriteLine("2. Add product");
            Console.WriteLine("3. Update product");
            Console.WriteLine("4. Delete product");
            Console.WriteLine("5. Exit");

            int choice;
            if (!int.TryParse(Console.ReadLine(), out choice))
            {
                Console.WriteLine("Invalid input. Please try again.");
                continue;
            }

            switch (choice)
            {
                case 1:
                    var products = dbConnection.GetAllProducts();
                    foreach (var product in products)
                    {
                        Console.WriteLine($"ID: {product.Id}, Name: {product.Name}, Description: {product.Description}, Price: {product.Price}, Quantity: {product.Quantity}");
                    }
                    break;
                case 2:
                    // Add product
                    break;
                case 3:
                    // Update product
                    break;
                case 4:
                    // Delete product
                    break;
                case 5:
                    return;
                default:
                    Console.WriteLine("Invalid option. Please try again.");
                    break;
            }
        }
    }
}
using System;
using MySql.Data.MySqlClient;
using System.Collections.Generic;

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
}

public class DatabaseConnection
{
    private readonly string _connectionString;

    public DatabaseConnection(string connectionString)
    {
        _connectionString = connectionString;
    }

    // Get all products from the database.
    public List<Product> GetAllProducts()
    {
        var products = new List<Product>();

        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("SELECT * FROM products;", connection))
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    products.Add(new Product
                    {
                        Id = reader.GetInt32(0),
                        Name = reader.GetString(1),
                        Description = reader.GetString(2),
                        Price = reader.GetDecimal(3),
                        Quantity = reader.GetInt32(4)
                    });
                }
            }
        }

        return products;
    }

    // Add a new product to the database.
    public void AddProduct(Product product)
    {
        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("INSERT INTO products (name, description, price, quantity) VALUES (@Name, @Description, @Price, @Quantity);", connection))
            {
                command.Parameters.AddWithValue("@Name", product.Name);
                command.Parameters.AddWithValue("@Description", product.Description);
                command.Parameters.AddWithValue("@Price", product.Price);
                command.Parameters.AddWithValue("@Quantity", product.Quantity);

                command.ExecuteNonQuery();
            }
        }
    }

    // Update an existing product in the database.
    public void UpdateProduct(Product product)
    {
        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("UPDATE products SET name=@Name, description=@Description, price=@Price, quantity=@Quantity WHERE id=@Id;", connection))
            {
                command.Parameters.AddWithValue("@Id", product.Id);
                command.Parameters.AddWithValue("@Name", product.Name);
                command.Parameters.AddWithValue("@Description", product.Description);
                command.Parameters.AddWithValue("@Price", product.Price);
                command.Parameters.AddWithValue("@Quantity", product.Quantity);

                command.ExecuteNonQuery();
            }
        }
    }

    // Delete a product from the database by its ID.
    public void DeleteProduct(int id)
    {
        using (var connection = new MySqlConnection(_connectionString))
        {
            connection.Open();

            using (var command = new MySqlCommand("DELETE FROM products WHERE id=@Id;", connection))
            {
                command.Parameters.AddWithValue("@Id", id);
                command.ExecuteNonQuery();
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        // Replace with your own connection string.
        var connectionString = "server=localhost;user=root;password=your_password;database=test";
        var dbConnection = new DatabaseConnection(connectionString);

        while (true)
        {
            Console.WriteLine("1. View products");
            Console.WriteLine("2. Add product");
            Console.WriteLine("3. Update product");
            Console.WriteLine("4. Delete product");
            Console.WriteLine("5. Exit");

            int choice;
            if (!int.TryParse(Console.ReadLine(), out choice))
            {
                Console.WriteLine("Invalid input. Please try again.");
                continue;
            }

            switch (choice)
            {
                case 1:
                    var products = dbConnection.GetAllProducts();
                    foreach (var product in products)
                    {
                        Console.WriteLine($"ID: {product.Id}, Name: {product.Name}, Description: {product.Description}, Price: {product.Price}, Quantity: {product.Quantity}");
                    }
                    break;
                case 2:
                    // Add product
                    break;
                case 3:
                    // Update product
                    break;
                case 4:
                    // Delete product
                    break;
                case 5:
                    return;
                default:
                    Console.WriteLine("Invalid option. Please try again.");
                    break;
            }
        }
    }
}