1
我想弄清楚如何讓我的應用程序發送一個通知在它從我的數據庫檢索到的指定日期/時間。從數據庫發送時間/日期通知
它並不需要做太多複雜的,它只是需要發送一個簡單的信息彈出/聲音通知。
我的代碼到目前爲止。
SqlConnection connectionString = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Goeli\Desktop\Feedr OIS\DateTimePlanner2\DateTimePlanner2\Database1.mdf;Integrated Security=True");
public Form1()
{
InitializeComponent();
dateTimePicker1.Format = DateTimePickerFormat.Custom;
timePicker2.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM/dd/yyyy";
timePicker2.CustomFormat = "HH:mm";
DisplayData();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text != "")
{
SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Planner(Name, Date, Time) VALUES(@Name, @Date, @Time)", connectionString);
connectionString.Open();
cmd.Parameters.AddWithValue("@Name", textBox1.Text);
cmd.Parameters.AddWithValue("@Date", dateTimePicker1.Text);
cmd.Parameters.AddWithValue("@Time", timePicker2.Text);
cmd.ExecuteNonQuery();
connectionString.Close();
MessageBox.Show("Successfully Planned");
DisplayData();
//ClearData();
}
else
{
MessageBox.Show("Please provide a name");
}
}
catch (Exception)
{
MessageBox.Show("Cannot have duplicate name");
}
}
private void DisplayData()
{
connectionString.Open();
DataTable dt = new DataTable();
SqlDataAdapter adapt = new SqlDataAdapter("select * from dbo.Planner", connectionString);
adapt.Fill(dt);
dataGridView1.DataSource = dt;
connectionString.Close();
}
private void button2_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("DELETE FROM dbo.Planner WHERE [email protected]", connectionString);
try
{
if (textBox1.Text != "")
{
connectionString.Open();
cmd.Parameters.AddWithValue("@Name", textBox1.Text);
cmd.ExecuteNonQuery();
connectionString.Close();
MessageBox.Show(" Successfully Deleted");
DisplayData();
}
else
{
MessageBox.Show("Please provide the name to delete");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
如果託管環境(具有有限功能)有一個名爲ATrigger的免費Web服務。在這裏您可以安排網絡通話。完全披露,可能會有幾秒鐘的漂移 –