简体   繁体   English

静态与动态控制+基于情境

[英]Static Vs Dynamic controls + Situation based

I'm building an web application to manage instructions based on different parameters (eg. JobCode, State, Customer, Product etc..). 我正在构建一个Web应用程序,以基于不同的参数(例如JobCode,状态,客户,产品等)来管理指令。 I have allocated some 20 filler fields for each of such parameters. 我为每个此类参数分配了约20个填充字段。 The display names of the fields may differ from One Project to another. 各个项目的字段显示名称可能不同。 (multiple implementation). (多种实现)。

Some project may not use all the 20 fields but only say 5-6 fields... 某些项目可能不会使用全部20个字段,而只会说5-6个字段...

Now, one of my colleague is suggesting me to customise the stored procedure to return and accept the fields with column names required by the project, and let the SP do the lookup with actual column names. 现在,我的一位同事建议我自定义存储过程,以返回并接受项目需要的具有列名的字段,并让SP用实际的列名进行查找。 He also suggests to build controls dynamically. 他还建议动态构建控件。

I thought of providing static controls to all the 20 fields and just populate the labels with the necessary field names and interact with SP using field names "Filler1", "Filler2". 我想为所有20个字段提供静态控件,并仅使用必要的字段名称填充标签,并使用字段名称“ Filler1”,“ Filler2”与SP进行交互。 This also means we need to make the non-required control invisible... 这也意味着我们需要使不需要的控件不可见。

As more experienced users... Can you enumerate the pros and cons in both... 作为经验更丰富的用户...您能否列举两者的优缺点...

Thanks 谢谢

Its never good practice to use a set number of fields as you are describing (its better to build it dynamically - but make sure you write efficient code). 在描述时使用一定数量的字段永远不是一个好习惯(最好动态创建它-但要确保编写高效的代码)。 By creating a set number of controls, you are limiting yourself, and creating a big maintenance problem. 通过创建一定数量的控件,您在限制自己,并造成了很大的维护问题。 You may not see it now, but later, what happens if the number of controls changes? 您现在可能看不到它,但是以后,如果控件数量发生变化,会发生什么?

Your colleague's suggestion would work. 您同事的建议会起作用。 At least you'll have the ability to change the number of controls at any time without recompiling your code. 至少您可以随时更改控件的数量,而无需重新编译代码。

For the end user it is going to be quite hard to understand the interface if the fields that are not applicable for a particular case are still visible. 如果对于特定情况不适用的字段仍然可见,那么对于最终用户而言,很难理解界面。

So I would indeed advise not to generate any fields you don't need, or at the very least hide them in case they are not needed. 因此,我的确建议不要生成不需要的任何字段,或者至少隐藏它们以防不需要。

As for where to put the logic...well it does make sense to pull the data that determines what fields should be shown when from the database. 至于放置逻辑的位置...那么从数据库中提取确定应该显示哪些字段的数据确实有意义。 But I would recommend against putting all the logic that actually renders the page inside a stored procedure. 但是我建议不要将所有实际呈现页面的逻辑放在存储过程中。 Rather, you would use the SP to fetch the data, and use your language (PHP, C#/ASP.NET, Java Servlet, what haveyou) to actually process the data and render the page. 相反,您将使用SP来获取数据,并使用您的语言(PHP,C#/ ASP.NET,Java Servlet等)来实际处理数据并呈现页面。

htht. htht。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM