forked from Anarchy4v/IS104
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomerGeneratedReport.vb
68 lines (55 loc) · 2.57 KB
/
CustomerGeneratedReport.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
Imports MySql.Data.MySqlClient
Public Class CustomerGeneratedReport
Private connectionString As String = "server=127.0.0.1;userid=root;password='';database=tgp_db"
Public Sub New()
InitializeComponent()
Dim currentDateAndTime As DateTime = DateTime.Now
Label2.Text = $"{currentDateAndTime}"
'auto closes fucking salesWindow
If Not IsNothing(Application.OpenForms("SalesWindow")) Then
CType(Application.OpenForms("SalesWindow"), SalesWindow).Close()
End If
LoadDataIntoDataGridView()
' Display data from SharedVariables
Label3.Text = $"{SharedVariables.OrderID}"
Label5.Text = $"{SharedVariables.discount:P}"
Label7.Text = $"₱{SharedVariables.totalAmount2:N2}"
Label9.Text = $"₱{SharedVariables.cashValue:N2}"
Label11.Text = $"₱{SharedVariables.Result:N2}"
Label13.Text = $"₱{SharedVariables.vatAmount:N2}"
End Sub
Private Sub LoadDataIntoDataGridView()
Try
Using connection As New MySqlConnection(connectionString)
connection.Open()
Dim query As String = "SELECT sales_name, sales_qty, sales_price FROM compute_sales"
Using adapter As New MySqlDataAdapter(query, connection)
Dim dataTable As New DataTable()
adapter.Fill(dataTable)
' Bind data to DataGridView
DataGridView1.DataSource = dataTable
End Using
End Using
Catch ex As Exception
' Handle any exceptions that might occur during data retrieval
MessageBox.Show($"Error loading data: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
' this will delete all existing rows in my compute_sales
Protected Overrides Sub OnFormClosing(ByVal e As FormClosingEventArgs)
MyBase.OnFormClosing(e)
If e.CloseReason = CloseReason.UserClosing Then
Try
Using connection As New MySqlConnection(connectionString)
connection.Open()
Dim deleteQuery As String = "DELETE FROM compute_sales"
Using command As New MySqlCommand(deleteQuery, connection)
command.ExecuteNonQuery()
End Using
End Using
Catch ex As Exception
MessageBox.Show($"Error executing SQL: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
End Class