-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminPayment.vb
84 lines (74 loc) · 3.64 KB
/
AdminPayment.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Imports System.Data.SqlClient
Imports System.Diagnostics
Public Class AdminPayment
Dim connectionString As String = "Data Source=DESKTOP-JI8QG4T\SQLSERVER2022;Initial Catalog=collegestudent;Integrated Security=True"
Private Sub ViewPayment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If IsAdmin Then
Dim query As String = "SELECT * FROM FEE_PAYMENT"
Dim dataTable As New DataTable()
Using connection As New SqlConnection(connectionString)
Dim dataAdapter As New SqlDataAdapter(query, connection)
connection.Open()
dataAdapter.Fill(dataTable)
End Using
With FeeDataGrid
.DataSource = dataTable
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
.ReadOnly = False
End With
Else
Dim query As String = "SELECT * FROM FEE_PAYMENT WHERE COURSE_YEAR = (SELECT Course_Year FROM studentreg WHERE StudentId = @stdID) AND DEPT = (SELECT Dept FROM studentreg WHERE StudentId = @stdID)"
Dim dataTable As New DataTable()
Using connection As New SqlConnection(connectionString)
Dim dataAdapter As New SqlDataAdapter(query, connection)
dataAdapter.SelectCommand.Parameters.AddWithValue("@stdID", CurrentStudentID)
connection.Open()
dataAdapter.Fill(dataTable)
End Using
With FeeDataGrid
.DataSource = dataTable
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
.ReadOnly = True
End With
End If
End Sub
Private Sub OkButton_Click(sender As Object, e As EventArgs) Handles OkButton.Click
If IsAdmin Then
Try
Dim changes As DataTable = CType(FeeDataGrid.DataSource, DataTable).GetChanges()
' Create a new DataAdapter to update the changes to the database
Using connection As New SqlConnection(connectionString)
Dim adapter As New SqlDataAdapter("SELECT * FROM FEE_PAYMENT", connection)
Dim builder As New SqlCommandBuilder(adapter)
' Update the database with the changes made to the DataTable
adapter.UpdateCommand = builder.GetUpdateCommand()
adapter.InsertCommand = builder.GetInsertCommand()
adapter.DeleteCommand = builder.GetDeleteCommand()
adapter.Update(changes)
' Update the original DataTable with the changes from the database
CType(FeeDataGrid.DataSource, DataTable).AcceptChanges()
End Using
MessageBox.Show("Updated the Table")
Catch ex As Exception
MessageBox.Show("Invalid entry.")
End Try
End If
Close()
End Sub
Private Sub PayButton_Click(sender As Object, e As EventArgs) Handles PayButton.Click
Dim url As String = "https://pay.google.com/"
Dim OpenURL As New ProcessStartInfo With {
.UseShellExecute = True,
.FileName = "explorer.exe",
.Arguments = url
}
Process.Start(OpenURL)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub CardPayButton_Click(sender As Object, e As EventArgs) Handles CardPayButton.Click
Dim cardPayment As New CardPayment()
cardPayment.Show()
End Sub
End Class