gpt4 book ai didi

c# - 在表中显示记录

转载 作者:太空宇宙 更新时间:2023-11-03 21:40:18 25 4
gpt4 key购买 nike

我有这样的数据库记录。

My Records

我想显示这样的表格 Table to show Like

the Days goes up to 32 and is by default 1 to 32. I have to insert the records where the days match.

因为我试过的方法太乱了而且也不行。你们能建议我一些方法吗?我需要在 HTML 表格中显示它。任何语言都很好..我只需要这个想法。最好是 MVC C#

更新谢谢你们……我从你们两个(unlimit 和 Joe Enos)那里得到了想法,我做到了。你能再帮我解决一个同样的问题吗?如果 区域 1 在同一天有另一条 2 小时 的记录怎么办?我需要分别显示它们。我将如何显示当天的记录?

enter image description here

最佳答案

你可以试试这样的,我没有检查语法的正确性等。

Dictionary<string,int[]> data = new Dictionary<string,int[]>();

foreach (var record in database)
{
if (!data.ContainsKey(record["location"]))
{
int[] days = new int[32];
days[record["day"]] = record["hour"];
data.Add(record["location"], days);
}
else
{
int[] days = data[record["location"]];
days[record["day"]] = record["hour"];
//data[record["location"]] = days;
}
}

变量 data 应该包含您想要的格式的数据。然后循环遍历它并填充 html 表。

编辑以回应 OP 的评论

如果每天有不止一组的小时数,并且这组的数量不固定,那么你可以使用这样的东西。

 Dictionary<string,ArrayList> day = new Dictionary<string,ArrayList>();
Dictionary<string,day> location = new Dictionary<string,day>();

此处 day 字典将包含 Day 1、Day 2、Day 3 等键... 并且值 ArrayList 将保留那天的一系列时间。

location 字典将包含 Area 1、Area 2 等键......,值将是 day 字典。

也许这会给你一些关于如何解决这个问题的提示。

关于c# - 在表中显示记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19651785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com