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服务。在这里您可以安排网络通话。完全披露,可能会有几秒钟的漂移 –