⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geneditadd.vbold

📁 聊天 聊天 聊天 聊天 聊天 聊天
💻 VBOLD
📖 第 1 页 / 共 2 页
字号:
Option Strict Off
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System.Collections 

Namespace Generic
Public Class GenEditAdd : Inherits Control : Implements INamingContainer

Private ls_display as string
Private ls_where as string
Private ls_sql as string
Private ls_ConnStr as string
Private ls_keyField as string
Private ls_keyValue as string
Private ls_Insertprocedure as string
Private ls_Updateprocedure as string
Private ls_exitpage as string  
Private lt_datatable as datatable
Private ls_mode as string
Private ls_RequiredFields as string
Private ls_editable as string
Private ls_DropDown as string
Private ls_fieldNames as string
Protected mytbl as table
Protected DDLColumn(10) as string
Protected CodeField(10) as string
Protected DisplayField(10) as string
Protected DDLSql(10) as string
Protected FieldNamesArray(15) as string
Public Property FieldNames as string 
	Get
	      Return Cstr(ViewState("ls_FieldNames"))
	End Get
	Set
		ViewState("ls_FieldNames") = value
	End Set
End Property
Public Property InsertProcedure as string 
	Get
		Return Cstr(ViewState("ls_Insertprocedure"))
	End Get
	Set
		ViewState("ls_Insertprocedure") = value
	End Set
End Property
Public Property UpdateProcedure as string 
	Get
		Return Cstr(ViewState("ls_Insertprocedure"))
	End Get
	Set
		ViewState("ls_Insertprocedure") = value
	End Set
End Property
Public Property DropDown as string 
	Get
	      Return Cstr(ViewState("ls_DropDown"))
	End Get
	Set
		ViewState("ls_DropDown") = value
	End Set
End Property
Public Property editable as string 
	Get
	      Return Cstr(ViewState("ls_editable"))
	End Get
	Set
		ViewState("ls_editable") = value
	End Set
End Property
Public Property RequiredFields as string 
Get
	Return Cstr(ViewState("ls_RequiredFields"))
End Get
Set
	ViewState("ls_RequiredFields") = value
End Set
End Property
Public Property Mode as string
	Get
		Return Cstr(ViewState("ls_mode"))
	End Get
	Set
		ViewState("ls_mode") = value
	End Set
End Property
Public Property ExitPage as string
	Get
		Return Cstr(ViewState("ls_exitpage"))
	End Get
	Set
		ViewState("ls_exitpage") = value
	End Set
End Property
Public Property t as datatable 
	Get
		Return lt_datatable
	End Get
	Set
		lt_datatable = value
	End Set
End Property
Public Property KeyField as string 
	Get
		Return Cstr(ViewState("ls_keyfield"))
	End Get
	Set
		ViewState("ls_keyfield") = value
	End Set
End Property
Public Property KeyValue as string 
	Get
		Return Cstr(ViewState("ls_keyvalue"))
	End Get
	Set
		ViewState("ls_keyvalue") = value
	End Set
End Property
Public Property display as string 
	Get
		Return Cstr(ViewState("ls_display"))
	End Get
	Set
		ViewState("ls_display") = value
	End Set
End Property
Public Property Where as string 
	Get
		Return Cstr(ViewState("ls_where"))
	End Get
	Set
		ViewState("ls_where") = value
	End Set
End Property
Public Property SQL as string 
	Get
		Return Cstr(ViewState("ls_sql"))
	End Get
	Set
		ViewState("ls_sql") = value
	End Set
End Property
Public Property ConnStr as string 
	Get
		Return Cstr(ViewState("ls_ConnStr") )
	End Get
	Set
		ViewState("ls_ConnStr")  = value
	End Set
