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

📄 geneditadd.vbold

📁 聊天 聊天 聊天 聊天 聊天 聊天
💻 VBOLD
📖 第 1 页 / 共 2 页
字号:
					Dim vReq As New  RequiredFieldValidator
					vReq.controltovalidate = c.ToString
					vReq.errormessage= "Please enter " + c.ToString 
					me.Controls.Add(vReq) 
				     End If
			     End IF
		     end if	
		 FieldsCount = FieldsCount + 1
		Next c
	     Next r   
	  '**************************************
			   'INSERT MODE
	   '*************************************
	  Else  
			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 _
			  or veditable.chars(FieldsCount) = "0" 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>"))	
			     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
				      myCommand = New OleDbDataAdapter(mSql, myConnection)
				      myCommand.Fill(ds, c.ToString)
				      DDL.DataSource = ds.Tables(c.ToString).DefaultView
				      DDL.DataBind
				      me.Controls.Add(new LiteralControl("</td>"))
			     Else
				     'value
				     me.Controls.Add(new LiteralControl("<td>"))
				     Dim Box As New TextBox
				     Box.ID = c.ToString
				     me.Controls.Add(box) 
				     me.Controls.Add(new LiteralControl("</td>"))
			     End If
			     '------Required field ------
			     If  vRequired.chars(FieldsCount) = "1"
				Dim vReq As New  RequiredFieldValidator
				vReq.controltovalidate = c.ToString
				vReq.errormessage= "Please enter " + c.ToString 
				me.Controls.Add(vReq) 
			     End If
			 End if
			 FieldsCount = FieldsCount + 1
			Next c
	  End If
	 me.Controls.Add(new LiteralControl("</tr>"))
	 me.Controls.Add(new LiteralControl("</Table>"))
	'--------add button
	Dim AddButton As New Button
	if mode = "insert" then
	AddButton.Text = "Add"
	else
	AddButton.Text = "Update"
	end if
	AddHandler AddButton.Click, AddressOf AddBtn_Click
	Me.Controls.Add(AddButton)
	Dim cancel As New Button
	cancel.Text = "Cancel"
	Me.Controls.Add(cancel)
	'------------Validation Summary
	me.Controls.Add(new LiteralControl("<br><br>"))
	Dim vSummary As New  ValidationSummary
	vSummary.headertext="There were errors on the page:"
	me.Controls.Add(vSummary) 
End Sub
Private Sub AddBtn_Click(Sender As Object, E As EventArgs)
	'Build the procedure call
	Dim s as String 	  
	Dim r As DataRow
	Dim c As DataColumn
	Dim cell as TableCell
	Dim row as DataRow
	Dim column as string
	Dim Value as string
	Dim Fieldscount as integer 
	Dim vdisplay as string
	Dim veditable as string
	veditable = editable + "000000000000000000000000000000000000000000"
	vDisplay = Display + "000000000000000000000000000000000000000"
	FieldsCount = 0
If mode = "update" then
	s = "Execute " + Updateprocedure + "" 
	  For Each r in t.Rows
	      For Each c in t.Columns
		IF  vdisplay.chars(FieldsCount) = "0" or c.ToString = KeyField _
		or veditable.chars(FieldsCount) = "0" then
		Else
			If isDropDown(c.ToString)  then    
			    Dim vdropdown As DropDownList
			      vdropdown = me.FindControl(c.ToString)
			      column = c.ToString
			      value = vdropdown.SelectedItem.value
			Else
				Dim tb As TextBox
				tb = me.FindControl(c.ToString)
				column = c.ToString
				Value = tb.text
			End If
			If Value = "" then 
			   Value = "NULL"
			End If
			If c.DataType.ToString = "System.String" Then
				If Value = "NULL" then
				   s = s + " @" + column + "=" + value + ", " 	
				Else
				   s = s + " @" + column + "='" + value + "', " 
				End If
			Else 
				s = s + " @" + column + "=" + value + ", " 
			End If
		End IF
		 FieldsCount = FieldsCount + 1
	    Next c
	  Next r   
	  s = s + "@" + KeyField + "=" + KeyValue
	  me.Controls.Add(new LiteralControl(s))
	  RunSql(s)
 Else
	s = "Execute " + Insertprocedure + "" 
	'Insert mode
	For Each c in t.Columns
		IF  vdisplay.chars(FieldsCount) = "0" or c.ToString = KeyField _
		or veditable.chars(FieldsCount) = "0"then
		Else
			'Dim tb As TextBox
			'tb = me.FindControl(c.ToString)
			'column = c.ToString
			'Value = tb.text
			If isDropDown(c.ToString)  then    
			    Dim vdropdown As DropDownList
			      vdropdown = me.FindControl(c.ToString)
			      column = c.ToString
			      value = vdropdown.SelectedItem.value
			Else
				Dim tb As TextBox
				tb = me.FindControl(c.ToString)
				column = c.ToString
				Value = tb.text
			End If
			If Value = "" then 
				Value = "NULL"
			End If
			If c.DataType.ToString = "System.String" Then
				If Value = "NULL" then
				   s = s + " @" + column + "=" + value + ", " 	
				Else
				   s = s + " @" + column + "='" + value + "', " 
				End If
			Else 
				s = s + " @" + column + "=" + value + ", " 
			End If
		End IF
		 FieldsCount = FieldsCount + 1
	   Next c
	 s = s + "@" + KeyField + "=NULL" 
	 me.Controls.Add(new LiteralControl(s))	 
	 RunSql(s)
