我想問一個問題,我想每隔15秒左右在數據庫中跟蹤quantity
..它工作正常,但問題是它檢查每一列有quantity
小於5中,具有小於5的quantity
不單個列我有像下面的圖像的數據庫:查看數據庫中數據每15秒
而從下面的圖像,我減去從下面的圖像的數量數據庫(上圖),因此數據庫中的數量(上圖)現在爲2,只要第一行和第二行(圖像下方)的數量小於5,它就會在Bott OM右上角像下面圖像:
的問題是,無論是數據庫仍然超過5或等於(例如第一或第二行中的數量:的第一行中的數量數據庫是2,但在第二行是50),右上角的框如上圖所示,它只顯示數據庫中第一行和第二行的數量小於5.
我的問題是:無論第一行還是第二行的數量超過5個,我如何顯示該框?
這裏是我使用的代碼:
系統管理類:
public static void GetQuantity()
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
string query = "SELECT [Quantity] FROM [Database]";
connection.Open();
using (OleDbCommand command = new OleDbCommand(query, connection))
{
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
int quantity = (int)reader["Quantity"];
UserInformation.Quantity = Convert.ToDecimal(quantity);
}
reader.Close();
}
}
connection.Close();
}
}
public static void CheckQuantity(CustomToolTip _customToolTip, IWin32Window _window, int _x, int _y, int _duration)
{
GetQuantity();
string message = string.Empty;
string productCode = string.Empty;
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
string query = "SELECT [ProductCode] FROM [Database] WHERE [Quantity] = @Quantity ORDER BY [ProductCode] ASC";
connection.Open();
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.Add("@Quantity", OleDbType.Decimal);
command.Parameters["@Quantity"].Value = UserInformation.Quantity;
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
productCode = (string)reader["ProductCode"];
if (UserInformation.Quantity < 5)
{
message += "- Product Code: " + productCode + "\n- Quantity: " + UserInformation.Quantity + "\n\n";
}
}
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.";
if (UserInformation.Language == "Indonesian")
{
_message1 = "Program mendeteksi bahwa: \n\n";
_message2 = "Memiliki kuantitas kurang dari 5.\nPerbarui segera.";
}
_customToolTip.Show(_message1 + message + _message2, _window, _x, _y, _duration);
}
reader.Close();
}
}
connection.Close();
}
}
用戶信息類:
public static decimal Quantity
{
get;
set;
}
主系統類:這裏我在哪裏打電話給方框並減去要求ntity從這個類到數據庫:
int timeLeft = 15;
Timer _timer = new Timer();
void MainSystem_Load(object sender, EventArgs e)
{
_timer.Interval = 1000;
_timer.Tick += Timer_Tick;
_timer.Start();
}
void Timer_Tick(object sender, EventArgs e)
{
timeLeft--;
if (timeLeft == 0)
{
_timer.Stop();
MessageBox.Show("The timer has been stopped");
SystemManager.GetQuantity();
if (UserInformation.Quantity < 5)
{
MessageBox.Show("The quantity less than 5");
SystemManager.CheckQuantity(customToolTip1, this, _screen.Right, _screen.Bottom, 5000);
timeLeft = 15;
_timer.Start();
}
else if (UserInformation.Quantity >= 5)
{
MessageBox.Show("The quantity more than 5 or equal");
timeLeft = 15;
_timer.Start();
}
else
{
MessageBox.Show("Nothing");
timeLeft = 15;
_timer.Start();
}
}
}
您的回答非常感謝!
非常感謝!
你能改寫這個問題?我不清楚你想達到什麼目的。 –
這個主題根本沒有意義。你的頭銜說你有一個錯誤,你沒有在線程中顯示,我無法按照你想要做的事情的意圖。 – Samuel
@LajosArpad:我編輯了這個問題先生,請讓我知道如果你仍然不清楚我正在努力達到什麼目的。謝謝 –