Foxtable(狐表)用户栏目专家坐堂 → 怎么判定上周有购买过电脑,代码要怎么写


  共有3250人关注过本帖树形打印复制链接

主题:怎么判定上周有购买过电脑,代码要怎么写

帅哥哟,离线,有人找我吗?
listfor
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:163 积分:1512 威望:0 精华:0 注册:2017/11/6 17:23:00
  发帖心情 Post By:2023/9/5 14:53:00 [显示全部帖子]

Imports System.Globalization

Public Sub CheckComputerPurchaseLastWeek()
Dim purchaseRecords As List(Of Dictionary(Of String, Object)) = New List(Of Dictionary(Of String, Object))() From {
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 8, 29)}, },
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 8, 30)}, },
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 9, 5)}, }
}

Dim currentDate As DateTime = DateTime.Now
Dim lastWeekStart As DateTime = currentDate.AddDays(-7).Date.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)

Dim hasPurchase As Boolean = False

For Each record In purchaseRecords
If record("purchaseDate").ToString("MM/dd/yyyy", CultureInfo.InvariantCulture) >= lastWeekStart Then
hasPurchase = True
Exit For
End If
Next

If hasPurchase Then
Console.WriteLine("上周有购买电脑")
Else
Console.WriteLine("上周没有购买电脑")
End If
End Sub
 

 回到顶部