특정 쿼리문을 체크하여 SMS 발송하기.
사용자가 직접 입력할수 있도록 데이터 베이스 체크하는 툴을 설정.
작업요청에 의한 사항으로 하면 할수록 소스는 간편화.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace DataBase_Check
{
public partial class DataBase_Check_Ver1 : Form
{
//변수 선언
private SqlConnection Conn;
private String ConnStr;
private String strQuary;
private MySqlConnection MySqlConn;
private String MySqlConnStr;
private String MystrQuary;
public DataBase_Check_Ver1()
{
InitializeComponent();
}
private void button_Start_Click(object sender, EventArgs e)
{
timer_Main.Start();
}
private void button_Stop_Click(object sender, EventArgs e)
{
timer_Main.Stop();
}
private void timer_Main_Tick(object sender, EventArgs e)
{
label_Time.Text = DateTime.Now.ToString("yy:MM:dd / hh:mm:ss");
//timer 체크시간
timer_Main.Interval = int.Parse(comboBox_Time.Text);
//데이터 베이스 불러오기.
DB_Check();
}
private void DB_Check()
{
ConnStr = "Data Source=" + textBox_IP.Text + ";Initial Catalog=" + textBox_DB_Name.Text + ";Persist Security Info=True;User ID=" + textBox_ID.Text + ";Password=" + textBox_Pwd.Text + "";
strQuary = "xxxxxx"
Conn = new SqlConnection();
Conn.ConnectionString = ConnStr;
Conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
cmd.CommandText = strQuary;
SqlDataReader dbReader = cmd.ExecuteReader();
label4.Text = "";
label5.Text = "";
while (dbReader.Read())
{
if (dbReader["A"].ToString().Trim()=="")
{
//MessageBox.Show("특이사항이 없습니다.");
label4.Text += "데이터가 검출되지 않았습니다.";
label5.Text += "데이터가 검출되지 않았습니다.";
}
else
{
label4.Text += dbReader["A"].ToString();
label5.Text += dbReader["B"].ToString();
MySQL_CONN();
}
}
Conn.Close();
}
private void MySQL_CONN()
{
string[] Phone_Num = new string[] { textBox_Phon_1.Text,textBox_Phone_2.Text, textBox_Phone_3.Text};
foreach (string ss in Phone_Num)
{
MySqlConnStr = "Data Source=xxxxxx;Database=xxxxxx;User id=xxxxxx;Password=xxxxxx";
MySqlConn = new MySqlConnection();
MySqlConn.ConnectionString = MySqlConnStr;
MySqlConn.Open();
MySqlCommand mycmd = new MySqlCommand();
mycmd.Connection = MySqlConn;
MystrQuary = "insert into smscli_tbl (destination, body, originator, callback) values ('" + ss + "','" + textBox_IP.Text + " / " + label4.Text + " / " + label5.Text + "','xxxxxx','xxxxxx')";
// 공백문자일경우 넘긴다.
if (ss.Trim() == "") continue;
mycmd.CommandText = MystrQuary;
//DB 서버 입력.
mycmd.ExecuteNonQuery();
MySqlConn.Close();
}
}
}
}