Imports System.Data.SqlClient Imports System.Drawing.Printing Imports Microsoft.Reporting.WinForms Public Class FrmCustomersReport Private ReadOnly SQL As New SQLControl Public strLanguageID As String Public strLanguageDesc As String Public strLanguageCode As String Private Sub FrmCustomersReport_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'ACDataDataSet.Customers' table. You can move, or remove it, as needed. Me.CustomersTableAdapter.Fill(Me.ACDataDataSet.Customers) Try LblCustomersCategories.Visible = False CategoriesCBX.Visible = False BtnRefresh.Visible = False CustomersReportRV.Visible = True CustomersContactInformation.Visible = False CustomersCategoriesRV.Visible = False If SQL.HasException(True) Then Exit Sub Me.LanguageIDTB.Text = FrmLanguages.strLanguageID Me.LanguageDescTB.Text = FrmLanguages.strLanguageDesc Me.LanguageCodeTB.Text = FrmLanguages.strLanguageCode Me.CustomersReportRV.RefreshReport() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click Try Me.Close() Me.Dispose() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub BtnLoadCustomersAddresses_Click(sender As Object, e As EventArgs) Handles BtnLoadCustomersAddresses.Click Try Me.CustomersReportRV.Visible = True Me.CustomersContactInformation.Visible = False Me.CustomersCategoriesRV.Visible = False Me.LblCustomersCategories.Visible = False Me.CategoriesCBX.Visible = False BtnRefresh.Visible = False Dim constr As String = SQL.DBCon.ConnectionString Dim DBCon As New SqlConnection(constr) Dim DBcmd As New SqlCommand("Select * From Sales.CustomersReportQuery", DBCon) Dim DBDA As New SqlDataAdapter(DBcmd) Dim DBDT As New DataTable() DBDA.Fill(DBDT) With Me.CustomersReportRV.LocalReport .DataSources.Clear() .ReportPath = "C:\AutoCashRegister\Reports\CustomersReport.rdlc" .DataSources.Add(New ReportDataSource("CustomersReportDataset", DBDT)) End With Dim ps As New System.Drawing.Printing.PageSettings With { .Landscape = True, .Margins = New Margins(0, 0, 0, 0), .PaperSize = New System.Drawing.Printing.PaperSize("Letter", 870, 1200) } CustomersReportRV.SetPageSettings(ps) Me.CustomersReportRV.RefreshReport() DBCon.Close() DBCon.Dispose() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub BtnCustomersContactsInformation_Click(sender As Object, e As EventArgs) Handles BtnCustomersContactsInformation.Click Try Me.CustomersReportRV.Visible = False Me.CustomersContactInformation.Visible = True Me.CustomersCategoriesRV.Visible = False Me.LblCustomersCategories.Visible = False Me.CategoriesCBX.Visible = False BtnRefresh.Visible = False Dim constr As String = SQL.DBCon.ConnectionString Dim DBCon As New SqlConnection(constr) Dim DBcmd As New SqlCommand("Select * From Sales.CustomersReportQuery", DBCon) Dim DBDA As New SqlDataAdapter(DBcmd) Dim DBDT As New DataTable() DBDA.Fill(DBDT) With Me.CustomersContactInformation.LocalReport .DataSources.Clear() .ReportPath = "C:\AutoCashRegister\Reports\CustomersContactInformation.rdlc" .DataSources.Add(New ReportDataSource("CustomersReportDataset", DBDT)) End With Dim ps As New System.Drawing.Printing.PageSettings With { .Landscape = True, .Margins = New Margins(0, 0, 0, 0), .PaperSize = New System.Drawing.Printing.PaperSize("Letter", 870, 1200) } CustomersContactInformation.SetPageSettings(ps) Me.CustomersContactInformation.RefreshReport() DBCon.Close() DBCon.Dispose() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Public Sub LoadCategoriesCBX() Try 'REFRESH COMBOBOX CategoriesCBX.Items.Clear() 'RUN QUERY SQL.ExecQuery("SELECT DISTINCT CustomerCategoryID, CustomerCategoryName FROM Sales.Customers ORDER BY CustomerCategoryName") 'LOOP ROW & ADD TO COMBOBOX For Each r As DataRow In SQL.DBDT.Rows CategoriesCBX.Items.Add(r("CustomerCategoryName").ToString) Next If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub BtnCustomersPerCategories_Click(sender As Object, e As EventArgs) Handles BtnCustomersPerCategories.Click Try LoadCategoriesCBX() LblCustomersCategories.Visible = True CategoriesCBX.Visible = True BtnRefresh.Visible = True CustomersReportRV.Visible = False CustomersContactInformation.Visible = False CustomersCategoriesRV.Visible = True Dim constr As String = SQL.DBCon.ConnectionString Dim DBCon As New SqlConnection(constr) Dim DBcmd As New SqlCommand("Select * From Sales.CustomersReportQuery", DBCon) Dim DBDA As New SqlDataAdapter(DBcmd) Dim DBDT As New DataTable() DBDA.Fill(DBDT) With Me.CustomersCategoriesRV.LocalReport .DataSources.Clear() .ReportPath = "C:\AutoCashRegister\Reports\CustomersCategories.rdlc" .DataSources.Add(New ReportDataSource("PerCategoriesDS", DBDT)) End With Dim ps As New System.Drawing.Printing.PageSettings With { .Landscape = True, .Margins = New Margins(0, 0, 0, 0), .PaperSize = New System.Drawing.Printing.PaperSize("Letter", 870, 1200) } CustomersCategoriesRV.SetPageSettings(ps) Me.CustomersCategoriesRV.RefreshReport() DBCon.Close() DBCon.Dispose() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub CategoriesCBX_TextChanged(sender As Object, e As EventArgs) Handles CategoriesCBX.TextChanged Try FindCategoryItem() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub FindCategoryItem() Try Dim constr As String = SQL.DBCon.ConnectionString Dim DBCon As New SqlConnection(constr) Dim DBcmd As New SqlCommand("SELECT * FROM Sales.CustomersPerCategoriesQuery WHERE CustomerCategoryName = '" & CategoriesCBX.Text & "'", DBCon) Dim DBDA As New SqlDataAdapter(DBcmd) Dim DBDT As New DataTable() DBDA.Fill(DBDT) With Me.CustomersCategoriesRV.LocalReport .DataSources.Clear() .ReportPath = "C:\AutoCashRegister\Reports\CustomersCategories.rdlc" .DataSources.Add(New ReportDataSource("PerCategoriesDS", DBDT)) End With Dim ps As New System.Drawing.Printing.PageSettings With { .Landscape = True, .Margins = New Margins(0, 0, 0, 0), .PaperSize = New System.Drawing.Printing.PaperSize("Letter", 870, 1200) } CustomersCategoriesRV.SetPageSettings(ps) Me.CustomersCategoriesRV.RefreshReport() DBCon.Close() DBCon.Dispose() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub Private Sub BtnRefresh_Click(sender As Object, e As EventArgs) Handles BtnRefresh.Click Try BtnCustomersPerCategories.PerformClick() If SQL.HasException(True) Then Exit Sub Catch ex As Exception MsgBox(ex.Message) System.IO.File.AppendAllText("C:\AutoCashRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine) End Try End Sub End Class