Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Partial Class Admin_Default_Admin
Inherits System.Web.UI.Page
Dim Conn As New SqlConnection
Dim Com As New SqlCommand
Dim webConnect As WebConnectDB
Dim dr As SqlDataReader
Dim sb As StringBuilder
Dim tmpPathFilePicture As String
Dim tmpPictureName As String
Dim dt As DataTable
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim strSQL As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
webConnect = New WebConnectDB 'ใช้ในการเชื่อมต่อกับฐานข้อมูล
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = webConnect.strConn
.Open()
End With
If Not Page.IsPostBack() Then
BindData()
Me.lblFullname.Text = Session("ssFullname").ToString()
End If
End Sub
Protected Sub BindData()
Dim strSQL As String
strSQL = " SELECT tblTool.ToolID,tblCategory.CategoryName,tblTool.ReceiveDate,tblDepartment.DepartmentName,tblCompany.CompanyName "
strSQL += " FROM tblTool INNER JOIN tblCategory ON tblTool.CategoryID = tblCategory.CategoryID"
strSQL += " INNER JOIN tblDepartment ON tblTool.DepartmentID = tblDepartment.DepartmentID"
strSQL += " INNER JOIN tblCompany ON tblTool.CompanyID = tblCompany.CompanyID"
strSQL += " ORDER BY tblTool.ToolID DESC "
Com = New SqlCommand(strSQL, Conn)
With Com
.Connection = Conn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
da.SelectCommand = Com
da.Fill(ds)
'*** BindData to GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
da = Nothing
End Sub
Protected Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'*** ToolID ***'
Dim lblToolID As Label = CType(e.Row.FindControl("lblToolID"), Label)
If Not IsNothing(lblToolID) Then
lblToolID.Text = e.Row.DataItem("ToolID")
End If
Dim lblCategory As Label = CType(e.Row.FindControl("lblCategory"), Label)
If Not IsNothing(lblCategory) Then
lblCategory.Text = e.Row.DataItem("CategoryName")
End If
Dim lblReceiveDate As Label = CType(e.Row.FindControl("lblReceiveDate"), Label)
If Not IsNothing(lblReceiveDate) Then
lblReceiveDate.Text = e.Row.DataItem("ReceiveDate")
End If
Dim lblDepartment As Label = CType(e.Row.FindControl("lblDepartment"), Label)
If Not IsNothing(lblDepartment) Then
lblDepartment.Text = e.Row.DataItem("DepartmentName")
End If
Dim lblCompany As Label = CType(e.Row.FindControl("lblCompany"), Label)
If Not IsNothing(lblCompany) Then
lblCompany.Text = e.Row.DataItem("CompanyName")
End If
Dim Image1 As Image = CType(e.Row.FindControl("Image1"), Image)
If Not IsNothing(Image1) Then
Image1.ImageUrl = e.Row.DataItem("ToolPic")
End If
'*** Button ***'
Dim ImaB1 As ImageButton = CType(e.Row.FindControl("ImaB1"), ImageButton)
If Not IsNothing(ImaB1) Then
'ImaB1.NavigateUrl = "JavaScript:void(0);"
ImaB1.Attributes.Add("OnClick", "JavaScript:OpenPopup('Show.aspx?ToolID=" & e.Row.DataItem("ToolID") & "');")
End If
Dim ImaB2 As ImageButton = CType(e.Row.FindControl("ImaB2"), ImageButton)
If Not IsNothing(ImaB2) Then
ImaB2.PostBackUrl = "Admin_Update.aspx?ToolID=" & e.Row.DataItem("ToolID")
End If
End If
End Sub
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
Conn.Close()
Conn = Nothing
End Sub
Protected Sub SearchData()
Dim strSQL As String
sb = New StringBuilder
sb.Remove(0, sb.Length())
strSQL = " SELECT tblTool.ToolID,tblCategory.CategoryName,tblTool.ReceiveDate,tblDepartment.DepartmentName,tblCompany.CompanyName "
strSQL += " FROM tblTool INNER JOIN tblCategory ON tblTool.CategoryID = tblCategory.CategoryID"
strSQL += " INNER JOIN tblDepartment ON tblTool.DepartmentID = tblDepartment.DepartmentID"
strSQL += " INNER JOIN tblCompany ON tblTool.CompanyID = tblCompany.CompanyID"
strSQL += " WHERE tblTool.ToolName LIKE '%" & txtSearch.Text & "%' "
strSQL += " AND tblTool.CategoryID LIKE '%" & ddlCategorySearch.SelectedValue & "%' "
strSQL += " ORDER BY tblTool.ToolID DESC "
Com = New SqlCommand(strSQL, Conn)
With Com
.Connection = Conn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
da.SelectCommand = Com
da.Fill(ds)
'*** BindData to GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
da = Nothing
End Sub
Protected Sub imgbSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbSearch.Click
SearchData()
End Sub
Sub ShowPageCommand(ByVal s As Object, ByVal e As GridViewPageEventArgs)
myGridView.PageIndex = e.NewPageIndex
BindData()
End Sub
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'ตรงนี้มันเชื่อมไปที่ฐานข้อมุลไหนครับ ?
'|
'|
'v
webConnect = New WebConnectDB 'ใช้ในการเชื่อมต่อกับฐานข้อมูล
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = webConnect.strConn
.Open()
End With
If Not Page.IsPostBack() Then
BindData()
Me.lblFullname.Text = Session("ssFullname").ToString()
End If
End Sub