自己写的一些类代码
以前在寫類代碼時候,改寫了一些自定義的類代碼,自己在做CManage時,一些傳統(tǒng)的類老是要重復地寫。有點煩,在參考同學的類代碼中。自己也寫了一些類。以下就是這個作業(yè)的類的代碼。
這里是一個類,存儲字段的類
Public?Class?ParmClass?Parm
????Public?str1?As?String
????Public?str2?As?String
????Public?str3?As?String
????Public?str4?As?String
????Public?str5?As?String
????Public?DataKeyField?As?String
????Public?DataTextField?As?String
????Public?DataValueField?As?String
????Public?objCtr?As?Object
End?Class ?'返回sqldatareader(數(shù)據(jù)讀取器)(用于查找數(shù)據(jù))
????Public?Function?ReturnReader()Function?ReturnReader(ByVal?myParm?As?Parm)?As?SqlDataReader
????????Dim?Cmd?As?SqlCommand?=?ReturnCmd(myParm)
????????Dim?MyDtr?As?SqlDataReader?=?Cmd.ExecuteReader(CommandBehavior.CloseConnection)
????????Return?MyDtr
????End?Function
????Public?Function?ReturnCmd()Function?ReturnCmd(ByVal?myParm?As?Parm)?As?SqlCommand
????????con.Open()
????????Dim?Cmd?As?SqlCommand
????????Cmd?=?New?SqlCommand(myParm.str1,?con)
????????Cmd.CommandType?=?CommandType.StoredProcedure
????????Return?Cmd
????End?Function
????'數(shù)據(jù)控件的數(shù)據(jù)綁定(通用于Dropdownlist,datagrid,datalist)(數(shù)據(jù)源是Datareader)
????Public?Sub?DataControlDataReaderBinding()Sub?DataControlDataReaderBinding(ByVal?myp?As?Parm)
????????myp.objCtr.DataSource?=?ReturnReader(myp)
????????If?TypeOf?(myp.objCtr)?Is?DataList?Or?TypeOf?(myp.objCtr)?Is?DataGrid?Then
????????????If?myp.DataKeyField?<>?""?Then
????????????????myp.objCtr.DataKeyField?=?myp.DataKeyField
????????????End?If
????????????myp.objCtr.DataBind()
????????ElseIf?TypeOf?(myp.objCtr)?Is?DropDownList?Then
????????????myp.objCtr.DataTextField?=?myp.DataTextField
????????????myp.objCtr.DataValueField?=?myp.DataValueField
????????????myp.objCtr.DataBind()
????????End?If
????????con.Close()
????End?Sub ??Dim?myTest?As?New?Test
????Private?Sub?ddlBindClass()Sub?ddlBindClass()
????????Dim?myParm?As?New?Parm
????????myParm.str1?=?"sp_SelectNewsClass"
????????myParm.objCtr?=?ddlBindNewsClass
????????myParm.DataTextField?=?"ClassName"
????????myTest.DataControlDataReaderBinding(myParm)
???????????End?Sub
這里是一個類,存儲字段的類
Public?Class?ParmClass?Parm
????Public?str1?As?String
????Public?str2?As?String
????Public?str3?As?String
????Public?str4?As?String
????Public?str5?As?String
????Public?DataKeyField?As?String
????Public?DataTextField?As?String
????Public?DataValueField?As?String
????Public?objCtr?As?Object
End?Class ?'返回sqldatareader(數(shù)據(jù)讀取器)(用于查找數(shù)據(jù))
????Public?Function?ReturnReader()Function?ReturnReader(ByVal?myParm?As?Parm)?As?SqlDataReader
????????Dim?Cmd?As?SqlCommand?=?ReturnCmd(myParm)
????????Dim?MyDtr?As?SqlDataReader?=?Cmd.ExecuteReader(CommandBehavior.CloseConnection)
????????Return?MyDtr
????End?Function
????Public?Function?ReturnCmd()Function?ReturnCmd(ByVal?myParm?As?Parm)?As?SqlCommand
????????con.Open()
????????Dim?Cmd?As?SqlCommand
????????Cmd?=?New?SqlCommand(myParm.str1,?con)
????????Cmd.CommandType?=?CommandType.StoredProcedure
????????Return?Cmd
????End?Function
????'數(shù)據(jù)控件的數(shù)據(jù)綁定(通用于Dropdownlist,datagrid,datalist)(數(shù)據(jù)源是Datareader)
????Public?Sub?DataControlDataReaderBinding()Sub?DataControlDataReaderBinding(ByVal?myp?As?Parm)
????????myp.objCtr.DataSource?=?ReturnReader(myp)
????????If?TypeOf?(myp.objCtr)?Is?DataList?Or?TypeOf?(myp.objCtr)?Is?DataGrid?Then
????????????If?myp.DataKeyField?<>?""?Then
????????????????myp.objCtr.DataKeyField?=?myp.DataKeyField
????????????End?If
????????????myp.objCtr.DataBind()
????????ElseIf?TypeOf?(myp.objCtr)?Is?DropDownList?Then
????????????myp.objCtr.DataTextField?=?myp.DataTextField
????????????myp.objCtr.DataValueField?=?myp.DataValueField
????????????myp.objCtr.DataBind()
????????End?If
????????con.Close()
????End?Sub ??Dim?myTest?As?New?Test
????Private?Sub?ddlBindClass()Sub?ddlBindClass()
????????Dim?myParm?As?New?Parm
????????myParm.str1?=?"sp_SelectNewsClass"
????????myParm.objCtr?=?ddlBindNewsClass
????????myParm.DataTextField?=?"ClassName"
????????myTest.DataControlDataReaderBinding(myParm)
???????????End?Sub
轉載于:https://www.cnblogs.com/zhangchenliang/archive/2006/05/22/406603.html
總結
- 上一篇: 小程序生成海报 详解
- 下一篇: [设计原则与模式] 如何理解TDD的