Reputation: 33
I'm trying to figure out how to make my application send a notification on the specified date/time which it retrieves from my database.
it does not need to do anything complicated like a pop-up/sound notification it just needs to send a simple message.
my code so far.
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);
}
}
}
}
Upvotes: 2
Views: 890
Reputation: 1716
As the fastest and simplest solution I would propose to use
Some simple synchronization needs to be involved.
As an alternative you can use 3rd party libraries, like FluentScheduler. For more heavyweight solutions if you need consistency across many instances of you application, consider Quartz.NET
Upvotes: 1