将演示文稿与数据层分开 [英] Separating presentation from data layer

查看:68
本文介绍了将演示文稿与数据层分开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好......我可以在这里使用一点TLC来理解,而不是用于解决特定问题的
...对不起,如果我有错误的小组,但我'' m

使用VB所以我认为这是最合适的。


我是一名高级初学者,但在所有书籍和课堂资料中我有,

我还没有发现一些关于这个问题的东西...很多很高的理论说话,但没有任何说法简单来说。


我正在建立一个应用程序,并希望将演示文稿和数据分开东西。

这里有一些根据我的理解,我想采取的方法背景:


在我的VS项目(一个ASP.NET项目)中,我有三件重要的事情:


1)Submit.aspx - 这是演示文稿thing。它主要包含

只是网页控件。文本框,DateTime控件(来自供应商),标签,

和提交按钮。例如,让我们说字段是:

FullName,PhoneNumber,DOB。


2)DataLayer.vb - 这是我的 ;数据"东西。它包含一个名为

" User"这是我表单中数据的模型。因此,FullName,PhoneNumber和DOB都有读/写

属性。此外,还有一种名为

" SaveToDB"的方法。确实如此 - 打开数据库连接并将数据插入表中。


3)Submit.aspx.vb - 代码-behind for Submit.aspx ...这里有一个事件

处理程序,用于提交按钮:


- 基于实例化实例化一个对象用户类

- 使用来自Web控件的值设置此对象的属性

- 调用该对象上的SaveToDB方法将值写入

数据库。


我的问题是:


1)我可能还想写几个其他类,可能要处理

有效期......我是否适合在DataLayer.Vb中编写它们?我的

混淆是因为在Visual Studio中,当我添加一个新项目时,它指的是

它是一个类...这只是应该包含一个班级?


2)这种方法是否合理---我知道这是一个小应用......只是一个

的例子,但如果是更大(即表格上的更多控件,更多

字段等),这是正确的方法吗?如果没有,我在做什么

错了?


3)在这样的应用程序中,你在表单中提交信息,是

最好回发并隐藏表单以显示成功,或者是否b / b
考虑更好的做法提交到第二页并拥有该页面

来电我的数据层?


提前感谢您的时间...


Michelle

解决方案

Michelle,


因为这是一个通用的方法问题,这里有一些一般的答案。


A dotNet webapplication with data是基本直接启动3层

应用程序。


第3层

页面(aspx),即来自中间层生成的HTML页面,该页面由客户的webbrowser处理,并与您的

数据库进行通信。


第2层

为处理请求和答案而创建的DLL适用于所有

用户同时活动


第1层

您的数据库。


实际上你在dotNet webdevelopment中一直忙于第2层。

客户端层是在数据库存在时生成的。


如果你正在构建应用程序(DLL),那么在你看来应该是你应该愚蠢的不要做你说的话。


创建所有数据库访问权限在一个单独的组件(类)中为此(和

添加比IDE的项目组件为此。


但请注意,该中的所有数据如果你将它设置为共享类,将由所有用户共享




因此我会在你的情况下至少制作两个(数据)类。


一个人可以通过

所有客户共享所有不可更新的日期(地址簿,文章列表等),而无需更新。


一个(或多个)用作帮助类,用于所有数据库

处理。那个你每次必须创建的新对象来自它使用的UI中的这个

类。这是因为如果生成的页面(再次)被发送到

客户端,则处理后的网页数据将完全从scoop中删除。 (一个webform不是持久的)


我希望这能给出一些想法。


Cor


Cor:


感谢您抽出时间...


您能解释一下最后两段吗? ---我不清楚你有什么建议的b $ b。你的意思是一个类文件(例如:readData.vb)只是从数据库读取操作和一个类文件(例如:updateData.vb)

那个只处理插入,删除和更新操作?


谢谢,

米歇尔


" Cor Ligthert [MVP ]" <无************ @ planet.nl>在消息中写道

news:uB ************** @ tk2msftngp13.phx.gbl ...

Michelle,
因为这是一个通用的方法问题,这里有一些一般的答案。

带有数据的dotNet网络应用程序基本上直接启动3层
应用程序。
页面(aspx),来自中间层生成的HTML页面,由客户端的webbrowser处理,并与您的
数据库进行通信。

第2层
DLL,用于处理请求和答案,同时为所有用户提供活动

第1层您的数据库。

您实际上在dotNet webdevelopment中一直忙于第2层。
客户端层是在数据库存在的情况下生成的。
如果你正在构建应用程序(DLL),那么你应该在我看来是愚蠢的,不要做你说的。

创建所有数据库访问为此工作的组件(类)(并将项目组件添加到IDE中。

但请注意,如果将其设置为共享,该类中的所有数据将为
由所有用户共享。

因此我会在你的情况下制作至少两个(数据)类。

一个分享所有不可更新的日期(地址簿,文章列表等等)所有客户都没有因此更新。

一个(或多个)用作帮助类,用于所有数据库处理。那个你必须在它使用的UI中每次创建这个
类的新对象。这是因为如果生成的页面(再次)被发送到客户端,则处理的web页面的数据将完全脱离scoop。 (网页形式不是永久性的)

我希望这能给出一些想法。

blockquote>

Michelle,


没有任何一项操作是为您在页面中使用的所有一致的

数据创建共享类。你可以做一次。


只要问一下(如果数据源什么都没有)


比你的页面有只需将数据加载到内存中一次


您不能在必须更新的数据中使用它(或者它应该是非常困难的

) 。


每次刷新页面时都需要创建对象。


我建议你使用单独的类。


我希望这能给出一个想法


Cor


Hi all... I could use a little TLC here for understanding and not for
solving a specific problem... sorry if I''ve got the wrong group, but I''m
using VB so I figured this was the most appropriate one.

I''m an advanced beginner, but in all of the books and class material I have,
I haven''t found something that gets to the point about this... lot''s of high
level theoretical talk, but nothing that says things in simple terms.

I''m building an app and want to separate the presentation and data "stuff".
Here''s some background on the approach I want to take as I understand it:

In my VS project (an ASP.NET project), I''ve got 3 important things:

1) Submit.aspx -- this is the presentation "thing". It contains mostly
just web controls. Textboxes, a DateTime control (from a vendor), labels,
and a submit button. For example purposes, let''s say the fields are:
FullName, PhoneNumber, DOB.

2) DataLayer.vb -- this is my "data" stuff. It contains a class called
"User" that is a model of the data in my form. So, there are read/write
properties for FullName, PhoneNumber and DOB. Also, there''s a method called
"SaveToDB" that does exactly that--- opens a database connection and Inserts
the data into a table.

