ASP.NET 2.0 添加到数据库的正确控制

发布于 2024-09-30 23:59:21 字数 951 浏览 2 评论 0原文

我正在寻找一些建议。我已经在 Oracle EnterpriseOne 平台上进行了大约 11 年的开发,现在正在跃迁到 c#。因此,我对编程并不陌生,但在创建 C# ASP.NET 网页时,我很难在脑海中记住几个概念。

我有以下场景:

所以我有一个订单标题+一个订单详细信息表,我想创建一个新订单,每个订单标题可能有多个订单行。

在 EnterpriseOne 中,我将有一个登陆屏幕,可以在其中搜索、选择和添加新订单。当您单击“添加”按钮时,我将加载一个标题屏幕(无网格),您可以在其中输入所有订单详细信息记录所共有的所有订单标题信息。单击“确定”(到标题屏幕)时,我将显示一个详细信息屏幕(网格),您可以在其中添加多个订单详细信息记录。

那么我该如何在 c# ASP.NET 2.0 中做到这一点呢?我想创建一个 N 层应用程序。

  1. 我创建了与我的订单标题和订单详细信息表相匹配的新类(OrdersHeader + Order Detail)。
  2. 我创建了一个新类 (OrdersDB),它与订单标题/详细信息类和数据库(使用 ADO.NET 和存储过程)进行交互。
  3. 在登陆屏幕上,我创建了一个指向 OrdersDB 的 ObjectDataSource 和 SelectMothod...因此这将返回 OrderDetails 的集合,并允许用户搜索和选择现有的 orderdetails。
  4. 我创建一个标题屏幕(当他们单击“添加”时),其中将包含文本框+标签的列表。单击“确定”时,我将从屏幕上的值创建一个新的 OrderHeader 类的实例,并将其传递给 OrdersDB 的插入方法。这是正确的吗?
  5. 在详细信息屏幕上,我应该使用哪个控件来让用户添加订单详细信息?我假设我可以使用 GridView,它被设置为允许插入,但是当查询空数据库时,这会带回一个空白网格(现在允许我添加新行)。

我希望这足够清楚。我确信我需要做什么是显而易见的,但我认为在另一个平台工作多年让我困惑了这个问题。

I am looking for some advice. I have been developing for about 11 years on the Oracle EnterpriseOne platform and am now making the leap to c#. So I am no stranger to programming but there are a couple of concepts I am struggling to tie up in my head when creating c# ASP.NET webpages.

I have the following scenario:

So I have an order header + an order detail table and I want to create a new order, there could potentially be multiple order lines for each order header.

In EnterpriseOne I would have a landing screen where could search, select and add new orders. When you click the add button i would load a header screen (no grid) where you would enter all the order header info, common to all order detail records. When clicking OK (to the header screen) I would display a detail screen (grid) where you could add the multiple order detail records.

So how do I do this in c# ASP.NET 2.0? I would like to create an N-tier application.

  1. I have created new classes (OrdersHeader + Order Detail) which match to my order header and order detail tables.
  2. I have created a new class (OrdersDB) which interacts with the order header/detail classes and the database (using ADO.NET and stored procedures).
  3. On the landing screen I have created an ObjectDataSource pointing to OrdersDB and the SelectMothod... so this will return a collection of OrderDetails and allow the user to seach and select on existing orderdetails.
  4. I create a header screen (when they click add) which will contain a list of text boxes +labels. When clicking OK I will create a instance of a new OrderHeader class from the values on screen and pass to the insert method of OrdersDB. is this correct?
  5. On the details screen which control should I use to let the user add order details? I was assuming I could use the GridView which was set up to allow Inserting but when inquiring on an empty DB this is bringing back a blank grid (and now allowing me to add new rows).

I hope thats clear enough. I am sure it is obvious what i need to do, but i think years of working in another platform has confused the issue for me.

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

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

发布评论

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

