为公司存储和选择多个州/城市的最佳方式?

发布于 2024-07-30 12:25:56 字数 724 浏览 6 评论 0原文

我有 A 公司。我需要能够将该公司链接到多个州,而每个州又可以链接到多个城市。 例如:

Company A
         \
          - State A
                  |-City A
                  |-City B
         \        |-City C
          - State B
                  |-City A
                  |-City B
         \        |-City C
          - State C
                  |-City A
                  |-City B
                  |-City C

我的问题是:

  1. 将其存储在表中的最佳方法是什么?
  2. 允许用户选择此选项而无需多次刷新页面的最简单方法是什么?

我使用 ASP.NET (Framework 3.5) 和 C#。 如果有任何控件可以做到这一点,那么指向它们的指针也将受到高度赞赏。

谢谢,

吉姆

编辑:例如,我需要选择“公司 A”。 然后选择“状态A”。 在“A 州”下,我选择“A、B 和 C 城市”。 然后选择“State B”,并在其下选择“City A & B”。

I have Company A. I need the ability to link this Company to multiple States, and each state can in turn be linked to multiple Cities. For example:

Company A
         \
          - State A
                  |-City A
                  |-City B
         \        |-City C
          - State B
                  |-City A
                  |-City B
         \        |-City C
          - State C
                  |-City A
                  |-City B
                  |-City C

My questions are:

  1. What is the best way to store this in a table?
  2. What is the easiest way to allow a user to choose this without multiple page refreshes?

I use ASP.NET (Framework 3.5) with C#. If there are any controls around that can do this, a pointer to them would be most appreciated too.

Thanks,

Jim

Edit: For example, I need to choose "Company A". Then choose "State A". Under "State A", I choose "City A, B & C". Then choose "State B" and under that choose "City A & B".

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

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

发布评论

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

评论(2

小ぇ时光︴ 2024-08-06 12:25:56

您可能希望将其存储在四个表中,

**Companies**
Name OtherInfo CompanyID

**States**
Name OtherInfo StateID

**Cities**
Name StateID CityID OtherInfo

**CompaniesInCities**
CompanyID CityID

这样,州和城市就可以在没有公司的情况下存在。

至于选择它们的控件,如果要选择单个城市,可以使用 AJAX CascadingDropDownList 可能是最好的选择。

在没有多次页面刷新的情况下执行此操作(至少如果我理解正确的话)将非常困难,并且可能会让用户感到困惑。 最好的办法是让它们尽可能无痛,这可能涉及也可能不涉及使用 AJAX。

You will probably want to store this in four tables

**Companies**
Name OtherInfo CompanyID

**States**
Name OtherInfo StateID

**Cities**
Name StateID CityID OtherInfo

**CompaniesInCities**
CompanyID CityID

This way, states and cities can exist without companies.

As far as a control to select them, if you want to select a single city, an AJAX CascadingDropDownList may be the best option.

Doing this without multiple page refreshes, at least if I understand you correctly, will be extremely difficult and probably confusing for the user. Your best shot is to make them as painless as possible, which may or may not involve using AJAX.

攀登最高峰 2024-08-06 12:25:56

要回答您的第一个问题,我会将其存储为:

STATE
----------------------------
STATE_KEY                      NOT NULL NUMBER                                                                                                                                                                                        
COUNTRY                        NOT NULL VARCHAR2(3)    (ISO 3-letter code)                                                                                                                                                                               
STATE_SHORT                    NOT NULL VARCHAR2(30)                                                                                                                                                                                  
STATE_NAME                     NOT NULL VARCHAR2(30)  


CITY
----------------------------
CITY_KEY                       NOT NULL NUMBER                                                                                                                                                                                        
STATE                          NOT NULL NUMBER    (FK into STATE)                                                                                                                                                         
CITY_NAME                      NOT NULL VARCHAR2(30)                                                                                                                                                                                  
LAT                                     NUMBER                                                                                                                                                                                        
LOG                                     NUMBER  

COMPANIES
----------------------------
STATE_ID NUMBER NOT NULL      (FK into State)
.... Other Data Cols.....


您可能会考虑做的一件事是将公司链接到城市键,并将 FK 链接到城市,并拥有像 usa;fl;null 和 usa;ca;null 这样的城市代表该州内的所有城市。 通过这种方式转换为基于特定城市的公司并不会真正改变您的整体计划。 如果您知道您将始终与与州相关的公司打交道,那么最好在公司中执行 state_id (如上所示)。

祝你的项目好运。

To answer your first question, I would store it something like:

STATE
----------------------------
STATE_KEY                      NOT NULL NUMBER                                                                                                                                                                                        
COUNTRY                        NOT NULL VARCHAR2(3)    (ISO 3-letter code)                                                                                                                                                                               
STATE_SHORT                    NOT NULL VARCHAR2(30)                                                                                                                                                                                  
STATE_NAME                     NOT NULL VARCHAR2(30)  


CITY
----------------------------
CITY_KEY                       NOT NULL NUMBER                                                                                                                                                                                        
STATE                          NOT NULL NUMBER    (FK into STATE)                                                                                                                                                         
CITY_NAME                      NOT NULL VARCHAR2(30)                                                                                                                                                                                  
LAT                                     NUMBER                                                                                                                                                                                        
LOG                                     NUMBER  

COMPANIES
----------------------------
STATE_ID NUMBER NOT NULL      (FK into State)
.... Other Data Cols.....


One thing you might consider doing is to link the companies to the city key and FK into city instead, and have a cities like usa;fl;null and usa;ca;null to represent all cities within that state. This way converting over to companies based on a specific city doesn't really change your overall scheme. If you know that you'll always be dealing with companies linked to states, then doing the state_id in companies (as shown above) would be preferrable.

Good luck with your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文