111,117
社区成员
发帖
与我相关
我的任务
分享
//定时扫描数据库,查看是否有"未读的" "普通聊天消息"
private void tmrScanDataBase_Tick(object sender, EventArgs e)
{
/*
* UserHelpper.HostId:当前登录的用户qq号
* messagestate:0未读,1已读
* messagetypeid:1普通聊天消息,2添加好友消息
*/
string sql = string.Format("select fromuserid from messages where touserid={0} and messagestate={1} and messagetypeid={2}", UserHelpper.HostId, 0, 1);
/*
* 这个地方要对查不到的情况,要拦截拦截一下,给出提示
*/
try
{
DBHelpper.connectionObj.Open();//打开数据库连接
SqlCommand commandObj = new SqlCommand(sql, DBHelpper.connectionObj);
friendId = (int)commandObj.ExecuteScalar();//只查看出一个,"来消息"的好友id
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "数据库出错3", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
DBHelpper.connectionObj.Close();//关闭数据库连接
}
if (friendId!=0 )//查出来了
{
tmrFlicker.Enabled = true;
}
}