[Solved] Quantity tracking in the database


In your CheckQuantity() method, you are:

  1. Only querying items that have the same quantity of the first ProductInfo that you’re constructing.
  2. Displaying the quantity from that single ProductInfo instead of the value you are querying from the database.

Instead, this should work better:

public static void CheckQuantity(CustomToolTip _customToolTip, IWin32Window _window, 
                                 int _x, int _y, int _duration)
{
    string message = string.Empty;

    string productCode = string.Empty;
    int quantity;

    string query =
        "SELECT [ProductCode], [Quantity] FROM [Database] " +
        "WHERE [Quantity] = < 5 ORDER BY [ProductCode] ASC";
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    using (OleDbCommand command = new OleDbCommand(query, connection))
    using (OleDbDataReader reader = command.ExecuteReader())
    {
        while (reader.Read())
        {
            productCode = (string)reader["ProductCode"];
            quantity = (int)reader["Quantity"];

            message += "- Product Code: " + productCode + 
                       "\n- Quantity: " + quantity + "\n\n";
        }
        reader.Close();
        connection.Close();
    }

    if (message != string.Empty)
    {
        SystemManager.SoundEffect(@"\Media\Speech Off.wav");

        string _message1 = "The system has detected the following: \n\n";
        string _message2 = "Have quantity less than 5.\nPlease update them immediately.";

        _customToolTip.Show(_message1 + message + _message2, _window, 
                            _x, _y, _duration);
    }
}

I think your code probably needs some reorganization. You have one query to check whether the products are below a certain quantity, and then you’re querying them all over again to re-obtain information that you have already retrieved. I suggest putting some thought into the matter and finding a way to do this with just one query.

1

solved Quantity tracking in the database