End if
End Sub
Sub RunSql(vSql as string)
	try
	Dim s as string			
	Dim myConnection As OleDbConnection
	myConnection = New OleDbConnection(ConnStr) 
	Dim mycommand As New OleDbCommand(vsql,myConnection)
	myconnection.Open()
	myCommand.ExecuteNonQuery()
	myconnection.Close()
	Catch ex As OleDbException
		     ' SQL error
		     Dim errItem   As OleDbError
		     Dim errString As String
		     Dim s as string
		     For Each errItem In ex.Errors
			 errString += ex.Message + "<br/>"
		     Next
		     s = "<br/><br/>SQL Error.Details follow:<br/>" & errString
		     me.Controls.Add(new LiteralControl(s))
	 catch myException as Exception
		  me.Controls.Add(new LiteralControl("Exception: " + myException.ToString()))
	end try
End sub
'-----------These Functions associated with DropDown Property--------------
Function ParseDropDown()
	Dim strChar As Object
	Dim s As String
	Dim j As Integer
	Dim count As Integer
	Dim idx as integer
	count = 1
	idx = 0
	strChar = Split(DropDown, ";")
	     For j = 0 To UBound(strChar)
		  If Len(strChar(j)) = 0 Then
		    Else
		      s = CStr(strChar(j))
			 If count = 1 then
				DDLColumn(idx) = s
			 Elseif count = 2 then
				CodeField(idx) = s
			 elseif count = 3 then
				DisplayField(idx) = s
			 elseif count = 4 then
				DDLSql(idx) = s
				count = 0
				idx = idx + 1
			End if
			count = count + 1 
		     End If
		Next
End Function
Function GetDDLIndex(vDDLColumn as string) as integer
	'Pass in the column where a drop-down list must appear
	' this function returns the row where its details are
	' stored in the array
	Dim i as integer, vKey as integer
	For i= 0 to UBound(DDlColumn)
	 If DDlColumn(i) = vDDLColumn
	  vKey = i
	 End if
	Next
	Return vKey
End Function
Function IsDropDown(vDDLColumn as string) as boolean
	Dim i as integer, vflag as integer
	vFlag = -1
	For i= 0 to UBound(DDlColumn)
		 If DDlColumn(i) = vDDLColumn
		  vflag = 1
		 End if
	Next
	If vFlag = 1 then
		Return True
	Else 
		Return False
	End If
End Function
'-----------------Drop Down Functions end---------
Function ParseFieldNames()
	'This function parses the FieldNames property
	Dim strChar As Object
	Dim s As String
	Dim j As Integer
	Dim count As Integer
	If len(FieldNames) <1 then
		Exit function
	End If
	strChar = Split(FieldNames, ";")
	For j = 0 To UBound(strChar)
	  If Len(strChar(j)) = 0 Then
	  Else
	     s = CStr(strChar(j))
	     FieldNamesArray(j) = s
	  End If
	Next
End Function

End Class
End Namespace

⌨️ 快捷键说明

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