0

I have employee data capture application. .net and t-sql.

It has number of lookup(metadata) tables which used to populate drop downs in the UI. ex: "Departments". Every lookup table has active flag. Sometimes this flag set to false. This means I should not load those inactive “Departments” in the drop down. This perfectly works for ADD NEW EMPLOYEE scenario. But in EDIT EMPLOYEE scenario, if one lookup record (Department-HR) happens to be inactive but associated with the EMPLOYEE for some reson, I have a problem that the Department-HR is missing in the drop down to select.

I know question looks silly. I can pass EmployeeId and load Active + all associated departments to EmployeeId, but I want to know a smarter and cleaner way to handle the situation.

4

1 回答 1

0

一种方法是防止删除一个部门,如果它首先被员工使用。如果他们在可能导致员工数据无效的时候被通知问题,这对用户会更有帮助。

如果您的数据库中有一个EmployeesandDepartments表(具有一对多或多对多关系),那么您将配置适当的外键。如果您实际上是从Departments表中删除部门行(而不是将它们标记为非活动),那么如果有任何员工记录引用正在删除的部门,那么显然您会遇到外键违规。

如果您将部门标记为“非活动”,那么当用户尝试将其标记为非活动时,您的 UI 可能会显示引用该部门的员工列表。然后可以为他们提供一个 UI,用于将员工分配到另一个部门。

无论哪种方式,我都不确定为什么您有专门用于填充部门下拉列表的表格?为什么不Departments直接从表中填充?添加新员工界面和编辑员工界面可以查询得到所有活跃部门的列表,编辑界面还可以查看员工当前部门的活跃状态,然后在用户进入时提示用户重新分配员工编辑屏幕。

于 2012-09-06T20:57:38.437 回答