如何使用从一种形式到另一种形式的编码 [英] How to use the coding from one form to another form

查看:83
本文介绍了如何使用从一种形式到另一种形式的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用vb.net2005.我需要如何使用从一种形式到另一种形式的编码.我还有另外两个表单,例如登录"表单,注册"表单,计算"表单.
我对每种表格使用了相同的代码.但是我需要我仅以一种形式编写通用代码,而在不编写每种形式的情况下习惯于另一种形式.

例如.

Hi,

I am using vb.net 2005. I need, how to use the coding from one form to another form. I have two more forms like, Login form, Registration form, Calculation form.
I used the same code to each forms. But i need i wrote the common code only in one form and it used to another forms without wrote the each forms.

for ex.


Imports System.Data
Imports System.Data.OleDb

Public Class Form1
Dim con As OleDbConnection
Dim com As OleDbCommand
Dim adp As OleDbDataAdapter
Dim reader As OleDbDataReader
Dim ds As DataSet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
.
.
.
.

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\gopi\password\pass.mdb")
con.Open()

End Sub
End Class


上面的粗体代码将以另一种形式使用.我需要使用它而无需写入另一种形式.是否有可能?如果可能,请举例说明.

谢谢
Gopi A


The above bold code will be use in another form. I need to use it without write into another form. Is it possible? if possible means please explain with example.

Thanks
Gopi A

推荐答案

这是数据库操作,应与UI分开,并保留在数据访问层中.

一个单独的类,它将执行数据库操作.在UI中,只需调用该类公开的方法即可.
This being database operations, it should be separated out from the UI and kept in a data access layer.

A separate class that would do database operations. In the UI, just call the methods exposed by that class.


最好在与UI分开的项目中执行与数据库相关的任务.这将使事情易于理解和维护.

您可以创建一个新类,如下所示:

It is good to perform database related tasks in a separate project than UI. It would make things easy to understand and maintain.

You can create a new class which might look something like this:

class DBOperations{

// initialize the objects required for database operation here
// you can make use of these objects throughout the class

CreateRecord(){
// Insert operations
}

UpdateRecords(){
// update operations
}

ReadRecords(){
// select operations
}
DeleteRecords(){
// delete operations
}
}



现在,在用户界面中,您要做的就是从此类中调用适当的方法.这堂课会好好休息的.

在这里,我没有提到方法的返回类型,参数和访问修饰符.您可以根据自己的项目来决定.

另外,不要使用硬编码的字符串,而使用配置文件并从那里读取它们.

*我不太了解VB,因此我使用了C#.希望您能理解.



Now, in your UI, all you should do is call the appropriate method from this class. This class will take care of rest.

Here I have not mentioned return types, parameters and access modifiers for the methods. You can decide those depending on your project.

Also, instead of having hardcoded strings, use config files and read them from there.

*I don''t know much of VB hence I used C#. I hope you understand it.


您好
我不清楚.请深入解释.

感谢您的快速答复.

感谢和问候,
Gopi A
Hi
I am not clear. Please explain deep.

Thanks for your quick reply.

thanks and regards,
Gopi A


这篇关于如何使用从一种形式到另一种形式的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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