2

Please note that the database design I have now is fully in sandbox mode. Nothing is finalized. Everything (again this is in sandbox mode) is in one single table. Also, I'm in now way looking for coding help. I'm looking for the right theoretical/logical approach to this puzzle so I can go in and play with the coding myself. I learn better that way. If I need coding help, I'll come back here for further assistance.

I'm in the process of creating the first of a few CheckBoxList for a manually created form submittal. I've been looking over multiple ways to not only create said CheckBoxList but to enter it into the database. However, the challenge I'm facing (mainly because I haven't encountered this scenario before and I'd like to learn this) is that I not only need to worry about entering the items correctly in the database but I will eventually need to produce a report or make a printable form from these entries.

Let's say I have an order form for a specific type of Barbeque grill and I will need to send this form out to distriution centers across the nation. The distribution centers will need to pull said barbecues if they are highlighted on the form.

Here's what the CheckBoxList for the distibution centers will look like:

All
Dallas
Miami
Los Angeles
Seattle
New York
Chicago
Phoenix
Montreal

If the specific city (or all the cities) are checked, then the distribution center will pull the barbecue grill for shipment.

The added part is that I want to:

  1. be able to create a grid view from this database for reporting to note which distribution center got orders for barbecues and

  2. be able to create reports to tell what distribution center sent out barbecue orders in a given month (among other reporting).

Here's what I'm playing around with right now.

In my aspx page I have a checkboxlist programmed with all the distribution centers entered as a listitem as well as an option for 'ALL' (of the distribution centers).

I also created a dedicated column in this table that holds all the information in the listitem and programmed a sqldataconnection to this table to play with the programmability of leveraging the database for this purpose.

When it comes to writing the selections to the database, I originally created a column for each destination city including the 'All' option. I was toying around with just putting the selections into one single column but with some of the information I've been reading today about Database Normalization, the former options seems to be a better one than the latter. Is this correct practice for situations such as this especially if I need to think about reporting? Do I put the CheckBoxList data in one cell in a specific column? Do I create seprate columns for each distribution center? Am I even on the right track here?

4

2 回答 2

2

根据您要存储的城市数量,我使用按位运算符来存储少量数据。实际上,它会将其存储在表中,如下所示:

CityID   Location
2        Dallas
4        Miami
8        New York
16       Chicago
32       Montreal

并继续在基地 2 中寻找其他城市。

当您的用户为订单选择多个城市时,插入到城市数据库中的值是按位或计算。因此,如果他们选择达拉斯、纽约和芝加哥,您将执行以下操作:

2 OR 8 OR 16

这将等于 26

现在,您可以对结果值使用按位与。因此,如果检查迈阿密,则评估如下:

26 AND 4 = 0

这表明未选择迈阿密。在评估中选择的任何值,它将返回其 ID,如下所示:

26 AND 8 = 8

同样,我只将它用于小数据子集,并使数据存储尽可能紧凑。在计算上,它可能比其他一些方法贵一点,但我不是 100% 确定。

于 2013-06-24T21:45:52.130 回答
1

注意:这可能不是最好的方法,但我已经看到它们使用过。

1)有一列逗号分隔的字符串如果选项在数据库中没有ID(有一个单独的引用表),这应该很好用

  • 您将需要遍历复选框列表,获得选定的选项并将它们与String.Join()
  • 您需要在从数据库接收到字符串时拆分字符串,并使用它来检查复选框,如果在结果数组中找到文本
  • 问题:您可能需要 DB 中的 split 函数将逗号分隔的字符串转换为行。在 web/stackoverflow 上有 split 函数实现

2) 您可以为位置设置一个单独的表,例如 xxxxtable_location,其中引用了主表的 FK。这将是一个多表

ParentID,   Location
1           Dallas
2           Miami
2           New York
2           Chicago
3           Miami
于 2013-06-24T20:13:20.027 回答