📄 webform1.aspx.vb
字号:
' Catch exc As Exception
' LogMessage(exc)
' Exit Sub
' Finally
' dcCust.Dispose()
' conn.Close()
' End Try
' 'Rebind the DataGrid
' BindData()
Case "Edit" '//Edit Case
DataGrid1.ShowFooter = False 'Hide the footer while editing
DataGrid1.EditItemIndex = e.Item.ItemIndex
BindData()
Case "Cancel" '//Cancel Case
Try
DataGrid1.ShowFooter = True
DataGrid1.EditItemIndex = -1
BindData()
Catch exc As Exception
LogMessage(exc)
Exit Sub
End Try
'Case "Delete" '//Delete Case
' Dim lstrCustomerID As String
' Dim conn
' Dim dcCust
' '//Get the Customer ID which is hidden bound column
' lstrCustomerID = e.Item.Cells(1).Text.ToUpper
' Try
' 'Check whether the records exists in child table before deleting...
' strSQL = "SELECT COUNT(*) FROM [Orders] WHERE [Orders].[CustomerID] = '" & lstrCustomerID & "'"
' conn = New SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath(ConfigurationSettings.AppSettings("MDBPATH")))
' dcCust = New SqlCommand(strSQL, conn)
' conn.Open()
' Dim count = dcCust.ExecuteScalar
' If (count > 0) Then
' Throw New Exception("Child records exists...")
' End If
' dcCust.Dispose()
' 'Create the SQL statement for addition
' strSQL = "DELETE FROM Customers WHERE CustomerID = '" & lstrCustomerID & "'"
' dcCust = New SqlCommand(strSQL, conn)
' dcCust.ExecuteNonQuery()
' LogMessage(New Exception("Record deleted successfully..."), ExceptionType.Green)
' Catch exc As Exception
' LogMessage(exc)
' Exit Sub
' Finally
' dcCust.Dispose()
' conn.Close()
' End Try
' 'Rebind the DataGrid
' BindData()
Case "Update" '//Update Case
Dim txtCustomerID As TextBox
'Dim txtCompanyName As TextBox
'Dim txtContactName As TextBox
'Dim txtContactTitle As TextBox
'Dim txtAddress As TextBox
Dim txtState As TextBox
Dim lstrCustomerID As String
'Dim lstrCompanyName As String
'Dim lstrContactName As String
'Dim lstrContactTitle As String
'Dim lstrRFC As String
'Dim lstrAddress As String
Dim lstrState As String
'Read in the values of the TextBoxes
txtCustomerID = e.Item.FindControl("edit_CustomerID") '//Customer ID will be in readonly format
lstrCustomerID = txtCustomerID.Text.ToUpper
'txtCompanyName = e.Item.FindControl("edit_CompanyName")
'lstrCompanyName = txtCompanyName.Text
'txtContactName = e.Item.FindControl("edit_ContactName")
'lstrContactName = txtContactName.Text
'txtContactTitle = e.Item.FindControl("edit_ContactTitle")
'lstrContactTitle = txtContactTitle.Text
'txtAddress = e.Item.FindControl("edit_Address")
'lstrAddress = txtAddress.Text
txtState = e.Item.FindControl("edit_State")
'lstrState = txtState.Text
lstrState = "通过"
Dim conn
Dim dcCust
Try
'Create the SQL statement for updation
strSQL = "UPDATE [凭证表] set [凭证状态] = '" & lstrState & "'"
strSQL = strSQL & " WHERE [凭证编号] = '" & lstrCustomerID & "'"
conn = New SqlConnection("Persist Security Info=False;Data Source=127.0.0.1;Initial Catalog=test;User ID=sa;Password=;")
dcCust = New SqlCommand(strSQL, conn)
conn.Open()
dcCust.ExecuteNonQuery()
LogMessage(New Exception("成功审核..."), ExceptionType.Green)
Catch exc As Exception
LogMessage(exc)
Exit Sub
Finally
dcCust.Dispose()
conn.Close()
End Try
'Rebind the DataGrid
DataGrid1.EditItemIndex = -1
BindData()
End Select
End Sub
'//This procedure is used for the purpose of edit on child grid
'//When your program uses the DataGrid control,
'//and your program has a child DataGrid control that is associated with each row of a parent DataGrid control,
'//a problem may occur. When you click Edit for the child DataGrid control, nothing happens.
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
Dim dgTemp As New DataGrid
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
dgTemp = CType(e.Item.FindControl("DataGrid2"), DataGrid)
If dgTemp.UniqueID = dgUniqueID Then
dgTemp.EditItemIndex = dgEditItemIndex
'If the Edit Item Index is -1, On Cancel click
If (dgEditItemIndex = -1) Then
dgTemp.ShowFooter = True
Else
dgTemp.ShowFooter = False
End If
'Set the Page Index for child datagrid
dgTemp.CurrentPageIndex = dgCurrentPageIndex
'//Call the procedure to alter the Current Sort Expression
alterSortExpression(dgTemp)
'//Following code is for displaying back child grid after handling its button events
Dim img As ImageButton
img = e.Item.Cells(0).FindControl("ImageButton1")
img.ImageUrl = "~/Images/Minus.gif"
Dim exp As PlaceHolder
exp = e.Item.Cells(2).FindControl("Expanded")
exp.Visible = True
dgTemp.DataBind()
dgUniqueID = ""
dgEditItemIndex = -1
End If
End If
End Sub
'//Procedure for Parent DataGrid paging
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
'//Procedure for Parent DataGrid Sorting
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
Dim SortExprs() As String
Dim CurrentSearchMode As String, NewSearchMode As String
Dim ColumnToSort As String, NewSortExpr As String
' Parse the sort expression - delimiter space
SortExprs = Split(e.SortExpression, " ")
ColumnToSort = SortExprs(0)
' If a sort order is specified get it, else default is Ascending
If SortExprs.Length() > 1 Then
CurrentSearchMode = SortExprs(1).ToUpper()
If CurrentSearchMode = "ASC" Then
NewSearchMode = "DESC"
Else
NewSearchMode = "ASC"
End If
Else ' If no mode specified, Default is descending
NewSearchMode = "DESC"
End If
' Derive the new sort expression.
NewSortExpr = ColumnToSort & " " & NewSearchMode
' Figure out the column index
Dim iIndex As Integer
Select Case ColumnToSort.ToUpper()
Case "[凭证表].[凭证编号]"
iIndex = 2
Case "[凭证表].[日期]"
iIndex = 3
Case "[凭证表].[借方合计]"
iIndex = 4
Case "[凭证表].[贷方合计]"
iIndex = 5
End Select
' alter the column's sort expression
DataGrid1.Columns(iIndex).SortExpression = NewSortExpr
'Reset the Page Number to start
DataGrid1.CurrentPageIndex = 0
' Sort the data in new order
BindData(NewSortExpr)
End Sub
#End Region
#Region "DataGrid2 Event handlers"
'//This procedure handles the Child Grid command events
'//On runtime child grid will have different UniqueID, E.G DataGrid_Ctl1, So we must use source object for DataGrid specific events
Public Sub DataGrid2_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
Dim strSQL As String
Select Case e.CommandName
'Case "Insert"
' Dim txtFreight As TextBox
' Dim txtShipName As TextBox
' Dim txtShipAddress As TextBox
' Dim lstrCustomerID As String
' Dim ldblFreight As Double
' Dim lstrShipName As String
' Dim lstrShipAddress As String
' '//Here the Session variable being used was stored when the Parenrt grid '+' clicked
' lstrCustomerID = Session("CustomerID")
' 'Read in the values of the TextBoxes
' txtFreight = e.Item.FindControl("add_Freight")
' ldblFreight = CDbl(txtFreight.Text)
' txtShipName = e.Item.FindControl("add_ShipName")
' lstrShipName = txtShipName.Text
' txtShipAddress = e.Item.FindControl("add_ShipAddress")
' lstrShipAddress = txtShipAddress.Text
' Dim conn
' Dim dcOrder
' Try
' conn = New SqlConnection("Persist Security Info=False;Data Source=127.0.0.1;Initial Catalog=test;User ID=sa;Password=;")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -