在老程序的基础上新增定时查询功能
页面加载时调用定时器
/// <summary>
/// 定时器
/// </summary>
public void Dsq()
{
System.Timers.Timer t = new System.Timers.Timer(3000);//实例化Timer类;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
}
调用定时器和查询方法,如果查到数据后弹窗提示
/// <summary>
/// 调用定时器
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
if (this.Search() != "" || this.Search() != null)
{
MessageBox.Show("托盘号为:" + this.Search() + "分配货位失败!");
}
}
调用QueryAllocationFailure()方法看有没有分配失败的托盘
/// <summary>
/// 查询是否有货位分配失败的托盘号
/// </summary>
/// <returns></returns>
public string Search()
{
this.aIN_COMP = new DALOG_IN_TASK();
DataTable data = this.aIN_COMP.QueryAllocationFailure();
int rowsCount = data.Rows.Count;
string palno = "";
if (rowsCount > 0)
{
palno = data.Rows[0]["PALNO"].ToString();
this.SearchEdit(palno);
}
return palno;
}
为不影响流程,弹窗提示后把状态恢复成默认状态
/// <summary>
/// 弹窗完毕后把状态恢复成默认状态
/// </summary>
public void SearchEdit(string palno)
{
try
{
string sql = "update FailurePrompt set STATE ='true' where PALNO ='" + palno+"'";
String server = "Server=.;Database=xxxx;User ID=xx;Password=xxxx;Trusted_Connection=False";
SqlConnection Con = new SqlConnection(server);
Con.Open();
SqlCommand cmd = new SqlCommand(sql, Con);
cmd.ExecuteNonQuery();
Con.Close();
}
catch (Exception ex)
{
throw;
}
}
真的笑死我了,因为是原来的框架不能改,所以总结简单粗暴的写了连接数据库字符串直接执行SQL语句,真的是老程序能跑就行!