基于“预订”的日渲染日历来自 MySQL 表 ASP.NET C#

发布于 2025-01-06 16:38:49 字数 1424 浏览 0 评论 0原文

我正在尝试处理结果以更改日期在 ASP.NET 页面日历上的显示方式。我希望这样,如果在特定日期进行了“预订”,那么它将在日历上显示为红色突出显示的单元格。 问题是我只能设法让它执行一次,它会突出显示一个单元格,然后不会移动到下一个“BookingDate”。

这是代码:

conn.Open();
            Reader = command.ExecuteReader();
            if (Reader.Read())
            {
                String BookingDate = Reader.GetValue(0).ToString();
                String Username = Reader.GetValue(1).ToString();
                String Client = Reader.GetValue(2).ToString();
                Reader.Close();
                conn.Close();
                String[] bookingDetails = new String[3];
                bookingDetails[0] = BookingDate;
                bookingDetails[1] = Username;
                bookingDetails[2] = Client;

                DateTime BookingDateShort = Convert.ToDateTime(BookingDate);
                DateTime CalanderDate = Convert.ToDateTime(e.Day.Date);

                for (int i = 0; i < GetDaysinMonth(); i++)
                {
                    if (CalanderDate.ToShortDateString().Equals(BookingDateShort.ToShortDateString()))
                    {
                        e.Cell.BackColor = System.Drawing.Color.Red;
                        e.Cell.ToolTip = "Username: " + Username + " | Client: " + Client + "";
                    }
                }
            }

我知道我需要执行某种循环以使其递归地遍历每个日期的处理,将其与预订日期进行比较并检查它们是否相等。然而,它只针对一个预订日期执行此操作。

有谁知道我该如何解决这个问题?

非常感谢

I am trying to process results to change how the dates are displayed on the calander of an ASP.NET page. I want it so that if a "Booking" has been made on a particular date then it will show on the calendar as a red highligthed cell.
The problem is I am only managing to get it to do this once, it highlights one cell and then doesn't move onto the next "BookingDate".

Here is the Code:

conn.Open();
            Reader = command.ExecuteReader();
            if (Reader.Read())
            {
                String BookingDate = Reader.GetValue(0).ToString();
                String Username = Reader.GetValue(1).ToString();
                String Client = Reader.GetValue(2).ToString();
                Reader.Close();
                conn.Close();
                String[] bookingDetails = new String[3];
                bookingDetails[0] = BookingDate;
                bookingDetails[1] = Username;
                bookingDetails[2] = Client;

                DateTime BookingDateShort = Convert.ToDateTime(BookingDate);
                DateTime CalanderDate = Convert.ToDateTime(e.Day.Date);

                for (int i = 0; i < GetDaysinMonth(); i++)
                {
                    if (CalanderDate.ToShortDateString().Equals(BookingDateShort.ToShortDateString()))
                    {
                        e.Cell.BackColor = System.Drawing.Color.Red;
                        e.Cell.ToolTip = "Username: " + Username + " | Client: " + Client + "";
                    }
                }
            }

I am aware that I need to do some kind of loop to make it recursively go over this processing each date, comparing it against the bookingdate and checking whether they are equal. However It only does it for one booking date.

Does anyone see how I could fix this?

Many Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2025-01-13 16:38:49

当您阅读时……您期待更多结果还是只期待一个结果……?所以你需要更改以将 if 读取更改为 While 循环,

以便你的 while 循环看起来像这样

while (reader.Read())
{
  //do your processing here to check the Calendar stuff 
}

When you are doing your read..are you expecting more results or just one..? is so you need to change to change your if read to a While loop

so your while loop would look something like this

while (reader.Read())
{
  //do your processing here to check the Calendar stuff 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文