End Property
Protected Overrides Sub CreateChildControls()
	'-----Parse the DropDown property
	ParseDropDown
	'---Parse FieldNames
	ParseFieldNames
	'---------------Input Form-------------
	Dim dv as DataView
	Dim myConnection As OleDbConnection
	Dim myCommand    As OleDbDataAdapter
	Dim ds           As New DataSet
	Dim vSql as string
	If len(Where) < 1 then
		vSql = SQL
		mode = "insert"
	Else
		vSql = SQL + Where
		mode = "update"
	End If
	myConnection = New OleDbConnection(ConnStr)    
	myCommand = New OleDbDataAdapter(vSql, myConnection)
	myCommand.Fill(ds, "vtable")
	dv = new DataView(ds.Tables("vtable"))
	Dim Fields as Integer
	t = dv.Table
	Dim r As DataRow
	Dim c As DataColumn
	Dim cell as TableCell
	Dim row as DataRow
	Dim Fieldscount as integer 
	Dim s as string
	Dim vdisplay as string
	Dim vRequired as string
	Dim veditable as string
	Dim idx as integer
	Dim vDisplayField as string
	Dim vCodeField as string
	Dim vDDLSql as string
	Dim VFieldName as string
	vDisplay = Display + "000000000000000000000000000000000000000000"
	vRequired = RequiredFields + "000000000000000000000000000000000000000000"
	veditable = editable + "000000000000000000000000000000000000000000"
	FieldsCount = 0
	s = "<A HREF=" + ExitPage + ">Back</A>"
	me.Controls.Add(new LiteralControl(s))
	s= "<table bgcolor ='antiquewhite' style='font: 8pt verdana'>"
		me.Controls.Add(new LiteralControl(s))
	me.Controls.Add(new LiteralControl("<tr>"))
	If mode = "insert" then
	s="<td colspan='2' bgcolor='#aaaadd'"
	s= s + " style='font:10pt verdana'>Add a New Record:</td>" 
	me.Controls.Add(new LiteralControl(s))
	Else
	s="<td colspan='2' bgcolor='#aaaadd' "
	s= s + " style='font:10pt verdana'>Edit Record:</td> "
	me.Controls.Add(new LiteralControl(s))
	End if
	me.Controls.Add(new LiteralControl("</tr>"))
	'**************************************
	'UPDATE MODE
	'*************************************
	   If mode = "update" then
	      For Each r in t.Rows
		      For Each c in t.Columns
		     'Get the field name
		     vFieldName = FieldNamesArray(FieldsCount)
		     If len(vFieldName) < 1 then
			vFieldName = c.ToString
		     End If
		      'Don't show this field
		      IF  vdisplay.chars(FieldsCount) = "0" or c.ToString = KeyField then
		      Else
			      me.Controls.Add(new LiteralControl("<tr>"))
			      'label
			      me.Controls.Add(new LiteralControl("<td>"))
			      'me.Controls.Add(new LiteralControl(c.ToString))
			      me.Controls.Add(new LiteralControl(vFieldName))
			      me.Controls.Add(new LiteralControl("</td>"))	
			     'value
			     '------Read only field  hence label 
			     IF veditable.chars(FieldsCount) = "0"		
			      me.Controls.Add(new LiteralControl("<td>"))
			      me.Controls.Add(new LiteralControl(r(c).ToString))
			      me.Controls.Add(new LiteralControl("</td>"))
			     '--------Editable Fields--------
			     Else
				     '--------Drop Down List----------
				    ' If c.ToString = "code_category" then
				     If isDropDown(c.ToString)  then
					'get the index & other parameters
					idx = GetDDLindex((c.ToString))
					vDisplayField =DisplayField(idx)
					vCodeField =CodeField(idx)
					vDDLSql =DDLSql(idx)
					me.Controls.Add(new LiteralControl("<td>"))
					Dim DDL As New DropDownList
					DDL.ID = c.ToString
					DDL.DataTextField = vDisplayField
					DDL.DataValueField = vCodeField
					me.Controls.Add(DDL) 
					'---Populate the drop down----
					Dim mSql as String
					msql = vDDLSQL
					myConnection = New OleDbConnection(ConnStr)    
					myCommand = New OleDbDataAdapter(mSql, myConnection)
					myCommand.Fill(ds, c.ToString)
					DDL.DataSource = ds.Tables(c.ToString).DefaultView
					DDL.DataBind
					'set the display field
					dim dv2 as dataview
					dv2 = new DataView(ds.Tables(c.ToString))
					If c.DataType.ToString = "System.String" Then
					   msql = vCodeField + " = '" + r(c).ToString +"'"
					Else
					   msql = vCodeField + " = " + r(c).ToString  
					End If	
					dv2.RowFilter = msql
					DDL.Selecteditem.text = dv2(0)(vDisplayField).ToString
					DDL.Selecteditem.value = dv2(0)(vCodeField).ToString
					me.Controls.Add(new LiteralControl("</td>"))
				    Else
					     '---------Text Boxes-------
					     me.Controls.Add(new LiteralControl("<td>"))
					     Dim Box As New TextBox
					     Box.Text = r(c).ToString
					     Box.ID = c.ToString
					     me.Controls.Add(box) 
					     me.Controls.Add(new LiteralControl("</td>"))
				     End If
				     '------Required field ------
				     IF  vRequired.chars(FieldsCount) = "1"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -