C# 배열 (2), Timer
데이터 베이스의 Insert 된 값을 Timer 을 걸어 주기적으로 데이터를 불러옵니다.
private void SMS_Check()
{
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ToString()))
{
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
//쿼리 10분전 데이터 불러오기.
//cmd.CommandText = "select 'no', ipaddr, msg, datetime from pushlog where datetime > date_format(date_add(now(),interval -10 minute), '%Y-%m-%d %H:%i:%s')";
//쿼리 10분전 chargeNo 18 번에 값을 출력.
cmd.CommandText = "select ipaddr,chargeNo,Msg,datetime from pushlog where chargeNo='18' and datetime > date_format(date_add(now(),interval -10 minute), '%Y-%m-%d %H:%i:%s') order by no desc";
//DataTable rows = new DataTable("rows");
MySqlDataReader DbReader = cmd.ExecuteReader();
while (DbReader.Read())
{
//모니터 확인
//Label1.Text += "<hr>" + "IPAddress : " + DbReader.GetString(0) + "<br>";
//Label1.Text += "SMS 수신자 번호 : " + DbReader.GetString(1) + "<br>";
//Label1.Text += "SMS 메세지 : " + DbReader.GetString(2) + "<br>";
//Label1.Text += "발송 시간 : " + DbReader.GetString(3) + "<p>";
// CheckCompanyList 한번만 실행.
//bool IsAction = false;
for (int i = 0; i < CheckEventList.Count; i++)
{
if (DbReader.GetString(2).Contains(CheckEventList[i].CheckString))
{
//wav 파일 재생.
SoundPlayer player = new SoundPlayer(CheckEventList[i].WavName);
player.PlaySync();
//반복
for (int ii = 0; ii < CheckCompanyList.Count; ii++)
{
//업체명
if (DbReader.GetString(2).Contains(CheckCompanyList[ii].CheckString))
{
SoundPlayer player2 = new SoundPlayer(CheckCompanyList[ii].WavName);
player2.PlaySync();
//한번만
// IsAction = true;
//break;
}
}
//if (IsAction) break;
}
}
}
DbReader.Close();
con.Close();
}
}
//Timer 진행.
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//Check_SMS();
Repeater_Data_Load();
SMS_Check2();
}