基于选择的半小时和一小时时段预订 - c# 和 sql

2023-12-05

我无法在选定的日期找到特定治疗的半小时和一小时时段的可用时间。 用户在预订结束时可以选择半小时和一小时 示例 = 在选定日期 - 上午 9 点预订 1 小时(上午 9 点至上午 10 点) 还有另一次预订 - 上午 11 点半小时(上午 11 点至上午 11:30) 那么用户不应该在同一选定的日期看到这两个时段 他应该在显示屏上看到这个(选择治疗师和日期后)

半小时:

  • 上午 9 点至上午 930 点❌(不可用)
  • 上午 930 点至上午 10 点❌(不可用)
  • 上午 10 点至 1030 ✅(有空)
  • 1030 至上午 11 点 ✅(有空)
  • 上午 11 点至 11:30 ❌(不可用)
  • 11:30 至 1200pm ✅(有空) 等等................... 。

    One Hour

  • 上午 9 点至上午 10 点❌(不可用)

  • 上午 10 点至上午 11 点✅(有空)
  • 上午 11 点到中午 12 点❌(不可用),((((如果可能的话,我们可以将上午 1130 点到中午 12:30 ✅(可用),然后从 12:30 继续序列,依此类推......)))
  • 中午 12 点至下午 1 点✅(有空)
  • 下午 1 点至 2 点✅(有空) 等等 - - - - - - - - - - - - - -

    我尝试这样做。

我创建了两张表 - 一张用于半小时时段,一张用于一小时时段。

这两个表有 timebegin 和 timeEnd

Half-an-hour slots table One-Hour time slots table

I have another table that has the booked entries. enter image description here

我尝试在 SQl 中使用 EXCEPT - 但这似乎给出了错误的结果

	SELECT T1.timeBegin from ClinicNew.HalfTiming T1 
		left join  ClinicNew.FullTiming T2
		On T1.TimeBegin=T2.TimeBegin
		EXCEPT
		select distinct T1.timeBegin from ClinicNew.HalfTiming T1 
		inner join ClinicNew.NewTreaterEngagedDTM T2
		On T1.timeBegin = T2.timeBegin
		where T2.BookedDate = '2014-04-15'
		and T2.TreaterID=

请帮忙


我认为您可能通过为不同长度的时间段设置多个表而使问题变得过于复杂。如果您想要间隔 15 分钟而不是 30 分钟,会发生什么情况?当您想要允许 90 分钟的约会时会发生什么?如果安排这些预约的办公室在不同日期的工作时间不同,会发生什么情况?

我在下面提出的解决方案使用一张表来存储约会,仅此而已。显示的其余逻辑可以轻松地进入存储过程或当您想要给定日期的可用约会列表时调用的东西。希望这些评论足以解释正在发生的事情。

-- Sample data from the question.
declare @Appointment table
(
    [ID] bigint not null identity(1, 1), -- Primary key.
    [BookedDate] date not null,          -- The date of the appointment.
    [Time] time(0) not null,             -- The start time of the appointment.
    [Duration] int not null              -- The length of the appointment in minutes.
);
insert @Appointment
    ([BookedDate], [Time], [Duration])
values
    ('2014-04-15', '09:00', 60),
    ('2014-04-15', '10:00', 30),
    ('2014-04-15', '17:00', 60),
    ('2014-04-15', '18:30', 30);

-- @StartTime is the time the office opens on the desired date.
-- @EndTime is the time the office closes on the desired date.
-- @Interval is the number of minutes that separate potential appointment times.
-- @DesiredDate is the date on which an appointment is requested.
-- @DesiredLength is the length of the requested appointment in minutes.
declare @StartTime time(0) = '09:00';
declare @EndTime time(0) = '21:00';
declare @Interval int = 30;
declare @DesiredDate date = '2014-04-15';
declare @DesiredLength int = 30;

-- This CTE enumerates all potential timeslots on the @DesiredDate given the above data.
with [TimeSlotCTE] as
(
    -- Base case: the first appointment slot of the day.
    select 
        [From] = @StartTime, 
        [To] = dateadd(minute, @DesiredLength, @StartTime)

    union all

    -- Recursive case: create a subsequent appointment slot as long as doing so won't
    -- take us past the office's closing time.
    select
        dateadd(minute, @Interval, [From]),
        dateadd(minute, @Interval, [To])
    from
        [TimeSlotCTE]
    where
        dateadd(minute, @Interval, [To]) <= @EndTime
)

-- Finally, we simply select every time slot defined above for which there does not
-- yet exist an overlapping appointment on the requested date.
select
    [T].[From],
    [T].[To],
    [Available] = 
        case when exists 
        (
            select 1 from @Appointment [A]
            where
                -- Forgot this line the first time around!
                [A].[BookedDate] = @DesiredDate and
                [A].[Time] < [T].[To] and
                dateadd(minute, [A].[Duration], [A].[Time]) > [T].[From]
        )
        then 'No' else 'Yes' end
from
    [TimeSlotCTE] [T];

如果我运行上面的代码,这是输出@DesiredLength = 30:

From        To          Available
09:00:00    09:30:00    No
09:30:00    10:00:00    No
10:00:00    10:30:00    No
10:30:00    11:00:00    Yes
11:00:00    11:30:00    Yes
11:30:00    12:00:00    Yes
12:00:00    12:30:00    Yes
12:30:00    13:00:00    Yes
13:00:00    13:30:00    Yes
13:30:00    14:00:00    Yes
14:00:00    14:30:00    Yes
14:30:00    15:00:00    Yes
15:00:00    15:30:00    Yes
15:30:00    16:00:00    Yes
16:00:00    16:30:00    Yes
16:30:00    17:00:00    Yes
17:00:00    17:30:00    No
17:30:00    18:00:00    No
18:00:00    18:30:00    Yes
18:30:00    19:00:00    No
19:00:00    19:30:00    Yes
19:30:00    20:00:00    Yes
20:00:00    20:30:00    Yes
20:30:00    21:00:00    Yes

这是与@DesiredLength = 60:

From        To          Available
09:00:00    10:00:00    No
09:30:00    10:30:00    No
10:00:00    11:00:00    No
10:30:00    11:30:00    Yes
11:00:00    12:00:00    Yes
11:30:00    12:30:00    Yes
12:00:00    13:00:00    Yes
12:30:00    13:30:00    Yes
13:00:00    14:00:00    Yes
13:30:00    14:30:00    Yes
14:00:00    15:00:00    Yes
14:30:00    15:30:00    Yes
15:00:00    16:00:00    Yes
15:30:00    16:30:00    Yes
16:00:00    17:00:00    Yes
16:30:00    17:30:00    No
17:00:00    18:00:00    No
17:30:00    18:30:00    No
18:00:00    19:00:00    No
18:30:00    19:30:00    No
19:00:00    20:00:00    Yes
19:30:00    20:30:00    Yes
20:00:00    21:00:00    Yes

这样的事情对你有用吗?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

基于选择的半小时和一小时时段预订 - c# 和 sql 的相关文章

  • 如何将非静态类成员“std::bind”绑定到 Win32 回调函数“WNDPROC”?

    我正在尝试将非静态类成员绑定到标准WNDPROC http msdn microsoft com en us library ms633573 aspx功能 我知道我可以通过将类成员设为静态来简单地做到这一点 但是 作为一名 C 11 ST
  • 确保 StreamReader 不会挂起等待数据

    下面的代码读取从 tcp 客户端流读取的所有内容 并且在下一次迭代中它将仅位于 Read 上 我假设正在等待数据 我如何确保它不会在没有任何内容可供读取时返回 我是否必须设置低超时 并在失败时响应异常 或者有更好的办法吗 TcpClient
  • 在 LINQ 中按 Id 连接多表和分组

    我想按categoryId显示列表产品的名称组 这是我的代码 我想要我的视图显示结果 Desktop PC HP Red PC Dell Yellow PC Asus Red SmartPhone Lumia 720 Blue 我的组模型
  • 错误:表达式不产生值

    我尝试将以下 C 代码转换为 VB NET 但在编译代码时出现 表达式不产生值 错误 C Code return Fluently Configure Mappings m gt m FluentMappings AddFromAssemb
  • 回发后刷新时提示确认表单重新提交。我做错了什么?

    我有一个以空白 默认状态启动的仪表板 我让用户能够将保存的状态加载到仪表板中 当他们单击 应用 按钮时 我运行以下代码 function CloseAndSave var radUpload find radUpload1ID var in
  • 在 Visual Studio 2010 中从 Fortran 调用 C++ 函数

    我想从 Fortran 调用 C 函数 为此 我在 Visual Studio 2010 中创建了一个 FORTRAN 项目 之后 我将一个 Cpp 项目添加到该 FORTRAN 项目中 当我要构建程序时出现以下错误 Error 1 unr
  • qdbusxml2cpp 未知类型

    在使用 qdbusxml2cpp 程序将以下 xml 转换为 Qt 类时 我收到此错误 qdbusxml2cpp c ObjectManager a ObjectManager ObjectManager cpp xml object ma
  • 从 Sharepoint 到 SQL Server 的实时同步

    我见过许多将 SQL Server 数据同步到 SharePoint 的解决方案 但没有见过将 SharePoint 列表同步到 SQL Server 的解决方案 有谁知道解决方案吗 商业化就好了 或者 我需要编写一个 Web 部件来创建多
  • C#:帮助理解 UML 类图中的 <>

    我目前正在做一个项目 我们必须从 UML 图编写代码 我了解 UML 类图的剖析 但我无法理解什么 lt
  • 如何禁用 fread() 中的缓冲?

    我正在使用 fread 和 fwrite 读取和写入套接字 我相信这些函数用于缓冲输入和输出 有什么方法可以在仍然使用这些功能的同时禁用缓冲吗 Edit 我正在构建一个远程桌面应用程序 远程客户端似乎 落后于服务器 我不知道可能是什么原因
  • 为什么 std::strstream 被弃用?

    我最近发现std strstream已被弃用 取而代之的是std stringstream 我已经有一段时间没有使用它了 但它做了我当时需要做的事情 所以很惊讶听到它的弃用 我的问题是为什么做出这个决定 有什么好处std stringstr
  • AES 128 CBC 蒙特卡罗测试

    我正在 AES 128 CBC 上执行 MCT 如中所述http csrc nist gov groups STM cavp documents aes AESAVS pdf http csrc nist gov groups STM ca
  • 如何通过SQL查询检查是否有JSON函数?

    有SQL 2016 中的 JSON 函数 https learn microsoft com en us sql t sql functions json functions transact sql例如 JSON VALUE JSON Q
  • 动态添加 ASP.Net 控件

    我有一个存储过程 它根据数据库中存储的记录数返回多行 现在我想有一种方法来创建 div 带有包含该行值的控件的标记 如果从数据库返回 10 行 则 10 div 必须创建标签 我有下面的代码来从数据库中获取结果 但我不知道如何从这里继续 S
  • 如何在非控制台应用程序中查看 cout 输出?

    输出到调试窗口似乎相当繁琐 我在哪里可以找到cout如果我正在编写非控制台信息 则输出 Like double i a b cout lt lt b lt lt endl I want to check out whether b is z
  • C++ 函数重载类似转换

    我收到一个错误 指出两个重载具有相似的转换 我尝试了太多的事情 但没有任何帮助 这是那段代码 CString GetInput int numberOfInput BOOL clearBuffer FALSE UINT timeout IN
  • 如果没有抽象成员,基类是否应该标记为抽象?

    如果一个类没有抽象成员 可以将其标记为抽象吗 即使没有实际理由直接实例化它 除了单元测试 是的 将不应该实例化的基类显式标记为抽象是合理且有益的 即使在没有抽象方法的情况下也是如此 它强制执行通用准则来使非叶类抽象 它阻止其他程序员创建该类
  • 我是否需要在外键上指定 ON DELETE NO ACTION?

    我有以下与 SQL Server 2012 一起使用的 DDL CREATE TABLE Subject SubjectId INT IDENTITY 1 1 NOT NULL Name NVARCHAR 50 Not NULL CONST
  • 无法接收 UDP Windows RT

    我正在为 Windows 8 RT 编写一个 Windows Store Metro Modern RT 应用程序 需要在端口 49030 上接收 UDP 数据包 但我似乎无法接收任何数据包 我已按照使用教程进行操作DatagramSock
  • 从列表中选择项目以求和

    我有一个包含数值的项目列表 我需要使用这些项目求和 我需要你的帮助来构建这样的算法 下面是一个用 C 编写的示例 描述了我的问题 int sum 21 List

随机推荐