【发布时间】:2014-12-27 10:24:42
【问题描述】:
我想问一个问题,我想每隔 15 秒左右跟踪数据库中的quantity。它工作正常,但问题是它检查每列 quantity 小于 5 ,而不是 quantity 的单列少于 5。我有如下图所示的数据库:
从下图中,我减去从下图到数据库(上图)的数量,所以数据库中的数量(上图)现在是 2,只要第一行和第二行中的数量(下图) ) 小于 5,它将在右下角显示如下图所示的框:
问题是,要么数据库第一行或者第二行的数量还是大于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;
}
主系统类:这里是我调用盒子的地方,减去从这个类到数据库的数量:
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();
}
}
}
非常感谢您的回答!
非常感谢!
【问题讨论】:
-
你能重新表述一下这个问题吗?我不清楚你想达到什么目标。
-
这个话题完全没有意义。你的标题说你有一个错误,你没有在线程本身中显示,我无法理解你的意图。
-
@LajosArpad:我已经编辑了问题,先生,如果您仍然不清楚我想要达到的目标,请告诉我。谢谢
-
@Samuel:我已经提到了问题中的错误,并且我已经更新了问题先生,如果您仍然不清楚我想要达到的目标,请告诉我。谢谢
标签: c# sql .net database winforms