如何可以显示多次通知后一个另一个

0

的问题

我有点失去了我不知道如何显示一个通知。 让我们说例如我国目前的时间"23/11/2021 08:00"我想创建一个提醒"23/11/2021 09:30"第一时间通知弹但是,如果我另外创建一个提醒"23/11/2021 09:35"的通知不会显示,除非我靠近的程序后第一个提醒通知已经显示,例如,如果用户设置了超过1提醒我们,具有相同的日期和时间,然后只有1个通知应以显示。

谢谢。

这是什么我看起来像

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

最好的答案

0

我会认为你可以启用的性质的前辈在设计时间。 我放弃的 BtnClear 在评论所以我忽略形式。负荷。

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

你不能分配的一个 StringFormatDateTimeCurrentDataTime 因为它是宣布为 Date. 你只配一个 Date 它是该线以上。 同 ReminderDateTime. 让你日期为 Date 直到你需要显示它们。

我分离的数据库码从用户界面的代码。 在你 While 循环,保持复盖值 ReminderDateTime 因此,只有最终值的变量。 有鉴于此,我只是改变选择 Last() 和使用 ExecuteScalar. 我不知道为什么你会想要的只是最后一个日期,但这是什么你的代码这样做。

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

谢谢你响应,我不想最后一个日期和时间,我要检查所有储存的日期和时间从我的数据库字段(ReminderDate)和比较的日期和时间存在我的数据库,与目前的日期和时间,如果比较"="然后通知应当显示,无论如果有另一个即将到来的提醒,例如像在5分钟时间。
Yousaer10

@Yousaer10请回答我的问题在评论有关问题的通知。
Mary

@Yousaer10关于ReminderDate,你可以编辑的代码,在你的问题,以显示你想要什么?
Mary

对不起我不知道,虽然循环将复盖所以我去除的同时循环,因为你说我一直复盖值的ReminderDateTime.
Yousaer10

我也回答了你的问题在我的职务。
Yousaer10

其他语言

此页面有其他语言版本

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