Option Explicit On
Option Strict On
Imports System.IO
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing.Drawing2D
Public Class Form1
Dim Conn As SqlConnection
Dim com As SqlCommand
Dim tr As SqlTransaction
Dim sb As StringBuilder
Dim dr As SqlDataReader
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
showdata1()
showdata2()
FormatDgvEquipment()
FormatDgvTransport()
End Sub
Private Sub showdata1()
Dim sqlEquipment As String
sqlEquipment = "SELECT * FROM Equipment ORDER BY EqmID"
Dim dr As SqlDataReader
Dim dt As DataTable
com = New SqlCommand()
With com
.CommandType = CommandType.Text
.CommandText = sqlEquipment
.Connection = Conn
dr = .ExecuteReader()
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
dgvEquipment.DataSource = dt
Else
dgvEquipment.DataSource = Nothing
End If
End With
dr.Close()
End Sub
Private Sub showdata2()
Dim sqlView_1 As String
sqlView_1 = "SELECT * FROM View_2 ORDER BY TrID"
Dim dr As SqlDataReader
Dim dt As DataTable
com = New SqlCommand()
With com
.CommandType = CommandType.Text
.CommandText = sqlView_1
.Connection = Conn
dr = .ExecuteReader()
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
dgvTransport.DataSource = dt
Else
dgvTransport.DataSource = Nothing
End If
End With
dr.Close()
End Sub
Private Sub FormatDgvEquipment()
With dgvEquipment
If .RowCount > 0 Then
.Columns(0).Width = 70
.Columns(1).Width = 120
.Columns(2).Width = 100
.Columns(3).Width = 90
.Columns(4).Width = 90
.Columns(5).Width = 90
.Columns(6).Width = 90
End If
End With
End Sub
Private Sub FormatDgvTransport()
With dgvTransport
If .RowCount > 0 Then
.Columns(0).Width = 70
.Columns(1).Width = 90
.Columns(2).Width = 120
.Columns(3).Width = 80
.Columns(4).Width = 80
.Columns(5).Width = 80
.Columns(6).Width = 180
.Columns(7).Width = 80
.Columns(8).Width = 90
.Columns(9).Width = 70
.Columns(10).Width = 100
End If
End With
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
If Conn IsNot Nothing Then
Conn.Close()
End If
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
End Sub
End Class