评论(2

累赘 2024-10-07 23:59:21

这实际上取决于您所迎合的用户界面。

如果您想要一个基本上可以直接编辑数据库中的行(编辑值、删除记录、添加记录)的屏幕,您可能需要GridView

它还取决于您对 ASP.NET Web 表单的熟悉程度/经验。 Web 表单在“拖放”意义上非常出色(在我看来,这也是它的缺点)。这意味着您可以将控件放在页面上并准备好开始。

但有时这是矫枉过正。我更喜欢仅在绝对必要时才使用网络控件。

我将保留一个简单的表单、基本表单字段,然后在服务器上构建实体并传递到业务层进行验证和持久化。完全控制流程。

顺便说一句,我在您的问题中没有看到您迄今为止的解决方案如何是 N 层的?如果您想要 N 层,您应该通过某种 Web 服务(即 WCF)与数据层(位于与 Web 层不同的计算机上)进行通信,而不是直接调用 OrdersDB

It really depends on the UI you are catering for.

If you want a single screen where you can basically directly edit rows in the database (edit values, delete records, add records) your probably looking for a GridView

It also depends on your comfort level/experience with ASP.NET Web Forms. Web Forms is great in the "drag and drop" sense (which IMO is also it's downfall). Meaning you can chuck a control on a page and be ready to go.

But sometimes it's overkill. I prefer to use the web controls only when absolutely necessary.

I would be keeping with a simple form, basic form fields, then constructing the entity on the server and passed onto the business tier for validation and persistence. Have full control over the process.

By the way, i don't see in your question how any of your solutions so far is N-Tier? If you want N-Tier, you should be communicating with your data tier (which would be on a seperate computer to your web tier) via some sort of web service (ie WCF), no directly calling OrdersDB

奶气 2024-10-07 23:59:21

我认为你的想法是正确的。问题是如何使用网格视图进行插入,不幸的是它没有附带插入项模板。最简单的方法是将插入控件放在面板中,并在单击“添加项目”按钮时显示控件。

您可以通过将插入控件添加到页脚项模板来使用网格视图进行插入,但您必须自己处理页脚行的隐藏和显示。此外,如果您绑定到空数据集,则页脚行也不会出现,因此您必须使用虚拟记录或其他内容填充网格视图,以便在没有项目时显示页脚,因此需要跳过一些步骤,但如果你用谷歌搜索,你应该会找到一些例子。这是看起来有效的一个: http: //www.aspdotnetfaq.com/Faq/How-to-insert-row-in-GridView-with-SqlDataSource.aspx

还有其他控件可以使用,例如detailsview和formview,但老实说我从不使用它们因为当您添加事务和自定义验证等复杂性时,这可能会很痛苦,我认为手动处理所有代码以进行编辑和插入会更容易,除非这是一个非常简单的情况。它们能够从数据库模式自动生成字段和标签,因此非常有用。

因此,至少对我来说,我使用网格视图进行查看,有时进行编辑,但很少用于插入,并且我很少使用内置更新和双向数据绑定。通常,如果我在网格视图中进行编辑,我将仅使用编辑按钮来捕获编辑项索引,并使用命令参数或网格数据键获取键并自己处理更新代码。并不是说这是最好的方法,这只是我最常用的方法。

I think you got the right idea. The problem is how do you do inserts with a grid view, and unfortunately it does not come with an insert item template. The easiest way to do this is just put your insert controls in a panel and show the controls when they click the add item button.

You can use the grid view for inserting, by adding the insert controls to the footer item templates, but you will have to handle the hiding and showing of the footer row yourself. Also the footer row will not appear if you are binding to an empty dataset, so you have to populate the gridview with a dummy record or something to get the footer to show up when there are no items so there are a few hoops to jump though, but if you google it you should find some examples. Here is one that looks valid: http://www.aspdotnetfaq.com/Faq/How-to-insert-row-in-GridView-with-SqlDataSource.aspx

There are also other controls you can use like detailsview and formview, but honestly I never use them because by the time you add in complexity like transactions and custom validations and all that it can be a pain and I think it is just easier to handle all the code manually for the edit and insert unless it is a really simple situation. They are nice for their ability to auto generate fields and labels from the database schema, so they can be useful.

So for me at least, I use grid view for viewing, and sometimes editing, but rarely for inserting, and I rarely use the built in updating with the two way data binding. Usually if I edit in grid view I will just use the edit button to capture the edit item index, and grab the key with the command argument or the griddatakeys and handle the update code myself. Not saying this is the best way, it is just how I most often do it.

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