Como pode exibir várias notificações, um após o outro

0

Pergunta

Estou um pouco perdida, eu não sei como exibir uma notificação após o outro. Vamos dizer, por exemplo, meu tempo é "23/11/2021 08:00" e eu quero criar um lembrete para "23/11/2021 09:30" a primeira vez que a notificação de pop-up, mas se eu criar outro lembrete para "23/11/2021 09:35" a notificação não aparecerá, a menos que eu fechar o programa após o primeiro lembrete de que a notificação foi apresentada e, por exemplo, se o usuário definir mais de 1 lembrete de que tem a mesma data e hora, em seguida, apenas 1 notificação deve ser exibido.

Obrigado.

Este é o meu formulário parece

Imports System.Data.OleDb

Public Class frmReminder

    Private CurrentReminderID As Integer = -1

    Private Sub frmReminder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BtnClear.PerformClick()
        Timer1.Enabled = True
        Timer2.Enabled = True
    End Sub

    Dim CurrentDateTime As Date
    Dim ReminderDateTime As Date

    Public Sub ShowNotification()
        Notification.ShowBalloonTip(1000, "Reminder", "Customer Order Due!", ToolTipIcon.None)
    End Sub

    Private Sub DateTimeVariable()
        CurrentDateTime = Date.Now
        CurrentDateTime = FormatDateTime(DateTime.Now, DateFormat.GeneralDate)
        ReminderDateTime = FormatDateTime(ReminderDateTime, DateFormat.GeneralDate)
        If CurrentDateTime = ReminderDateTime Then
            ShowNotification()

        Else
            If DbConnect() Then
                Dim SQLCmd As New OleDbCommand
                With SQLCmd
                    .Connection = cn
                    .CommandText = "SELECT ReminderDate FROM TblReminder"
                    Dim rs As OleDbDataReader = .ExecuteReader()
                        ReminderDateTime = (rs(0))
                End With
            End If
            cn.Close()
        End If
    End Sub

    Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
        Label6.Text = ""
        TxtCustName.Text = ""
        TxtDeviceInfo.Text = ""
        TxtPrice.Text = ""
        TxtReminderDateTime.ResetText()
        CurrentReminderID = -1
    End Sub

    Private Sub BtnSetReminder_Click(sender As Object, e As EventArgs) Handles BtnSetReminder.Click

        If TxtCustName.Text.Length < 1 Then
            MessageBox.Show("Customer name is empty!" & vbCrLf, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            TxtCustName.Focus()

        ElseIf TxtDeviceInfo.Text.Length < 1 Then
            MessageBox.Show("Device Information is empty!" & vbCrLf, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            TxtDeviceInfo.Focus()

        ElseIf TxtPrice.Text.Length < 1 Then
            MessageBox.Show("No price entered!" & vbCrLf, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            TxtPrice.Focus()

        ElseIf DbConnect() Then
            Dim SQLCmd As New OleDbCommand
            If CurrentReminderID = -1 Then
                With SQLCmd
                    .Connection = cn
                    .CommandText = "Insert into TblReminder (CustomerName, DeviceInfo, RepairPrice, ReminderDate)"
                    .CommandText &= "Values (@CustomerName, @DeviceInfo, @RepairPrice, @ReminderDate)"
                    .Parameters.AddWithValue("@CustomerName", TxtCustName.Text)
                    .Parameters.AddWithValue("@DeviceInfo", TxtDeviceInfo.Text)
                    .Parameters.AddWithValue("@RepairPrice", TxtPrice.Text)
                    .Parameters.AddWithValue(" @ReminderDate", TxtReminderDateTime.Text)
                    .ExecuteNonQuery()

                    .CommandText = "Select @@Identity"
                    CurrentReminderID = .ExecuteScalar
                    Label6.Text = CurrentReminderID
                    'ShowNotification()
                End With
            End If
        End If
    End Sub

    Private Sub TxtCustName_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtCustName.KeyPress
        If Not Char.IsLetter(e.KeyChar) Then 'Checks if key pressed isn't a digit
            If Asc(e.KeyChar) <> Keys.Back Then 'Checks the key pressed wasn't Backspace
                e.Handled = True 'It doesn't take any further action
            End If
        End If
    End Sub

    Private Sub TxtPrice_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtPrice.KeyPress
        If Not Char.IsDigit(e.KeyChar) Then 'Checks if key pressed isn't a digit
            If Asc(e.KeyChar) <> Keys.Back Then 'Checks the key pressed wasn't Backspace
                e.Handled = True 'It doesn't take any further action
            End If
        End If
    End Sub

    Private Sub Notification_Click(sender As Object, e As EventArgs) Handles Notification.Click
        frmReminderInfo.Show()
    End Sub

    Private Sub Notification_BalloonTipClicked(sender As Object, e As EventArgs) Handles Notification.BalloonTipClicked
        frmReminderInfo.Show()
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        DateTimeVariable()
    End Sub

    Private Sub BtnOpenReminders_Click(sender As Object, e As EventArgs) Handles BtnOpenReminders.Click
        frmReminderInfo.Show()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        TxtCurrentDateTime.Text = Date.Now.ToString("dd/MM/yyyy      HH:mm")
    End Sub
End Class
ms-access notifications timer vb.net
2021-11-23 23:32:41
1

Melhor resposta

0

Eu acho que você poderia definir o Habilitado propriedades dos Temporizadores em tempo de design. Eu dispensada a BtnClear nos comentários que assim que eu sou ignorado Formulário.Carrega totalmente.

CurrentDateTime = FormatDateTime(DateTime.Now, DateFormat.GeneralDate)
ReminderDateTime = FormatDateTime(ReminderDateTime, DateFormat.GeneralDate)

Você não pode atribuir a um String a partir de FormatDateTime para CurrentDataTime porque ele é declarado como um Date. Você acabou de atribuir um Date é a linha acima. Mesmo com ReminderDateTime. Mantê-lo datas Date até que você precisa para exibi-los.

Separei o banco de dados de código a partir de código da interface do usuário. Em seu While loop, você manter substituindo o valor de ReminderDateTime de modo que apenas o valor final é o valor da variável. Em vista disso eu só mudei a seleção para Last() e usados ExecuteScalar. Eu não sei por que você iria querer apenas a última data, mas que é o que o seu código está fazendo.

Private CurrentReminderID As Integer = -1
Private CurrentDateTime As Date
Private ReminderDateTime As Date

Public Sub ShowNotification()
    Notification.ShowBalloonTip(1000, "Reminder", "Customer Order Due!", ToolTipIcon.None)
End Sub

Private Sub DateTimeVariable()
    CurrentDateTime = Date.Now
    If CurrentDateTime = ReminderDateTime Then
        ShowNotification()
    Else
        ReminderDateTime = RetrieveReminderDate()
    End If
End Sub

Private Function RetrieveReminderDate() As Date
    Dim RemindDate As New Date
    Using cn As New OleDbConnection(OPConStr),
            cmd As New OleDbCommand("SELECT Last(ReminderDate) FROM TblReminder", cn)
        cn.Open()
        RemindDate = CDate(cmd.ExecuteScalar)
    End Using
    Return RemindDate
End Function

Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
    Label6.Text = ""
    TxtCustName.Text = ""
    TxtDeviceInfo.Text = ""
    TxtPrice.Text = ""
    DtpReminderDateTime.ResetText()
    CurrentReminderID = -1
End Sub

Private Sub BtnSetReminder_Click(sender As Object, e As EventArgs) Handles BtnSetReminder.Click
    Dim price As Decimal
    If TxtCustName.Text.Length < 1 Then
        MessageBox.Show("Customer name is empty!" & vbCrLf, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        TxtCustName.Focus()
        Exit Sub
    ElseIf TxtDeviceInfo.Text.Length < 1 Then
        MessageBox.Show("Device Information is empty!" & vbCrLf, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        TxtDeviceInfo.Focus()
        Exit Sub
    ElseIf Not Decimal.TryParse(TxtPrice.Text, price) Then
        MessageBox.Show("No price entered!" & vbCrLf, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        TxtPrice.Focus()
        Exit Sub
    Else
        If CurrentReminderID = -1 Then
            CurrentReminderID = SaveReminder(TxtCustName.Text, TxtDeviceInfo.Text, price, DtpReminderDateTime.Value)
        End If
    End If
End Sub

Private Function SaveReminder(Name As String, Device As String, Price As Decimal, RemindDate As Date) As Integer
    Dim Id As Integer
    Using cn As New OleDbConnection(OPConStr),
            cmd As New OleDbCommand("Insert into TblReminder (CustomerName, DeviceInfo, RepairPrice, ReminderDate)
                                    Values (@CustomerName, @DeviceInfo, @RepairPrice, @ReminderDate)")
        With cmd.Parameters
            .Add("@CustomerName", OleDbType.VarChar).Value = Name
            .Add("@DeviceInfo", OleDbType.VarChar).Value = Device
            .Add("@RepairPrice", OleDbType.Decimal).Value = Price
            .Add(" @ReminderDate", OleDbType.Date).Value = RemindDate
        End With
        cn.Open()
        cmd.ExecuteNonQuery()
        cmd.CommandText = "Select @@Identity"
        Id = CInt(cmd.ExecuteScalar)
    End Using
    Return Id
End Function

Private Sub Notification_Click(sender As Object, e As EventArgs) Handles Notification.Click
    frmReminderInfo.Show()
End Sub

Private Sub Notification_BalloonTipClicked(sender As Object, e As EventArgs) Handles Notification.BalloonTipClicked
    frmReminderInfo.Show()
End Sub

Private Sub BtnOpenReminders_Click(sender As Object, e As EventArgs) Handles BtnOpenReminders.Click
    frmReminderInfo.Show()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    TxtCurrentDateTime.Text = Date.Now.ToString("dd/MM/yyyy      HH:mm")
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    DateTimeVariable()
End Sub
2021-11-24 17:12:59

Obrigado por responder, eu não quero a última data e hora, quero verificar se todos os armazenados data e horas do meu campo de banco de dados (ReminderDate) e comparar a data e o horário armazenado no meu banco de dados com a data e hora atual, se a comparação é "=", em seguida, a notificação deverá ser apresentado independentemente se há outro próximo lembrete no como, por exemplo, em 5 minutos o tempo.
Yousaer10

@Yousaer10 por Favor, responda a minha pergunta em comentários sobre a sua pergunta a respeito de Notificações.
Mary

@Yousaer10 Sobre ReminderDate, você pode editar o código em seu questão de mostrar o que você quer?
Mary

Desculpe, eu não sabia que o loop while seria substituir assim que eu removi o loop while desde que você disse eu continuei substituindo o Valor de ReminderDateTime.
Yousaer10

Eu também respondeu a suas perguntas em meu post.
Yousaer10

Em outros idiomas

Esta página está em outros idiomas

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................