我试图弄清楚如何让我的应用程序在从我的数据库中检索的指定日期/时间发送通知。
它不需要做任何复杂的事情,比如弹出/声音通知,它只需要发送一条简单的信息。
我的代码到目前为止。
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 Name=@Name", 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);
}
}
}
}
答案 0 :(得分:1)
作为我建议使用的最快最简单的解决方案
需要进行一些简单的同步。
作为替代方案,您可以使用第三方库,例如FluentScheduler。对于更重要的解决方案,如果您需要在应用程序的许多实例中保持一致性,请考虑Quartz.NET