我正在为我的课程作业创建一个应用程序,但有一件事我无法弄清楚如何完成。这是我需要用winforms中的数据创建一个表。
该表需要在行上的列和时间上有一周中的几天。我不想从数据库中获取数据并填写表格。该表适用于医生手术中的患者预约。
答案 0 :(得分:0)
听起来您需要先关注SQL Server数据库,然后再关注C#表单。
设置您的表格,使其具有与此类似的表格:
select
getdate() as Curr_Date
,datename(dw,getdate()) as Weekday_Name
,datepart(dw,getdate()) as Weekday_Number
,case when datepart(dw,getdate()) = 1 then 'Your Column Value Goes Here' end as Sunday
,case when datepart(dw,getdate()) = 2 then 'Your Column Value Goes Here' end as Monday
,case when datepart(dw,getdate()) = 3 then 'Your Column Value Goes Here' end as Tuesday
,case when datepart(dw,getdate()) = 4 then 'Your Column Value Goes Here' end as Wednesday
,case when datepart(dw,getdate()) = 5 then 'Your Column Value Goes Here' end as Thursday
,case when datepart(dw,getdate()) = 6 then 'Your Column Value Goes Here' end as Friday
,case when datepart(dw,getdate()) = 7 then 'Your Column Value Goes Here' end as Saturday
您将getdate()
替换为真实数据的实际时间戳。
您将使用数据的实际值替换'Your Column Value Goes Here'
最后,您将希望您的C#表单捕获特定单元格。
我刚刚再次阅读你的帖子。看起来你想要排队的时间?如果是这样,尝试这样的事情:
select
getdate() as Curr_Date
,datename(dw,getdate()) as Weekday_Name
,datepart(dw,getdate()) as Weekday_Number
,case when datepart(dw,getdate()) = 1 then cast(getdate() as time) end as Sunday
,case when datepart(dw,getdate()) = 2 then cast(getdate() as time) end as Monday
,case when datepart(dw,getdate()) = 3 then cast(getdate() as time) end as Tuesday
,case when datepart(dw,getdate()) = 4 then cast(getdate() as time) end as Wednesday
,case when datepart(dw,getdate()) = 5 then cast(getdate() as time) end as Thursday
,case when datepart(dw,getdate()) = 6 then cast(getdate() as time) end as Friday
,case when datepart(dw,getdate()) = 7 then cast(getdate() as time) end as Saturday
因为我感觉很慷慨,实际上喜欢写SQL ......
create table Schedule
(
Person varchar(15)
,Appointment datetime
)
;
insert into Schedule values
('John Doe','2017-11-20 9:25:00'),
('Jane Doe','2017-11-22 9:15:00'),
('Michael','2017-11-24 9:25:00'),
('Sam','2017-11-26 9:15:00')
;
create table Time_Table
(
Start_Time time,
End_Time time,
Time_Name Varchar(20)
)
;
insert into Time_Table values
('9:00' , '9:10' , '9:10 - 9:10' )
,('9:10' , '9:20' , '9:10 - 9:20' )
,('9:20' , '9:30' , '9:20 - 9:30' )
,('9:30' , '9:40' , '9:30 - 9:40' )
,('9:40' , '9:50' , '9:40 - 9:50' )
,('9:50' , '10:00' , '9:50 - 10:00' )
;
select
a.Time_Name
,max(case when datepart(dw,b.Appointment) = 1 then b.Person end) as Sunday
,max(case when datepart(dw,b.Appointment) = 2 then b.Person end) as Monday
,max(case when datepart(dw,b.Appointment) = 3 then b.Person end) as Tuesday
,max(case when datepart(dw,b.Appointment) = 4 then b.Person end) as Wednesday
,max(case when datepart(dw,b.Appointment) = 5 then b.Person end) as Thursday
,max(case when datepart(dw,b.Appointment) = 6 then b.Person end) as Friday
,max(case when datepart(dw,b.Appointment) = 7 then b.Person end) as Saturday
from Time_Table a
LEFT JOIN Schedule b ON cast(b.Appointment as time) between a.Start_Time and a.End_Time
group by
a.Time_Name
order by a.Time_Name
这是您的作业的SQL Server版本。您的任务的重点显然与学习与数据库交互的基础知识有关。我不会在这里为你构建一个CRUD应用程序,但这至少应该为你提供一个非常坚实的基础。