3) Submit.aspx.vb -- The code-behind for Submit.aspx... there''s an event
handler here for the Submit button that:

- instantiates an object based on the User class
- sets the properties of this object using values from the web controls
- calls the SaveToDB method on that object to write the values to the
Database.

My questions are:

1) I might also like to write a couple of other classes, possibly to handle
validity... is it appropriate for me to write them in the DataLayer.Vb? My
confusion is because in Visual Studio, when I add a new item, it refers to
it as a "Class"... is this only supposed to contain ONE class?

2) Is this approach reasonable--- I know this is a small app... just an
example, but if it were a lot bigger (i.e. more controls on the form, more
fields, etc), would this be the right approach? If not, what am I doing
wrong?

3) In an app like this, where you are submitting information in a form, is
it better to postback and hide the form to display success, or is it
considered better practice to submit to a second page and have that page
call my data layer?

Thank you in advance for your time...

Michelle

解决方案

Michelle,

As this is a general approach question, here some general answers.

A dotNet webapplication with data is basicly direct starting a 3 tier
application.

Tier 3
The page (aspx), that is from the middle tier generated HTML page which is
processed by the webbrowser of the client and which communitace with your
database.

Tier 2
The DLL, that is created for handling the request and answers and is for all
users at the same time active

Tier 1
Your database.

You are in fact all the time in dotNet webdevelopment busy with Tier 2. The
client tier is generated from that while the database exist.

If you are building the application (the DLL), than you should in my opinion
be stupid not to do what you say.

Create all database access in a seperated components (classes) for this (and
add than the item component to your IDE for this.

However be aware that all data in that class if you set it shared, will be
shared by all users.

Therefore I would make in your situation at least two (data) classes.

One to share all non updatable date (addressbooks, article lists, etc) by
all clients, without consequently updating.

One (or more) to use as a helper class, to use for all your database
handling. That one you have to create every time as new object from this
class in the UI''s that it uses. This because the data of a handled web page
will go completly out of scoop if the generated page is (again) sent to the
client. (A webform is not persistent)

I hope this gives some idea.

Cor


Cor:

Thanks for taking the time...

Can you explain your last 2 paragraphs?--- it''s unclear to me what you''re
suggesting. Do you mean one class file (eg: readData.vb) that does just
read operations from the database, and one class file (eg: updateData.vb)
that handles only Insert, Delete and Update operations?

Thanks,
Michelle

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...

Michelle,

As this is a general approach question, here some general answers.

A dotNet webapplication with data is basicly direct starting a 3 tier
application.

Tier 3
The page (aspx), that is from the middle tier generated HTML page which is
processed by the webbrowser of the client and which communitace with your
database.

Tier 2
The DLL, that is created for handling the request and answers and is for
all users at the same time active

Tier 1
Your database.

You are in fact all the time in dotNet webdevelopment busy with Tier 2.
The client tier is generated from that while the database exist.

If you are building the application (the DLL), than you should in my
opinion be stupid not to do what you say.

Create all database access in a seperated components (classes) for this
(and add than the item component to your IDE for this.

However be aware that all data in that class if you set it shared, will be
shared by all users.

Therefore I would make in your situation at least two (data) classes.

One to share all non updatable date (addressbooks, article lists, etc) by
all clients, without consequently updating.

One (or more) to use as a helper class, to use for all your database
handling. That one you have to create every time as new object from this
class in the UI''s that it uses. This because the data of a handled web
page will go completly out of scoop if the generated page is (again) sent
to the client. (A webform is not persistent)

I hope this gives some idea.

Cor



Michelle,

No one of the actions is to create a shared class for all your consistent
data you use in your pages. Than you can do that one time.

Just ask in the creation of that ( if a datasource is nothing)

Than your pages have only to load that data in memory once

You cannot use that in data that has to be updated (or it should be in a
very difficult way).

The objects from that will you have to be created everytime new at pageload.

I suggest you to use seperated classes for those.

I hope that this gives an idea

Cor


这篇关于将演示文稿与数据层分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